Search in sources :

Example 11 with AuthorityGranter

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="));
}
Also used : AuthorityGranter(com.thoughtworks.go.server.security.AuthorityGranter) UserDetails(org.springframework.security.userdetails.UserDetails) Username(com.thoughtworks.go.server.domain.Username) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 12 with AuthorityGranter

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);
}
Also used : LdapConfig(com.thoughtworks.go.config.LdapConfig) AuthorityGranter(com.thoughtworks.go.server.security.AuthorityGranter) GoCipher(com.thoughtworks.go.security.GoCipher) SecurityConfig(com.thoughtworks.go.config.SecurityConfig) PasswordFileConfig(com.thoughtworks.go.config.PasswordFileConfig) Test(org.junit.Test)

Example 13 with AuthorityGranter

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()));
}
Also used : AuthorityGranter(com.thoughtworks.go.server.security.AuthorityGranter) Username(com.thoughtworks.go.server.domain.Username) GoUserPrinciple(com.thoughtworks.go.server.security.userdetail.GoUserPrinciple) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 14 with AuthorityGranter

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);
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AuthorityGranter(com.thoughtworks.go.server.security.AuthorityGranter) FilterChain(javax.servlet.FilterChain) TestingClock(com.thoughtworks.go.util.TestingClock) AnonymousAuthenticationProvider(com.thoughtworks.go.server.newsecurity.providers.AnonymousAuthenticationProvider) MockHttpServletResponse(com.thoughtworks.go.http.mocks.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

AuthorityGranter (com.thoughtworks.go.server.security.AuthorityGranter)14 Test (org.junit.Test)8 TestingClock (com.thoughtworks.go.util.TestingClock)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 SecurityService (com.thoughtworks.go.server.service.SecurityService)4 UserDetails (org.springframework.security.userdetails.UserDetails)4 SecurityConfig (com.thoughtworks.go.config.SecurityConfig)3 AuthorizationExtension (com.thoughtworks.go.plugin.access.authorization.AuthorizationExtension)3 Username (com.thoughtworks.go.server.domain.Username)3 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)3 PluginRoleService (com.thoughtworks.go.server.service.PluginRoleService)3 UserService (com.thoughtworks.go.server.service.UserService)3 MockHttpServletResponse (com.thoughtworks.go.http.mocks.MockHttpServletResponse)2 AnonymousAuthenticationProvider (com.thoughtworks.go.server.newsecurity.providers.AnonymousAuthenticationProvider)2 GoUserPrinciple (com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)2 FilterChain (javax.servlet.FilterChain)2 UsernamePasswordAuthenticationToken (org.springframework.security.providers.UsernamePasswordAuthenticationToken)2 User (org.springframework.security.userdetails.User)2 LdapConfig (com.thoughtworks.go.config.LdapConfig)1