Search in sources :

Example 11 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 {
    PAM pam = null;
    UnixUser user = null;
    try {
        pam = new PAM(this.getService());
        UsernamePasswordToken upToken = (UsernamePasswordToken) token;
        user = pam.authenticate(upToken.getUsername(), new String(upToken.getPassword()));
    } catch (PAMException e) {
        handleAuthFailure(token, e.getMessage(), e);
    } finally {
        if (pam != null) {
            pam.dispose();
        }
    }
    HashRequest hashRequest = new HashRequest.Builder().setSource(token.getCredentials()).setAlgorithmName(HASHING_ALGORITHM).build();
    Hash credentialsHash = hashService.computeHash(hashRequest);
    /* 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) HashRequest(org.apache.shiro.crypto.hash.HashRequest) SimpleAuthenticationInfo(org.apache.shiro.authc.SimpleAuthenticationInfo) Hash(org.apache.shiro.crypto.hash.Hash) 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 Hash (org.apache.shiro.crypto.hash.Hash)1 HashRequest (org.apache.shiro.crypto.hash.HashRequest)1