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