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.Collection;
21
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 import edu.internet2.middleware.shibboleth.common.attribute.BaseAttribute;
26 import edu.internet2.middleware.shibboleth.common.attribute.provider.BasicAttribute;
27 import edu.internet2.middleware.shibboleth.common.attribute.provider.ScopedAttributeValue;
28 import edu.internet2.middleware.shibboleth.common.attribute.resolver.AttributeResolutionException;
29 import edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.ShibbolethResolutionContext;
30
31
32
33
34
35 public class PrescopedAttributeDefinition extends BaseAttributeDefinition {
36
37
38 private final Logger log = LoggerFactory.getLogger(PrescopedAttributeDefinition.class);
39
40
41 private String scopeDelimiter;
42
43
44
45
46
47
48 public PrescopedAttributeDefinition(String delimiter) {
49 scopeDelimiter = delimiter;
50 }
51
52
53 public BaseAttribute<ScopedAttributeValue> doResolve(ShibbolethResolutionContext resolutionContext)
54 throws AttributeResolutionException {
55 BasicAttribute<ScopedAttributeValue> attribute = new BasicAttribute<ScopedAttributeValue>();
56 attribute.setId(getId());
57
58 Collection<?> values = getValuesFromAllDependencies(resolutionContext);
59 if (values == null || values.isEmpty()) {
60 return attribute;
61 }
62
63 String[] stringValues;
64 for (Object value : values) {
65 if (!(value instanceof String)) {
66 continue;
67 }
68
69 stringValues = ((String) value).split(scopeDelimiter);
70 if (stringValues.length < 2) {
71 log.error("Input attribute value {} does not contain delimited {} and can not be split", value,
72 scopeDelimiter);
73 throw new AttributeResolutionException("Input attribute value can not be split.");
74 }
75 attribute.getValues().add(new ScopedAttributeValue(stringValues[0], stringValues[1]));
76 }
77
78 return attribute;
79 }
80
81
82
83
84
85
86 public String getScopeDelimited() {
87 return scopeDelimiter;
88 }
89
90
91 public void validate() throws AttributeResolutionException {
92
93 }
94 }