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.resolver.provider.attributeDefinition;
19
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.List;
23 import java.util.Locale;
24 import java.util.Map;
25
26 import org.opensaml.xml.util.LazyMap;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 import edu.internet2.middleware.shibboleth.common.attribute.BaseAttribute;
31 import edu.internet2.middleware.shibboleth.common.attribute.encoding.AttributeEncoder;
32 import edu.internet2.middleware.shibboleth.common.attribute.resolver.AttributeResolutionException;
33 import edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.AbstractResolutionPlugIn;
34 import edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.ShibbolethResolutionContext;
35
36
37
38
39 public abstract class BaseAttributeDefinition extends AbstractResolutionPlugIn<BaseAttribute> implements
40 AttributeDefinition {
41
42
43 private final Logger log = LoggerFactory.getLogger(BaseAttributeDefinition.class);
44
45
46 private boolean dependencyOnly;
47
48
49 private ArrayList<AttributeEncoder> encoders;
50
51
52 private String sourceAttributeID;
53
54
55 private Map<Locale, String> displayNames;
56
57
58 private Map<Locale, String> displayDescriptions;
59
60
61 public BaseAttributeDefinition() {
62 dependencyOnly = false;
63 encoders = new ArrayList<AttributeEncoder>(3);
64 displayNames = new LazyMap<Locale, String>();
65 displayDescriptions = new LazyMap<Locale, String>();
66 }
67
68
69
70
71
72
73 public Map<Locale, String> getDisplayDescriptions() {
74 return displayDescriptions;
75 }
76
77
78
79
80
81
82 public Map<Locale, String> getDisplayNames() {
83 return displayNames;
84 }
85
86
87 public boolean isDependencyOnly() {
88 return dependencyOnly;
89 }
90
91
92
93
94
95
96
97 public void setDependencyOnly(boolean isDependencyOnly) {
98 dependencyOnly = isDependencyOnly;
99 }
100
101
102 public List<AttributeEncoder> getAttributeEncoders() {
103 return encoders;
104 }
105
106
107 public BaseAttribute resolve(ShibbolethResolutionContext resolutionContext) throws AttributeResolutionException {
108 BaseAttribute resolvedAttribute = doResolve(resolutionContext);
109
110 if(resolvedAttribute == null){
111 log.error("{} produced a null attribute, this is not allowed", getId());
112 throw new AttributeResolutionException(getId() + " produced a null attribute");
113 }
114
115 if(getDisplayNames() != null) {
116 resolvedAttribute.getDisplayNames().putAll(displayNames);
117 }
118
119 if(getDisplayDescriptions() != null){
120 resolvedAttribute.getDisplayDescriptions().putAll(displayDescriptions);
121 }
122
123 if (getAttributeEncoders() != null) {
124 resolvedAttribute.getEncoders().addAll(getAttributeEncoders());
125 }
126
127 return resolvedAttribute;
128 }
129
130
131
132
133
134
135
136
137
138
139
140 protected abstract BaseAttribute doResolve(ShibbolethResolutionContext resolutionContext)
141 throws AttributeResolutionException;
142
143
144
145
146
147
148
149 protected Collection<Object> getValuesFromAllDependencies(ShibbolethResolutionContext context) {
150 return getValuesFromAllDependencies(context, getSourceAttributeID());
151 }
152
153
154
155
156
157
158 public String getSourceAttributeID() {
159 if (sourceAttributeID != null) {
160 return sourceAttributeID;
161 } else {
162 return getId();
163 }
164 }
165
166
167
168
169
170
171 public void setSourceAttributeID(String newSourceAttributeID) {
172 sourceAttributeID = newSourceAttributeID;
173 }
174 }