Import of attribute resolver code.
[java-idp.git] / src / edu / internet2 / middleware / shibboleth / aa / attrresolv / provider / CustomAttributeDefinition.java
1 /* 
2  * The Shibboleth License, Version 1. 
3  * Copyright (c) 2002 
4  * University Corporation for Advanced Internet Development, Inc. 
5  * All rights reserved
6  * 
7  * 
8  * Redistribution and use in source and binary forms, with or without 
9  * modification, are permitted provided that the following conditions are met:
10  * 
11  * Redistributions of source code must retain the above copyright notice, this 
12  * list of conditions and the following disclaimer.
13  * 
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.
22  * 
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
28  * 
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.
33  * 
34  * 
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.
48  */
49
50 package edu.internet2.middleware.shibboleth.aa.attrresolv.provider;
51
52 import java.security.Principal;
53
54 import org.apache.log4j.Logger;
55 import org.w3c.dom.Element;
56
57 import edu.internet2.middleware.shibboleth.aa.attrresolv.AttributeDefinitionPlugIn;
58 import edu.internet2.middleware.shibboleth.aa.attrresolv.Dependencies;
59 import edu.internet2.middleware.shibboleth.aa.attrresolv.ResolutionPlugIn;
60 import edu.internet2.middleware.shibboleth.aa.attrresolv.ResolutionPlugInException;
61 import edu.internet2.middleware.shibboleth.aa.attrresolv.ResolverAttribute;
62
63 /**
64  * 
65  * Wrapper class for custom <code>AttributeDefinitionPlugIn</code> implementations.
66  * 
67  * @author Walter Hoehn (wassa@columbia.edu)
68  *
69  */
70 public class CustomAttributeDefinition implements ResolutionPlugIn, AttributeDefinitionPlugIn {
71
72         private static Logger log = Logger.getLogger(CustomAttributeDefinition.class.getName());
73         private AttributeDefinitionPlugIn custom;
74
75         public CustomAttributeDefinition(Element e) throws ResolutionPlugInException {
76                 if (!e.getTagName().equals("CustomAttributeDefinition")) {
77                         log.error("Incorrect attribute definition configuration: expected <CustomAttributeDefinition> .");
78                         throw new ResolutionPlugInException("Failed to initialize Attribute Definition PlugIn.");
79                 }
80
81                 String className = e.getAttribute("class");
82                 if (className == null || className.equals("")) {
83                         log.error("Custom Attribute Definition requires specification of the attribute \"class\".");
84                         throw new ResolutionPlugInException("Failed to initialize Attribute Definition PlugIn.");
85                 } else {
86                         try {
87                                 Class[] params = { Class.forName("org.w3c.dom.Element"), };
88                                 Object[] passElement = { e };
89                                 custom =
90                                         (AttributeDefinitionPlugIn) Class.forName(className).getConstructor(params).newInstance(
91                                                 passElement);
92                         } catch (Exception loaderException) {
93                                 log.error(
94                                         "Failed to load Custom Attribute Definition PlugIn implementation class: "
95                                                 + loaderException.getMessage());
96                                 throw new ResolutionPlugInException("Failed to initialize Attribute Definition PlugIn.");
97                         }
98                 }
99         }
100
101         /**
102          * @see edu.internet2.middleware.shibboleth.aa.attrresolv.AttributeDefinitionPlugIn#resolve(edu.internet2.middleware.shibboleth.aa.attrresolv.ResolverAttribute, java.security.Principal, java.lang.String, edu.internet2.middleware.shibboleth.aa.attrresolv.Dependencies)
103          */
104         public void resolve(ResolverAttribute attribute, Principal principal, String requester, Dependencies depends)
105                 throws ResolutionPlugInException {
106                 custom.resolve(attribute, principal, requester, depends);
107         }
108
109         /**
110          * @see edu.internet2.middleware.shibboleth.aa.attrresolv.BaseResolutionPlugIn#getId()
111          */
112         public String getId() {
113                 return custom.getId();
114         }
115
116         /**
117          * @see edu.internet2.middleware.shibboleth.aa.attrresolv.provider.BaseResolutionPlugIn#getTTL()
118          */
119         public long getTTL() {
120                 return custom.getTTL();
121         }
122
123         /**
124          * @see edu.internet2.middleware.shibboleth.aa.attrresolv.AttributeDefinitionPlugIn#getAttributeDefinitionDependencyIds()
125          */
126         public String[] getAttributeDefinitionDependencyIds() {
127                 return custom.getAttributeDefinitionDependencyIds();
128         }
129
130         /**
131          * @see edu.internet2.middleware.shibboleth.aa.attrresolv.AttributeDefinitionPlugIn#getDataConnectorDependencyIds()
132          */
133         public String[] getDataConnectorDependencyIds() {
134                 return custom.getDataConnectorDependencyIds();
135         }
136
137 }