Search in sources :

Example 1 with PAMException

use of org.jvnet.libpam.PAMException in project atlas by apache.

the class PamLoginModule method performLogin.

private boolean performLogin() throws LoginException {
    try {
        UnixUser user = pam.authenticate(username, password);
        principal = new PamPrincipal(user);
        authSucceeded = true;
        return true;
    } catch (PAMException ex) {
        LoginException le = new FailedLoginException("Invalid username or password");
        le.initCause(ex);
        throw le;
    }
}
Also used : UnixUser(org.jvnet.libpam.UnixUser) FailedLoginException(javax.security.auth.login.FailedLoginException) LoginException(javax.security.auth.login.LoginException) FailedLoginException(javax.security.auth.login.FailedLoginException) PAMException(org.jvnet.libpam.PAMException)

Example 2 with PAMException

use of org.jvnet.libpam.PAMException in project incubator-atlas by apache.

the class PamLoginModule method performLogin.

private boolean performLogin() throws LoginException {
    try {
        UnixUser user = pam.authenticate(username, password);
        principal = new PamPrincipal(user);
        authSucceeded = true;
        return true;
    } catch (PAMException ex) {
        LoginException le = new FailedLoginException("Invalid username or password");
        le.initCause(ex);
        throw le;
    }
}
Also used : UnixUser(org.jvnet.libpam.UnixUser) FailedLoginException(javax.security.auth.login.FailedLoginException) LoginException(javax.security.auth.login.LoginException) FailedLoginException(javax.security.auth.login.FailedLoginException) PAMException(org.jvnet.libpam.PAMException)

Example 3 with PAMException

use of org.jvnet.libpam.PAMException in project ranger by apache.

the class PamLoginModule method performLogin.

private boolean performLogin() throws LoginException {
    try {
        if (_passwordchar != null) {
            UnixUser user = _pam.authenticate(_username, String.valueOf(_passwordchar));
            _principal = new PamPrincipal(user);
            _authSucceeded = true;
            return true;
        } else {
            throw new PAMException("Password is Null or Empty!!!");
        }
    } catch (PAMException ex) {
        LoginException le = new FailedLoginException("Invalid username or password");
        le.initCause(ex);
        throw le;
    }
}
Also used : UnixUser(org.jvnet.libpam.UnixUser) FailedLoginException(javax.security.auth.login.FailedLoginException) LoginException(javax.security.auth.login.LoginException) FailedLoginException(javax.security.auth.login.FailedLoginException) PAMException(org.jvnet.libpam.PAMException)

Example 4 with PAMException

use of org.jvnet.libpam.PAMException in project drill by axbaretto.

the class Pam4jUserAuthenticator method authenticate.

@Override
public void authenticate(String user, String password) throws UserAuthenticationException {
    for (String profile : profiles) {
        PAM pam = null;
        try {
            pam = new PAM(profile);
            pam.authenticate(user, password);
        } catch (PAMException ex) {
            logger.error("PAM auth failed for user: {} against {} profile. Exception: {}", user, profile, ex.getMessage());
            throw new UserAuthenticationException(String.format("PAM auth failed for user: %s using profile: %s", user, profile));
        } finally {
            if (pam != null) {
                pam.dispose();
            }
        }
        // No need to check for null unixUser as in case of failure we will not reach here.
        logger.trace("PAM authentication was successful for user: {} using profile: {}", user, profile);
    }
}
Also used : PAM(org.jvnet.libpam.PAM) PAMException(org.jvnet.libpam.PAMException)

Example 5 with PAMException

use of org.jvnet.libpam.PAMException in project knox by apache.

the class KnoxPamRealm method doGetAuthenticationInfo.

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    UsernamePasswordToken upToken = (UsernamePasswordToken) token;
    UnixUser user = null;
    try {
        user = (new PAM(this.getService())).authenticate(upToken.getUsername(), new String(upToken.getPassword()));
    } catch (PAMException e) {
        handleAuthFailure(token, e.getMessage(), e);
    }
    HashRequest.Builder builder = new HashRequest.Builder();
    Hash credentialsHash = hashService.computeHash(builder.setSource(token.getCredentials()).setAlgorithmName(HASHING_ALGORITHM).build());
    /* Coverity Scan CID 1361684 */
    if (credentialsHash == null) {
        handleAuthFailure(token, "Failed to compute hash", null);
    }
    return new SimpleAuthenticationInfo(new UnixUserPrincipal(user), credentialsHash.toHex(), credentialsHash.getSalt(), getName());
}
Also used : UnixUser(org.jvnet.libpam.UnixUser) SimpleAuthenticationInfo(org.apache.shiro.authc.SimpleAuthenticationInfo) PAM(org.jvnet.libpam.PAM) PAMException(org.jvnet.libpam.PAMException) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken)

Aggregations

PAMException (org.jvnet.libpam.PAMException)11 PAM (org.jvnet.libpam.PAM)8 UnixUser (org.jvnet.libpam.UnixUser)8 LoginException (javax.security.auth.login.LoginException)4 FailedLoginException (javax.security.auth.login.FailedLoginException)3 SimpleAuthenticationInfo (org.apache.shiro.authc.SimpleAuthenticationInfo)3 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)3 AuthenticationException (org.apache.shiro.authc.AuthenticationException)2 UserModel (com.gitblit.models.UserModel)1 PamRealm (com.sun.enterprise.security.auth.realm.pam.PamRealm)1