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