use of com.thoughtworks.go.server.security.AuthorityGranter in project gocd by gocd.
the class FileAuthenticationProviderTest method shouldHandleApacheFormatFile.
@Test
public void shouldHandleApacheFormatFile() throws IOException {
setupFile("cread:{SHA}OPhRtj5TCERacn3mvwItERz8uCk=");
when(securityService.isUserAdmin(new Username(new CaseInsensitiveString("cread")))).thenReturn(true);
when(userService.findUserByName("cread")).thenReturn(new com.thoughtworks.go.domain.User("cread", "Chriss Readds", "cread@humble.com"));
AuthorityGranter authorityGranter = new AuthorityGranter(securityService);
FileAuthenticationProvider provider = new FileAuthenticationProvider(goConfigService, authorityGranter, userService, securityService);
final UserDetails details = provider.retrieveUser("cread", null);
assertThat(details.getAuthorities()[0].getAuthority(), is("ROLE_SUPERVISOR"));
assertThat(details.isAccountNonExpired(), is(true));
assertThat(details.isAccountNonLocked(), is(true));
assertThat(details.isCredentialsNonExpired(), is(true));
assertThat(details.isEnabled(), is(true));
assertThat(details.getUsername(), is("cread"));
assertThat(details.getPassword(), is("OPhRtj5TCERacn3mvwItERz8uCk="));
}
use of com.thoughtworks.go.server.security.AuthorityGranter in project gocd by gocd.
the class FileAuthenticationProviderTest method shouldThrowExceptionIfFileDoesNotExist.
@Test(expected = UsernameNotFoundException.class)
public void shouldThrowExceptionIfFileDoesNotExist() throws Exception {
when(goConfigService.security()).thenReturn(new SecurityConfig(new LdapConfig(new GoCipher()), new PasswordFileConfig("ueyrweiyri"), true, null));
AuthorityGranter authorityGranter = new AuthorityGranter(securityService);
FileAuthenticationProvider provider = new FileAuthenticationProvider(goConfigService, authorityGranter, userService, securityService);
provider.retrieveUser("blah", null);
}
use of com.thoughtworks.go.server.security.AuthorityGranter in project gocd by gocd.
the class FileAuthenticationProviderTest method shouldStripOutAuthoritiesThatIsSpecifiedInPasswordFile.
@Test
public void shouldStripOutAuthoritiesThatIsSpecifiedInPasswordFile() throws Exception {
setupFile("jez=" + SHA1_BADGER + ",ROLE_OF_GOD");
when(securityService.isUserAdmin(new Username(new CaseInsensitiveString("jez")))).thenReturn(true);
when(userService.findUserByName("jez")).thenReturn(new com.thoughtworks.go.domain.User("jez", "Jezz Humbles", "jez@humble.com"));
AuthorityGranter authorityGranter = new AuthorityGranter(securityService);
FileAuthenticationProvider provider = new FileAuthenticationProvider(goConfigService, authorityGranter, userService, securityService);
final GoUserPrinciple details = (GoUserPrinciple) provider.retrieveUser("jez", null);
assertThat(details.getUsername(), is("jez"));
assertThat(details.getDisplayName(), is("Jezz Humbles"));
assertThat(details.getAuthorities().length, is(2));
assertThat(details.getAuthorities()[0].getAuthority(), Is.is(GoAuthority.ROLE_SUPERVISOR.name()));
assertThat(details.getAuthorities()[1].getAuthority(), is(GoAuthority.ROLE_USER.name()));
}
use of com.thoughtworks.go.server.security.AuthorityGranter in project gocd by gocd.
the class AuthenticationFilterChainTest method setUp.
@BeforeEach
void setUp() throws IOException {
response = new MockHttpServletResponse();
filterChain = mock(FilterChain.class);
securityService = mock(SecurityService.class);
clock = new TestingClock();
systemEnvironment = new SystemEnvironment();
final AnonymousAuthenticationProvider anonymousAuthenticationProvider = new AnonymousAuthenticationProvider(clock, new AuthorityGranter(securityService));
assumeAnonymousUserFilter = new AssumeAnonymousUserFilter(securityService, anonymousAuthenticationProvider);
}
Aggregations