Package javax.security.auth.login

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


    */
   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

      {
         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

         }
      }
      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

         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

         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

         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

  @Override
  public boolean login() throws LoginException {

    // prompt for a user name and password
    if (callbackHandler == null) {
      throw new LoginException("Error: no CallbackHandler available "
          + "to garner authentication information from the user");
    }

    Callback[] callbacks = new Callback[3];
    callbacks[0] = new NameCallback(LoginUtils.USER);
    callbacks[1] = new PasswordCallback(LoginUtils.PASSWORD, false);
    callbacks[2] = new TextOutputCallback(TextOutputCallback.INFORMATION,
        LoginUtils.CRED_MESSAGE);

    try {
      callbackHandler.handle(callbacks);
      username = ((NameCallback) callbacks[0]).getName();
      char[] tmpPassword = ((PasswordCallback) callbacks[1]).getPassword();
      if (tmpPassword == null) {
        // treat a NULL password as an empty password
        tmpPassword = new char[0];
      }
      password = new char[tmpPassword.length];
      System.arraycopy(tmpPassword, 0, password, 0, tmpPassword.length);
      ((PasswordCallback) callbacks[1]).clearPassword();

    } catch (java.io.IOException ioe) {
      throw new LoginException(ioe.toString());
    } catch (UnsupportedCallbackException uce) {
      throw new LoginException("Error: " + uce.getCallback().toString()
          + " not available to garner authentication information "
          + "from the user");
    }

    // verify the username/password
View Full Code Here

        loginSucceeded = false;
        Callback[] callbacks = new Callback[]{new NameCallback("username"), new PasswordCallback("passsword", false)};
        try {
            callbackHandler.handle(callbacks);
        } catch (IOException e) {
            throw (LoginException) new LoginException("Could not execute callbacks").initCause(e);
        } catch (UnsupportedCallbackException e) {
            throw (LoginException) new LoginException("Could not execute callbacks").initCause(e);
        }
        String userName = ((NameCallback) callbacks[0]).getName();
        String password = new String(((PasswordCallback) callbacks[1]).getPassword());
        identity = (SubjectId) ClientSecurity.directAuthentication(securityRealm, userName, password, new ServerMetaData(serverURI));
        loginSucceeded = true;
View Full Code Here

                    if (sit instanceof Destroyable) {
                        // Try to destroy the credential
                        try {
                            ((Destroyable) sit).destroy();
                        } catch (Exception e) {
                            throw new LoginException();
                        }
                    } else {
                        throw new LoginException();
                    }
                } finally {
                    sit = null;
                }
            }
View Full Code Here

TOP

Related Classes of javax.security.auth.login.LoginException

Copyright © 2018 www.massapicom. 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.