Package javax.security.auth.login

Examples of javax.security.auth.login.LoginException


   {
      if( trace )
         log.trace("enter: login()");

      if (roles == null)
         throw new LoginException("Missing roles.properties file.");
      boolean wasSuccessful = super.login();

      if( trace )
         log.trace("exit: login()");
View Full Code Here


      if (user != null) {
        subject.getPrincipals().add(new User(user.getName()));
        return true;
      }
      LOG.error("Can't find user in " + subject);
      throw new LoginException("Can't find user name");
    }
View Full Code Here

        callbacks[1] = new PasswordCallback("Password: ", false);

        try {
            callbackHandler.handle(callbacks);
        } catch (IOException ioe) {
            throw new LoginException(ioe.getMessage());
        } catch (UnsupportedCallbackException uce) {
            throw new LoginException(uce.getMessage() + " not available to obtain information from user");
        }

        String user = ((NameCallback) callbacks[0]).getName();

        char[] tmpPassword = ((PasswordCallback) callbacks[1]).getPassword();
        if (tmpPassword == null) {
            tmpPassword = new char[0];
        }

        String password = new String(tmpPassword);
        principals = new HashSet<Principal>();

        try {
            connection = dataSource.getConnection();

            //Retrieve user credentials from database.
            passwordStatement = connection.prepareStatement(passwordQuery);
            passwordStatement.setString(1, user);
            passwordResultSet = passwordStatement.executeQuery();

            if (!passwordResultSet.next()) {
                if (!this.detailedLoginExcepion) {
                    throw new LoginException("login failed");
                } else {
                    throw new LoginException("Password for " + user + " does not match");
                }
            } else {
                String storedPassword = passwordResultSet.getString(1);

                if (!checkPassword(password, storedPassword)) {
                    if (!this.detailedLoginExcepion) {
                        throw new LoginException("login failed");
                    } else {
                        throw new LoginException("Password for " + user + " does not match");
                    }
                }
                principals.add(new UserPrincipal(user));
            }

            //Retrieve user roles from database
            roleStatement = connection.prepareStatement(roleQuery);
            roleStatement.setString(1, user);
            roleResultSet = roleStatement.executeQuery();
            while (roleResultSet.next()) {
                String role = roleResultSet.getString(1);
                principals.add(new RolePrincipal(role));
            }
        } catch (Exception ex) {
            throw new LoginException("Error has occured while retrieving credentials from database:" + ex.getMessage());
        } finally {
            try {
                if (passwordResultSet != null) {
                    passwordResultSet.close();
                }
View Full Code Here

        {
            handler.handle(callbacks);
        }
        catch (IOException e)
        {
            throw new LoginException(e.getMessage());
        }
        catch (UnsupportedCallbackException e)
        {
            throw new LoginException(e.getMessage());
        }

        String name = ((NameCallback) callbacks[0]).getName();
        char[] password = ((PasswordCallback) callbacks[1]).getPassword();
View Full Code Here

        }

        @Override
        public Subject login(HttpPrincipal principal) throws LoginException {
            if (!principal.getPassword().equalsIgnoreCase("secret")) {
                throw new LoginException("Login denied");
            }
            // login success so return a subject
            return new Subject();
        }
View Full Code Here

         username = cbName.getName();
      }
      catch (Exception ex)
      {
         log.error("Error logging in", ex);
         LoginException le = new LoginException(ex.getMessage());
         le.initCause(ex);
         throw le;
      }
     
      // If an authentication method has been specified, use that to authenticate
      MethodExpression mb = Identity.instance().getAuthenticateMethod();
      if (mb != null)
      {
         try
         {
           return (Boolean) mb.invoke();     
         }
         catch (Exception ex)
         {
            log.error("Error invoking login method", ex);
            throw new LoginException(ex.getMessage());
         }
      }
     
      // Otherwise if identity management is enabled, use it.
      IdentityManager identityManager = IdentityManager.instance();
      if (identityManager != null && identityManager.isEnabled())
      {
         Identity identity = Identity.instance();
        
         try
         {
            boolean success = identityManager.authenticate(username, identity.getCredentials().getPassword());
           
            if (success)
            {
               for (String role : identityManager.getImpliedRoles(username))
               {
                  identity.addRole(role);
               }
            }
           
            return success;
         }
         catch (Exception ex)
         {
            log.error("Error invoking login method", ex);
            LoginException le = new LoginException(ex.getMessage());
            le.initCause(ex);
            throw le;
         }
      }
      else
      {
         log.error("No authentication method defined - " +
               "please define authenticate-method for <security:identity/> in components.xml");
         throw new LoginException("No authentication method defined");
      }

   }
View Full Code Here

      if (user != null) {
        subject.getPrincipals().add(new User(user.getName()));
        return true;
      }
      LOG.error("Can't find user in " + subject);
      throw new LoginException("Can't find user name");
    }
View Full Code Here

        PasswordCallback passwordCallback = new PasswordCallback("password", true);

        try {
            callbackHandler.handle(new Callback[]{usernameCallback, passwordCallback});
        } catch (UnsupportedCallbackException ex) {
            LoginException le = new LoginException("callback is not supported");
            le.initCause(ex);
            throw le;
        } catch (IOException ex) {
            LoginException le = new LoginException("io error in callback handler");
            le.initCause(ex);
            throw le;
        }

        String password = new String(passwordCallback.getPassword());
        Properties props = new Properties();
View Full Code Here

    public static LoginException newLoginException(String msg, Object [] params) {
        String message = rb().getString(msg);
        if(params != null) {
            message = MessageFormat.format(message, params);
        }
        return new LoginException(message);
    }
View Full Code Here

        }
        return new LoginException(message);
    }
   
    public static LoginException newLoginException(String msg, Throwable cause, Object [] params) {
        LoginException ret = newLoginException(msg, params);
        ret.initCause(cause);
        return ret;
    }
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.