### Question:
AmbariProxiedUserDetailsService implements UserDetailsService { boolean validateUser(AmbariTProxyConfiguration tProxyConfiguration, String proxyUserName, String proxiedUserName) { String allowedUsers = tProxyConfiguration.getAllowedUsers(proxyUserName); if (StringUtils.isNotEmpty(allowedUsers)) { String[] userSpecs = allowedUsers.split("\\s*,\\s*"); for (String userSpec : userSpecs) { if ("*".equals(userSpec) || (userSpec.equalsIgnoreCase(proxiedUserName))) { return true; } } } return false; } AmbariProxiedUserDetailsService(Configuration configuration, Users users); @Override UserDetails loadUserByUsername(String proxiedUserName); UserDetails loadProxiedUser(String proxiedUserName,
                                     String proxyUserName,
                                     TrustedProxyAuthenticationDetails trustedProxyAuthenticationDetails);  }### Answer:
@Test public void testValidateUser() { AmbariProxiedUserDetailsService service = new AmbariProxiedUserDetailsService(createNiceMock(Configuration.class), createNiceMock(Users.class)); AmbariTProxyConfiguration tproxyConfigration = createMock(AmbariTProxyConfiguration.class); expect(tproxyConfigration.getAllowedUsers("proxyUser")).andReturn("*").once(); expect(tproxyConfigration.getAllowedUsers("proxyUser")).andReturn("validUser").once(); expect(tproxyConfigration.getAllowedUsers("proxyUser")).andReturn("validuser").once(); expect(tproxyConfigration.getAllowedUsers("proxyUser")).andReturn("validUser, tom, *").once(); expect(tproxyConfigration.getAllowedUsers("proxyUser")).andReturn(null).once(); expect(tproxyConfigration.getAllowedUsers("proxyUser")).andReturn("").once(); expect(tproxyConfigration.getAllowedUsers("proxyUser")).andReturn("notValidUser").once(); replayAll(); Assert.assertTrue(service.validateUser(tproxyConfigration, "proxyUser", "validUser")); Assert.assertTrue(service.validateUser(tproxyConfigration, "proxyUser", "validUser")); Assert.assertTrue(service.validateUser(tproxyConfigration, "proxyUser", "validUser")); Assert.assertTrue(service.validateUser(tproxyConfigration, "proxyUser", "validUser")); Assert.assertFalse(service.validateUser(tproxyConfigration, "proxyUser", "validUser")); Assert.assertFalse(service.validateUser(tproxyConfigration, "proxyUser", "validUser")); Assert.assertFalse(service.validateUser(tproxyConfigration, "proxyUser", "validUser")); verifyAll(); }