2 * The Shibboleth License, Version 1.
4 * University Corporation for Advanced Internet Development, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * Redistributions of source code must retain the above copyright notice, this
12 * list of conditions and the following disclaimer.
14 * Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution, if any, must include
17 * the following acknowledgment: "This product includes software developed by
18 * the University Corporation for Advanced Internet Development
19 * <http://www.ucaid.edu>Internet2 Project. Alternately, this acknowledegement
20 * may appear in the software itself, if and wherever such third-party
21 * acknowledgments normally appear.
23 * Neither the name of Shibboleth nor the names of its contributors, nor
24 * Internet2, nor the University Corporation for Advanced Internet Development,
25 * Inc., nor UCAID may be used to endorse or promote products derived from this
26 * software without specific prior written permission. For written permission,
27 * please contact shibboleth@shibboleth.org
29 * Products derived from this software may not be called Shibboleth, Internet2,
30 * UCAID, or the University Corporation for Advanced Internet Development, nor
31 * may Shibboleth appear in their name, without prior written permission of the
32 * University Corporation for Advanced Internet Development.
35 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
36 * AND WITH ALL FAULTS. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
38 * PARTICULAR PURPOSE, AND NON-INFRINGEMENT ARE DISCLAIMED AND THE ENTIRE RISK
39 * OF SATISFACTORY QUALITY, PERFORMANCE, ACCURACY, AND EFFORT IS WITH LICENSEE.
40 * IN NO EVENT SHALL THE COPYRIGHT OWNER, CONTRIBUTORS OR THE UNIVERSITY
41 * CORPORATION FOR ADVANCED INTERNET DEVELOPMENT, INC. BE LIABLE FOR ANY DIRECT,
42 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
43 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
44 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
47 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 package edu.internet2.middleware.shibboleth.aa.attrresolv.provider;
52 import java.security.Principal;
53 import java.util.Arrays;
54 import java.util.Iterator;
55 import java.util.LinkedHashSet;
58 import javax.naming.NamingEnumeration;
59 import javax.naming.NamingException;
60 import javax.naming.directory.Attribute;
61 import javax.naming.directory.Attributes;
63 import org.apache.log4j.Logger;
64 import org.w3c.dom.Element;
66 import edu.internet2.middleware.shibboleth.aa.attrresolv.AttributeDefinitionPlugIn;
67 import edu.internet2.middleware.shibboleth.aa.attrresolv.Dependencies;
68 import edu.internet2.middleware.shibboleth.aa.attrresolv.ResolutionPlugInException;
69 import edu.internet2.middleware.shibboleth.aa.attrresolv.ResolverAttribute;
72 * Basic <code>AttributeDefinitionPlugIn</code> implementation. Operates as a proxy for attributes
73 * gathered by Connectors.
75 * @author Walter Hoehn (wassa@columbia.edu)
77 public class SimpleAttributeDefinition extends BaseAttributeDefinition implements AttributeDefinitionPlugIn {
79 private static Logger log = Logger.getLogger(SimpleAttributeDefinition.class.getName());
80 private String connectorMapping;
81 private String smartScope;
82 private ValueHandler valueHandler;
85 * Constructor for SimpleAttributeDefinition. Creates a PlugIn based on configuration
86 * information presented in a DOM Element.
88 public SimpleAttributeDefinition(Element e) throws ResolutionPlugInException {
92 String sourceName = e.getAttribute("sourceName");
93 if (sourceName == null || sourceName.equals("")) {
94 int index = getId().lastIndexOf("#");
96 index = getId().lastIndexOf(":");
97 int slashIndex = getId().lastIndexOf("/");
98 if (slashIndex > index) {
102 connectorMapping = getId().substring(index + 1);
104 connectorMapping = sourceName;
107 log.debug("Mapping attribute to name (" + connectorMapping + ") in connector.");
109 String smartScopingSpec = e.getAttribute("smartScope");
110 if (smartScopingSpec != null && !smartScopingSpec.equals("")) {
111 smartScope = smartScopingSpec;
113 if (smartScope != null) {
114 log.debug("Smart Scope (" + smartScope + ") enabled for attribute (" + getId() + ").");
116 log.debug("Smart Scoping disabled for attribute (" + getId() + ").");
119 String valueHandlerSpec = e.getAttribute("valueHandler");
121 if (valueHandlerSpec != null && !valueHandlerSpec.equals("")) {
122 if (smartScope == null) {
124 Class handlerClass = Class.forName(valueHandlerSpec);
125 valueHandler = (ValueHandler) handlerClass.newInstance();
126 } catch (ClassNotFoundException cnfe) {
128 "Value Handler implementation specified for attribute ("
130 + ") cannot be found: "
132 throw new ResolutionPlugInException(
133 "Value Handler implementation specified for attribute (" + getId() + ") cannot be found.");
134 } catch (Exception oe) {
136 "Value Handler implementation specified for attribute ("
138 + ") coudl not be loaded: "
140 throw new ResolutionPlugInException(
141 "Value Handler implementation specified for attribute (" + getId() + ") could not be loaded.");
145 "Specification of \"valueHandler\' cannot be used in combination with \"smartScope\". Ignoring Value Handler for attribute ("
151 if (valueHandler != null) {
152 log.debug("Custom Value Handler enabled for attribute (" + getId() + ").");
158 * @see edu.internet2.middleware.shibboleth.aa.attrresolv.AttributeDefinitionPlugIn#resolve(edu.internet2.middleware.shibboleth.aa.attrresolv.ArpAttribute, java.security.Principal, java.lang.String, edu.internet2.middleware.shibboleth.aa.attrresolv.Dependencies)
160 public void resolve(ResolverAttribute attribute, Principal principal, String requester, Dependencies depends)
161 throws ResolutionPlugInException {
162 log.debug("Resolving attribute: (" + getId() + ")");
163 Set results = new LinkedHashSet();
164 if (!connectorDependencyIds.isEmpty()) {
165 results.addAll(Arrays.asList(getValuesFromConnectors(depends)));
168 //if (!attributeDependencyIds.isEmpty()) {
169 //results.addAll(Arrays.asList(getValuesFromAttributes(depends)));
172 if (lifeTime != -1) {
173 attribute.setLifetime(lifeTime);
176 if (smartScope != null) {
177 attribute.registerValueHandler(new ScopedStringValueHandler(smartScope));
179 if (smartScope == null && valueHandler != null) {
180 attribute.registerValueHandler(valueHandler);
183 Iterator resultsIt = results.iterator();
184 while (resultsIt.hasNext()) {
185 attribute.addValue(resultsIt.next());
187 attribute.setResolved();
190 protected Object[] getValuesFromAttributes(Dependencies depends) {
192 Set results = new LinkedHashSet();
194 Iterator attrDependIt = attributeDependencyIds.iterator();
195 while (attrDependIt.hasNext()) {
196 ResolverAttribute attribute = depends.getAttributeResolution((String) attrDependIt.next());
197 if (attribute != null) {
198 log.debug("Found value(s) for attribute (" + getId() + ").");
199 for (Iterator iterator = attribute.getValues(); iterator.hasNext();) {
200 results.add(iterator.next());
204 "An attribute dependency of attribute (" + getId() + ") was not included in the dependency chain.");
208 if (results.isEmpty()) {
209 log.debug("An attribute dependency of attribute (" + getId() + ") supplied no values.");
211 return results.toArray();
214 protected Object[] getValuesFromConnectors(Dependencies depends) {
216 Set results = new LinkedHashSet();
218 Iterator connectorDependIt = connectorDependencyIds.iterator();
219 while (connectorDependIt.hasNext()) {
220 Attributes attrs = depends.getConnectorResolution((String) connectorDependIt.next());
222 Attribute attr = attrs.get(connectorMapping);
224 log.debug("Found value(s) for attribute (" + getId() + ").");
226 NamingEnumeration valuesEnum = attr.getAll();
227 while (valuesEnum.hasMore()) {
228 results.add(valuesEnum.next());
230 } catch (NamingException e) {
232 "An problem was encountered resolving the dependencies of attribute ("
241 if (results.isEmpty()) {
242 log.debug("A connector dependency of attribute (" + getId() + ") supplied no values.");
244 return results.toArray();