Search in sources :

Example 6 with UnixUser

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);
}
Also used : UnixUser(org.jvnet.libpam.UnixUser) PAM(org.jvnet.libpam.PAM) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test)

Example 7 with UnixUser

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;
}
Also used : UnixUser(org.jvnet.libpam.UnixUser) LoginException(javax.security.auth.login.LoginException) PAM(org.jvnet.libpam.PAM) PAMException(org.jvnet.libpam.PAMException) PamRealm(com.sun.enterprise.security.auth.realm.pam.PamRealm)

Example 8 with UnixUser

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

Example 9 with UnixUser

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());
}
Also used : UnixUser(org.jvnet.libpam.UnixUser) SimpleAuthenticationInfo(org.apache.shiro.authc.SimpleAuthenticationInfo) AuthenticationException(org.apache.shiro.authc.AuthenticationException) PAM(org.jvnet.libpam.PAM) PAMException(org.jvnet.libpam.PAMException) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken)

Aggregations

UnixUser (org.jvnet.libpam.UnixUser)9 PAMException (org.jvnet.libpam.PAMException)7 PAM (org.jvnet.libpam.PAM)5 LoginException (javax.security.auth.login.LoginException)4 SimpleAuthenticationInfo (org.apache.shiro.authc.SimpleAuthenticationInfo)3 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)3 FailedLoginException (javax.security.auth.login.FailedLoginException)2 AuthenticationException (org.apache.shiro.authc.AuthenticationException)2 PamRealm (com.sun.enterprise.security.auth.realm.pam.PamRealm)1 Principal (com.yahoo.athenz.auth.Principal)1 Test (org.testng.annotations.Test)1