Package javax.security.auth.login

Examples of javax.security.auth.login.LoginException


        callbacks[0] = new NameCallback("User name");
        callbacks[1] = new PasswordCallback("Password", false);
        try {
            callbackHandler.handle(callbacks);
        } catch (IOException ioe) {
            throw (LoginException) new LoginException().initCause(ioe);
        } catch (UnsupportedCallbackException uce) {
            throw (LoginException) new LoginException().initCause(uce);
        }
        resourcePrincipalName = ((NameCallback) callbacks[0]).getName();
        userName = ((NameCallback) callbacks[0]).getName();
        password = ((PasswordCallback) callbacks[1]).getPassword();
        return false;
View Full Code Here


                    char[] password = ((String) credentials).toCharArray();
                    callbackHandler = new PasswordCallbackHandler(username, password);
                } else if (credentials instanceof X509Certificate[]) {
                    X509Certificate[] certs = (X509Certificate[]) credentials;
                    if (certs.length < 1) {
                        throw new LoginException("no certificates supplied");
                    }
                    callbackHandler = new CertificateCallbackHandler(certs[0]);
                } else {
                    throw new LoginException("Cannot extract credentials from class: " + credentials.getClass().getName());
                }

                //set up the login context
                LoginContext loginContext = ContextManager.login(securityRealmName, callbackHandler);
                callbackHandler.clear();
View Full Code Here

                char[] password = ((String) credentials).toCharArray();
                callbackHandler = new PasswordCallbackHandler(username, password);
            } else if (credentials instanceof X509Certificate[]) {
                X509Certificate[] certs = (X509Certificate[]) credentials;
                if (certs.length < 1) {
                    throw new LoginException("no certificates supplied");
                }
                callbackHandler = new CertificateCallbackHandler(certs[0]);
            } else {
                throw new LoginException("Cannot extract credentials from class: " + credentials.getClass().getName());
            }

            //set up the login context
            LoginContext loginContext = new LoginContext(loginDomainName, callbackHandler);
            loginContext.login();
View Full Code Here

        callbacks[0] = new NameCallback("User name");
        callbacks[1] = new PasswordCallback("Password", false);
        try {
            handler.handle(callbacks);
        } catch (IOException ioe) {
            throw (LoginException) new LoginException().initCause(ioe);
        } catch (UnsupportedCallbackException uce) {
            throw (LoginException) new LoginException().initCause(uce);
        }
        cbUsername = ((NameCallback) callbacks[0]).getName();
        cbPassword = new String(((PasswordCallback) callbacks[1]).getPassword());

        if (cbUsername == null || "".equals(cbUsername)
            || cbPassword == null || "".equals(cbPassword)) {
            return false;
        }

        try {
            return authenticate(cbUsername, cbPassword);
        } catch (Exception e) {
            throw (LoginException) new LoginException("LDAP Error").initCause(e);
        }
    }
View Full Code Here

        callbacks[0] = new NameCallback("User name");
        callbacks[1] = new PasswordCallback("Password", false);
        try {
            callbackHandler.handle(callbacks);
        } catch (IOException ioe) {
            throw (LoginException) new LoginException().initCause(ioe);
        } catch (UnsupportedCallbackException uce) {
            throw (LoginException) new LoginException().initCause(uce);
        }
        resourcePrincipalName = ((NameCallback) callbacks[0]).getName();
        userName = ((NameCallback) callbacks[0]).getName();
        password = ((PasswordCallback) callbacks[1]).getPassword();
        return resourcePrincipalName != null && userName != null && password != null;
View Full Code Here

                delegate = lmc.getLoginModule();
                delegate.initialize(subject,callbackHandler,sharedState,options);
                logger.info("No JAAS Configuration provider found would be directly invoking LoginModule {}",delegateLoginModuleClass);
            } catch (ConfigurationException e) {
                //Behaviour is same as org.apache.jackrabbit.core.security.authentication.LocalAuthContext.login()
                loginException = new LoginException(e.getMessage());
            }
        }
    }
