Added encoding of usernames so that "||" can be handled.
authorwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Tue, 4 Jun 2002 17:02:43 +0000 (17:02 +0000)
committerwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Tue, 4 Jun 2002 17:02:43 +0000 (17:02 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@25 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/common/AQHTest.java
src/edu/internet2/middleware/shibboleth/common/AttributeQueryHandle.java

index 1f644b9..8aeeb63 100755 (executable)
@@ -80,7 +80,7 @@ public class AQHTest extends TestCase {
        public void testExpiration() {
                try {
                        AttributeQueryHandle aqh = new AttributeQueryHandle("Walter", goodKey, 1l, testHs);
-                       Thread.sleep(2);
+                       Thread.sleep(50);
                        assertTrue("AttributeQueryHandle failed to expire appropriately", aqh.isExpired());
                } catch (InterruptedException e) {
                } catch (HandleException e) {
@@ -101,4 +101,36 @@ public class AQHTest extends TestCase {
                        fail("Failed to create AttributeQueryHandle" + e);
                }
        }
+       
+       /**
+        * Make sure that it is works to create an AQH where the username contains
+        * the character that is used for field separation during serialization
+        */
+       
+       public void testSeparator() {
+               
+               try {
+                       
+               String userName = "Test||Test";
+               
+               //Create an AQH
+               AttributeQueryHandle originalAQH =
+                       new AttributeQueryHandle(userName, goodKey, 300000l, testHs);
+                       
+               //Ensure that the principal was set correctly
+               assertEquals("Principal incorrect", userName, originalAQH.getPrincipal());
+               
+               //Create a new AQH from the serialized first AQH
+               AttributeQueryHandle secondAQH =
+                       new AttributeQueryHandle(originalAQH.serialize(), goodKey);
+                       
+               //Ensure that the principal was set correctly
+               assertEquals("Principal incorrect", userName, secondAQH.getPrincipal());
+               
+               } catch (HandleException e) {
+                       fail("Failed to create AttributeQueryHandle" + e);
+               }
+               
+               
+       }
 }
\ No newline at end of file
index a0b7ebd..e165826 100755 (executable)
@@ -37,10 +37,13 @@ public class AttributeQueryHandle {
                        cipher.init(Cipher.DECRYPT_MODE, key);
                        StringTokenizer tokenizer =
                                new StringTokenizer(
-                                       new String(cipher.doFinal(Base64.decode(handle))),
+                                       new String(cipher.doFinal(Base64.decode(handle)), "UTF-8"),
                                        "||",
                                        false);
-                       principal = tokenizer.nextToken();
+                       principal =
+                               new String(
+                                       Base64.decode(tokenizer.nextToken().getBytes("ASCII")),
+                                       "UTF-8");
                        expirationTime = new Long(tokenizer.nextToken()).longValue();
                        handleID = tokenizer.nextToken();
                } catch (Exception e) {
@@ -74,14 +77,23 @@ public class AttributeQueryHandle {
                        UUIDGenerator uuidGen = UUIDGenerator.getInstance();
                        UUID nameSpaceUUID = new UUID(UUID.NAMESPACE_URL);
                        handleID =
-                       uuidGen.generateNameBasedUUID(nameSpaceUUID, hsLocation)+ ":" + uuidGen.generateTimeBasedUUID();
-                       
+                               uuidGen.generateNameBasedUUID(nameSpaceUUID, hsLocation)
+                                       + ":"
+                                       + uuidGen.generateTimeBasedUUID();
+
                        Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");
                        cipher.init(Cipher.ENCRYPT_MODE, key);
                        cipherTextHandle =
                                cipher.doFinal(
-                                       (principal + "||" + expirationTime + "||" + handleID)
-                                               .getBytes("UTF-8"));
+                                       (
+                                               new String(
+                                                       Base64.encode(principal.getBytes("UTF-8")),
+                                                       "ASCII")
+                                                       + "||"
+                                                       + expirationTime
+                                                       + "||"
+                                                       + handleID).getBytes(
+                                               "UTF-8"));
 
                } catch (Exception e) {
                        throw new HandleException("Error creating handle: " + e);
@@ -114,7 +126,7 @@ public class AttributeQueryHandle {
 
        public boolean isExpired() {
 
-               if (System.currentTimeMillis() > expirationTime) {
+               if (System.currentTimeMillis() >= expirationTime) {
                        return true;
                } else {
                        return false;
@@ -125,7 +137,7 @@ public class AttributeQueryHandle {
        /**
         * Returns a <code>String</code> representation of the unique identifier for this handle.
         */
-       
+
        public String getHandleID() {
                return handleID;
        }