geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r592223 - in /geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security: ./ jaas/
Date Tue, 06 Nov 2007 01:48:35 GMT
Author: djencks
Date: Mon Nov  5 17:48:34 2007
New Revision: 592223

URL: http://svn.apache.org/viewvc?rev=592223&view=rev
Log:
GERONIMO-3570 GERONIMO-3571 GERONIMO-3575 Provide an AbstractLoginModuleTest to uniformize
test setup and make it easier to determine if all relevant tests have been supplied.

Added:
    geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/AbstractLoginModuleTest.java
  (with props)
Removed:
    geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginCertificatePropertiesFileAdvancedTest.java
    geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginPropertiesFileAdvancedTest.java
    geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginSQLAdvancedTest.java
Modified:
    geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/AbstractTest.java
    geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginCertificatePropertiesFileTest.java
    geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginPropertiesFileTest.java
    geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginSQLTest.java

Modified: geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/AbstractTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/AbstractTest.java?rev=592223&r1=592222&r2=592223&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/AbstractTest.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/AbstractTest.java
Mon Nov  5 17:48:34 2007
@@ -69,7 +69,7 @@
         if (needServerInfo) {
             gbean = buildGBeanData("name", "ServerInfo", BasicServerInfo.GBEAN_INFO);
             serverInfo = gbean.getAbstractName();
-            gbean.setAttribute("baseDirectory", ".");
+            gbean.setAttribute("baseDirectory", BASEDIR.getAbsolutePath());
             kernel.loadGBean(gbean, ServerInfo.class.getClassLoader());
             kernel.startGBean(serverInfo);
         }

