Search in sources :

Example 6 with AuthorityGranter

use of com.thoughtworks.go.server.security.AuthorityGranter in project gocd by gocd.

the class PreAuthenticatedAuthenticationProviderTest method setUp.

@Before
public void setUp() throws Exception {
    pluginId = "github.oauth";
    user = new User("username", "displayname", "emailId");
    authorities = new GrantedAuthority[] { GoAuthority.ROLE_USER.asAuthority() };
    authorizationExtension = mock(AuthorizationExtension.class);
    authorityGranter = mock(AuthorityGranter.class);
    userService = mock(UserService.class);
    pluginRoleService = mock(PluginRoleService.class);
    goConfigService = mock(GoConfigService.class);
    authenticationProvider = new PreAuthenticatedAuthenticationProvider(authorizationExtension, pluginRoleService, userService, authorityGranter, goConfigService);
    AuthenticationResponse authenticationResponse = new AuthenticationResponse(user, asList("admin"));
    securityConfig = new SecurityConfig();
    stub(goConfigService.security()).toReturn(securityConfig);
    stub(authorizationExtension.authenticateUser(any(String.class), any(Map.class), any(List.class), any(List.class))).toReturn(authenticationResponse);
    stub(authorityGranter.authorities(anyString())).toReturn(authorities);
    securityConfig.securityAuthConfigs().add(new SecurityAuthConfig("github", pluginId));
}
Also used : AuthorityGranter(com.thoughtworks.go.server.security.AuthorityGranter) User(com.thoughtworks.go.plugin.access.authorization.models.User) UserService(com.thoughtworks.go.server.service.UserService) AuthorizationExtension(com.thoughtworks.go.plugin.access.authorization.AuthorizationExtension) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) PluginRoleService(com.thoughtworks.go.server.service.PluginRoleService) AuthenticationResponse(com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) SecurityConfig(com.thoughtworks.go.config.SecurityConfig) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Map(java.util.Map) Before(org.junit.Before)

Example 7 with AuthorityGranter

use of com.thoughtworks.go.server.security.AuthorityGranter in project gocd by gocd.

the class AnonymousAuthenticationProviderTest method setUp.

@BeforeEach
void setUp() {
    clock = new TestingClock();
    securityService = mock(SecurityService.class);
    authorityGranter = new AuthorityGranter(securityService);
    anonymousAuthenticationProvider = new AnonymousAuthenticationProvider(clock, authorityGranter);
}
Also used : AuthorityGranter(com.thoughtworks.go.server.security.AuthorityGranter) SecurityService(com.thoughtworks.go.server.service.SecurityService) TestingClock(com.thoughtworks.go.util.TestingClock) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with AuthorityGranter

use of com.thoughtworks.go.server.security.AuthorityGranter in project gocd by gocd.

the class WebBasedPluginAuthenticationProviderTest method setUp.

@BeforeEach
void setUp() {
    SecurityService securityService = mock(SecurityService.class);
    authorityGranter = spy(new AuthorityGranter(securityService));
    goConfigService = mock(GoConfigService.class);
    userService = mock(UserService.class);
    authorizationExtension = mock(AuthorizationExtension.class);
    pluginRoleService = mock(PluginRoleService.class);
    clock = new TestingClock();
    securityConfig = new SecurityConfig();
    githubSecurityAuthconfig = new SecurityAuthConfig("github", PLUGIN_ID);
    securityConfig.securityAuthConfigs().add(githubSecurityAuthconfig);
    when(goConfigService.security()).thenReturn(securityConfig);
    addPluginSupportingWebBasedAuthentication(PLUGIN_ID);
    authenticationProvider = new WebBasedPluginAuthenticationProvider(authorizationExtension, authorityGranter, goConfigService, pluginRoleService, userService, clock);
}
Also used : AuthorityGranter(com.thoughtworks.go.server.security.AuthorityGranter) UserService(com.thoughtworks.go.server.service.UserService) SecurityService(com.thoughtworks.go.server.service.SecurityService) AuthorizationExtension(com.thoughtworks.go.plugin.access.authorization.AuthorizationExtension) PluginRoleService(com.thoughtworks.go.server.service.PluginRoleService) TestingClock(com.thoughtworks.go.util.TestingClock) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 9 with AuthorityGranter

use of com.thoughtworks.go.server.security.AuthorityGranter in project gocd by gocd.

the class PasswordBasedPluginAuthenticationProviderTest method setUp.

@BeforeEach
void setUp() {
    SecurityService securityService = mock(SecurityService.class);
    AuthorityGranter authorityGranter = new AuthorityGranter(securityService);
    GoConfigService goConfigService = mock(GoConfigService.class);
    userService = mock(UserService.class);
    authorizationExtension = mock(AuthorizationExtension.class);
    pluginRoleService = mock(PluginRoleService.class);
    clock = new TestingClock();
    securityConfig = new SecurityConfig();
    when(goConfigService.security()).thenReturn(securityConfig);
    provider = new PasswordBasedPluginAuthenticationProvider(authorizationExtension, authorityGranter, goConfigService, pluginRoleService, userService, clock);
}
Also used : AuthorityGranter(com.thoughtworks.go.server.security.AuthorityGranter) UserService(com.thoughtworks.go.server.service.UserService) SecurityConfig(com.thoughtworks.go.config.SecurityConfig) SecurityService(com.thoughtworks.go.server.service.SecurityService) AuthorizationExtension(com.thoughtworks.go.plugin.access.authorization.AuthorizationExtension) PluginRoleService(com.thoughtworks.go.server.service.PluginRoleService) TestingClock(com.thoughtworks.go.util.TestingClock) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with AuthorityGranter

use of com.thoughtworks.go.server.security.AuthorityGranter in project gocd by gocd.

the class AssumeAnonymousUserFilterTest method setUp.

@BeforeEach
void setUp() {
    clock = new TestingClock();
    securityService = mock(SecurityService.class);
    anonymousAuthenticationProvider = new AnonymousAuthenticationProvider(clock, new AuthorityGranter(securityService));
    filterChain = mock(FilterChain.class);
    response = new MockHttpServletResponse();
    request = new MockHttpServletRequest();
}
Also used : AuthorityGranter(com.thoughtworks.go.server.security.AuthorityGranter) SecurityService(com.thoughtworks.go.server.service.SecurityService) MockHttpServletRequest(com.thoughtworks.go.http.mocks.MockHttpServletRequest) 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