org.jvnet.libpam.PAMException Java Examples
The following examples show how to use
org.jvnet.libpam.PAMException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PamLoginModule.java From atlas with Apache License 2.0 | 6 votes |
private boolean performLogin() throws LoginException { try { UnixUser user = pam.authenticate(username, password); principal = new PamPrincipal(user); authSucceeded = true; if (LOG.isDebugEnabled()) LOG.debug("user " + username ); return true; } catch (PAMException ex) { LoginException le = new FailedLoginException("Invalid username or password"); le.initCause(ex); throw le; } }
Example #2
Source File: UserAuthorityTest.java From athenz with Apache License 2.0 | 6 votes |
@Test public void testNullSimplePrincipal() throws PAMException { PAM pam = Mockito.mock(PAM.class); UnixUser user = new UnixUser(System.getenv("USER")); Mockito.when(pam.authenticate("testuser", "testpwd")).thenReturn(user); UserAuthority authority = new UserAuthority(); UserAuthority userAuthority = Mockito.spy(authority); doReturn(null).when(userAuthority).getSimplePrincipal(anyString(), anyString(), anyLong()); 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); assertNull(principal); }
Example #3
Source File: PamLoginModule.java From incubator-atlas with Apache License 2.0 | 6 votes |
private boolean performLogin() throws LoginException { try { UnixUser user = pam.authenticate(username, password); principal = new PamPrincipal(user); authSucceeded = true; return true; } catch (PAMException ex) { LoginException le = new FailedLoginException("Invalid username or password"); le.initCause(ex); throw le; } }
Example #4
Source File: PamRealm.java From zeppelin with Apache License 2.0 | 6 votes |
@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()); }
Example #5
Source File: PamLoginModule.java From ranger with Apache License 2.0 | 6 votes |
private boolean performLogin() throws LoginException { try { if (_passwordchar != null) { UnixUser user = _pam.authenticate(_username, String.valueOf(_passwordchar)); _principal = new PamPrincipal(user); _authSucceeded = true; return true; } else { throw new PAMException("Password is Null or Empty!!!"); } } catch (PAMException ex) { LoginException le = new FailedLoginException("Invalid username or password"); le.initCause(ex); throw le; } }
Example #6
Source File: PamLoginModule.java From atlas with Apache License 2.0 | 5 votes |
private void createPam(String service) throws LoginException { try { pam = new PAM(service); } catch (PAMException ex) { LoginException le = new LoginException("Error initializing PAM"); le.initCause(ex); throw le; } }
Example #7
Source File: UserAuthorityTest.java From athenz with Apache License 2.0 | 5 votes |
@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); 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); }
Example #8
Source File: UserAuthorityTest.java From athenz with Apache License 2.0 | 5 votes |
@Test public void testUserAuthorityAuthenticateException() throws PAMException { PAM pam = Mockito.mock(PAM.class); UserAuthority userAuthority = new UserAuthority(); userAuthority.setPAM(pam); Mockito.when(pam.authenticate("testuser", "testpwd")).thenThrow(RuntimeException.class); Principal principal = userAuthority.authenticate("Basic dGVzdHVzZXI6dGVždšB3ZA==", "10.72.118.45", "GET", null); assertNull(principal); principal = userAuthority.authenticate("Basic dGVzdHVzZXI6dGVzdHB3ZA==", "10.72.118.45", "GET", null); assertNull(principal); }
Example #9
Source File: UserAuthorityTest.java From athenz with Apache License 2.0 | 5 votes |
@Test public void testAuthenticateException() throws PAMException { PAM pam = Mockito.mock(PAM.class); UserAuthority userAuthority = new UserAuthority(); userAuthority.setPAM(pam); Mockito.when(pam.authenticate("testuser", "testpwd")).thenReturn(null); Principal principal = userAuthority.authenticate("Basic dGVzdHVzZXI6dGVzdHB3ZA==", "10.72.118.45", "GET", null); assertNull(principal); principal = userAuthority.authenticate("Basic ", "10.72.118.45", "GET", null); assertNull(principal); }
Example #10
Source File: PamLoginModule.java From incubator-atlas with Apache License 2.0 | 5 votes |
private void createPam(String service) throws LoginException { try { pam = new PAM(service); } catch (PAMException ex) { LoginException le = new LoginException("Error initializing PAM"); le.initCause(ex); throw le; } }
Example #11
Source File: PamLoginModule.java From ranger with Apache License 2.0 | 5 votes |
private void createPam(String service) throws LoginException { try { _pam = new PAM(service); } catch (PAMException ex) { LoginException le = new LoginException("Error initializing PAM"); le.initCause(ex); throw le; } }
Example #12
Source File: CLibrary.java From keycloak with Apache License 2.0 | 5 votes |
public static passwd loadPasswd(String userName) throws PAMException { passwd pwd = libc.getpwnam(userName); if (pwd == null) { throw new PAMException("No user information is available"); } return pwd; }
Example #13
Source File: UserAuthority.java From athenz with Apache License 2.0 | 4 votes |
PAM getPAM() throws PAMException { if (pam != null) { return pam; } return new PAM(serviceName); }
Example #14
Source File: UserAuthorityTest.java From athenz with Apache License 2.0 | 4 votes |
@Test public void testGetPAM() throws PAMException { UserAuthority userAuthority = new UserAuthority(); assertNotNull(userAuthority.getPAM()); }