[jboss-cvs] JBossAS SVN: r74648 - in projects/security/security-jboss-sx/trunk/jbosssx/src: tests/org/jboss/test/authentication/jaas and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jun 16 18:33:15 EDT 2008


Author: anil.saldhana at jboss.com
Date: 2008-06-16 18:33:15 -0400 (Mon, 16 Jun 2008)
New Revision: 74648

Added:
   projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/authentication/jaas/helpers/
   projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/authentication/jaas/helpers/SharedStatePopulatingLoginModule.java
   projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/authentication/jaas/helpers/SharedStateRetrievingLoginModule.java
Modified:
   projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/auth/spi/UsernamePasswordLoginModule.java
   projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/authentication/jaas/LoginModulesUnitTestCase.java
Log:
SECURITY-158: fix the shared state password variable

Modified: projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/auth/spi/UsernamePasswordLoginModule.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/auth/spi/UsernamePasswordLoginModule.java	2008-06-16 22:15:13 UTC (rev 74647)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/auth/spi/UsernamePasswordLoginModule.java	2008-06-16 22:33:15 UTC (rev 74648)
@@ -227,7 +227,7 @@
       if( getUseFirstPass() == true )
       {    // Add the username and password to the shared state map
          sharedState.put("javax.security.auth.login.name", username);
-         sharedState.put("javax.security.auth.login.password", credential);
+         sharedState.put("javax.security.auth.login.password", password);
       }
       super.loginOk = true;
       super.log.trace("User '" + identity + "' authenticated, loginOk="+loginOk);

Modified: projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/authentication/jaas/LoginModulesUnitTestCase.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/authentication/jaas/LoginModulesUnitTestCase.java	2008-06-16 22:15:13 UTC (rev 74647)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/authentication/jaas/LoginModulesUnitTestCase.java	2008-06-16 22:33:15 UTC (rev 74648)
@@ -147,6 +147,30 @@
         return entry;
      }  
      
