Examples of LoginException


Examples of javax.security.auth.login.LoginException

     *      <code>LoginModule</code> should be ignored.
     */
    public boolean login() throws LoginException {
        /*  Authenticate user   */
        if (callbackHandler == null) {
            throw new LoginException("No callback handler is available");
        }
        NameCallback nameCallback = new NameCallback("username");
        PasswordCallback pwdCallback = new PasswordCallback("password", false);
        Callback[] callbacks = new Callback[] {nameCallback, pwdCallback};

        String username = null;
        char[] password = null;
        try {
            callbackHandler.handle(callbacks);
            username = nameCallback.getName();
            password = pwdCallback.getPassword();
        } catch (java.io.IOException ioe) {
            throw new LoginException(ioe.toString());
        } catch (UnsupportedCallbackException ce) {
            throw new LoginException("Error: " + ce.getCallback().toString());
        }
        /* check username and password */
        UserManager userManager = UserManager.getInstance();
        loggedInUser = userManager.verifyUsernamePassword(username, password);
        loginStatus = loggedInUser != null;
View Full Code Here

Examples of javax.security.auth.login.LoginException

         this.systemSubject = lc.getSubject();
      }
      catch(Throwable t)
      {
         log.fatal("SystemAuthenticator failed, server will shutdown NOW!", t);
         LoginException le = new LoginException("SystemAuthenticator failed, msg="+t.getMessage());
         Thread shutdownThread = new Thread("SystemAuthenticatorExitThread")
         {
            public void run()
            {
               System.exit(1);
View Full Code Here

Examples of javax.security.auth.login.LoginException

      String username = userPrincipal.getName();
      // First try to locate an SRPServerInterface using JNDI
      try
      {
         if( cacheJndiName == null )
            throw new LoginException("Required cacheJndiName option not set");
         InitialContext iniCtx = new InitialContext();
         CachePolicy cache = (CachePolicy) iniCtx.lookup(cacheJndiName);
         SRPSessionKey key;
         if( userPrincipal instanceof SRPPrincipal )
         {
            SRPPrincipal srpPrincpal = (SRPPrincipal) userPrincipal;
            key = new SRPSessionKey(username, srpPrincpal.getSessionID());
         }
         else
         {
            key = new SRPSessionKey(username);
         }
         Object cacheCredential = cache.get(key);
         if( cacheCredential == null )
         {
            throw new LoginException("No SRP session found for: "+key);
         }
         log.trace("Found SRP cache credential: "+cacheCredential);
         /** The cache object should be the SRPServerSession object used in the
          authentication of the client.
          */
         if( cacheCredential instanceof SRPServerSession )
         {
            session = (SRPServerSession) cacheCredential;
            if( validateCache(session) == false )
               throw new LoginException("Failed to validate SRP session key for: "+key);
         }
         else
         {
            throw new LoginException("Unknown type of cache credential: "+cacheCredential.getClass());
         }
      }
      catch(NamingException e)
      {
         log.error("Failed to load SRP auth cache", e);
         throw new LoginException("Failed to load SRP auth cache: "+e.toString(true));
      }
     
      log.trace("Login succeeded");
      // Put the username and the client challenge into the sharedState map
      sharedState.put("javax.security.auth.login.name", username);
View Full Code Here

Examples of javax.security.auth.login.LoginException

            privateCredentials.remove(params);
         }
      }
      catch(Exception e)
      {
         throw new LoginException("Failed to remove commit information, "+e.getMessage());
      }
      return true;
   }
View Full Code Here

Examples of javax.security.auth.login.LoginException

    */
   private void getUserInfo() throws LoginException
   {
      // Get the security association info
      if( handler == null )
         throw new LoginException("No CallbackHandler provied");

      SecurityAssociationCallback sac = new SecurityAssociationCallback();
      Callback[] callbacks = { sac };
      try
      {
         handler.handle(callbacks);
         userPrincipal = sac.getPrincipal();
         clientChallenge = (byte[]) sac.getCredential();
         sac.clearCredential();
      }
      catch(java.io.IOException e)
      {
         throw new LoginException(e.toString());
      }
      catch(UnsupportedCallbackException uce)
      {
         throw new LoginException("UnsupportedCallback: " + uce.getCallback().toString());
      }
      catch(ClassCastException e)
      {
         throw new LoginException("Credential info is not of type byte[], "+ e.getMessage());
      }
   }
View Full Code Here

