diff --git a/core/src/main/java/org/acegisecurity/concurrent/SessionRegistry.java b/core/src/main/java/org/acegisecurity/concurrent/SessionRegistry.java
index 110fb88c82..b022ca8c19 100644
--- a/core/src/main/java/org/acegisecurity/concurrent/SessionRegistry.java
+++ b/core/src/main/java/org/acegisecurity/concurrent/SessionRegistry.java
@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,6 +24,14 @@ package org.acegisecurity.concurrent;
public interface SessionRegistry {
//~ Methods ================================================================
+ /**
+ * Obtains all the known principals in the SessionRegistry.
+ *
+ * @return each of the unique principals, which can then be presented to
+ * {@link #getAllSessions(Object)}.
+ */
+ public Object[] getAllPrincipals();
+
/**
* Obtains all the known sessions for the specified principal. Sessions
* that have expired or destroyed are not returned.
@@ -50,7 +58,8 @@ public interface SessionRegistry {
/**
* Updates the given sessionId so its last request time is
* equal to the present date and time. Silently returns if the given
- * sessionId cannot be found or the session is marked to expire.
+ * sessionId cannot be found or the session is marked to
+ * expire.
*
* @param sessionId for which to update the date and time of the last
* request (should never be null)
diff --git a/core/src/main/java/org/acegisecurity/concurrent/SessionRegistryImpl.java b/core/src/main/java/org/acegisecurity/concurrent/SessionRegistryImpl.java
index cd9b176f1f..36035b2041 100644
--- a/core/src/main/java/org/acegisecurity/concurrent/SessionRegistryImpl.java
+++ b/core/src/main/java/org/acegisecurity/concurrent/SessionRegistryImpl.java
@@ -144,4 +144,8 @@ public class SessionRegistryImpl implements SessionRegistry,
}
}
}
+
+ public Object[] getAllPrincipals() {
+ return principals.keySet().toArray();
+ }
}
diff --git a/core/src/test/java/org/acegisecurity/concurrent/SessionRegistryImplTests.java b/core/src/test/java/org/acegisecurity/concurrent/SessionRegistryImplTests.java
index bc6a276ad1..6e1bae7cb2 100644
--- a/core/src/test/java/org/acegisecurity/concurrent/SessionRegistryImplTests.java
+++ b/core/src/test/java/org/acegisecurity/concurrent/SessionRegistryImplTests.java
@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -52,6 +52,23 @@ public class SessionRegistryImplTests extends TestCase {
assertNull(sessionRegistry.getSessionInformation(sessionId));
}
+ public void testMultiplePrincipals() throws Exception {
+ Object principal1 = "principal_1";
+ Object principal2 = "principal_2";
+ String sessionId1 = "1234567890";
+ String sessionId2 = "9876543210";
+ String sessionId3 = "5432109876";
+
+ SessionRegistryImpl sessionRegistry = new SessionRegistryImpl();
+
+ sessionRegistry.registerNewSession(sessionId1, principal1);
+ sessionRegistry.registerNewSession(sessionId2, principal1);
+ sessionRegistry.registerNewSession(sessionId3, principal2);
+
+ assertEquals(principal1, sessionRegistry.getAllPrincipals()[0]);
+ assertEquals(principal2, sessionRegistry.getAllPrincipals()[1]);
+ }
+
public void testSessionInformationLifecycle() throws Exception {
Object principal = "Some principal object";
String sessionId = "1234567890";
@@ -95,6 +112,33 @@ public class SessionRegistryImplTests extends TestCase {
assertNull(sessionRegistry.getAllSessions(principal));
}
+ public void testTwoSessionsOnePrincipalExpiring() throws Exception {
+ Object principal = "Some principal object";
+ String sessionId1 = "1234567890";
+ String sessionId2 = "9876543210";
+ SessionRegistryImpl sessionRegistry = new SessionRegistryImpl();
+
+ // Register new Session
+ sessionRegistry.registerNewSession(sessionId1, principal);
+ assertEquals(1, sessionRegistry.getAllSessions(principal).length);
+ assertEquals(sessionId1,
+ sessionRegistry.getAllSessions(principal)[0].getSessionId());
+
+ // Register new Session
+ sessionRegistry.registerNewSession(sessionId2, principal);
+ assertEquals(2, sessionRegistry.getAllSessions(principal).length);
+ assertEquals(sessionId2,
+ sessionRegistry.getAllSessions(principal)[1].getSessionId());
+
+ // Expire one session
+ SessionInformation session = sessionRegistry.getSessionInformation(sessionId2);
+ session.expireNow();
+
+ // Check retrieval still correct
+ assertTrue(sessionRegistry.getSessionInformation(sessionId2).isExpired());
+ assertFalse(sessionRegistry.getSessionInformation(sessionId1).isExpired());
+ }
+
public void testTwoSessionsOnePrincipalHandling() throws Exception {
Object principal = "Some principal object";
String sessionId1 = "1234567890";
@@ -124,32 +168,4 @@ public class SessionRegistryImplTests extends TestCase {
assertNull(sessionRegistry.getSessionInformation(sessionId2));
assertNull(sessionRegistry.getAllSessions(principal));
}
-
- public void testTwoSessionsOnePrincipalExpiring() throws Exception {
- Object principal = "Some principal object";
- String sessionId1 = "1234567890";
- String sessionId2 = "9876543210";
- SessionRegistryImpl sessionRegistry = new SessionRegistryImpl();
-
- // Register new Session
- sessionRegistry.registerNewSession(sessionId1, principal);
- assertEquals(1, sessionRegistry.getAllSessions(principal).length);
- assertEquals(sessionId1,
- sessionRegistry.getAllSessions(principal)[0].getSessionId());
-
- // Register new Session
- sessionRegistry.registerNewSession(sessionId2, principal);
- assertEquals(2, sessionRegistry.getAllSessions(principal).length);
- assertEquals(sessionId2,
- sessionRegistry.getAllSessions(principal)[1].getSessionId());
-
- // Expire one session
- SessionInformation session = sessionRegistry.getSessionInformation(sessionId2);
- session.expireNow();
-
- // Check retrieval still correct
- assertTrue(sessionRegistry.getSessionInformation(sessionId2).isExpired());
- assertFalse(sessionRegistry.getSessionInformation(sessionId1).isExpired());
- }
-
}