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.encoding.provider;
19
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import javax.xml.namespace.QName;
24
25 import org.opensaml.Configuration;
26 import org.opensaml.xml.XMLObject;
27 import org.opensaml.xml.XMLObjectBuilder;
28 import org.opensaml.xml.schema.XSString;
29
30 import edu.internet2.middleware.shibboleth.common.attribute.BaseAttribute;
31 import edu.internet2.middleware.shibboleth.common.attribute.provider.ScopedAttributeValue;
32 import edu.internet2.middleware.shibboleth.common.xmlobject.ShibbolethScopedValue;
33
34
35
36
37
38
39 public abstract class AbstractScopedAttributeEncoder<EncodedType> extends AbstractAttributeEncoder<EncodedType> {
40
41
42 private final XMLObjectBuilder<ShibbolethScopedValue> shibScopeValueBuilder = Configuration.getBuilderFactory()
43 .getBuilder(ShibbolethScopedValue.TYPE_NAME);
44
45
46 private final XMLObjectBuilder<XSString> stringValueBuilder = Configuration.getBuilderFactory().getBuilder(
47 XSString.TYPE_NAME);
48
49
50 private String scopeType;
51
52
53 private String scopeDelimiter;
54
55
56 private String scopeAttribute;
57
58
59
60
61
62
63 public String getScopeAttribute() {
64 return scopeAttribute;
65 }
66
67
68
69
70
71
72 public String getScopeDelimiter() {
73 return scopeDelimiter;
74 }
75
76
77
78
79
80
81 public String getScopeType() {
82 return scopeType;
83 }
84
85
86
87
88
89
90 public void setScopeAttribute(String newScopeAttribute) {
91 scopeAttribute = newScopeAttribute;
92 }
93
94
95
96
97
98
99 public void setScopeDelimiter(String newScopeDelimiter) {
100 scopeDelimiter = newScopeDelimiter;
101 }
102
103
104
105
106
107
108 public void setScopeType(String newScopeType) {
109 scopeType = newScopeType;
110 }
111
112
113
114
115
116
117
118
119
120 @SuppressWarnings("unchecked")
121 protected List<XMLObject> encodeAttributeValues(QName objectName, BaseAttribute<ScopedAttributeValue> attribute) {
122 ArrayList<XMLObject> encodedValues = new ArrayList<XMLObject>();
123
124 if ("attribute".equals(getScopeType())) {
125 ShibbolethScopedValue scopedValue;
126
127 for (ScopedAttributeValue attributeValue : attribute.getValues()) {
128 if (attributeValue == null) {
129 continue;
130 }
131
132 scopedValue = shibScopeValueBuilder.buildObject(objectName);
133 scopedValue.setScopeAttributeName(getScopeAttribute());
134 scopedValue.setScope(attributeValue.getScope());
135 scopedValue.setValue(attributeValue.getValue());
136
137 encodedValues.add(scopedValue);
138 }
139
140 } else if ("inline".equals(getScopeType())) {
141 XSString scopedValue;
142
143 for (ScopedAttributeValue attributeValue : attribute.getValues()) {
144 if (attributeValue == null) {
145 continue;
146 }
147
148 scopedValue = stringValueBuilder.buildObject(objectName, XSString.TYPE_NAME);
149 scopedValue.setValue(attributeValue.getValue() + getScopeDelimiter() + attributeValue.getScope());
150
151 encodedValues.add(scopedValue);
152 }
153
154 }
155
156 return encodedValues;
157 }
158 }