Example usage for javax.security.auth.login AccountNotFoundException AccountNotFoundException

List of usage examples for javax.security.auth.login AccountNotFoundException AccountNotFoundException

Introduction

In this page you can find the example usage for javax.security.auth.login AccountNotFoundException AccountNotFoundException.

Prototype

public AccountNotFoundException(String msg) 

Source Link

Document

Constructs a AccountNotFoundException with the specified detail message.

Usage

From source file:com.echounion.portal.util.MyQueryDatabaseAuthenticationHandler.java

@Override
protected HandlerResult authenticateUsernamePasswordInternal(final UsernamePasswordCredential credential)
        throws GeneralSecurityException, PreventedException {
    final String username = credential.getUsername();
    final ShiroKit shiroKit = (ShiroKit) this.getPasswordEncoder();
    shiroKit.setSalt(username);//w  w w .j a v  a2s. com
    final String encryptedPassword = shiroKit.encode(credential.getPassword());

    try {
        final String e = (String) this.getJdbcTemplate().queryForObject(this.sql, String.class,
                new Object[] { username });
        if (!e.equals(encryptedPassword)) {
            throw new FailedLoginException("Password does not match value on record.");
        }
    } catch (final IncorrectResultSizeDataAccessException var5) {
        if (var5.getActualSize() == 0) {
            throw new AccountNotFoundException(username + " not found with SQL query");
        }

        throw new FailedLoginException("Multiple records found for " + username);
    } catch (final DataAccessException var6) {
        throw new PreventedException("SQL exception while executing query for " + username, var6);
    }

    return this.createHandlerResult(credential, this.principalFactory.createPrincipal(username), (List) null);
}

From source file:com.hs.mail.security.login.PropertiesLoginModule.java

@Override
protected Principal[] validate(Callback[] callbacks) throws LoginException {
    String username = ((NameCallback) callbacks[0]).getName();
    char[] password = ((PasswordCallback) callbacks[1]).getPassword();

    String entry = getLine(file, username + "=");
    if (entry == null)
        throw new AccountNotFoundException("Account for " + username + " not found");
    int index = entry.indexOf('=');
    if (index == -1)
        throw new FailedLoginException("Invalid user record");
    entry = entry.substring(index + 1);//from   w w w . j  a  v  a2s .c o m
    index = entry.indexOf(':');
    if (index == -1)
        throw new FailedLoginException("Invalid user record");
    String encodedPwd = entry.substring(0, index);
    String roles = entry.substring(index + 1);
    StringTokenizer st = new StringTokenizer(roles, ",");
    Principal[] principals = new Principal[st.countTokens() + 1];
    for (int i = 0; i < principals.length - 1; i++) {
        principals[i] = new RolePrincipal(st.nextToken().trim());
    }
    principals[principals.length - 1] = new UserPrincipal(username);
    boolean ok = checkPassword(encodedPwd, password);
    if (!ok)
        throw new CredentialException("Incorrect password for " + username);
    else
        return principals;
}

From source file:com.hs.mail.imap.user.DefaultUserManager.java

/**
 * Authenticate the given user against the given password. When
 * authenticated, the ID of the user will be supplied.
 * /* w  w  w.j a  v a 2  s  .c o m*/
 * @param username
 *            user name
 * @param password
 *            password supplied
 * @return id of the user when authenticated
 * @throws LoginException
 *             when the user does not exist or not authenticated
 */
public long login(String username, String password) throws LoginException {
    String address = toAddress(username);
    User user = DaoFactory.getUserDao().getUserByAddress(address);
    if (user == null) {
        throw new AccountNotFoundException("Account for " + username + " not found");
    }
    if (Config.getAuthScheme() != null) {
        CallbackHandler callbackHandler = new BasicCallbackHandler(address, password.toCharArray());
        LoginContext lc = new LoginContext(Config.getAuthScheme(), callbackHandler);
        lc.login();
    } else {
        if (!password.equals(user.getPassword())) {
            throw new CredentialException("Incorrect password for " + username);
        }
    }
    return user.getID();
}

