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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jun 17 14:37:06 EDT 2008


Author: anil.saldhana at jboss.com
Date: 2008-06-17 14:37:06 -0400 (Tue, 17 Jun 2008)
New Revision: 74711

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/helpers/SharedStatePopulatingLoginModule.java
   projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/authentication/jaas/helpers/SharedStateRetrievingLoginModule.java
Log:
SECURITY-158: use callbackhandler data

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-17 18:29:38 UTC (rev 74710)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/authentication/jaas/LoginModulesUnitTestCase.java	2008-06-17 18:37:06 UTC (rev 74711)
@@ -150,9 +150,7 @@
      AppConfigurationEntry[] testSharedMap()
      {
         String name = "org.jboss.test.authentication.jaas.helpers.SharedStatePopulatingLoginModule";
-        HashMap options = new HashMap();
-        options.put("username", "anil");
-        options.put("password", "superman");
+        HashMap options = new HashMap(); 
         options.put("useFirstPass", "true");  
      
         String anothername = 
@@ -382,7 +380,7 @@
   public void testSharedMap() throws Exception
   {
      log.info("testSharedMap");
-     UsernamePasswordHandler handler = new UsernamePasswordHandler("jduke", "jduke".toCharArray());
+     UsernamePasswordHandler handler = new UsernamePasswordHandler("anil", "superman".toCharArray());
      LoginContext lc = new LoginContext("testSharedMap", handler);
      lc.login();
      Subject subject = lc.getSubject();

Modified: 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	2008-06-17 18:29:38 UTC (rev 74710)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/authentication/jaas/helpers/SharedStatePopulatingLoginModule.java	2008-06-17 18:37:06 UTC (rev 74711)
@@ -21,9 +21,14 @@
  */
 package org.jboss.test.authentication.jaas.helpers;
 
+import java.io.IOException;
 import java.security.Principal;
 import java.security.acl.Group;
 
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
 import javax.security.auth.login.LoginException;
 
 import org.jboss.security.SimpleGroup;
@@ -44,8 +49,20 @@
    @Override
    public boolean login() throws LoginException
    {
-      username = (String) this.options.get("username");
-      Object cred = this.options.get("password");
+      NameCallback nc = new NameCallback("User name: ", "guest");
+      PasswordCallback pc = new PasswordCallback("Password: ", false);
+      Callback[] callbacks = {nc, pc};
+      try
+      {
+         this.callbackHandler.handle(callbacks);
+      }
+      catch (Exception e)
+      {
+         throw new LoginException(e.getLocalizedMessage());
+      }
+      
+      username = nc.getName();
+      Object cred = pc.getPassword();
       if(username == null)
          throw new LoginException("No username");
       this.sharedState.put("javax.security.auth.login.name", username);

Modified: 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	2008-06-17 18:29:38 UTC (rev 74710)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/authentication/jaas/helpers/SharedStateRetrievingLoginModule.java	2008-06-17 18:37:06 UTC (rev 74711)
@@ -50,7 +50,18 @@
       String id = (String) options.get("username");
       Object pass = options.get("password");
       
-      if(!(username.equals(id) && cred == pass))
+      boolean idmatch = username.equals(id);
+      boolean passmatch = false;
+      
+      if(cred instanceof char[])
+      { 
+         String a = (String) pass;
+         String b = new String((char[])cred);
+         passmatch = a.equals(b);
+      }
+      else
+         passmatch = ((String)cred).equals(pass);
+      if(!idmatch && passmatch)
          throw new LoginException(username + "=" + id + "::" + cred + "=" + pass);
       super.loginOk = true;
       return super.login();




More information about the jboss-cvs-commits mailing list