+     AppConfigurationEntry[] testSharedMap()
+     {
+        String name = "org.jboss.test.authentication.jaas.helpers.SharedStatePopulatingLoginModule";
+        HashMap options = new HashMap();
+        options.put("username", "anil");
+        options.put("password", "superman");
+        options.put("useFirstPass", "true");  
+     
+        String anothername = 
+           "org.jboss.test.authentication.jaas.helpers.SharedStateRetrievingLoginModule";
+        
+        HashMap anotherOptions = new HashMap();
+        anotherOptions.put("username", "anil");
+        anotherOptions.put("password", "superman");
+        
+        AppConfigurationEntry ace = new AppConfigurationEntry(name,
+        AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, options);
+        
+        AppConfigurationEntry anotherAce = new AppConfigurationEntry(anothername,
+              AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, anotherOptions);
+        AppConfigurationEntry[] entry = {ace,anotherAce};
+        return entry;
+     }
+     
      AppConfigurationEntry[] other()
      {
         AppConfigurationEntry ace = new AppConfigurationEntry(TestLoginModule.class.getName(),
@@ -172,7 +196,8 @@
      {
         return "secret";
      }
-  }
+  } 
+  
   public static class HashTestLoginModule extends TestLoginModule
   {
      /** This represents the 'true' password in its hashed form
@@ -217,7 +242,7 @@
         String passwordHash = CryptoUtil.encodeBase64(hash);
         return passwordHash;
      }
-  }
+  } 
   
   public LoginModulesUnitTestCase(String testName)
   {
@@ -352,4 +377,18 @@
 
      lc.logout();
   }
-}
+  
+
+  public void testSharedMap() throws Exception
+  {
+     log.info("testSharedMap");
+     UsernamePasswordHandler handler = new UsernamePasswordHandler("jduke", "jduke".toCharArray());
+     LoginContext lc = new LoginContext("testSharedMap", handler);
+     lc.login();
+     Subject subject = lc.getSubject();
+     Set groups = subject.getPrincipals(Group.class);
+     assertTrue("Principals contains jduke", subject.getPrincipals().contains(new SimplePrincipal("anil")));
+     lc.logout();
+  }
+
+}
\ No newline at end of file

Added: projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/authentication/jaas/helpers/SharedStatePopulatingLoginModule.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/authentication/jaas/helpers/SharedStatePopulatingLoginModule.java	                        (rev 0)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/authentication/jaas/helpers/SharedStatePopulatingLoginModule.java	2008-06-16 22:33:15 UTC (rev 74648)
@@ -0,0 +1,78 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.authentication.jaas.helpers;
+
+import java.security.Principal;
+import java.security.acl.Group;
+
+import javax.security.auth.login.LoginException;
+
+import org.jboss.security.SimpleGroup;
+import org.jboss.security.SimplePrincipal;
+import org.jboss.security.auth.spi.UsernamePasswordLoginModule;
+
+/**
+ * Places the username password from options 
+ * onto the shated state
+ * @author Anil.Saldhana at redhat.com
+ */
+public class SharedStatePopulatingLoginModule
+extends UsernamePasswordLoginModule
+{
+   private String username = null;
+
+   @SuppressWarnings("unchecked")
+   @Override
+   public boolean login() throws LoginException
+   {
+      username = (String) this.options.get("username");
+      Object cred = this.options.get("password");
+      if(username == null)
+         throw new LoginException("No username");
+      this.sharedState.put("javax.security.auth.login.name", username);
+      this.sharedState.put("javax.security.auth.login.password", cred);
+      super.loginOk = true;
+      return true;
+   }
+
+   @Override
+   protected Principal getIdentity()
+   {
+      return new SimplePrincipal(username);
+   }
+
+   @Override
+   protected Group[] getRoleSets()
+   {
+      SimpleGroup roles = new SimpleGroup("Roles");
+      Group[] roleSets = {roles};
+      roles.addMember(new SimplePrincipal("TestRole"));
+      roles.addMember(new SimplePrincipal("Role2"));
+      return roleSets;
+   }
+
+   @Override
+   protected String getUsersPassword() throws LoginException
+   {
+      return (String) this.options.get("password");
+   }
+}
\ No newline at end of file

Added: projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/authentication/jaas/helpers/SharedStateRetrievingLoginModule.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/authentication/jaas/helpers/SharedStateRetrievingLoginModule.java	                        (rev 0)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/authentication/jaas/helpers/SharedStateRetrievingLoginModule.java	2008-06-16 22:33:15 UTC (rev 74648)
@@ -0,0 +1,70 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.authentication.jaas.helpers;
+
+import java.security.Principal;
+import java.security.acl.Group;
+
+import javax.security.auth.login.LoginException;
+
+import org.jboss.security.SimplePrincipal;
+import org.jboss.security.auth.spi.AbstractServerLoginModule;
+
+/**
+ * Retrieves the username password from options 
+ * from the shated state
+ * @author Anil.Saldhana at redhat.com
+ */
+public class SharedStateRetrievingLoginModule
+extends AbstractServerLoginModule
+{
+   private String username = null;
+
+   @SuppressWarnings("unchecked")
+   @Override
+   public boolean login() throws LoginException
+   {
+      username = (String) sharedState.get("javax.security.auth.login.name");
+      Object cred = sharedState.get("javax.security.auth.login.password");
+      
+      //Get the ones to verify from options
+      String id = (String) options.get("username");
+      Object pass = options.get("password");
+      
+      if(!(username.equals(id) && cred == pass))
+         throw new LoginException(username + "=" + id + "::" + cred + "=" + pass);
+      super.loginOk = true;
+      return super.login();
+   }
+
+   @Override
+   protected Principal getIdentity()
+   {
+      return new SimplePrincipal(username);
+   }
+
+   @Override
+   protected Group[] getRoleSets() throws LoginException
+   {
+      return null;
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list