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());
}
Aggregations