From source file:info.magnolia.jaas.sp.jcr.MagnoliaAuthenticationModule.java

/**
 * Checks is the credentials exist in the repository.
 * @throws LoginException or specific subclasses (which will be handled further for user feedback)
 *//*w w  w . j a  v a2  s.  c om*/
@Override
public void validateUser() throws LoginException {
    initUser();

    if (this.user == null) {
        throw new AccountNotFoundException("User account " + this.name + " not found.");
    }

    matchPassword();

    if (!this.user.isEnabled()) {
        throw new AccountLockedException("User account " + this.name + " is locked.");
    }

    if (!UserManager.ANONYMOUS_USER.equals(user.getName()) && !isAdmin()) {
        // update last access date for all non anonymous users
        getUserManager().updateLastAccessTimestamp(user);
    }
}

From source file:com.connsec.authentication.AcceptJdbcUsersAuthenticationHandler.java

/**
 * {@inheritDoc}/*from ww  w.j  a  v a  2  s.  co m*/
 **/
@Override
protected HandlerResult authenticateUsernamePasswordInternal(final UsernamePasswordCredential credential)
        throws GeneralSecurityException, PreventedException {

    final String username = credential.getUsername();
    final UserInfo u = this.userInfoService.loadUserInfo(username);

    if (u == null) {
        logger.debug("{} was not found in the map.", username);
        throw new AccountNotFoundException(username + " not found in backing map.");
    }

    final String encodedPassword = this.getPasswordEncoder().encode(credential.getPassword());
    if (!u.getPassword().equals(encodedPassword)) {
        throw new FailedLoginException();
    }
    WebContext.setUserInfo(u);

    insertLoginHistory(u, "WebLogin", "Web", "100000", "Success");
    return createHandlerResult(credential, this.principalFactory.createPrincipal(username), null);
}

From source file:io.cos.cas.adaptors.mongodb.OpenScienceFrameworkAuthenticationHandler.java

@Override
protected final HandlerResult doAuthentication(final Credential credential)
        throws GeneralSecurityException, PreventedException {
    final OpenScienceFrameworkCredential osfCredential = (OpenScienceFrameworkCredential) credential;
    if (osfCredential.getUsername() == null) {
        throw new AccountNotFoundException("Username is null.");
    }/*  w  ww.j a  v  a2s .  c o m*/
    final String transformedUsername = this.principalNameTransformer.transform(osfCredential.getUsername());
    if (transformedUsername == null) {
        throw new AccountNotFoundException("Transformed username is null.");
    }
    osfCredential.setUsername(transformedUsername);
    return authenticateInternal(osfCredential);
}

From source file:io.cos.cas.adaptors.mongodb.OpenScienceFrameworkAuthenticationHandler.java

/**
 * Authenticates a Open Science Framework credential.
 *
 * @param credential the credential object bearing the username, password, etc...
 *
 * @return HandlerResult resolved from credential on authentication success or null if no principal could be resolved
 * from the credential.//from w  w  w . j a v  a  2  s  . co m
 *
 * @throws GeneralSecurityException On authentication failure.
 * @throws PreventedException On the indeterminate case when authentication is prevented.
 */
