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