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