View Full Code Here

     */
    public boolean login() throws LoginException {

        // Set up our CallbackHandler requests
        if (callbackHandler == null)
            throw new LoginException("No CallbackHandler specified");
        Callback callbacks[] = new Callback[2];
        callbacks[0] = new NameCallback("Username: ");
        callbacks[1] = new PasswordCallback("Password: ", false);

        // Interact with the user to retrieve the username and password
        String username = null;
        String password = null;
        try {
            callbackHandler.handle(callbacks);
            username = ((NameCallback) callbacks[0]).getName();
            password =
                new String(((PasswordCallback) callbacks[1]).getPassword());
        } catch (IOException e) {
            throw new LoginException(e.toString());
        } catch (UnsupportedCallbackException e) {
            throw new LoginException(e.toString());
        }

        // Validate the username and password we have received
        principal = super.authenticate(username, password);

View Full Code Here

               identity = createIdentity(name);
            }
            catch(Exception e)
            {
               log.debug("Failed to create principal", e);
               throw new LoginException("Failed to create principal: "+ e.getMessage());
            }
         }
         Object password = sharedState.get("javax.security.auth.login.password");
         if( password instanceof char[] )
            credential = (char[]) password;
         else if( password != null )
         {
            String tmp = password.toString();
            credential = tmp.toCharArray();
         }
         return true;
      }

      super.loginOk = false;
      String[] info = getUsernameAndPassword();
      String username = info[0];
      String password = info[1];
      if( username == null && password == null )
      {
         identity = unauthenticatedIdentity;
         super.log.trace("Authenticating as unauthenticatedIdentity="+identity);
      }

      if( identity == null )
      {
         try
         {
            identity = createIdentity(username);
         }
         catch(Exception e)
         {
            log.debug("Failed to create principal", e);
            throw new LoginException("Failed to create principal: "+ e.getMessage());
         }

         // Hash the user entered password if password hashing is in use
         if( hashAlgorithm != null && hashUserPassword == true )
            password = createPasswordHash(username, password, "digestCallback");
View Full Code Here

   {
      String[] info = {null, null};
      // prompt for a username and password
      if( callbackHandler == null )
      {
         throw new LoginException("Error: no CallbackHandler available " +
         "to collect authentication information");
      }
     
      NameCallback nc = new NameCallback("User name: ", "guest");
      PasswordCallback pc = new PasswordCallback("Password: ", false);
      Callback[] callbacks = {nc, pc};
      String username = null;
      String password = null;
      try
      {
         callbackHandler.handle(callbacks);
         username = nc.getName();
         char[] tmpPassword = pc.getPassword();
         if( tmpPassword != null )
         {
            credential = new char[tmpPassword.length];
            System.arraycopy(tmpPassword, 0, credential, 0, tmpPassword.length);
            pc.clearPassword();
            password = new String(credential);
         }
      }
      catch(IOException e)
      {
         LoginException le = new LoginException("Failed to get username/password");
         le.initCause(e);
         throw le;
      }
      catch(UnsupportedCallbackException e)
      {
         LoginException le = new LoginException("CallbackHandler does not support: " + e.getCallback());
         le.initCause(e);
         throw le;
      }
      info[0] = username;
      info[1] = password;
      return info;
View Full Code Here

            String passwordHash = (String) createPasswordHash.invoke(this, args);
            return passwordHash;
         }
         catch (InvocationTargetException e)
         {
            LoginException le = new LoginException("Failed to delegate createPasswordHash");
            le.initCause(e.getTargetException());
            throw le;
         }
         catch(Exception e)
         {
            LoginException le = new LoginException("Failed to delegate createPasswordHash");
            le.initCause(e);
            throw le;           
         }
      }

      DigestCallback callback = null;
      String callbackClassName = (String) options.get(digestOption);
      if( callbackClassName != null )
      {
         try
         {
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            Class callbackClass = loader.loadClass(callbackClassName);
            callback = (DigestCallback) callbackClass.newInstance();
            if( log.isTraceEnabled() )
               log.trace("Created DigestCallback: "+callback);
         }
         catch (Exception e)
         {
            if( log.isTraceEnabled() )
               log.trace("Failed to load DigestCallback", e);
            SecurityException ex = new SecurityException("Failed to load DigestCallback");
            ex.initCause(e);
            throw ex;
         }
         Map tmp = new HashMap();
         tmp.putAll(options);
         tmp.put("javax.security.auth.login.name", username);
         tmp.put("javax.security.auth.login.password", password);

         callback.init(tmp);
         // Check for a callbacks
         Callback[] callbacks = (Callback[]) tmp.get("callbacks");
         if( callbacks != null )
         {
            try
            {
               callbackHandler.handle(callbacks);
            }
            catch(IOException e)
            {
               LoginException le = new LoginException(digestOption+" callback failed");
               le.initCause(e);
               throw le;
            }
            catch(UnsupportedCallbackException e)
            {
               LoginException le = new LoginException(digestOption+" callback failed");
               le.initCause(e);
               throw le;
            }
         }
      }
      String passwordHash = Util.createPasswordHash(hashAlgorithm, hashEncoding,
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.