geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r225798 - in /geronimo/branches/v1_0_M4-QA/modules/security/src/test/org/apache/geronimo/security/jaas: MultipleLoginDomainTest.java NoLoginModuleReuseTest.java
Date Thu, 28 Jul 2005 15:23:11 GMT
Author: djencks
Date: Thu Jul 28 08:23:07 2005
New Revision: 225798

URL: http://svn.apache.org/viewcvs?rev=225798&view=rev
Log:
GERONIMO-677 simple test, fix up multiple login domains test

Added:
    geronimo/branches/v1_0_M4-QA/modules/security/src/test/org/apache/geronimo/security/jaas/NoLoginModuleReuseTest.java
Modified:
    geronimo/branches/v1_0_M4-QA/modules/security/src/test/org/apache/geronimo/security/jaas/MultipleLoginDomainTest.java

Modified: geronimo/branches/v1_0_M4-QA/modules/security/src/test/org/apache/geronimo/security/jaas/MultipleLoginDomainTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/v1_0_M4-QA/modules/security/src/test/org/apache/geronimo/security/jaas/MultipleLoginDomainTest.java?rev=225798&r1=225797&r2=225798&view=diff
==============================================================================
--- geronimo/branches/v1_0_M4-QA/modules/security/src/test/org/apache/geronimo/security/jaas/MultipleLoginDomainTest.java
(original)
+++ geronimo/branches/v1_0_M4-QA/modules/security/src/test/org/apache/geronimo/security/jaas/MultipleLoginDomainTest.java
Thu Jul 28 08:23:07 2005
@@ -38,29 +38,22 @@
      * The crucial line is commented out so as to avoid breaking the build.
      * @throws Exception
      */
-    public void XtestMultipleLoginDomains() throws Exception {
+    public void testMultipleLoginDomains() throws Exception {
         JaasLoginModuleConfiguration m1 = new JaasLoginModuleConfiguration(MockLoginModule.class.getName(),
LoginModuleControlFlag.REQUIRED, new HashMap(), true, "D1");
         JaasLoginModuleConfiguration m2 = new JaasLoginModuleConfiguration(MockLoginModule.class.getName(),
LoginModuleControlFlag.REQUIRED, new HashMap(), true, "D2");
-        JaasLoginModuleConfiguration m3 = new JaasLoginModuleConfiguration(MockLoginModule2.class.getName(),
LoginModuleControlFlag.REQUIRED, new HashMap(), true, "D3");
         JaasSecurityContext c = new JaasSecurityContext("realm", new JaasLoginModuleConfiguration[]
{m1, m2}, this.getClass().getClassLoader());
-        ClassLoader cl = this.getClass().getClassLoader();
         Subject s = c.getSubject();
-        m1.getLoginModule(cl).initialize(s, null, null, null);
-        m2.getLoginModule(cl).initialize(s, null, null, null);
-        m3.getLoginModule(cl).initialize(s, null, null, null);
-        m1.getLoginModule(cl).login();
-        m2.getLoginModule(cl).login();
-        m3.getLoginModule(cl).login();
-        m1.getLoginModule(cl).commit();
+        c.getLoginModule(0).initialize(s, null, null, null);
+        c.getLoginModule(1).initialize(s, null, null, null);
+        c.getLoginModule(0).login();
+        c.getLoginModule(1).login();
+        c.getLoginModule(0).commit();
         c.processPrincipals("D1");
         assertEquals(2, s.getPrincipals().size());
-        m2.getLoginModule(cl).commit();
+        c.getLoginModule(1).commit();
         c.processPrincipals("D2");
         //Uncomment the following line to verify that the subject will have only 2 principals
rather than the desired 3 after both
         //login modules have tried to add the same principal to the subject.
-        assertEquals(3, s.getPrincipals().size());
-        c.processPrincipals("D3");
-        //algorithmm is still broken, as can be seen by uncommenting the next line
 //        assertEquals(3, s.getPrincipals().size());
     }
 
@@ -90,28 +83,4 @@
         }
     }
 
-    public static class MockLoginModule2 implements LoginModule {
-
-        Subject subject;
-
-        public void initialize(Subject subject, CallbackHandler callbackHandler, Map map,
Map map1) {
-            this.subject = subject;
-        }
-
-        public boolean login() throws LoginException {
-            return true;
-        }
-
-        public boolean commit() throws LoginException {
-            return true;
-        }
-
-        public boolean abort() throws LoginException {
-            return false;
-        }
-
-        public boolean logout() throws LoginException {
-            return false;
-        }
-    }
 }

Added: geronimo/branches/v1_0_M4-QA/modules/security/src/test/org/apache/geronimo/security/jaas/NoLoginModuleReuseTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/v1_0_M4-QA/modules/security/src/test/org/apache/geronimo/security/jaas/NoLoginModuleReuseTest.java?rev=225798&view=auto
==============================================================================
--- geronimo/branches/v1_0_M4-QA/modules/security/src/test/org/apache/geronimo/security/jaas/NoLoginModuleReuseTest.java
(added)
+++ geronimo/branches/v1_0_M4-QA/modules/security/src/test/org/apache/geronimo/security/jaas/NoLoginModuleReuseTest.java
Thu Jul 28 08:23:07 2005
@@ -0,0 +1,81 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  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 org.apache.geronimo.security.jaas;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.security.auth.Subject;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.login.LoginException;
+import javax.security.auth.spi.LoginModule;
+
+import junit.framework.TestCase;
+
+import org.apache.geronimo.security.realm.providers.GeronimoGroupPrincipal;
+
+/**
+ * @version $Rev:  $ $Date:  $
+ */
+public class NoLoginModuleReuseTest extends TestCase {
+
+    public void testNoLoginModuleReuse() throws Exception {
+        JaasLoginModuleConfiguration m1 = new JaasLoginModuleConfiguration(MockLoginModule.class.getName(),
LoginModuleControlFlag.REQUIRED, new HashMap(), true, "D1");
+        doSecurityContextLogin(m1);
+        doSecurityContextLogin(m1);
+    }
+
+    private void doSecurityContextLogin(JaasLoginModuleConfiguration m1) throws LoginException
{
+        JaasSecurityContext c = new JaasSecurityContext("realm", new JaasLoginModuleConfiguration[]
{m1}, this.getClass().getClassLoader());
+        Subject s = c.getSubject();
+        c.getLoginModule(0).initialize(s, null, null, null);
+        c.getLoginModule(0).login();
+        c.getLoginModule(0).commit();
+        c.processPrincipals("D1");
+    }
+
+    public static class MockLoginModule implements LoginModule {
+
+        private Subject subject;
+        private boolean used = false;
+
+        public void initialize(Subject subject, CallbackHandler callbackHandler, Map map,
Map map1) {
+            this.subject = subject;
+        }
+
+        public boolean login() throws LoginException {
+            if (used) {
+                throw new LoginException("already used");
+            }
+            used = true;
+            return true;
+        }
+
+        public boolean commit() throws LoginException {
+            subject.getPrincipals().add(new GeronimoGroupPrincipal("Foo"));
+            return true;
+        }
+
+        public boolean abort() throws LoginException {
+            return false;
+        }
+
+        public boolean logout() throws LoginException {
+            return false;
+        }
+    }
+
+}



Mime
View raw message