User: starksm 
  Date: 02/02/08 15:53:34

  Modified:    src/main/org/jboss/security/srp/jaas
                        SRPCacheLoginModule.java SRPLoginModule.java
  Log:
  Synch with the latest 2.4 branch changes
  
  Revision  Changes    Path
  1.5       +15 -11    
jbosssx/src/main/org/jboss/security/srp/jaas/SRPCacheLoginModule.java
  
  Index: SRPCacheLoginModule.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosssx/src/main/org/jboss/security/srp/jaas/SRPCacheLoginModule.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SRPCacheLoginModule.java  24 Nov 2001 21:47:25 -0000      1.4
  +++ SRPCacheLoginModule.java  8 Feb 2002 23:53:34 -0000       1.5
  @@ -19,8 +19,8 @@
   import javax.security.auth.login.LoginException;
   import javax.security.auth.spi.LoginModule;
   
  +import org.jboss.logging.Logger;
   import org.jboss.security.auth.callback.SecurityAssociationCallback;
  -import org.jboss.security.srp.PkgCategory;
   import org.jboss.security.srp.SRPServerSession;
   import org.jboss.security.srp.SRPServerInterface;
   import org.jboss.security.srp.SRPServerInterface.SRPParameters;
  @@ -37,11 +37,12 @@
   information managed by the SRPSerice.
   domainName,
   
  -@author [EMAIL PROTECTED]
  -@version $Revision: 1.4 $
  +@author [EMAIL PROTECTED]
  +@version $Revision: 1.5 $
   */
   public class SRPCacheLoginModule implements LoginModule
   {
  +    private static Logger log = Logger.getLogger(SRPCacheLoginModule.class);
       private Subject subject;
       private CallbackHandler handler;
       private Map sharedState;
  @@ -50,7 +51,6 @@
       private byte[] clientChallenge;
       private SRPServerSession session;
       private Principal userPrincipal;
  -    private boolean debug;
       private boolean loginFailed;
   
       public SRPCacheLoginModule()
  @@ -74,10 +74,8 @@
           this.handler = handler;
           this.sharedState = sharedState;
           cacheJndiName = (String) options.get("cacheJndiName");
  +        log.trace("cacheJndiName="+cacheJndiName);
           domainName = (String) options.get("domainName");
  -        String d = (String) options.get("debug");
  -        if( d != null )
  -            debug = Boolean.valueOf(d).booleanValue();
       }
   
       /** Access the user Principal object and credentials by passing a
  @@ -104,6 +102,11 @@
               InitialContext iniCtx = new InitialContext();
               CachePolicy cache = (CachePolicy) iniCtx.lookup(cacheJndiName);
               Object cacheCredential = cache.get(userPrincipal);
  +            if( cacheCredential == null )
  +            {
  +               throw new LoginException("No SRP session found for: "+username);
  +            }
  +            log.trace("Found SRP cache credential: "+cacheCredential);
               /** The cache object should be the SRPServerSession object used in the
                   authentication of the client.
               */
  @@ -120,11 +123,11 @@
           }
           catch(NamingException e)
           {
  -            e.printStackTrace();
  +            log.error("Failed to load SRP auth cache", e);
               throw new LoginException("Failed to load SRP auth cache: 
"+e.toString(true));
           }
   
  -        PkgCategory.debug("Login succeeded");
  +        log.trace("Login succeeded");
           // Put the username and the client challenge into the sharedState map
           sharedState.put("javax.security.auth.login.name", username);
           sharedState.put("javax.security.auth.login.password", clientChallenge);
  @@ -133,7 +136,7 @@
       }
   
       /** All login modules have completed the login() phase, commit if we
  -    succeeded. This entails adding the principal to the subject Principals set.
  +    succeeded. This entails adding the princial to the subject Principals set.
       It also adds the client challenge response to the PublicCredentials set
       and the private session key to the PrivateCredentials set.
       @return false, if the login() failed, true if the commit succeeds.
  @@ -143,7 +146,8 @@
       {
           if( loginFailed == true )
               return false;
  -        subject.getPrincipals().add(userPrincipal);
  +        Set principals = subject.getPrincipals();
  +        principals.add(userPrincipal);
           subject.getPublicCredentials().add(clientChallenge);
           byte[] sessionKey = session.getSessionKey();
           subject.getPrivateCredentials().add(sessionKey);
  
  
  
  1.4       +45 -27    jbosssx/src/main/org/jboss/security/srp/jaas/SRPLoginModule.java
  
  Index: SRPLoginModule.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosssx/src/main/org/jboss/security/srp/jaas/SRPLoginModule.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SRPLoginModule.java       5 Jan 2002 08:01:43 -0000       1.3
  +++ SRPLoginModule.java       8 Feb 2002 23:53:34 -0000       1.4
  @@ -21,7 +21,8 @@
   import javax.security.auth.login.LoginException;
   import javax.security.auth.spi.LoginModule;
   
  -import org.jboss.security.srp.PkgCategory;
  +import org.jboss.logging.Logger;
  +import org.jboss.security.Util;
   import org.jboss.security.srp.SRPClientSession;
   import org.jboss.security.srp.SRPServerInterface;
   import org.jboss.security.srp.SRPServerInterface.SRPParameters;
  @@ -30,11 +31,30 @@
   to authenticate a username & password in a secure fashion without
   using an encrypted channel.
   
  +The supported configuration options include:
  +<ul>
  + <li>principalClassName: the fully qualified class name of the 
java.security.Principal
  + implementation to use. The implementation must provide a public constructor that
  + accepts a single String argument representing the name of the principal.
  + If not specified this defaults to org.jboss.security.SimplePrincipal.
  + </li>
  +
  + <li>srpServerJndiName: the JNDI name of the SRPServerInterface object to use
  + for communicating with the SRP authentication server. If both srpServerJndiName
  + and srpServerRmiUrl options are specified, the srpServerJndiName is tried before
  + srpServerRmiUrl.
  + </li>
  +
  + <li>srpServerRmiUrl: the RMI protocol URL string for the location of the
  + SRPServerInterface proxy to use for communicating with the SRP authentication 
server.
  + </li>
  +</ul>
  +
   This product uses the 'Secure Remote Password' cryptographic
   authentication system developed by Tom Wu ([EMAIL PROTECTED]).
   
  -@author [EMAIL PROTECTED]
  -@version $Revision: 1.3 $
  +@author [EMAIL PROTECTED]
  +@version $Revision: 1.4 $
   */
   public class SRPLoginModule implements LoginModule
   {
  @@ -48,8 +68,8 @@
       private String password;
       private Principal userPrincipal;
       private byte[] sessionKey;
  -    private boolean debug;
       private boolean loginFailed;
  +    private Logger log;
   
       /** Creates new SRPLoginModule */
       public SRPLoginModule()
  @@ -67,7 +87,6 @@
           srpServerJndiName: the jndi name of the SRPServerInterface implimentation 
to use. This
               is tried before srpServerRmiUrl.
           srpServerRmiUrl: the rmi url for the SRPServerInterface implimentation to 
use.
  -        debug: if true, print the login module progress details
       */
       public void initialize(Subject subject, CallbackHandler handler, Map 
sharedState, Map options)
       {
  @@ -75,11 +94,11 @@
           this.handler = handler;
           this.sharedState = sharedState;
           principalClassName = (String) options.get("principalClassName");
  +        if( principalClassName == null )
  +           principalClassName = "org.jboss.security.SimplePrincipal";
           srpServerJndiName = (String) options.get("srpServerJndiName");
           srpServerRmiUrl = (String) options.get("srpServerRmiUrl");
  -        String o = (String) options.get("debug");
  -        if( o != null )
  -            debug = Boolean.valueOf(o).booleanValue();
  +        log = Logger.getLogger(getClass());
       }
   
       /** This is where the SRP protocol exchange occurs.
  @@ -107,47 +126,46 @@
           if( server == null )
               throw new LoginException("Failed to access a SRPServerInterface 
instance");
   
  -        boolean debug = PkgCategory.isDebugEnabled();
           byte[] M1, M2;
           SRPClientSession client = null;
           try
           {   // Perform the SRP login protocol
  -            if (debug)
  -               PkgCategory.debug("Getting SRP parameters for username: "+username);
  +            log.trace("Getting SRP parameters for username: "+username);
  +            Util.init();
               SRPParameters params = server.getSRPParameters(username);
  -            if (debug)
  -               PkgCategory.debug("Creating SRPClientSession");
  +            log.trace("N: "+Util.tob64(params.N));
  +            log.trace("g: "+Util.tob64(params.g));
  +            log.trace("s: "+Util.tob64(params.s));
  +            byte[] hn = Util.newDigest().digest(params.N);
  +            log.trace("H(N): "+Util.tob64(hn));
  +            byte[] hg = Util.newDigest().digest(params.g);
  +            log.trace("H(g): "+Util.tob64(hg));
  +            log.trace("Creating SRPClientSession");
               client = new SRPClientSession(username, password, params.s, params.N, 
params.g);
  -            if (debug)
  -               PkgCategory.debug("Generating client public key");
  +            log.trace("Generating client public key");
               byte[] A = client.exponential();
  -            if (debug)
  -               PkgCategory.debug("Exchanging public keys");
  +            log.trace("Exchanging public keys");
               byte[] B = server.init(username, A);
  -            if (debug)
  -               PkgCategory.debug("Generating server challenge");
  +            log.trace("Generating server challenge");
               M1 = client.response(B);
  -            if (debug)
  -               PkgCategory.debug("Exchanging challenges");
  +            log.trace("Exchanging challenges");
               M2 = server.verify(username, M1);
               sessionKey = client.getSessionKey();
           }
           catch(Exception e)
           {
  -            PkgCategory.warn("Failed complete SRP login", e);
  -            throw new LoginException("Failed complete SRP login, 
msg="+e.getMessage());
  +            log.warn("Failed to complete SRP login", e);
  +            throw new LoginException("Failed to complete SRP login, 
msg="+e.getMessage());
           }
           finally
           {
               server = null;
           }
   
  -        if (debug)
  -           PkgCategory.debug("Verifying server response");
  +        log.trace("Verifying server response");
           if( client.verify(M2) == false )
               throw new LoginException("Failed to validate server reply");
  -        if (debug)
  -           PkgCategory.debug("Login succeeded");
  +        log.trace("Login succeeded");
   
           // Put the username and the client challenge into the sharedState map
           sharedState.put("javax.security.auth.login.name", username);
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to