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;
19
20 import java.util.Collection;
21 import java.util.Comparator;
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.TreeSet;
26
27 import edu.internet2.middleware.shibboleth.common.attribute.BaseAttribute;
28 import edu.internet2.middleware.shibboleth.common.profile.provider.SAMLProfileRequestContext;
29
30
31
32
33 public class ShibbolethFilteringContext {
34
35
36 private SAMLProfileRequestContext attributeRequestContext;
37
38
39 private Map<String, BaseAttribute> unfilteredAttributes;
40
41
42 private Map<String, Collection> retainedValues;
43
44
45 private Map<String, List<MatchFunctor>> denyValueRules;
46
47
48
49
50
51
52
53 public ShibbolethFilteringContext(Map<String, BaseAttribute> attributes, SAMLProfileRequestContext context) {
54 attributeRequestContext = context;
55 unfilteredAttributes = attributes;
56 retainedValues = new HashMap<String, Collection>();
57 denyValueRules = new HashMap<String, List<MatchFunctor>>();
58 }
59
60
61
62
63
64
65 public SAMLProfileRequestContext getAttributeRequestContext() {
66 return attributeRequestContext;
67 }
68
69
70
71
72
73
74 public Map<String, BaseAttribute> getUnfilteredAttributes() {
75 return unfilteredAttributes;
76 }
77
78
79
80
81
82
83
84
85
86
87 public Collection getRetainedValues(String attributeId, boolean prepopulate) {
88 BaseAttribute attribute = unfilteredAttributes.get(attributeId);
89 Collection attributeValues = null;
90 if (!retainedValues.containsKey(attributeId) && prepopulate) {
91 if (prepopulate) {
92 if (attribute != null) {
93 attributeValues = attribute.getValues();
94 }
95
96 retainedValues.put(attributeId, attributeValues);
97 }
98 } else {
99 attributeValues = retainedValues.get(attributeId);
100 }
101
102 if (attributeValues == null) {
103 Comparator valueComparator = null;
104 if (attribute != null) {
105 valueComparator = attribute.getValueComparator();
106 }
107 if (valueComparator == null) {
108 valueComparator = new ObjectStringComparator();
109 }
110 attributeValues = new TreeSet<Object>(valueComparator);
111 retainedValues.put(attributeId, attributeValues);
112 }
113 return attributeValues;
114 }
115
116
117
118
119
120
121
122 public Map<String, List<MatchFunctor>> getDenyValueRules() {
123 return denyValueRules;
124 }
125
126
127 private class ObjectStringComparator implements Comparator<Object> {
128
129
130 public int compare(Object o1, Object o2) {
131 if (o1 == null) {
132 return -1;
133 }
134
135 if (o2 == null) {
136 return 1;
137 }
138
139 return o1.toString().compareTo(o2.toString());
140 }
141 }
142 }