Examples of javax.security.auth.login.LoginException

      {
         srpServer = loadServer(srpServerRmiUrl);
      }
      else
      {
         throw new LoginException("No option specified to access a SRPServerInterface instance");
      }
      if( srpServer == null )
         throw new LoginException("Failed to access a SRPServerInterface instance");
     
      byte[] M1, M2;
      SRPClientSession client = null;
      try
      {   // Perform the SRP login protocol
         if( trace )
            log.trace("Getting SRP parameters for username: "+username);
         CryptoUtil.init();
         Object[] sessionInfo = srpServer.getSRPParameters(username, multipleSessions);
         params = (SRPParameters) sessionInfo[0];
         sessionID = (Integer) sessionInfo[1];
         if( sessionID == null )
            sessionID = new Integer(0);
         if( trace )
         {
            log.trace("SessionID: "+sessionID);
            log.trace("N: "+CryptoUtil.tob64(params.N));
            log.trace("g: "+CryptoUtil.tob64(params.g));
            log.trace("s: "+CryptoUtil.tob64(params.s));
            log.trace("cipherAlgorithm: "+params.cipherAlgorithm);
            log.trace("hashAlgorithm: "+params.hashAlgorithm);
         }
         byte[] hn = CryptoUtil.newDigest().digest(params.N);
         if( trace )
            log.trace("H(N): "+CryptoUtil.tob64(hn));
         byte[] hg = CryptoUtil.newDigest().digest(params.g);
         if( trace )
         {
            log.trace("H(g): "+CryptoUtil.tob64(hg));
            log.trace("Creating SRPClientSession");
         }

         if( abytes != null )
            client = new SRPClientSession(username, password, params, abytes);
         else
            client = new SRPClientSession(username, password, params);
         if( trace )
            log.trace("Generating client public key");

         byte[] A = client.exponential();
         if( trace )
            log.trace("Exchanging public keys");
         byte[] B = srpServer.init(username, A, sessionID.intValue());
         if( trace )
            log.trace("Generating server challenge");
         M1 = client.response(B);

         if( trace )
            log.trace("Exchanging challenges");
         sessionKey = client.getSessionKey();
         if( auxChallenge != null )
         {
            auxChallenge = encryptAuxChallenge(auxChallenge, params.cipherAlgorithm,
                  params.cipherIV, sessionKey);
            M2 = srpServer.verify(username, M1, auxChallenge, sessionID.intValue());
         }
         else
         {
            M2 = srpServer.verify(username, M1, sessionID.intValue());
         }
      }
      catch(Exception e)
      {
         if (e instanceof LoginException) throw (LoginException) e;
         final LoginException loginException = new LoginException("Failed to complete SRP login (" + e.getMessage() + ")");
         loginException.initCause(e);
         throw loginException;
      }

      if( trace )
         log.trace("Verifying server response");
      if( client.verify(M2) == false )
         throw new LoginException("Failed to validate server reply");
      if( trace )
         log.trace("Login succeeded");
     
      // Put the principal and the client challenge into the sharedState map
      userPrincipal = new SRPPrincipal(username, sessionID);
View Full Code Here

Examples of javax.security.auth.login.LoginException

         }
      }
      catch(Exception e)
      {
         if (e instanceof LoginException) throw (LoginException) e;
         final LoginException loginException = new LoginException("Failed to remove user principal (" + e.getMessage() + ")");
         loginException.initCause(e);
         throw loginException;
      }
      return true;
   }
View Full Code Here

Examples of javax.security.auth.login.LoginException

         return;
      }
     
      // Request a username and password
      if( handler == null )
         throw new LoginException("No CallbackHandler provied to SRPLoginModule");
     
      NameCallback nc = new NameCallback("Username: ", "guest");
      PasswordCallback pc = new PasswordCallback("Password: ", false);
      ByteArrayCallback bac = new ByteArrayCallback("Public key random number: ");
      TextInputCallback tic = new TextInputCallback("Auxillary challenge token: ");
      ArrayList tmpList = new ArrayList();
      tmpList.add(nc);
      tmpList.add(pc);
      if( externalRandomA == true )
         tmpList.add(bac);
      if( hasAuxChallenge == true )
         tmpList.add(tic);
      Callback[] callbacks = new Callback[tmpList.size()];
      tmpList.toArray(callbacks);
      try
      {
         handler.handle(callbacks);
         username = nc.getName();
         _password = pc.getPassword();
         if( _password != null )
            password = _password;
         pc.clearPassword();
         if( externalRandomA == true )
            abytes = bac.getByteArray();
         if( hasAuxChallenge == true )
            this.auxChallenge = tic.getText();
      }
      catch(java.io.IOException e)
      {
         final LoginException loginException = new LoginException(e.toString());
         loginException.initCause(e);
         throw loginException;
      }
      catch(UnsupportedCallbackException uce)
      {
         final LoginException loginException = new LoginException("UnsupportedCallback: " + uce.getCallback().toString());
         loginException.initCause(uce);
         throw loginException;
      }
   }
View Full Code Here

Examples of javax.security.auth.login.LoginException

         sealedObject = CryptoUtil.createSealedObject(cipherAlgorithm, tmpKey, cipherIV, data);
      }
      catch(Exception e)
      {
         if (e instanceof LoginException) throw (LoginException) e;
         final LoginException loginException = new LoginException("Failed to encrypt aux challenge");
         loginException.initCause(e);
         throw loginException;
      }
      return sealedObject;
   }
View Full Code Here

Examples of javax.security.auth.login.LoginException

         secretKey = CryptoUtil.createSecretKey(cipherAlgorithm, key);
      }
      catch(Exception e)
      {
         if (e instanceof LoginException) throw (LoginException) e;
         final LoginException loginException = new LoginException("Failed to create SecretKey");
         loginException.initCause(e);
         throw loginException;
      }
      return secretKey;
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.