Created a connector for the attribute resolver that allows for specificaion of fixed...
authorwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Thu, 26 Jan 2006 20:43:08 +0000 (20:43 +0000)
committerwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Thu, 26 Jan 2006 20:43:08 +0000 (20:43 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@1926 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/aa/attrresolv/ResolutionPlugInFactory.java
src/edu/internet2/middleware/shibboleth/aa/attrresolv/provider/StaticDataConnector.java [new file with mode: 0644]
src/schemas/shibboleth-resolver-1.0.xsd

index 382c47f..3ae9b69 100644 (file)
@@ -1,16 +1,9 @@
 /*
- * Copyright [2005] [University Corporation for Advanced Internet Development, Inc.]
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Copyright [2005] [University Corporation for Advanced Internet Development, Inc.] Licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in
+ * writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ * OF ANY KIND, either express or implied. See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
@@ -30,6 +23,7 @@ import edu.internet2.middleware.shibboleth.aa.attrresolv.provider.PersistentIDAt
 import edu.internet2.middleware.shibboleth.aa.attrresolv.provider.RegExAttributeDefinition;
 import edu.internet2.middleware.shibboleth.aa.attrresolv.provider.SAML2PersistentID;
 import edu.internet2.middleware.shibboleth.aa.attrresolv.provider.SimpleAttributeDefinition;
+import edu.internet2.middleware.shibboleth.aa.attrresolv.provider.StaticDataConnector;
 
 /**
  * Factory that instanciates Resolution PlugIns based on Resolver configuration elements.
@@ -57,6 +51,8 @@ public class ResolutionPlugInFactory {
 
                if (e.getTagName().equals("JDBCDataConnector")) { return new JDBCDataConnector(e); }
 
+               if (e.getTagName().equals("StaticDataConnector")) { return new StaticDataConnector(e); }
+
                if (e.getTagName().equals("RegExAttributeDefinition")) { return new RegExAttributeDefinition(e); }
 
                if (e.getTagName().equals("FormattedAttributeDefinition")) { return new FormattedAttributeDefinition(e); }
diff --git a/src/edu/internet2/middleware/shibboleth/aa/attrresolv/provider/StaticDataConnector.java b/src/edu/internet2/middleware/shibboleth/aa/attrresolv/provider/StaticDataConnector.java
new file mode 100644 (file)
index 0000000..01d03ca
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * Copyright [2005] [University Corporation for Advanced Internet Development, Inc.] Licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in
+ * writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ * OF ANY KIND, either express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package edu.internet2.middleware.shibboleth.aa.attrresolv.provider;
+
+import java.security.Principal;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+
+import org.apache.log4j.Logger;
+import org.w3c.dom.CharacterData;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import edu.internet2.middleware.shibboleth.aa.attrresolv.AttributeResolver;
+import edu.internet2.middleware.shibboleth.aa.attrresolv.DataConnectorPlugIn;
+import edu.internet2.middleware.shibboleth.aa.attrresolv.Dependencies;
+import edu.internet2.middleware.shibboleth.aa.attrresolv.ResolutionPlugInException;
+
+/**
+ * <code>DataConnectorPlugIn</code> implementation that allows static values to be declared in the resolver
+ * configuration.
+ * 
+ * @author Walter Hoehn
+ */
+public class StaticDataConnector extends BaseResolutionPlugIn implements DataConnectorPlugIn {
+
+       private static Logger log = Logger.getLogger(StaticDataConnector.class.getName());
+       private ArrayList<Attribute> sourceData = new ArrayList<Attribute>();
+
+       public StaticDataConnector(Element e) throws ResolutionPlugInException {
+
+               super(e);
+
+               NodeList attributeNodes = e.getElementsByTagNameNS(AttributeResolver.resolverNamespace, "Attribute");
+               if (attributeNodes.getLength() < 1) {
+                       log.error("Static Data Connector requires an \"Attribute\" specification.");
+                       throw new ResolutionPlugInException("Static Data Connector requires an \"Attribute\" specification.");
+               }
+
+               // Iterator over all <Attribute/> nodes
+               // For each one, create a JNDI attribute object
+               for (int i = 0; i < attributeNodes.getLength(); i++) {
+                       Element attributeElement = (Element) attributeNodes.item(i);
+                       String name = attributeElement.getAttribute("name");
+                       if (name == null) {
+                               log.error("Static Data Connector \"Attribute\" element requires a \"name\" specification.");
+                               throw new ResolutionPlugInException(
+                                               "Static Data Connector \"Attribute\" element requires a \"name\" specification.");
+                       }
+
+                       // For each <Attribute/> element, iterator over all <Value/> children, pull the text node children and stick
+                       // them into the JNDI attribute as values
+                       Attribute attribute = new BasicAttribute(name, true);
+                       NodeList valueNodes = attributeElement.getElementsByTagNameNS(AttributeResolver.resolverNamespace, "Value");
+                       if (valueNodes.getLength() < 1) {
+                               log.error("Static Data Connector \"Attribute\" element requires a \"Value\" element specification.");
+                               throw new ResolutionPlugInException(
+                                               "Static Data Connector \"Attribute\" element requires a \"Value\" element specification.");
+                       }
+
+                       for (int j = 0; j < valueNodes.getLength(); j++) {
+                               Element valueElement = (Element) valueNodes.item(j);
+                               if (!valueElement.hasChildNodes() || valueElement.getFirstChild().getNodeType() != Node.TEXT_NODE) {
+                                       log.error("Static Data Connector \"Value\" specification must contain text data.");
+                                       throw new ResolutionPlugInException(
+                                                       "Static Data Connector \"Value\" specification must contain text data.");
+                               }
+                               attribute.add(((CharacterData) valueElement.getFirstChild()).getData());
+
+                       }
+                       sourceData.add(attribute);
+               }
+       }
+
+       /**
+        * @see edu.internet2.middleware.shibboleth.aa.attrresolv.DataConnectorPlugIn#resolve(java.security.Principal,
+        *      java.lang.String, java.lang.String, edu.internet2.middleware.shibboleth.aa.attrresolv.Dependencies)
+        */
+       public Attributes resolve(Principal principal, String requester, String responder, Dependencies depends)
+                       throws ResolutionPlugInException {
+
+               log.debug("Resolving connector: (" + getId() + ")");
+               log.debug(getId() + " resolving for principal: (" + principal.getName() + ")");
+
+               BasicAttributes attributes = new BasicAttributes();
+               Iterator<Attribute> iterator = sourceData.iterator();
+               while (iterator.hasNext()) {
+                       Attribute attribute = (Attribute) iterator.next().clone();
+                       for (int i = 0; i < attribute.size(); i++) {
+                               try {
+                                       attribute.set(i, ((String) attribute.get(i)).replaceAll("%PRINCIPAL%", principal.getName()));
+                               } catch (NamingException e) {
+                                       log.error("Error constructing static attribute values: " + e);
+                                       throw new ResolutionPlugInException("Error constructing static attribute values.");
+                               }
+                       }
+                       attributes.put(attribute);
+               }
+
+               return attributes;
+       }
+
+       /**
+        * @see edu.internet2.middleware.shibboleth.aa.attrresolv.DataConnectorPlugIn#getFailoverDependencyId()
+        */
+       public String getFailoverDependencyId() {
+
+               return null;
+       }
+}
index 76c902c..83b703a 100644 (file)
                                                </xs:complexContent>
                                        </xs:complexType>
                                </xs:element>
+                               <xs:element name="StaticDataConnector" minOccurs="0" maxOccurs="unbounded">
+                                       <xs:complexType>
+                                               <xs:complexContent>
+                                                       <xs:extension base="resolver:BaseDataConnector">
+                                                               <xs:sequence minOccurs="1" maxOccurs="unbounded">
+                                                                       <xs:element name="Attribute">
+                                                                               <xs:complexType>
+                                                                                       <xs:sequence minOccurs="1" maxOccurs="unbounded">
+                                                                                               <xs:element name="Value" type="xs:string" minOccurs="1" maxOccurs="unbounded"/>
+                                                                                       </xs:sequence>
+                                                                                       <xs:attribute name="name" type="xs:string" use="required"/>
+                                                                               </xs:complexType>
+                                                                       </xs:element>
+                                                               </xs:sequence>
+                                                       </xs:extension>
+                                               </xs:complexContent>
+                                       </xs:complexType>
+                               </xs:element>
                                <xs:element name="JNDIDirectoryDataConnector" minOccurs="0" maxOccurs="unbounded">
                                        <xs:complexType>
                                                <xs:complexContent>