UserAuthority implements Authority { public UserAuthority() { serviceName = System.getProperty(ATHENZ_PROP_PAM_SERVICE_NAME, "login"); } UserAuthority(); @Override void initialize(); @Override String getID(); @Override String getDomain(); @Override String getHeader(); @Override String getAuthenticateChallenge(); @Override boolean allowAuthorization(); @Override Principal authenticate(String creds, String remoteAddr, String httpMethod, StringBuilder errMsg); static final String ATHENZ_AUTH_CHALLENGE; }
@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")); principal = userAuthority.authenticate("Basic dGVzdHVzZXIK", "10.72.118.45", "GET", errMsg); assertNull(principal); }