Search in sources :

Example 1 with PamReturnValue

use of net.sf.jpam.PamReturnValue in project scheduling by ow2-proactive.

the class PAMLoginModule method pamLogUser.

private boolean pamLogUser(String username, String password) throws LoginException {
    logger.debug("Authenticating user " + username + " with PAM.");
    removeOldFailedAttempts(username);
    if (tooManyFailedAttempts(username)) {
        String message = "Too many failed login/attempts, please try again in " + retryInHowManyMinutes(username) + " minutes.";
        logger.warn(message);
        throw new FailedLoginException(message);
    }
    PamReturnValue answer = pam.authenticate(username, password);
    if (answer.equals(PamReturnValue.PAM_SUCCESS)) {
        subject.getPrincipals().add(new UserNamePrincipal(username));
        resetFailedAttempt(username);
        super.groupMembershipFromFile(username);
        return true;
    } else {
        logger.info("PAM authentication failed for user " + username + ": " + answer);
        storeFailedAttempt(username);
        throw new FailedLoginException(answer.toString());
    }
}
Also used : UserNamePrincipal(org.ow2.proactive.authentication.principals.UserNamePrincipal) FailedLoginException(javax.security.auth.login.FailedLoginException) PamReturnValue(net.sf.jpam.PamReturnValue)

Aggregations

FailedLoginException (javax.security.auth.login.FailedLoginException)1 PamReturnValue (net.sf.jpam.PamReturnValue)1 UserNamePrincipal (org.ow2.proactive.authentication.principals.UserNamePrincipal)1