geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vamsic...@apache.org
Subject svn commit: r597830 - in /geronimo/server: branches/2.0/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/ trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/
Date Sat, 24 Nov 2007 09:17:32 GMT
Author: vamsic007
Date: Sat Nov 24 01:17:31 2007
New Revision: 597830

URL: http://svn.apache.org/viewvc?rev=597830&view=rev
Log:
GERONIMO-3625 Review WrappingLoginModule
 o Moving principal wrapping tests to a different testcase.

Added:
    geronimo/server/branches/2.0/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/WrappingLoginModuleTest.java
  (with props)
    geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/WrappingLoginModuleTest.java
  (with props)
Modified:
    geronimo/server/branches/2.0/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginCertificatePropertiesFileTest.java
    geronimo/server/branches/2.0/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginPropertiesFileTest.java
    geronimo/server/branches/2.0/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginSQLTest.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/branches/2.0/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginCertificatePropertiesFileTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.0/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginCertificatePropertiesFileTest.java?rev=597830&r1=597829&r2=597830&view=diff
==============================================================================
--- geronimo/server/branches/2.0/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginCertificatePropertiesFileTest.java
(original)
+++ geronimo/server/branches/2.0/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginCertificatePropertiesFileTest.java
Sat Nov 24 01:17:31 2007
@@ -30,9 +30,7 @@
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.security.ContextManager;
-import org.apache.geronimo.security.DomainPrincipal;
 import org.apache.geronimo.security.IdentificationPrincipal;
