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.Set;
22
23 import org.opensaml.xml.util.DatatypeHelper;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 import edu.internet2.middleware.shibboleth.common.attribute.BaseAttribute;
28 import edu.internet2.middleware.shibboleth.common.attribute.provider.BasicAttribute;
29 import edu.internet2.middleware.shibboleth.common.attribute.resolver.AttributeResolutionException;
30 import edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.ShibbolethResolutionContext;
31
32
33
34
35
36 public class MappedAttributeDefinition extends BaseAttributeDefinition {
37
38
39 private static Logger log = LoggerFactory.getLogger(MappedAttributeDefinition.class);
40
41
42 private String defaultValue;
43
44
45 private boolean passThru;
46
47
48 private Collection<ValueMap> valueMaps;
49
50
51
52 public MappedAttributeDefinition() {
53 valueMaps = new ArrayList<ValueMap>(5);
54 }
55
56
57 protected BaseAttribute doResolve(ShibbolethResolutionContext resolutionContext)
58 throws AttributeResolutionException {
59 BasicAttribute<String> attribute = new BasicAttribute<String>();
60 attribute.setId(getId());
61 boolean valueMapMatch;
62
63 for (Object o : getValuesFromAllDependencies(resolutionContext)) {
64 valueMapMatch = false;
65 Set<String> mappedValues;
66
67 for (ValueMap valueMap : valueMaps) {
68 mappedValues = valueMap.evaluate(o.toString());
69 if (!mappedValues.isEmpty()) {
70 valueMapMatch = true;
71 attribute.getValues().addAll(mappedValues);
72 }
73 }
74
75 if (!valueMapMatch) {
76 if (passThru) {
77 attribute.getValues().add(o.toString());
78 } else if (!DatatypeHelper.isEmpty(defaultValue)) {
79 attribute.getValues().add(getDefaultValue());
80 }
81 }
82 }
83
84 return attribute;
85 }
86
87
88 public void validate() throws AttributeResolutionException {
89 if (passThru && !DatatypeHelper.isEmpty(defaultValue)) {
90 log.error("MappedAttributeDefinition (" + getId()
91 + ") may not have a DefaultValue string with passThru enabled.");
92 throw new AttributeResolutionException("MappedAttributeDefinition (" + getId()
93 + ") may not have a DefaultValue string with passThru enabled.");
94 }
95 }
96
97
98
99
100
101 public String getDefaultValue() {
102 return defaultValue;
103 }
104
105
106
107
108
109 public void setDefaultValue(String newDefaultValue) {
110 defaultValue = newDefaultValue;
111 }
112
113
114
115
116
117 public boolean isPassThru() {
118 return passThru;
119 }
120
121
122
123
124
125 public void setPassThru(boolean newPassThru) {
126 passThru = newPassThru;
127 }
128
129
130
131
132
133 public Collection<ValueMap> getValueMaps() {
134 return valueMaps;
135 }
136
137 }