Added: geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/AbstractLoginModuleTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/AbstractLoginModuleTest.java?rev=592223&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/AbstractLoginModuleTest.java
(added)
+++ geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/AbstractLoginModuleTest.java
Mon Nov  5 17:48:34 2007
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 javax.management.MalformedObjectNameException;
+
+import org.apache.geronimo.security.AbstractTest;
+import org.apache.geronimo.security.realm.GenericSecurityRealm;
+import org.apache.geronimo.gbean.GBeanData;
+import org.apache.geronimo.gbean.AbstractName;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public abstract class AbstractLoginModuleTest extends AbstractTest {
+    protected static final String SIMPLE_REALM = "simple-realm";
+    protected static final String COMPLEX_REALM = "complex-realm";
+    protected AbstractName clientCE;
+    protected AbstractName testCE;
+    protected AbstractName testRealm;
+    protected AbstractName testRealm2;
+    protected AbstractName neverFailModule;
+
+    public void setUp() throws Exception {
+        needServerInfo = true;
+        needLoginConfiguration = true;
+        super.setUp();
+
+        GBeanData gbean;
+
+        gbean = setupTestLoginModule();
+        testCE = gbean.getAbstractName();
+        kernel.loadGBean(gbean, LoginModuleGBean.class.getClassLoader());
+
+        gbean = buildGBeanData("name", "PropertiesLoginModuleUse", JaasLoginModuleUse.getGBeanInfo());
+        AbstractName testUseName = gbean.getAbstractName();
+        gbean.setAttribute("controlFlag", LoginModuleControlFlag.REQUIRED);
+        gbean.setReferencePattern("LoginModule", testCE);
+        kernel.loadGBean(gbean, JaasLoginModuleUse.class.getClassLoader());
+
+        gbean = buildGBeanData("name", "PropertiesSecurityRealm", GenericSecurityRealm.getGBeanInfo());
+        testRealm = gbean.getAbstractName();
+        gbean.setAttribute("realmName", SIMPLE_REALM);
+        gbean.setAttribute("wrapPrincipals", Boolean.TRUE);
+        gbean.setReferencePattern("LoginModuleConfiguration", testUseName);
+        gbean.setReferencePattern("ServerInfo", serverInfo);
+        kernel.loadGBean(gbean, GenericSecurityRealm.class.getClassLoader());
+
+        gbean = buildGBeanData("name", "NeverFailLoginModule", LoginModuleGBean.getGBeanInfo());
+        neverFailModule = gbean.getAbstractName();
+        gbean.setAttribute("loginModuleClass", "org.apache.geronimo.security.jaas.NeverFailLoginModule");
+        gbean.setAttribute("options", null);
+        gbean.setAttribute("loginDomainName", "NeverFailDomain");
+        gbean.setAttribute("wrapPrincipals", Boolean.TRUE);
+        kernel.loadGBean(gbean, LoginModuleGBean.class.getClassLoader());
+        kernel.startGBean(neverFailModule);
+
+        gbean = buildGBeanData("name", "PropertiesLoginModuleUse2", JaasLoginModuleUse.getGBeanInfo());
+        AbstractName propsUseName = gbean.getAbstractName();
+        gbean.setAttribute("controlFlag", LoginModuleControlFlag.OPTIONAL);
+        gbean.setReferencePattern("LoginModule", testCE);
+        kernel.loadGBean(gbean, JaasLoginModuleUse.class.getClassLoader());
+        kernel.startGBean(propsUseName);
+
+        gbean = buildGBeanData("name", "NeverFailLoginModuleUse", JaasLoginModuleUse.getGBeanInfo());
+        AbstractName neverFailUseName = gbean.getAbstractName();
+        gbean.setAttribute("controlFlag", LoginModuleControlFlag.REQUIRED);
+        gbean.setReferencePattern("LoginModule", neverFailModule);
+        gbean.setReferencePattern("Next", propsUseName);
+        kernel.loadGBean(gbean, JaasLoginModuleUse.class.getClassLoader());
+        kernel.startGBean(neverFailUseName);
+
+        gbean = buildGBeanData("name", "PropertiesSecurityRealm2", GenericSecurityRealm.getGBeanInfo());
+        testRealm2 = gbean.getAbstractName();
+        gbean.setAttribute("realmName", COMPLEX_REALM);
+        gbean.setAttribute("wrapPrincipals", Boolean.TRUE);
+        gbean.setReferencePattern("LoginModuleConfiguration", neverFailUseName);
+        gbean.setReferencePattern("ServerInfo", serverInfo);
+        kernel.loadGBean(gbean, GenericSecurityRealm.class.getClassLoader());
+
+        kernel.startGBean(loginConfiguration);
+        kernel.startGBean(testCE);
+        kernel.startGBean(testUseName);
+        kernel.startGBean(testRealm);
+
+        kernel.startGBean(neverFailModule);
+        kernel.startGBean(neverFailUseName);
+        kernel.startGBean(propsUseName);
+        kernel.startGBean(testRealm2);
+    }
+
+    protected abstract GBeanData setupTestLoginModule() throws Exception;
+
+    public void tearDown() throws Exception {
+        kernel.stopGBean(testRealm);
+        kernel.stopGBean(testCE);
+        kernel.stopGBean(neverFailModule);
+        kernel.stopGBean(loginConfiguration);
+        kernel.stopGBean(serverInfo);
+
+        kernel.unloadGBean(testCE);
+        kernel.unloadGBean(testRealm);
+        kernel.unloadGBean(loginConfiguration);
+        kernel.unloadGBean(serverInfo);
+
+        super.tearDown();
+    }
+
+    public abstract void testLogin() throws Exception;
+
+    public abstract void testNullUserLogin() throws Exception;
+
+    public abstract void testBadUserLogin() throws Exception;
+
+    public abstract void testNullPasswordLogin() throws Exception;
+
+    public abstract void testBadPasswordLogin() throws Exception;
+
+    public abstract void testNoPrincipalsAddedOnFailure() throws Exception;
+}

Propchange: geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/AbstractLoginModuleTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/AbstractLoginModuleTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/AbstractLoginModuleTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginCertificatePropertiesFileTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginCertificatePropertiesFileTest.java?rev=592223&r1=592222&r2=592223&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginCertificatePropertiesFileTest.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginCertificatePropertiesFileTest.java
Mon Nov  5 17:48:34 2007
@@ -27,6 +27,7 @@
 import javax.security.auth.Subject;
 import javax.security.auth.login.LoginContext;
 import javax.security.auth.login.LoginException;
+import javax.management.MalformedObjectNameException;
 
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.GBeanData;
@@ -43,7 +44,7 @@
  * 
  * @version $Rev$ $Date$
  */
