Changed HandleRepository interface to reference a specific Principal implementation.
authorwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Thu, 6 Feb 2003 19:52:51 +0000 (19:52 +0000)
committerwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Thu, 6 Feb 2003 19:52:51 +0000 (19:52 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@454 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/aa/AAServlet.java
src/edu/internet2/middleware/shibboleth/aa/arp/ArpTests.java
src/edu/internet2/middleware/shibboleth/common/AuthNPrincipal.java [moved from src/edu/internet2/middleware/shibboleth/aa/arp/AAPrincipal.java with 86% similarity]
src/edu/internet2/middleware/shibboleth/hs/HandleRepository.java
src/edu/internet2/middleware/shibboleth/hs/HandleServlet.java
src/edu/internet2/middleware/shibboleth/hs/provider/BaseHandleRepository.java
src/edu/internet2/middleware/shibboleth/hs/provider/CryptoHandleRepository.java
src/edu/internet2/middleware/shibboleth/hs/provider/MemoryHandleRepository.java

index 3c8ecac..8a2ddd6 100755 (executable)
@@ -75,9 +75,9 @@ import org.opensaml.SAMLException;
 import org.opensaml.SAMLIdentifier;
 
 import edu.internet2.middleware.eduPerson.Init;
-import edu.internet2.middleware.shibboleth.aa.arp.AAPrincipal;
 import edu.internet2.middleware.shibboleth.aa.arp.ArpEngine;
 import edu.internet2.middleware.shibboleth.aa.arp.ArpException;
+import edu.internet2.middleware.shibboleth.common.AuthNPrincipal;
 import edu.internet2.middleware.shibboleth.hs.HandleRepository;
 import edu.internet2.middleware.shibboleth.hs.HandleRepositoryException;
 import edu.internet2.middleware.shibboleth.hs.HandleRepositoryFactory;
@@ -209,7 +209,7 @@ public class AAServlet extends HttpServlet {
                        Principal principal = null;
                        if (saml.getHandle().equalsIgnoreCase("foo")) {
                                // for testing
-                               principal = new AAPrincipal("test-handle");
+                               principal = new AuthNPrincipal("test-handle");
                        } else {
                                principal = handleRepository.getPrincipal(saml.getHandle());
                                if (principal == null) {
index 7aff835..a7e4805 100755 (executable)
@@ -75,6 +75,8 @@ import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import org.xml.sax.SAXParseException;
 
+import edu.internet2.middleware.shibboleth.common.*;
+
 /**
  * Validation suite for <code>Arp</code> processing.
  * 
@@ -440,7 +442,7 @@ public class ArpTests extends TestCase {
                        fail("Error adding User ARP to Memory Repository.");
                }
 
-               Arp userArp2 = new Arp(new AAPrincipal("TestPrincipal"));
+               Arp userArp2 = new Arp(new AuthNPrincipal("TestPrincipal"));
                userArp2.setDescription("Test User Arp 2.");
                try {
                        repository.update(userArp2);
@@ -497,7 +499,7 @@ public class ArpTests extends TestCase {
                                directXML.toString().replaceAll(">[\t\r\n ]+<", "><").equals(
                                        processedXML.toString().replaceAll(">[\t\r\n ]+<", "><")));
 
-                       Arp userArp = repository.getUserPolicy(new AAPrincipal("test"));
+                       Arp userArp = repository.getUserPolicy(new AuthNPrincipal("test"));
 
                        inStream = new FileInputStream("data/arp.user.test.xml");
                        parser.parse(new InputSource(inStream));
@@ -513,7 +515,7 @@ public class ArpTests extends TestCase {
                                directXML.toString().replaceAll(">[\t\r\n ]+<", "><").equals(
                                        processedXML.toString().replaceAll(">[\t\r\n ]+<", "><")));
 
-                       Arp[] allArps = repository.getAllPolicies(new AAPrincipal("test"));
+                       Arp[] allArps = repository.getAllPolicies(new AuthNPrincipal("test"));
 
                        assertTrue("File-based ARP Repository did not return the correct number of ARPs.", (allArps.length == 2));
                
@@ -536,7 +538,7 @@ public class ArpTests extends TestCase {
                }
 
                try {
-                       Principal principal1 = new AAPrincipal("TestPrincipal");
+                       Principal principal1 = new AuthNPrincipal("TestPrincipal");
                        URL url1 = new URL("http://www.example.edu/");
                        URI[] list1 = { new URI("urn:mace:eduPerson:1.0:eduPersonAffiliation")};
                        URI[] list2 =
@@ -688,7 +690,7 @@ public class ArpTests extends TestCase {
                                + "                     </Rule>"
                                + "     </AttributeReleasePolicy>";
 
-               Principal principal1 = new AAPrincipal("TestPrincipal");
+               Principal principal1 = new AuthNPrincipal("TestPrincipal");
                URL url1 = new URL("http://www.example.edu/");
                TestAttribute testAttribute =
                        new TestAttribute(
@@ -738,7 +740,7 @@ public class ArpTests extends TestCase {
                                + "                     </Rule>"
                                + "     </AttributeReleasePolicy>";
 
-               Principal principal1 = new AAPrincipal("TestPrincipal");
+               Principal principal1 = new AuthNPrincipal("TestPrincipal");
                URL url1 = new URL("http://www.example.edu/");
                TestAttribute testAttribute1 =
                        new TestAttribute(
@@ -792,7 +794,7 @@ public class ArpTests extends TestCase {
                                + "                     </Rule>"
                                + "     </AttributeReleasePolicy>";
 
-               Principal principal1 = new AAPrincipal("TestPrincipal");
+               Principal principal1 = new AuthNPrincipal("TestPrincipal");
                URL url1 = new URL("http://www.example.edu/");
                TestAttribute testAttribute =
                        new TestAttribute(
@@ -847,7 +849,7 @@ public class ArpTests extends TestCase {
                                + "                     </Rule>"
                                + "     </AttributeReleasePolicy>";
 
-               Principal principal1 = new AAPrincipal("TestPrincipal");
+               Principal principal1 = new AuthNPrincipal("TestPrincipal");
                URL url1 = new URL("http://www.example.edu/");
                TestAttribute testAttribute =
                        new TestAttribute(
@@ -907,7 +909,7 @@ public class ArpTests extends TestCase {
                                + "                     </Rule>"
                                + "     </AttributeReleasePolicy>";
 
-               Principal principal1 = new AAPrincipal("TestPrincipal");
+               Principal principal1 = new AuthNPrincipal("TestPrincipal");
                URL url1 = new URL("http://www.example.edu/");
                TestAttribute testAttribute =
                        new TestAttribute(
@@ -970,7 +972,7 @@ public class ArpTests extends TestCase {
                                + "                     </Rule>"
                                + "     </AttributeReleasePolicy>";
 
-               Principal principal1 = new AAPrincipal("TestPrincipal");
+               Principal principal1 = new AuthNPrincipal("TestPrincipal");
                URL url1 = new URL("http://www.example.edu/");
                TestAttribute testAttribute =
                        new TestAttribute(
@@ -1028,7 +1030,7 @@ public class ArpTests extends TestCase {
                                + "                     </Rule>"
                                + "     </AttributeReleasePolicy>";
 
-               Principal principal1 = new AAPrincipal("TestPrincipal");
+               Principal principal1 = new AuthNPrincipal("TestPrincipal");
                URL url1 = new URL("http://www.example.edu/");
                TestAttribute testAttribute =
                        new TestAttribute(
@@ -1088,7 +1090,7 @@ public class ArpTests extends TestCase {
                                + "                     </Rule>"
                                + "     </AttributeReleasePolicy>";
 
-               Principal principal1 = new AAPrincipal("TestPrincipal");
+               Principal principal1 = new AuthNPrincipal("TestPrincipal");
                URL url1 = new URL("http://www.example.edu/");
                TestAttribute testAttribute =
                        new TestAttribute(
@@ -1145,7 +1147,7 @@ public class ArpTests extends TestCase {
                                + "                     </Rule>"
                                + "     </AttributeReleasePolicy>";
 
-               Principal principal1 = new AAPrincipal("TestPrincipal");
+               Principal principal1 = new AuthNPrincipal("TestPrincipal");
                URL url1 = new URL("http://www.example.edu/");
                TestAttribute testAttribute =
                        new TestAttribute(
@@ -1198,7 +1200,7 @@ public class ArpTests extends TestCase {
                                + "                     </Rule>"
                                + "     </AttributeReleasePolicy>";
 
-               Principal principal1 = new AAPrincipal("TestPrincipal");
+               Principal principal1 = new AuthNPrincipal("TestPrincipal");
                URL url1 = new URL("http://www.example.edu/");
                TestAttribute testAttribute =
                        new TestAttribute(
@@ -1249,7 +1251,7 @@ public class ArpTests extends TestCase {
                                + "                     </Rule>"
                                + "     </AttributeReleasePolicy>";
 
-               Principal principal1 = new AAPrincipal("TestPrincipal");
+               Principal principal1 = new AuthNPrincipal("TestPrincipal");
                URL url1 = new URL("http://www.example.edu/");
                TestAttribute testAttribute =
                        new TestAttribute(
@@ -1300,7 +1302,7 @@ public class ArpTests extends TestCase {
                                + "                     </Rule>"
                                + "     </AttributeReleasePolicy>";
 
-               Principal principal1 = new AAPrincipal("TestPrincipal");
+               Principal principal1 = new AuthNPrincipal("TestPrincipal");
                URL url1 = new URL("http://www.example.edu/");
                TestAttribute testAttribute =
                        new TestAttribute(
@@ -1351,7 +1353,7 @@ public class ArpTests extends TestCase {
                                + "                     </Rule>"
                                + "     </AttributeReleasePolicy>";
 
-               Principal principal1 = new AAPrincipal("TestPrincipal");
+               Principal principal1 = new AuthNPrincipal("TestPrincipal");
                URL url1 = new URL("https://foo.com/");
                TestAttribute testAttribute =
                        new TestAttribute(
@@ -1402,7 +1404,7 @@ public class ArpTests extends TestCase {
                                + "                     </Rule>"
                                + "     </AttributeReleasePolicy>";
 
-               Principal principal1 = new AAPrincipal("TestPrincipal");
+               Principal principal1 = new AuthNPrincipal("TestPrincipal");
                URL url1 = new URL("http://www.example.edu/");
                TestAttribute testAttribute =
                        new TestAttribute(
@@ -1453,7 +1455,7 @@ public class ArpTests extends TestCase {
                                + "                     </Rule>"
                                + "     </AttributeReleasePolicy>";
 
-               Principal principal1 = new AAPrincipal("TestPrincipal");
+               Principal principal1 = new AuthNPrincipal("TestPrincipal");
                URL url1 = new URL("http://www.example.edu/index.html");
                TestAttribute testAttribute =
                        new TestAttribute(
@@ -1504,7 +1506,7 @@ public class ArpTests extends TestCase {
                                + "                     </Rule>"
                                + "     </AttributeReleasePolicy>";
 
-               Principal principal1 = new AAPrincipal("TestPrincipal");
+               Principal principal1 = new AuthNPrincipal("TestPrincipal");
                URL url1 = new URL("https://www.example.edu/index.html");
                TestAttribute testAttribute =
                        new TestAttribute(
@@ -1572,7 +1574,7 @@ public class ArpTests extends TestCase {
                                + "                     </Rule>"
                                + "     </AttributeReleasePolicy>";
 
-               Principal principal1 = new AAPrincipal("TestPrincipal");
+               Principal principal1 = new AuthNPrincipal("TestPrincipal");
                URL url1 = new URL("https://www.example.edu/index.html");
                TestAttribute testAttribute1 =
                        new TestAttribute(
@@ -1633,7 +1635,7 @@ public class ArpTests extends TestCase {
                                + "                     </Rule>"
                                + "     </AttributeReleasePolicy>";
 
-               Principal principal1 = new AAPrincipal("TestPrincipal");
+               Principal principal1 = new AuthNPrincipal("TestPrincipal");
                URL url1 = new URL("http://www.example.edu/");
                TestAttribute testAttribute1 =
                        new TestAttribute(
@@ -1687,7 +1689,7 @@ public class ArpTests extends TestCase {
                                + "                     </Rule>"
                                + "     </AttributeReleasePolicy>";
 
-               Principal principal1 = new AAPrincipal("TestPrincipal");
+               Principal principal1 = new AuthNPrincipal("TestPrincipal");
                URL url1 = new URL("http://www.example.edu/");
                TestAttribute testAttribute =
                        new TestAttribute(
@@ -1796,7 +1798,7 @@ public class ArpTests extends TestCase {
                                + "                     </Rule>"
                                + "     </AttributeReleasePolicy>";
 
-               Principal principal1 = new AAPrincipal("TestPrincipal");
+               Principal principal1 = new AuthNPrincipal("TestPrincipal");
                URL url1 = new URL("http://www.example.edu/test/index.html");
 
                TestAttribute entitlementInput =
@@ -1953,7 +1955,7 @@ public class ArpTests extends TestCase {
                                + "                     </Rule>"
                                + "     </AttributeReleasePolicy>";
 
-               Principal principal1 = new AAPrincipal("TestPrincipal");
+               Principal principal1 = new AuthNPrincipal("TestPrincipal");
                URL url1 = new URL("http://www.external.com/");
 
                TestAttribute entitlementInput =
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-package edu.internet2.middleware.shibboleth.aa.arp;
+package edu.internet2.middleware.shibboleth.common;
 
+import java.io.Serializable;
 import java.security.Principal;
 
 /**
- * <code>Principal</code> for use within the Shibboleth Attribute Authority.
+ * Shibboleth <code>Principal</code> that represents an Authenticated individual.
  * 
  * @author Walter Hoehn (wassa@columbia.edu)
  */
 
-public class AAPrincipal implements Principal {
+public class AuthNPrincipal implements Principal, Serializable {
 
        private String principalName;
 
        /**
-        * Constructor for AAPrincipal.
+        * Constructor for AuthNPrincipal.
         */
 
-       public AAPrincipal(String principalName) {
+       public AuthNPrincipal(String principalName) {
                this.principalName = principalName;
        }
 
@@ -81,17 +82,17 @@ public class AAPrincipal implements Principal {
         * @see java.lang.Object#equals(Object)
         */
        public boolean equals(Object obj) {
-               if (!(obj instanceof AAPrincipal)) {
+               if (!(obj instanceof AuthNPrincipal)) {
                        return false;
                }
-               return ((AAPrincipal) obj).getName().equals(getName());
+               return ((AuthNPrincipal) obj).getName().equals(getName());
        }
 
        /**
         * @see java.lang.Object#hashCode()
         */
        public int hashCode() {
-               return "AAPrincipal".hashCode() + principalName.hashCode();
+               return "AuthNPrincipal".hashCode() + principalName.hashCode();
        }
 
 }
index 9cee2de..4ef63f0 100644 (file)
@@ -49,7 +49,7 @@
 
 package edu.internet2.middleware.shibboleth.hs;
 
-import java.security.Principal;
+import edu.internet2.middleware.shibboleth.common.AuthNPrincipal;
 
 /**
  * Defines a mechanism for communicating identities between the Shibboleth Handle
@@ -61,13 +61,13 @@ public interface HandleRepository {
 
        /**
         * Creates an opaque identifier that may be shared with target sites and subsequently 
-        * used in attribute requests for the given <code>Principal</code>.
+        * used in attribute requests for the given <code>AuthNPrincipal</code>.
         */
-       public String getHandle(Principal principal);
+       public String getHandle(AuthNPrincipal principal);
 
        /**
-        * Finds the <code>Principal</code> associated with a given opaque identifier.
+        * Finds the <code>AuthNPrincipal</code> associated with a given opaque identifier.
         */
-       public Principal getPrincipal(String handle);
+       public AuthNPrincipal getPrincipal(String handle);
 
 }
index ebcc7af..153abe6 100644 (file)
@@ -81,7 +81,7 @@ import org.opensaml.SAMLException;
 import org.opensaml.SAMLResponse;
 import sun.misc.BASE64Decoder;
 
-import edu.internet2.middleware.shibboleth.aa.arp.AAPrincipal;
+import edu.internet2.middleware.shibboleth.common.AuthNPrincipal;
 import edu.internet2.middleware.shibboleth.common.Constants;
 import edu.internet2.middleware.shibboleth.common.ShibPOSTProfile;
 import edu.internet2.middleware.shibboleth.common.ShibPOSTProfileFactory;
@@ -230,7 +230,7 @@ public class HandleServlet extends HttpServlet {
                        req.setAttribute("shire", req.getParameter("shire"));
                        req.setAttribute("target", req.getParameter("target"));
 
-                       String handle = handleRepository.getHandle(new AAPrincipal(req.getRemoteUser()));
+                       String handle = handleRepository.getHandle(new AuthNPrincipal(req.getRemoteUser()));
                        log.info("Issued Handle (" + handle + ") to (" + req.getRemoteUser() + ")");
 
                        byte[] buf =
index d690223..25ed001 100644 (file)
 
 package edu.internet2.middleware.shibboleth.hs.provider;
 
-import java.security.Principal;
 import java.util.Properties;
 
 import org.apache.log4j.Logger;
 
+import edu.internet2.middleware.shibboleth.common.AuthNPrincipal;
 import edu.internet2.middleware.shibboleth.hs.HandleRepository;
 import edu.internet2.middleware.shibboleth.hs.HandleRepositoryException;
 
@@ -92,7 +92,7 @@ public abstract class BaseHandleRepository implements HandleRepository {
 
        }
        
-       protected HandleEntry createHandleEntry(Principal principal) {
+       protected HandleEntry createHandleEntry(AuthNPrincipal principal) {
                return new HandleEntry(principal, handleTTL);
        }
                
@@ -101,10 +101,10 @@ public abstract class BaseHandleRepository implements HandleRepository {
 }
 
 class HandleEntry {
-       protected Principal principal;
+       protected AuthNPrincipal principal;
        protected long expirationTime;
 
-       protected HandleEntry(Principal principal, long TTL) {
+       protected HandleEntry(AuthNPrincipal principal, long TTL) {
                this.principal = principal;
                expirationTime = System.currentTimeMillis() + TTL;
        }
index 6f67532..12d17cc 100644 (file)
@@ -49,9 +49,9 @@
 
 package edu.internet2.middleware.shibboleth.hs.provider;
 
-import java.security.Principal;
 import java.util.Properties;
 
+import edu.internet2.middleware.shibboleth.common.AuthNPrincipal;
 import edu.internet2.middleware.shibboleth.hs.HandleRepository;
 import edu.internet2.middleware.shibboleth.hs.HandleRepositoryException;
 
@@ -70,14 +70,14 @@ public class CryptoHandleRepository extends BaseHandleRepository implements Hand
        /**
         * @see edu.internet2.middleware.shibboleth.hs.HandleRepository#getHandle(Principal)
         */
-       public String getHandle(Principal principal) {
+       public String getHandle(AuthNPrincipal principal) {
                return null;
        }
 
        /**
         * @see edu.internet2.middleware.shibboleth.hs.HandleRepository#getPrincipal(String)
         */
-       public Principal getPrincipal(String handle) {
+       public AuthNPrincipal getPrincipal(String handle) {
                return null;
        }
 
index 0a77edd..1f4fcdb 100644 (file)
@@ -49,7 +49,6 @@
 
 package edu.internet2.middleware.shibboleth.hs.provider;
 
-import java.security.Principal;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -61,6 +60,7 @@ import java.util.Map.Entry;
 import org.apache.log4j.Logger;
 import org.doomdark.uuid.UUIDGenerator;
 
+import edu.internet2.middleware.shibboleth.common.AuthNPrincipal;
 import edu.internet2.middleware.shibboleth.hs.HandleRepository;
 import edu.internet2.middleware.shibboleth.hs.HandleRepositoryException;
 
@@ -82,7 +82,7 @@ public class MemoryHandleRepository extends BaseHandleRepository implements Hand
        /**
         * @see edu.internet2.middleware.shibboleth.hs.HandleRepository#getHandle(Principal)
         */
-       public String getHandle(Principal principal) {
+       public String getHandle(AuthNPrincipal principal) {
                String handle = UUIDGenerator.getInstance().generateRandomBasedUUID().toString();
                log.debug("Assigning handle (" + handle + ") to principal (" + principal.getName() + ").");
                synchronized (cache.handleEntries) {
@@ -94,7 +94,7 @@ public class MemoryHandleRepository extends BaseHandleRepository implements Hand
        /**
         * @see edu.internet2.middleware.shibboleth.hs.HandleRepository#getPrincipal(String)
         */
-       public Principal getPrincipal(String handle) {
+       public AuthNPrincipal getPrincipal(String handle) {
                synchronized (cache.handleEntries) {
                        if (!cache.handleEntries.containsKey(handle)) {
                                log.debug("Repository does not contain an entry for this Attribute Query Handle.");