1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package edu.internet2.middleware.shibboleth.common.attribute.filtering.provider.match.basic;
19
20 import edu.internet2.middleware.shibboleth.common.attribute.BaseAttribute;
21 import edu.internet2.middleware.shibboleth.common.attribute.filtering.provider.FilterProcessingException;
22 import edu.internet2.middleware.shibboleth.common.attribute.filtering.provider.ShibbolethFilteringContext;
23
24
25
26
27
28 public class NumOfAttributeValuesMatchFunctor extends AbstractMatchFunctor {
29
30
31 private String attributeId;
32
33
34 private int minimumValues;
35
36
37 private int maximumValues;
38
39
40
41
42
43
44
45
46 public NumOfAttributeValuesMatchFunctor(String id, int min, int max) {
47 attributeId = id;
48 minimumValues = min;
49 maximumValues = max;
50 }
51
52
53 protected boolean doEvaluatePolicyRequirement(ShibbolethFilteringContext filterContext)
54 throws FilterProcessingException {
55 return isWithinRange(filterContext.getUnfilteredAttributes().get(attributeId));
56 }
57
58
59 protected boolean doEvaluateValue(ShibbolethFilteringContext filterContext, String id, Object value)
60 throws FilterProcessingException {
61 return isWithinRange(filterContext.getUnfilteredAttributes().get(attributeId));
62 }
63
64
65
66
67
68
69
70
71 protected boolean isWithinRange(BaseAttribute attribute) {
72 if (attribute == null) {
73 return false;
74 }
75
76 int numOfValues = attribute.getValues().size();
77
78 return numOfValues >= minimumValues && numOfValues <= maximumValues;
79 }
80 }