-public class LoginCertificatePropertiesFileTest extends AbstractTest {
+public class LoginCertificatePropertiesFileTest extends AbstractLoginModuleTest {
     protected AbstractName clientCE;
     protected AbstractName testCE;
     protected AbstractName testRealm;
@@ -70,6 +71,7 @@
                         +"PjUnrEF1laqhX4Rx+2u56VBA2SBnEaeADawaXWkD\n"
                         +"-----END CERTIFICATE-----";
 
+/*
     public void setUp() throws Exception {
         needServerInfo = true;
         needLoginConfiguration = true;
@@ -111,24 +113,28 @@
         cert = (X509Certificate) certFac.generateCertificate(new ByteArrayInputStream(certText.getBytes()));
         badCert = (X509Certificate) certFac.generateCertificate(new ByteArrayInputStream(badCertText.getBytes()));
     }
+*/
 
-    public void tearDown() throws Exception {
-        kernel.stopGBean(testRealm);
-        kernel.stopGBean(testCE);
-        kernel.stopGBean(loginConfiguration);
-        kernel.stopGBean(serverInfo);
-
-        kernel.unloadGBean(testCE);
-        kernel.unloadGBean(testRealm);
-        kernel.unloadGBean(loginConfiguration);
-        kernel.unloadGBean(serverInfo);
+    protected GBeanData setupTestLoginModule() throws Exception {
+        CertificateFactory certFac = CertificateFactory.getInstance("X.509");
+        cert = (X509Certificate) certFac.generateCertificate(new ByteArrayInputStream(certText.getBytes()));
+        badCert = (X509Certificate) certFac.generateCertificate(new ByteArrayInputStream(badCertText.getBytes()));
 
-        super.tearDown();
+        GBeanData gbean = buildGBeanData("name", "CertificatePropertiesLoginModule", LoginModuleGBean.getGBeanInfo());
+        testCE = gbean.getAbstractName();
+        gbean.setAttribute("loginModuleClass", "org.apache.geronimo.security.realm.providers.CertificatePropertiesFileLoginModule");
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put("usersURI", "src/test/data/data/cert-users.properties");
+        props.put("groupsURI", "src/test/data/data/groups.properties");
+        gbean.setAttribute("options", props);
+        gbean.setAttribute("loginDomainName", "CertProperties");
+        gbean.setAttribute("wrapPrincipals", Boolean.TRUE);
+        return gbean;
     }
 
     public void testLogin() throws Exception {
 
-        LoginContext context = new LoginContext("cert-properties-realm", new CertCallback(cert));
+        LoginContext context = new LoginContext(SIMPLE_REALM, new CertCallback(cert));
 
         context.login();
         Subject subject = context.getSubject();
@@ -144,8 +150,8 @@
         assertTrue("id of server subject should be null", ContextManager.getSubjectId(subject)
== null);
     }
 
-    public void testNullCertificateLogin() throws Exception {
-        LoginContext context = new LoginContext("cert-properties-realm", new CertCallback(null));
+    public void testNullUserLogin() throws Exception {
+        LoginContext context = new LoginContext(SIMPLE_REALM, new CertCallback(null));
 
         try {
             context.login();
@@ -154,8 +160,8 @@
         }
     }
 
-    public void testBadUserCertificate() throws Exception {
-        LoginContext context = new LoginContext("cert-properties-realm", new CertCallback(badCert));
+    public void testBadUserLogin() throws Exception {
+        LoginContext context = new LoginContext(SIMPLE_REALM, new CertCallback(badCert));
 
         try {
             context.login();
@@ -163,4 +169,23 @@
         } catch (LoginException e) {
         }
     }
+
+    public void testNullPasswordLogin() throws Exception {
+        //not relevant
+    }
+
+    public void testBadPasswordLogin() throws Exception {
+        //not relevant
+    }
+
+    public void testNoPrincipalsAddedOnFailure() throws Exception {
+        LoginContext context = new LoginContext(COMPLEX_REALM, new CertCallback(badCert));
+
+        context.login();
+        Subject subject = context.getSubject();
+        assertTrue("expected non-null subject", subject != null);
+        assertEquals("expected zero principals", 0, subject.getPrincipals().size());
+        context.logout();
+    }
+
 }

Modified: geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginPropertiesFileTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginPropertiesFileTest.java?rev=592223&r1=592222&r2=592223&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginPropertiesFileTest.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginPropertiesFileTest.java
Mon Nov  5 17:48:34 2007
@@ -24,6 +24,7 @@
 import javax.security.auth.Subject;
 import javax.security.auth.login.LoginContext;
 import javax.security.auth.login.LoginException;
+import javax.management.MalformedObjectNameException;
 
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.GBeanData;
@@ -38,66 +39,24 @@
 /**
  * @version $Rev$ $Date$
  */
-public class LoginPropertiesFileTest extends AbstractTest {
-    protected AbstractName clientCE;
-    protected AbstractName testCE;
-    protected AbstractName testRealm;
-
-    public void setUp() throws Exception {
-        needServerInfo = true;
-        needLoginConfiguration = true;
-        super.setUp();
+public class LoginPropertiesFileTest extends AbstractLoginModuleTest {
 
+    protected GBeanData setupTestLoginModule() throws MalformedObjectNameException {
         GBeanData gbean;
-
         gbean = buildGBeanData("name", "PropertiesLoginModule", LoginModuleGBean.getGBeanInfo());
-        testCE = gbean.getAbstractName();
         gbean.setAttribute("loginModuleClass", "org.apache.geronimo.security.realm.providers.PropertiesFileLoginModule");
         Map<String, Object> props = new HashMap<String, Object>();
-        props.put("usersURI", new File(BASEDIR, "src/test/data/data/users.properties").toURI().toString());
-        props.put("groupsURI", new File(BASEDIR, "src/test/data/data/groups.properties").toURI().toString());
+        props.put("usersURI", "src/test/data/data/users.properties");
+        props.put("groupsURI", "src/test/data/data/groups.properties");
         gbean.setAttribute("options", props);
         gbean.setAttribute("loginDomainName", "TestProperties");
         gbean.setAttribute("wrapPrincipals", Boolean.TRUE);
-        kernel.loadGBean(gbean, LoginModuleGBean.class.getClassLoader());
-
-        gbean = buildGBeanData("name", "PropertiesLoginModuleUse", JaasLoginModuleUse.getGBeanInfo());
-        AbstractName testUseName = gbean.getAbstractName();
-        gbean.setAttribute("controlFlag", LoginModuleControlFlag.REQUIRED);
-        gbean.setReferencePattern("LoginModule", testCE);
-        kernel.loadGBean(gbean, JaasLoginModuleUse.class.getClassLoader());
-
-        gbean = buildGBeanData("name", "PropertiesSecurityRealm", GenericSecurityRealm.getGBeanInfo());
-        testRealm = gbean.getAbstractName();
-        gbean.setAttribute("realmName", "properties-realm");
-        gbean.setAttribute("wrapPrincipals", Boolean.TRUE);
-        gbean.setReferencePattern("LoginModuleConfiguration", testUseName);
-        gbean.setReferencePattern("ServerInfo", serverInfo);
-        kernel.loadGBean(gbean, GenericSecurityRealm.class.getClassLoader());
-
-        kernel.startGBean(loginConfiguration);
-        kernel.startGBean(testCE);
-        kernel.startGBean(testUseName);
-        kernel.startGBean(testRealm);
-    }
-
-    public void tearDown() throws Exception {
-        kernel.stopGBean(testRealm);
-        kernel.stopGBean(testCE);
-        kernel.stopGBean(loginConfiguration);
-        kernel.stopGBean(serverInfo);
-
-        kernel.unloadGBean(testCE);
-        kernel.unloadGBean(testRealm);
-        kernel.unloadGBean(loginConfiguration);
-        kernel.unloadGBean(serverInfo);
-
-        super.tearDown();
+        return gbean;
     }
 
     public void testLogin() throws Exception {
 
-        LoginContext context = new LoginContext("properties-realm", new AbstractTest.UsernamePasswordCallback("alan",
"starcraft"));
+        LoginContext context = new LoginContext(SIMPLE_REALM, new AbstractTest.UsernamePasswordCallback("alan",
"starcraft"));
 
         context.login();
         Subject subject = context.getSubject();
@@ -114,7 +73,7 @@
     }
 
     public void testNullUserLogin() throws Exception {
-        LoginContext context = new LoginContext("properties-realm", new UsernamePasswordCallback(null,
"starcraft"));
+        LoginContext context = new LoginContext(SIMPLE_REALM, new UsernamePasswordCallback(null,
"starcraft"));
 
         try {
             context.login();
@@ -124,7 +83,7 @@
     }
 
     public void testBadUserLogin() throws Exception {
-        LoginContext context = new LoginContext("properties-realm", new UsernamePasswordCallback("bad",
"starcraft"));
+        LoginContext context = new LoginContext(SIMPLE_REALM, new UsernamePasswordCallback("bad",
"starcraft"));
 
         try {
             context.login();
@@ -134,7 +93,7 @@
     }
 
     public void testNullPasswordLogin() throws Exception {
-        LoginContext context = new LoginContext("properties-realm", new UsernamePasswordCallback("alan",
null));
+        LoginContext context = new LoginContext(SIMPLE_REALM, new UsernamePasswordCallback("alan",
null));
 
         try {
             context.login();
@@ -144,7 +103,7 @@
     }
 
     public void testBadPasswordLogin() throws Exception {
-        LoginContext context = new LoginContext("properties-realm", new UsernamePasswordCallback("alan",
"bad"));
+        LoginContext context = new LoginContext(SIMPLE_REALM, new UsernamePasswordCallback("alan",
"bad"));
 
         try {
             context.login();
@@ -152,4 +111,15 @@
         } catch (LoginException e) {
         }
     }
+
+    public void testNoPrincipalsAddedOnFailure() throws Exception {
+        LoginContext context = new LoginContext(COMPLEX_REALM, new UsernamePasswordCallback("alan",
"bad"));
+
+        context.login();
+        Subject subject = context.getSubject();
+        assertTrue("expected non-null subject", subject != null);
+        assertTrue("expected zero principals", subject.getPrincipals().size() == 0);
+        context.logout();
+    }
+
 }

Modified: geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginSQLTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginSQLTest.java?rev=592223&r1=592222&r2=592223&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginSQLTest.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginSQLTest.java
Mon Nov  5 17:48:34 2007
@@ -28,29 +28,18 @@
 import javax.security.auth.login.LoginContext;
 import javax.security.auth.login.LoginException;
 
-import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.GBeanData;
-import org.apache.geronimo.security.AbstractTest;
-import org.apache.geronimo.security.ContextManager;
 import org.apache.geronimo.security.DomainPrincipal;
-import org.apache.geronimo.security.IdentificationPrincipal;
 import org.apache.geronimo.security.RealmPrincipal;
-import org.apache.geronimo.security.realm.GenericSecurityRealm;
 
 
 /**
  * @version $Rev$ $Date$
  */
-public class LoginSQLTest extends AbstractTest {
-    private File basedir = new File(System.getProperty("basedir"));
-    private String hsqldbURL = "jdbc:hsqldb:" + new File(basedir, "target/database/LoginSQLTest");
-    
-    protected AbstractName sqlRealm;
-    protected AbstractName sqlModule;
-
-    public void setUp() throws Exception {
-        super.setUp();
+public class LoginSQLTest extends AbstractLoginModuleTest {
+    private String hsqldbURL = "jdbc:hsqldb:" + new File(BASEDIR, "target/database/LoginSQLTest");
 
+    protected GBeanData setupTestLoginModule() throws Exception {
         DriverManager.registerDriver(new org.hsqldb.jdbcDriver());
 
         Connection conn = DriverManager.getConnection(hsqldbURL, "sa", "");
@@ -86,7 +75,6 @@
         conn.close();
 
         GBeanData gbean = buildGBeanData("name", "SQLLoginModule", LoginModuleGBean.getGBeanInfo());
-        sqlModule = gbean.getAbstractName();
         gbean.setAttribute("loginModuleClass", "org.apache.geronimo.security.realm.providers.SQLLoginModule");
         Map<String, Object> props = new HashMap<String, Object>();
         props.put("jdbcURL", hsqldbURL);
@@ -98,30 +86,11 @@
         gbean.setAttribute("options", props);
         gbean.setAttribute("loginDomainName", "SQLDomain");
         gbean.setAttribute("wrapPrincipals", Boolean.TRUE);
-        kernel.loadGBean(gbean, LoginModuleGBean.class.getClassLoader());
-        kernel.startGBean(sqlModule);
-
-        gbean = buildGBeanData("name", "SQLLoginModuleUse", JaasLoginModuleUse.getGBeanInfo());
-        AbstractName testUseName = gbean.getAbstractName();
-        gbean.setAttribute("controlFlag", LoginModuleControlFlag.REQUIRED);
-        gbean.setReferencePattern("LoginModule", sqlModule);
-        kernel.loadGBean(gbean, JaasLoginModuleUse.class.getClassLoader());
-        kernel.startGBean(testUseName);
-
-        gbean = buildGBeanData("name", "SQLSecurityRealm", GenericSecurityRealm.getGBeanInfo());
-        sqlRealm = gbean.getAbstractName();
-        gbean.setAttribute("realmName", "sql-realm");
-        gbean.setReferencePattern("LoginModuleConfiguration", testUseName);
-        kernel.loadGBean(gbean, GenericSecurityRealm.class.getClassLoader());
-        kernel.startGBean(sqlRealm);
-
+        return gbean;
     }
 
     public void tearDown() throws Exception {
-        kernel.stopGBean(sqlRealm);
-        kernel.stopGBean(sqlModule);
-        kernel.unloadGBean(sqlRealm);
-        kernel.unloadGBean(sqlModule);
+
 
         super.tearDown();
 
@@ -132,6 +101,7 @@
 
             conn.prepareStatement("DROP TABLE Users;").executeUpdate();
             conn.prepareStatement("DROP TABLE Groups;").executeUpdate();
+            conn.close();
         } catch (SQLException e) {
             //who knows??
         }
@@ -139,7 +109,7 @@
     }
 
     public void testLogin() throws Exception {
-        LoginContext context = new LoginContext("sql-realm", new UsernamePasswordCallback("alan",
"starcraft"));
+        LoginContext context = new LoginContext(SIMPLE_REALM, new UsernamePasswordCallback("alan",
"starcraft"));
 
         context.login();
         Subject subject = context.getSubject();
@@ -152,7 +122,7 @@
     }
 
     public void testNullUserLogin() throws Exception {
-        LoginContext context = new LoginContext("sql-realm", new UsernamePasswordCallback(null,
"starcraft"));
+        LoginContext context = new LoginContext(SIMPLE_REALM, new UsernamePasswordCallback(null,
"starcraft"));
 
         try {
             context.login();
@@ -162,7 +132,7 @@
     }
 
     public void testBadUserLogin() throws Exception {
-        LoginContext context = new LoginContext("sql-realm", new UsernamePasswordCallback("bad",
"starcraft"));
+        LoginContext context = new LoginContext(SIMPLE_REALM, new UsernamePasswordCallback("bad",
"starcraft"));
     
         try {
             context.login();
@@ -172,7 +142,7 @@
     }
 
     public void testNullPasswordLogin() throws Exception {
-        LoginContext context = new LoginContext("sql-realm", new UsernamePasswordCallback("alan",
null));
+        LoginContext context = new LoginContext(SIMPLE_REALM, new UsernamePasswordCallback("alan",
null));
 
         try {
             context.login();
@@ -182,12 +152,22 @@
     }
 
     public void testBadPasswordLogin() throws Exception {
-        LoginContext context = new LoginContext("sql-realm", new UsernamePasswordCallback("alan",
"bad"));
+        LoginContext context = new LoginContext(SIMPLE_REALM, new UsernamePasswordCallback("alan",
"bad"));
 
         try {
             context.login();
             fail("Should not allow this login with bad password");
         } catch (LoginException e) {
         }
+    }
+
+    public void testNoPrincipalsAddedOnFailure() throws Exception {
+        LoginContext context = new LoginContext(COMPLEX_REALM, new UsernamePasswordCallback("alan",
"bad"));
+
+        context.login();
+        Subject subject = context.getSubject();
+        assertTrue("expected non-null subject", subject != null);
+        assertTrue(subject.getPrincipals().size() == 0);
+        context.logout();
     }
 }



Mime
View raw message