protected final HandlerResult authenticateInternal(final OpenScienceFrameworkCredential credential)
        throws GeneralSecurityException, PreventedException {

    final String username = credential.getUsername().toLowerCase();
    final String plainTextPassword = credential.getPassword();
    final String verificationKey = credential.getVerificationKey();
    final String oneTimePassword = credential.getOneTimePassword();

    final OpenScienceFrameworkUser user = this.mongoTemplate.findOne(new Query(new Criteria()
            .orOperator(Criteria.where("emails").is(username), Criteria.where("username").is(username))),
            OpenScienceFrameworkUser.class);

    if (user == null) {
        throw new AccountNotFoundException(username + " not found with query");
    }

    Boolean validPassphrase = Boolean.FALSE;
    if (credential.isRemotePrincipal()) {
        // remote principal's are already verified by a third party (in our case a third party SAML authentication).
        validPassphrase = Boolean.TRUE;
    } else if (verificationKey != null && verificationKey.equals(user.verificationKey)) {
        // verification key can substitute as a temporary password.
        validPassphrase = Boolean.TRUE;
    } else if (BCrypt.checkpw(plainTextPassword, user.password)) {
        validPassphrase = Boolean.TRUE;
    }
    if (!validPassphrase) {
        throw new FailedLoginException(username + " invalid verification key or password");
    }

    final TimeBasedOneTimePassword timeBasedOneTimePassword = this.mongoTemplate.findOne(new Query(Criteria
            .where("owner").is(user.id).and("isConfirmed").is(Boolean.TRUE).and("deleted").is(Boolean.FALSE)),
            TimeBasedOneTimePassword.class);

    if (timeBasedOneTimePassword != null && timeBasedOneTimePassword.totpSecret != null) {
        if (oneTimePassword == null) {
            throw new OneTimePasswordRequiredException("Time-based One Time Password required");
        }
        try {
            final Long longOneTimePassword = Long.valueOf(oneTimePassword);
            if (!TotpUtils.checkCode(timeBasedOneTimePassword.getTotpSecretBase32(), longOneTimePassword,
                    TOTP_INTERVAL, TOTP_WINDOW)) {
                throw new OneTimePasswordFailedLoginException(
                        username + " invalid time-based one time password");
            }
        } catch (final Exception e) {
            throw new OneTimePasswordFailedLoginException(username + " invalid time-based one time password");
        }
    }

    // Validate basic information such as username/password and a potential One-Time Password before
    // providing any indication of account status.
    if (!user.isRegistered) {
        throw new LoginNotAllowedException(username + " is not registered");
    }
    if (!user.isClaimed) {
        throw new LoginNotAllowedException(username + " is not claimed");
    }
    if (user.isMerged()) {
        throw new LoginNotAllowedException("Cannot log in to a merged user " + username);
    }
    if (user.isDisabled()) {
        throw new AccountDisabledException(username + " is disabled");
    }
    if (!user.isActive()) {
        throw new LoginNotAllowedException(username + " is not active");
    }

    final Map<String, Object> attributes = new HashMap<>();
    attributes.put("username", user.username);
    attributes.put("givenName", user.givenName);
    attributes.put("familyName", user.familyName);
    return createHandlerResult(credential, this.principalFactory.createPrincipal(user.id, attributes), null);
}

From source file:org.betaconceptframework.astroboa.engine.service.security.AstroboaLogin.java

/**
 * Override login to provide extra checks in case user credentials are
 * correct/*from  www  . ja va 2  s . c o  m*/
 * @return 
 */
public Subject login() throws LoginException {

    boolean loginIsSuccessful = internalLogin();

    if (loginIsSuccessful == true) {

        if (!loggedInPerson.isEnabled()) {
            throw new AccountNotFoundException(getUsername());
        }

        //Add identity 
        addIdentityPrincipalToSubject();

        //Add PersonUserIdPrincipal to subject
        addPersonUserIdPrincipalToSubject();

        //Add display name principal
        addDisplayNamePrincipalToSubject();

        //Add roles to subject
        addRolesToSubject();

        return subject;
    } else {
        throw new LoginException(getUsername());
    }

}

From source file:org.betaconceptframework.astroboa.engine.service.security.AstroboaLogin.java

private void loadPersonByUserName(String username) throws LoginException {

    if (loggedInPerson == null) {
        try {/* w  w  w .ja  v  a  2s  . c om*/

            loggedInPerson = getIdentityStore().retrieveUser(username);

        } catch (Exception e) {
            logger.error("Problem when loading person for username " + username, e);
            throw new LoginException("Problem when loading person for username " + username);
        }

        if (loggedInPerson == null) {
            throw new AccountNotFoundException(username);
        }

    }
}