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