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