use of org.jvnet.libpam.UnixUser in project athenz by yahoo.
the class UserAuthorityTest method testUserAuthority.
@Test
public void testUserAuthority() throws PAMException {
PAM pam = Mockito.mock(PAM.class);
UnixUser user = new UnixUser(System.getenv("USER"));
Mockito.when(pam.authenticate("testuser", "testpwd")).thenReturn(user);
UserAuthority userAuthority = new UserAuthority();
userAuthority.setPAM(pam);
assertEquals(userAuthority.getDomain(), expectedDomain);
assertEquals(userAuthority.getHeader(), expectedHeader);
StringBuilder errMsg = new StringBuilder();
Principal principal = userAuthority.authenticate(testToken, "10.72.118.45", "GET", errMsg);
assertNotNull(principal);
assertNotNull(principal.getAuthority());
assertEquals(principal.getCredentials(), testToken);
assertEquals(principal.getDomain(), expectedDomain);
assertEquals(principal.getName(), expectedUserId);
}
use of org.jvnet.libpam.UnixUser in project Payara by payara.
the class PamLoginModule method authenticate.
/**
* Invokes the authentication call.This class uses the default PAM service
* - sshd
* @param username OS User to authenticate.
* @param password Given password.
* @returns null if authentication failed,
* returns the UnixUser object if authentication succeeded.
*/
private UnixUser authenticate(String username, String password) throws LoginException {
UnixUser user = null;
String pamService = null;
if (_currentRealm instanceof PamRealm) {
pamService = ((PamRealm) _currentRealm).getPamService();
} else {
throw new LoginException("pamrealm.invalid_realm");
}
try {
user = new PAM(pamService).authenticate(username, password);
} catch (PAMException e) {
_logger.log(Level.SEVERE, "pam_exception_authenticate", e);
}
return user;
}
use of org.jvnet.libpam.UnixUser 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());
}
use of org.jvnet.libpam.UnixUser in project SSM by Intel-bigdata.
the class PamRealm method doGetAuthenticationInfo.
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
UsernamePasswordToken userToken = (UsernamePasswordToken) token;
UnixUser user;
try {
user = (new PAM(this.getService())).authenticate(userToken.getUsername(), new String(userToken.getPassword()));
} catch (PAMException e) {
throw new AuthenticationException("Authentication failed for PAM.", e);
}
return new SimpleAuthenticationInfo(new UserPrincipal(user), userToken.getCredentials(), getName());
}
Aggregations