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;
18
19 import java.util.ArrayList;
20 import java.util.Collection;
21 import java.util.List;
22 import java.util.Map;
23
24 import edu.internet2.middleware.shibboleth.common.attribute.BaseAttribute;
25 import edu.internet2.middleware.shibboleth.common.attribute.resolver.AttributeResolutionException;
26 import edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.attributeDefinition.AttributeDefinition;
27 import edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.dataConnector.DataConnector;
28
29
30
31
32
33
34
35 public abstract class AbstractResolutionPlugIn<ResolvedType> implements ResolutionPlugIn<ResolvedType> {
36
37
38 private String id;
39
40
41 private List<String> dependencyIds;
42
43
44 public AbstractResolutionPlugIn() {
45 dependencyIds = new ArrayList<String>();
46 }
47
48
49 public List<String> getDependencyIds() {
50 return dependencyIds;
51 }
52
53
54 public String getId() {
55 return id;
56 }
57
58
59
60
61
62
63 public void setId(String newId) {
64 id = newId;
65 }
66
67
68
69
70
71
72
73
74 protected Collection<Object> getValuesFromAllDependencies(ShibbolethResolutionContext context, String sourceAttribute) {
75 List<Object> values = new ArrayList<Object>();
76
77 for (String id : getDependencyIds()) {
78 if (context.getResolvedAttributeDefinitions().containsKey(id)) {
79 values.addAll(getValuesFromAttributeDependency(context, id));
80 } else if (context.getResolvedDataConnectors().containsKey(id)) {
81 values.addAll(getValuesFromConnectorDependency(context, id, sourceAttribute));
82 }
83 }
84
85 return values;
86 }
87
88
89
90
91
92
93
94
95
96 protected Collection<Object> getValuesFromAttributeDependency(ShibbolethResolutionContext context, String id) {
97 List<Object> values = new ArrayList<Object>();
98
99 AttributeDefinition definition = context.getResolvedAttributeDefinitions().get(id);
100 if (definition != null) {
101 try {
102 BaseAttribute attribute = definition.resolve(context);
103 for (Object o : attribute.getValues()) {
104 values.add(o);
105 }
106 } catch (AttributeResolutionException e) {
107
108 }
109 }
110
111 return values;
112 }
113
114
115
116
117
118
119
120
121
122
123 protected Collection<Object> getValuesFromConnectorDependency(ShibbolethResolutionContext context, String id, String sourceAttribute) {
124 List<Object> values = new ArrayList<Object>();
125
126 DataConnector connector = context.getResolvedDataConnectors().get(id);
127 if (connector != null) {
128 try {
129 Map<String, BaseAttribute> attributes = connector.resolve(context);
130 for (String attributeId : attributes.keySet()) {
131 if (attributeId != null && attributeId.equals(sourceAttribute)) {
132 for (Object o : attributes.get(attributeId).getValues()) {
133 values.add(o);
134 }
135 }
136 }
137 } catch (AttributeResolutionException e) {
138
139 }
140
141 }
142
143 return values;
144 }
145 }