-import org.apache.geronimo.security.RealmPrincipal;
 
 
 /**
@@ -80,7 +78,7 @@
         props.put("groupsURI", "src/test/data/data/groups.properties");
         gbean.setAttribute("options", props);
         gbean.setAttribute("loginDomainName", "CertProperties");
-        gbean.setAttribute("wrapPrincipals", Boolean.TRUE);
+        gbean.setAttribute("wrapPrincipals", Boolean.FALSE);
         return gbean;
     }
 
@@ -92,14 +90,12 @@
         Subject subject = context.getSubject();
 
         assertTrue("expected non-null subject", subject != null);
-        assertTrue("subject should have no remote principal", subject.getPrincipals(IdentificationPrincipal.class).size()
== 0);
-        assertEquals("subject should have 9 principals (" + subject.getPrincipals().size()
+ ")", 9, subject.getPrincipals().size());
-        assertEquals("subject should have 3 realm principals (" + subject.getPrincipals(RealmPrincipal.class).size()
+ ")", 3, subject.getPrincipals(RealmPrincipal.class).size());
-        assertEquals("subject should have 3 domain principals (" + subject.getPrincipals(DomainPrincipal.class).size()
+ ")", 3, subject.getPrincipals(DomainPrincipal.class).size());
+        assertEquals("Remote principals", 0, subject.getPrincipals(IdentificationPrincipal.class).size());
+        assertEquals("Principals", 3, subject.getPrincipals().size());
 
         context.logout();
-        assertEquals("subject should have no principals (" + subject.getPrincipals().size()
+ ")", 0, subject.getPrincipals().size());
-
+        assertEquals("Principals upon logout", 0, subject.getPrincipals().size());
+ 
         assertTrue("id of server subject should be null", ContextManager.getSubjectId(subject)
== null);
     }
 
@@ -137,7 +133,7 @@
         context.login();
         Subject subject = context.getSubject();
         assertTrue("expected non-null subject", subject != null);
-        assertEquals("expected zero principals", 0, subject.getPrincipals().size());
+        assertEquals("Principals added upon failed login", 0, subject.getPrincipals().size());
         context.logout();
     }
 

Modified: geronimo/server/branches/2.0/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginPropertiesFileTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.0/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginPropertiesFileTest.java?rev=597830&r1=597829&r2=597830&view=diff
==============================================================================
--- geronimo/server/branches/2.0/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginPropertiesFileTest.java
(original)
+++ geronimo/server/branches/2.0/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginPropertiesFileTest.java
Sat Nov 24 01:17:31 2007
@@ -50,7 +50,7 @@
         props.put("groupsURI", "src/test/data/data/groups.properties");
         gbean.setAttribute("options", props);
         gbean.setAttribute("loginDomainName", "TestProperties");
-        gbean.setAttribute("wrapPrincipals", Boolean.TRUE);
+        gbean.setAttribute("wrapPrincipals", Boolean.FALSE);
         return gbean;
     }
 
@@ -62,13 +62,11 @@
         Subject subject = context.getSubject();
 
         assertTrue("expected non-null subject", subject != null);
-        assertTrue("subject should have no remote principal", subject.getPrincipals(IdentificationPrincipal.class).size()
== 0);
-        assertEquals("subject should have 6 principals (" + subject.getPrincipals().size()
+ ")", 6, subject.getPrincipals().size());
-        assertEquals("subject should have 2 realm principals (" + subject.getPrincipals(RealmPrincipal.class).size()
+ ")", 2, subject.getPrincipals(RealmPrincipal.class).size());
-        assertEquals("subject should have 2 domain principals (" + subject.getPrincipals(DomainPrincipal.class).size()
+ ")", 2, subject.getPrincipals(DomainPrincipal.class).size());
+        assertEquals("Remote principals", 0, subject.getPrincipals(IdentificationPrincipal.class).size());
+        assertEquals("Principals", 2, subject.getPrincipals().size());
 
         context.logout();
-        assertEquals("subject should have no principals (" + subject.getPrincipals().size()
+ ")", 0, subject.getPrincipals().size());
+        assertEquals("Principals upon logout", 0, subject.getPrincipals().size());
  
         assertTrue("id of server subject should be null", ContextManager.getSubjectId(subject)
== null);
     }
@@ -119,7 +117,7 @@
         context.login();
         Subject subject = context.getSubject();
         assertTrue("expected non-null subject", subject != null);
-        assertTrue("expected zero principals", subject.getPrincipals().size() == 0);
+        assertEquals("Principals added upon failed login", 0, subject.getPrincipals().size());
         context.logout();
     }
 

Modified: geronimo/server/branches/2.0/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginSQLTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.0/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginSQLTest.java?rev=597830&r1=597829&r2=597830&view=diff
==============================================================================
--- geronimo/server/branches/2.0/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginSQLTest.java
(original)
+++ geronimo/server/branches/2.0/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/LoginSQLTest.java
Sat Nov 24 01:17:31 2007
@@ -29,8 +29,8 @@
 import javax.security.auth.login.LoginException;
 
 import org.apache.geronimo.gbean.GBeanData;
-import org.apache.geronimo.security.DomainPrincipal;
-import org.apache.geronimo.security.RealmPrincipal;
+import org.apache.geronimo.security.ContextManager;
+import org.apache.geronimo.security.IdentificationPrincipal;
 
 
 /**
@@ -85,7 +85,7 @@
         props.put("groupSelect", "SELECT UserName, GroupName FROM Groups where UserName =
?");
         gbean.setAttribute("options", props);
         gbean.setAttribute("loginDomainName", "SQLDomain");
-        gbean.setAttribute("wrapPrincipals", Boolean.TRUE);
+        gbean.setAttribute("wrapPrincipals", Boolean.FALSE);
         return gbean;
     }
 
@@ -114,12 +114,13 @@
         context.login();
         Subject subject = context.getSubject();
         assertTrue("expected non-null subject", subject != null);
-        assertEquals("server-side subject should have 6 principal", 6, subject.getPrincipals().size());
-        assertEquals("server-side subject should have two realm principals", 2, subject.getPrincipals(RealmPrincipal.class).size());
-        assertEquals("server-side subject should have two domain principals", 2, subject.getPrincipals(DomainPrincipal.class).size());
+        assertEquals("Remote principals", 0, subject.getPrincipals(IdentificationPrincipal.class).size());
+        assertEquals("Principals", 2, subject.getPrincipals().size());
 
         context.logout();
-        assertEquals("subject should have no principals (" + subject.getPrincipals().size()
+ ")", 0, subject.getPrincipals().size());
+        assertEquals("Principals upon logout", 0, subject.getPrincipals().size());
+ 
+        assertTrue("id of server subject should be null", ContextManager.getSubjectId(subject)
== null);
     }
 
     public void testNullUserLogin() throws Exception {
@@ -168,7 +169,7 @@
         context.login();
         Subject subject = context.getSubject();
         assertTrue("expected non-null subject", subject != null);
-        assertTrue(subject.getPrincipals().size() == 0);
+        assertEquals("Principals added upon failed login", 0, subject.getPrincipals().size());
         context.logout();
     }
 }

Added: geronimo/server/branches/2.0/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/WrappingLoginModuleTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.0/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/WrappingLoginModuleTest.java?rev=597830&view=auto
==============================================================================
--- geronimo/server/branches/2.0/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/WrappingLoginModuleTest.java
(added)
+++ geronimo/server/branches/2.0/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/WrappingLoginModuleTest.java
Sat Nov 24 01:17:31 2007
@@ -0,0 +1,122 @@
+/**
+ *  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 java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MalformedObjectNameException;
+import javax.security.auth.Subject;
+import javax.security.auth.login.LoginContext;
+import javax.security.auth.login.LoginException;
+
+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;
+
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WrappingLoginModuleTest extends AbstractLoginModuleTest {
+
+    protected GBeanData setupTestLoginModule() throws MalformedObjectNameException {
+        GBeanData gbean;
+        gbean = buildGBeanData("name", "PropertiesLoginModule", LoginModuleGBean.getGBeanInfo());
+        gbean.setAttribute("loginModuleClass", "org.apache.geronimo.security.realm.providers.PropertiesFileLoginModule");
+        Map<String, Object> props = new HashMap<String, Object>();
+        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); // wrapPrincipals should be true
for this test.
+        return gbean;
+    }
+
+    public void testLogin() throws Exception {
+
+        LoginContext context = new LoginContext(SIMPLE_REALM, new AbstractTest.UsernamePasswordCallback("alan",
"starcraft"));
+
+        context.login();
+        Subject subject = context.getSubject();
+
+        assertTrue("expected non-null subject", subject != null);
+        assertEquals("Remote principals", 0, subject.getPrincipals(IdentificationPrincipal.class).size());
+        assertEquals("Principals", 6, subject.getPrincipals().size());
+        assertEquals("Realm principals", 2, subject.getPrincipals(RealmPrincipal.class).size());
+        assertEquals("Domain principals", 2, subject.getPrincipals(DomainPrincipal.class).size());
+
+        context.logout();
+        assertEquals("Principals upon logout", 0, subject.getPrincipals().size());
+ 
+        assertTrue("id of server subject should be null", ContextManager.getSubjectId(subject)
== null);
+    }
+
+    public void testNullUserLogin() throws Exception {
+        LoginContext context = new LoginContext(SIMPLE_REALM, new UsernamePasswordCallback(null,
"starcraft"));
+
+        try {
+            context.login();
+            fail("Should not allow this login with null username");
+        } catch (LoginException e) {
+        }
+    }
+
+    public void testBadUserLogin() throws Exception {
+        LoginContext context = new LoginContext(SIMPLE_REALM, new UsernamePasswordCallback("bad",
"starcraft"));
+
+        try {
+            context.login();
+            fail("Should not allow this login with bad username");
+        } catch (LoginException e) {
+        }
+    }
+
+    public void testNullPasswordLogin() throws Exception {
+        LoginContext context = new LoginContext(SIMPLE_REALM, new UsernamePasswordCallback("alan",
null));
+
+        try {
+            context.login();
+            fail("Should not allow this login with null password");
+        } catch (LoginException e) {
+        }
+    }
+
+    public void testBadPasswordLogin() throws Exception {
+        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("expected zero principals", subject.getPrincipals().size() == 0);
+        context.logout();
+    }
+}

Propchange: geronimo/server/branches/2.0/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/WrappingLoginModuleTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/branches/2.0/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/WrappingLoginModuleTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/branches/2.0/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/WrappingLoginModuleTest.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=597830&r1=597829&r2=597830&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
Sat Nov 24 01:17:31 2007
@@ -30,9 +30,7 @@
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.security.ContextManager;
-import org.apache.geronimo.security.DomainPrincipal;
 import org.apache.geronimo.security.IdentificationPrincipal;
-import org.apache.geronimo.security.RealmPrincipal;
 
 
 /**
@@ -80,7 +78,7 @@
         props.put("groupsURI", "src/test/data/data/groups.properties");
         gbean.setAttribute("options", props);
         gbean.setAttribute("loginDomainName", "CertProperties");
-        gbean.setAttribute("wrapPrincipals", Boolean.TRUE);
+        gbean.setAttribute("wrapPrincipals", Boolean.FALSE);
         return gbean;
     }
 
@@ -92,14 +90,12 @@
         Subject subject = context.getSubject();
 
         assertTrue("expected non-null subject", subject != null);
-        assertTrue("subject should have no remote principal", subject.getPrincipals(IdentificationPrincipal.class).size()
== 0);
-        assertEquals("subject should have 9 principals (" + subject.getPrincipals().size()
+ ")", 9, subject.getPrincipals().size());
-        assertEquals("subject should have 3 realm principals (" + subject.getPrincipals(RealmPrincipal.class).size()
+ ")", 3, subject.getPrincipals(RealmPrincipal.class).size());
-        assertEquals("subject should have 3 domain principals (" + subject.getPrincipals(DomainPrincipal.class).size()
+ ")", 3, subject.getPrincipals(DomainPrincipal.class).size());
+        assertEquals("Remote principals", 0, subject.getPrincipals(IdentificationPrincipal.class).size());
+        assertEquals("Principals", 3, subject.getPrincipals().size());
 
         context.logout();
-        assertEquals("subject should have no principals (" + subject.getPrincipals().size()
+ ")", 0, subject.getPrincipals().size());
-
+        assertEquals("Principals upon logout", 0, subject.getPrincipals().size());
+ 
         assertTrue("id of server subject should be null", ContextManager.getSubjectId(subject)
== null);
     }
 
@@ -137,7 +133,7 @@
         context.login();
         Subject subject = context.getSubject();
         assertTrue("expected non-null subject", subject != null);
-        assertEquals("expected zero principals", 0, subject.getPrincipals().size());
+        assertEquals("Principals added upon failed login", 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=597830&r1=597829&r2=597830&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
Sat Nov 24 01:17:31 2007
@@ -50,7 +50,7 @@
         props.put("groupsURI", "src/test/data/data/groups.properties");
         gbean.setAttribute("options", props);
         gbean.setAttribute("loginDomainName", "TestProperties");
-        gbean.setAttribute("wrapPrincipals", Boolean.TRUE);
+        gbean.setAttribute("wrapPrincipals", Boolean.FALSE);
         return gbean;
     }
 
@@ -62,13 +62,11 @@
         Subject subject = context.getSubject();
 
         assertTrue("expected non-null subject", subject != null);
-        assertTrue("subject should have no remote principal", subject.getPrincipals(IdentificationPrincipal.class).size()
== 0);
-        assertEquals("subject should have 6 principals (" + subject.getPrincipals().size()
+ ")", 6, subject.getPrincipals().size());
-        assertEquals("subject should have 2 realm principals (" + subject.getPrincipals(RealmPrincipal.class).size()
+ ")", 2, subject.getPrincipals(RealmPrincipal.class).size());
-        assertEquals("subject should have 2 domain principals (" + subject.getPrincipals(DomainPrincipal.class).size()
+ ")", 2, subject.getPrincipals(DomainPrincipal.class).size());
+        assertEquals("Remote principals", 0, subject.getPrincipals(IdentificationPrincipal.class).size());
+        assertEquals("Principals", 2, subject.getPrincipals().size());
 
         context.logout();
-        assertEquals("subject should have no principals (" + subject.getPrincipals().size()
+ ")", 0, subject.getPrincipals().size());
+        assertEquals("Principals upon logout", 0, subject.getPrincipals().size());
  
         assertTrue("id of server subject should be null", ContextManager.getSubjectId(subject)
== null);
     }
@@ -119,7 +117,7 @@
         context.login();
         Subject subject = context.getSubject();
         assertTrue("expected non-null subject", subject != null);
-        assertTrue("expected zero principals", subject.getPrincipals().size() == 0);
+        assertEquals("Principals added upon failed login", 0, subject.getPrincipals().size());
         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=597830&r1=597829&r2=597830&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
Sat Nov 24 01:17:31 2007
@@ -29,8 +29,8 @@
 import javax.security.auth.login.LoginException;
 
 import org.apache.geronimo.gbean.GBeanData;
-import org.apache.geronimo.security.DomainPrincipal;
-import org.apache.geronimo.security.RealmPrincipal;
+import org.apache.geronimo.security.ContextManager;
+import org.apache.geronimo.security.IdentificationPrincipal;
 
 
 /**
@@ -85,7 +85,7 @@
         props.put("groupSelect", "SELECT UserName, GroupName FROM Groups where UserName =
?");
         gbean.setAttribute("options", props);
         gbean.setAttribute("loginDomainName", "SQLDomain");
-        gbean.setAttribute("wrapPrincipals", Boolean.TRUE);
+        gbean.setAttribute("wrapPrincipals", Boolean.FALSE);
         return gbean;
     }
 
@@ -114,12 +114,13 @@
         context.login();
         Subject subject = context.getSubject();
         assertTrue("expected non-null subject", subject != null);
-        assertEquals("server-side subject should have 6 principal", 6, subject.getPrincipals().size());
-        assertEquals("server-side subject should have two realm principals", 2, subject.getPrincipals(RealmPrincipal.class).size());
-        assertEquals("server-side subject should have two domain principals", 2, subject.getPrincipals(DomainPrincipal.class).size());
+        assertEquals("Remote principals", 0, subject.getPrincipals(IdentificationPrincipal.class).size());
+        assertEquals("Principals", 2, subject.getPrincipals().size());
 
         context.logout();
-        assertEquals("subject should have no principals (" + subject.getPrincipals().size()
+ ")", 0, subject.getPrincipals().size());
+        assertEquals("Principals upon logout", 0, subject.getPrincipals().size());
+ 
+        assertTrue("id of server subject should be null", ContextManager.getSubjectId(subject)
== null);
     }
 
     public void testNullUserLogin() throws Exception {
@@ -168,7 +169,7 @@
         context.login();
         Subject subject = context.getSubject();
         assertTrue("expected non-null subject", subject != null);
-        assertTrue(subject.getPrincipals().size() == 0);
+        assertEquals("Principals added upon failed login", 0, subject.getPrincipals().size());
         context.logout();
     }
 }

Added: geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/WrappingLoginModuleTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/WrappingLoginModuleTest.java?rev=597830&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/WrappingLoginModuleTest.java
(added)
+++ geronimo/server/trunk/framework/modules/geronimo-security/src/test/java/org/apache/geronimo/security/jaas/WrappingLoginModuleTest.java
Sat Nov 24 01:17:31 2007
@@ -0,0 +1,122 @@
+/**
+ *  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 java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MalformedObjectNameException;
+import javax.security.auth.Subject;
+import javax.security.auth.login.LoginContext;
+import javax.security.auth.login.LoginException;
+
+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;
+
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WrappingLoginModuleTest extends AbstractLoginModuleTest {
+
+    protected GBeanData setupTestLoginModule() throws MalformedObjectNameException {
+        GBeanData gbean;
+        gbean = buildGBeanData("name", "PropertiesLoginModule", LoginModuleGBean.getGBeanInfo());
+        gbean.setAttribute("loginModuleClass", "org.apache.geronimo.security.realm.providers.PropertiesFileLoginModule");
+        Map<String, Object> props = new HashMap<String, Object>();
+        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); // wrapPrincipals should be true
for this test.
+        return gbean;
+    }
+
+    public void testLogin() throws Exception {
+
+        LoginContext context = new LoginContext(SIMPLE_REALM, new AbstractTest.UsernamePasswordCallback("alan",
"starcraft"));
+
+        context.login();
+        Subject subject = context.getSubject();
+
+        assertTrue("expected non-null subject", subject != null);
+        assertEquals("Remote principals", 0, subject.getPrincipals(IdentificationPrincipal.class).size());
+        assertEquals("Principals", 6, subject.getPrincipals().size());
+        assertEquals("Realm principals", 2, subject.getPrincipals(RealmPrincipal.class).size());
+        assertEquals("Domain principals", 2, subject.getPrincipals(DomainPrincipal.class).size());
+
+        context.logout();
+        assertEquals("Principals upon logout", 0, subject.getPrincipals().size());
+ 
+        assertTrue("id of server subject should be null", ContextManager.getSubjectId(subject)
== null);
+    }
+
+    public void testNullUserLogin() throws Exception {
+        LoginContext context = new LoginContext(SIMPLE_REALM, new UsernamePasswordCallback(null,
"starcraft"));
+
+        try {
+            context.login();
+            fail("Should not allow this login with null username");
+        } catch (LoginException e) {
+        }
+    }
+
+    public void testBadUserLogin() throws Exception {
+        LoginContext context = new LoginContext(SIMPLE_REALM, new UsernamePasswordCallback("bad",
"starcraft"));
+
+        try {
+            context.login();
+            fail("Should not allow this login with bad username");
+        } catch (LoginException e) {
+        }
+    }
+
+    public void testNullPasswordLogin() throws Exception {
+        LoginContext context = new LoginContext(SIMPLE_REALM, new UsernamePasswordCallback("alan",
null));
+
+        try {
+            context.login();
+            fail("Should not allow this login with null password");
+        } catch (LoginException e) {
+        }
+    }
+
+    public void testBadPasswordLogin() throws Exception {
+        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("expected zero principals", subject.getPrincipals().size() == 0);
+        context.logout();
+    }
+}

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

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

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



Mime
View raw message