Search in sources :

Example 6 with PAM

use of org.jvnet.libpam.PAM in project athenz by yahoo.

the class UserAuthorityTest method testAllowAuthorization.

@Test
public void testAllowAuthorization() {
    PAM pam = Mockito.mock(PAM.class);
    UserAuthority userAuthority = new UserAuthority();
    userAuthority.setPAM(pam);
    assertFalse(userAuthority.allowAuthorization());
}
Also used : PAM(org.jvnet.libpam.PAM) Test(org.testng.annotations.Test)

Example 7 with PAM

use of org.jvnet.libpam.PAM in project athenz by yahoo.

the class UserAuthorityTest method testUserAuthority.

@Test
public void testUserAuthority() throws PAMException {
    PAM pam = Mockito.mock(PAM.class);
    UnixUser user = Mockito.mock(UnixUser.class);
    Mockito.when(pam.authenticate("testuser", "testpwd")).thenReturn(user);
    UserAuthority userAuthority = new UserAuthority();
    userAuthority.setPAM(pam);
    String expectedDomain = "user";
    assertEquals(userAuthority.getDomain(), expectedDomain);
    String expectedHeader = "Authorization";
    assertEquals(userAuthority.getHeader(), expectedHeader);
    assertTrue(userAuthority.isValidUser("user1"));
    StringBuilder errMsg = new StringBuilder();
    String testToken = "Basic dGVzdHVzZXI6dGVzdHB3ZA==";
    Principal principal = userAuthority.authenticate(testToken, "10.72.118.45", "GET", errMsg);
    assertNotNull(principal);
    assertEquals(principal.getName(), "testuser");
    assertEquals(principal.getDomain(), expectedDomain);
    assertEquals(principal.getCredentials(), testToken);
    assertEquals(principal.getUnsignedCredentials(), "testuser");
    assertNotNull(principal.getAuthority());
    assertEquals(principal.getCredentials(), testToken);
    assertTrue(userAuthority.isValidUser("user1"));
    // authenticate user without password which should fail
    principal = userAuthority.authenticate("Basic dGVzdHVzZXIK", "10.72.118.45", "GET", errMsg);
    assertNull(principal);
}
Also used : UnixUser(org.jvnet.libpam.UnixUser) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PAM(org.jvnet.libpam.PAM) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test)

Example 8 with PAM

use of org.jvnet.libpam.PAM in project athenz by yahoo.

the class UserAuthorityTest method testUserAuthorityInvalidFormat.

@Test
public void testUserAuthorityInvalidFormat() {
    PAM pam = Mockito.mock(PAM.class);
    UserAuthority userAuthority = new UserAuthority();
    userAuthority.setPAM(pam);
    StringBuilder errMsg = new StringBuilder();
    Principal principal = userAuthority.authenticate("dGVzdHVzZXI6dGVzdHB3ZA==", "10.72.118.45", "GET", errMsg);
    assertNull(principal);
}
Also used : PAM(org.jvnet.libpam.PAM) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test)

Example 9 with PAM

use of org.jvnet.libpam.PAM in project zeppelin by apache.

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)

Example 10 with PAM

use of org.jvnet.libpam.PAM 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

PAM (org.jvnet.libpam.PAM)14 PAMException (org.jvnet.libpam.PAMException)8 UnixUser (org.jvnet.libpam.UnixUser)7 Test (org.testng.annotations.Test)6 Principal (com.yahoo.athenz.auth.Principal)5 SimpleAuthenticationInfo (org.apache.shiro.authc.SimpleAuthenticationInfo)3 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)3 AuthenticationException (org.apache.shiro.authc.AuthenticationException)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 UserModel (com.gitblit.models.UserModel)1 PamRealm (com.sun.enterprise.security.auth.realm.pam.PamRealm)1 LoginException (javax.security.auth.login.LoginException)1 Hash (org.apache.shiro.crypto.hash.Hash)1 HashRequest (org.apache.shiro.crypto.hash.HashRequest)1