The beginnings of ARP serialization. A little more debugging code.
authorwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Thu, 19 Dec 2002 23:01:27 +0000 (23:01 +0000)
committerwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Thu, 19 Dec 2002 23:01:27 +0000 (23:01 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@390 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/aa/arp/Arp.java
src/edu/internet2/middleware/shibboleth/aa/arp/ArpEngine.java
src/edu/internet2/middleware/shibboleth/aa/arp/Rule.java

index 35b5aad..98b2f0c 100755 (executable)
@@ -55,6 +55,11 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
 
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.log4j.Logger;
 import org.apache.xerces.parsers.DOMParser;
 import org.w3c.dom.CharacterData;
 import org.w3c.dom.Document;
@@ -74,6 +79,7 @@ public class Arp {
        private Set rules = new HashSet();
        private String description;
        private boolean sitePolicy = false;
+       private static Logger log = Logger.getLogger(Arp.class.getName());
 
        /**
         * Creates an Arp for the specified <code>Principal</code>.
@@ -160,24 +166,29 @@ public class Arp {
         * @return the xml <code>Element</code>
         */
 
-       Element unmarshall() {
+       Element unmarshall() throws ArpMarshallingException {
 
-               DOMParser parser = new DOMParser();
-               Document placeHolder = parser.getDocument();
-               Element policyNode = placeHolder.createElement("AttributeReleasePolicy");
+               try {
+                       Document placeHolder = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+                       Element policyNode = placeHolder.createElement("AttributeReleasePolicy");
+                       if (description != null) {
+                               Element descriptionNode = placeHolder.createElement("Description");
+                               descriptionNode.appendChild(placeHolder.createTextNode(description));
+                               policyNode.appendChild(descriptionNode);
+                       }
 
-               if (description != null) {
-                       Element descriptionNode = placeHolder.createElement("Description");
-                       descriptionNode.appendChild(placeHolder.createTextNode(description));
-                       policyNode.appendChild(descriptionNode);
-               }
+                       Rule[] rules = getAllRules();
+                       for (int i = 0; rules.length > i; i++) {
+                               policyNode.appendChild(placeHolder.importNode(rules[i].unmarshall(), true));
+                       }
+
+                       return policyNode;
 
-               Rule[] rules = getAllRules();
-               for (int i = 0; rules.length > i; i++) {
-                       policyNode.appendChild(rules[i].unmarshall());
+               } catch (ParserConfigurationException e) {
+                       log.error("Encountered a problem unmarshalling an ARP: " + e);
+                       throw new ArpMarshallingException("Encountered a problem unmarshalling an ARP.");
                }
 
-               return policyNode;
        }
 
        /**
index d91efa1..1c5d754 100755 (executable)
@@ -49,6 +49,8 @@
 
 package edu.internet2.middleware.shibboleth.aa.arp;
 
+import java.io.IOException;
+import java.io.StringWriter;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
@@ -62,6 +64,8 @@ import java.util.Properties;
 import java.util.Set;
 
 import org.apache.log4j.Logger;
+import org.apache.xml.serialize.OutputFormat;
+import org.apache.xml.serialize.XMLSerializer;
 
 /**
  *  Defines a processing engine for Attribute Release Policies.
@@ -144,7 +148,24 @@ public class ArpEngine {
                        effectiveArp.setDescription("Effective ARP.");
 
                        Arp[] userPolicies = repository.getAllPolicies(principal);
-                       log.debug("Creating effective ARP from (" + userPolicies.length + ") polic(y|ies).");
+
+                       if (log.isDebugEnabled()) {
+                               log.debug("Creating effective ARP from (" + userPolicies.length + ") polic(y|ies).");
+                               try {
+                                       for (int i = 0; userPolicies.length > i; i++) {
+                                               StringWriter writer = new StringWriter();
+                                               OutputFormat format = new OutputFormat();
+                                               format.setIndent(4);
+                                               XMLSerializer serializer = new XMLSerializer(writer, format);
+                                               serializer.serialize(userPolicies[i].unmarshall());
+                                               log.debug(
+                                                       "Dumping ARP from:" + System.getProperty("line.separator") + writer.toString());
+                                       }
+                               } catch (ArpMarshallingException ame) {
+                               } catch (IOException ioe) {
+                               }
+                       }
+
                        for (int i = 0; userPolicies.length > i; i++) {
                                Rule[] rules = userPolicies[i].getMatchingRules(requester, resource);
 
@@ -213,6 +234,14 @@ public class ArpEngine {
                throws ArpProcessingException {
 
                Set releaseSet = new HashSet();
+               
+               log.info("Applying Attribute Release Policies.");
+               if (log.isDebugEnabled()) {
+                       log.debug("Processing the following attributes:");
+                       for (int i = 0;attributes.length > i; i++) {
+                               log.debug("Attribute: (" + attributes[i].getName() + ")");      
+                       }
+               }
 
                //Gather all applicable ARP attribute specifiers
                Set attributeNames = new HashSet();
index 91aade3..5f91617 100755 (executable)
@@ -57,8 +57,10 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
 
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
 import org.apache.log4j.Logger;
-import org.apache.xerces.parsers.DOMParser;
 import org.w3c.dom.CharacterData;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -110,19 +112,23 @@ public class Rule {
         * @return the xml <code>Element</code>
         */
 
-       public Element unmarshall() {
+       public Element unmarshall() throws ArpMarshallingException {
 
-               DOMParser parser = new DOMParser();
-               Document placeHolder = parser.getDocument();
-               Element ruleNode = placeHolder.createElement("Rule");
+               try {
+                       Document placeHolder = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+                       Element ruleNode = placeHolder.createElement("Rule");
 
-               if (description != null) {
-                       Element descriptionNode = placeHolder.createElement("Description");
-                       descriptionNode.appendChild(placeHolder.createTextNode(description));
-                       ruleNode.appendChild(descriptionNode);
-               }
+                       if (description != null) {
+                               Element descriptionNode = placeHolder.createElement("Description");
+                               descriptionNode.appendChild(placeHolder.createTextNode(description));
+                               ruleNode.appendChild(descriptionNode);
+                       }
 
-               return ruleNode;
+                       return ruleNode;
+               } catch (ParserConfigurationException e) {
+                       log.error("Encountered a problem unmarshalling an ARP Rule: " + e);
+                       throw new ArpMarshallingException("Encountered a problem unmarshalling an ARP Rule.");
+               }
        }
 
        /**