Package javax.security.auth.login

Examples of javax.security.auth.login.FailedLoginException


        // Report results based on success or failure
        if (principal != null) {
            return (true);
        } else {
            throw new
                FailedLoginException("Username or password is incorrect");
        }

    }
View Full Code Here


                        found = true;
                        break;
                    }
                }
                if (!found) {
                    throw new FailedLoginException("User does not have the required role " + role);
                }
            }
            session.setAttribute(SUBJECT_ATTRIBUTE_KEY, subject);
            return true;
        } catch (Exception e) {
View Full Code Here

        } catch (NullPointerException e) {
            //error handled in the next statement
        }
        if (userInfos == null) {
          if (!this.detailedLoginExcepion) {
            throw new FailedLoginException("login failed");
          } else {
            throw new FailedLoginException("User " + user + " does not exist");
          }
        }
       
        // the password is in the first position
        String[] infos = userInfos.split(",");
        String storedPassword = infos[0];
       
        // check if the stored password is flagged as encrypted
        String encryptedPassword = getEncryptedPassword(storedPassword);
        if (!storedPassword.equals(encryptedPassword)) {
            if (debug) {
                LOG.debug("The password isn't flagged as encrypted, encrypt it.");
            }
            if (debug) {
                LOG.debug("Rebuild the user informations string.");
            }
            userInfos = encryptedPassword + ",";
            for (int i = 1; i < infos.length; i++) {
                if (i == (infos.length - 1)) {
                    userInfos = userInfos + infos[i];
                } else {
                    userInfos = userInfos + infos[i] + ",";
                }
            }
            if (debug) {
                LOG.debug("Push back the user informations in the users properties.");
            }
            if (user.contains("\\")) {
                users.remove(user);
                user = user.replace("\\", "\\\\");
            }
            users.put(user, userInfos);
            try {
                if (debug) {
                    LOG.debug("Store the users properties file.");
                }
                users.save();
            } catch (IOException ioe) {
                LOG.warn("Unable to write user properties file " + f, ioe);
            }
            storedPassword = encryptedPassword;
        }

        // check the provided password
        if (!checkPassword(password, storedPassword)) {
          if (!this.detailedLoginExcepion) {
            throw new FailedLoginException("login failed");
          } else {
            throw new FailedLoginException("Password for " + user + " does not match");
          }
        }

        principals = new HashSet<Principal>();
        principals.add(new UserPrincipal(user));
View Full Code Here

         if( rs.next() == false )
         {
            if( trace )
               log.trace("No roles found");
            if( aslm.getUnauthenticatedIdentity() == null )
               throw new FailedLoginException("No matching username found in Roles");
            /* We are running with an unauthenticatedIdentity so create an
               empty Roles set and return.
            */
            Group[] roleSets = { new SimpleGroup("Roles") };
            return roleSets;
View Full Code Here

         rs = ps.executeQuery();
         if( rs.next() == false )
         {
            if(trace)
               log.trace("Query returned no matches from db");
            throw new FailedLoginException("No matching username found in Principals");
         }
        
         password = rs.getString(1);
         password = convertRawPassword(password);
         if(trace)
View Full Code Here

         }

         if (!validateCredential(alias, credential))
         {
            log.debug("Bad credential for alias=" + alias);
            throw new FailedLoginException("Supplied Credential did not match existing credential for " + alias);
         }
      }

      if (getUseFirstPass() == true)
      {
View Full Code Here

        return true;
    }
    else
    {
        succeeded = false;
      throw new FailedLoginException( "Login failed" );
    }
  }
View Full Code Here

        assert callbacks.length == 2;

        cbUsername = ((NameCallback) callbacks[0]).getName();

        if (Strings.checkNullBlankString(cbUsername)) {
            throw new FailedLoginException();
        }

        char[] provided = ((PasswordCallback) callbacks[1]).getPassword();
        cbPassword = provided == null ? null : new String(provided);

        try {
            Connection conn;
            if (dataSource != null) {
                conn = dataSource.getConnection();
            } else if (driver != null) {
                conn = driver.connect(connectionURL, properties);
            } else {
                conn = DriverManager.getConnection(connectionURL, properties);
            }

            try {
                PreparedStatement statement = conn.prepareStatement(userSelect);
                try {
                    int count = statement.getParameterMetaData().getParameterCount();
                    for (int i = 0; i < count; i++) {
                        statement.setObject(i + 1, cbUsername);
                    }
                    ResultSet result = statement.executeQuery();

                    try {
                        boolean found = false;
                        while (result.next()) {
                            String userName = result.getString(1);
                            String userPassword = result.getString(2);

                            if (cbUsername.equals(userName)) {
                                found = true;
                                if (!checkPassword(userPassword, cbPassword)) {
                                    throw new FailedLoginException();
                                }
                                break;
                            }
                        }
                        if (!found) {
                            // User does not exist
                            throw new FailedLoginException();
                        }
                    } finally {
                        result.close();
                    }
                } finally {
View Full Code Here

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

        String password = users.getProperty(user);

        if (password == null) throw new FailedLoginException("User does not exist");
        if (!password.equals(new String(tmpPassword))) throw new FailedLoginException("Password does not match");

        users.clear();

        if (debug) {
            log.debug("Logged in as '" + user+"'");
View Full Code Here

          password="";

        try {
            boolean result = authenticate(username, password);
            if (!result) {
                throw new FailedLoginException();
            } else {
                return true;
            }
        } catch (Exception e) {
            throw (LoginException)new LoginException("LDAP Error").initCause(e);
View Full Code Here

TOP

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

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.