@Test public void testAuthenticate() throws Exception { PAM pam = createNiceMock(PAM.class); UnixUser unixUser = createNiceMock(UnixUser.class); expect(pam.authenticate(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))).andReturn(unixUser).atLeastOnce(); expect(unixUser.getGroups()).andReturn(new HashSet<String>(Arrays.asList("group"))).atLeastOnce(); EasyMock.replay(unixUser); EasyMock.replay(pam); Authentication authentication = new UsernamePasswordAuthenticationToken("allowedUser", "password"); Authentication result = authenticationProvider.authenticateViaPam(pam,authentication); assertEquals("allowedUser", result.getName()); }
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { if(isPamEnabled()){ PAM pam; try{ String pamConfig = configuration.getPamConfigurationFile(); pam = new PAM(pamConfig); } catch(PAMException ex) { LOG.error("Unable to Initialize PAM." + ex.getMessage()); throw new AuthenticationServiceException("Unable to Initialize PAM - ", ex); } return authenticateViaPam(pam, authentication); } else { return null; } }
AmbariPamAuthenticationProvider implements AuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { if(isPamEnabled()){ PAM pam; try{ String pamConfig = configuration.getPamConfigurationFile(); pam = new PAM(pamConfig); } catch(PAMException ex) { LOG.error("Unable to Initialize PAM." + ex.getMessage()); throw new AuthenticationServiceException("Unable to Initialize PAM - ", ex); } return authenticateViaPam(pam, authentication); } else { return null; } } }
AmbariPamAuthenticationProvider implements AuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { if(isPamEnabled()){ PAM pam; try{ String pamConfig = configuration.getPamConfigurationFile(); pam = new PAM(pamConfig); } catch(PAMException ex) { LOG.error("Unable to Initialize PAM." + ex.getMessage()); throw new AuthenticationServiceException("Unable to Initialize PAM - ", ex); } return authenticateViaPam(pam, authentication); } else { return null; } } @Inject  AmbariPamAuthenticationProvider(Configuration configuration); }
AmbariPamAuthenticationProvider implements AuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { if(isPamEnabled()){ PAM pam; try{ String pamConfig = configuration.getPamConfigurationFile(); pam = new PAM(pamConfig); } catch(PAMException ex) { LOG.error("Unable to Initialize PAM." + ex.getMessage()); throw new AuthenticationServiceException("Unable to Initialize PAM - ", ex); } return authenticateViaPam(pam, authentication); } else { return null; } } @Inject  AmbariPamAuthenticationProvider(Configuration configuration); @Override Authentication authenticate(Authentication authentication); @Override boolean supports(Class<?> authentication); }
AmbariPamAuthenticationProvider implements AuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { if(isPamEnabled()){ PAM pam; try{ String pamConfig = configuration.getPamConfigurationFile(); pam = new PAM(pamConfig); } catch(PAMException ex) { LOG.error("Unable to Initialize PAM." + ex.getMessage()); throw new AuthenticationServiceException("Unable to Initialize PAM - ", ex); } return authenticateViaPam(pam, authentication); } else { return null; } } @Inject  AmbariPamAuthenticationProvider(Configuration configuration); @Override Authentication authenticate(Authentication authentication); @Override boolean supports(Class<?> authentication);  }