Search in sources :

Example 1 with AuthorizationExtension

use of com.thoughtworks.go.plugin.access.authorization.AuthorizationExtension in project gocd by gocd.

the class WebBasedAuthenticationFilterTest method setUp.

@Before
public void setUp() throws Exception {
    request = mock(HttpServletRequest.class);
    response = mock(HttpServletResponse.class);
    filterChain = mock(FilterChain.class);
    authorizationExtension = mock(AuthorizationExtension.class);
    goConfigService = mock(GoConfigService.class);
    siteUrlProvider = mock(SiteUrlProvider.class);
    securityConfig = new SecurityConfig();
    securityAuthConfig = new SecurityAuthConfig("github", "github.oauth", new ConfigurationProperty());
    securityConfig.securityAuthConfigs().add(securityAuthConfig);
    stub(goConfigService.security()).toReturn(securityConfig);
    filter = new WebBasedAuthenticationFilter(authorizationExtension, goConfigService, siteUrlProvider);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) SecurityConfig(com.thoughtworks.go.config.SecurityConfig) AuthorizationExtension(com.thoughtworks.go.plugin.access.authorization.AuthorizationExtension) FilterChain(javax.servlet.FilterChain) SiteUrlProvider(com.thoughtworks.go.server.web.SiteUrlProvider) HttpServletResponse(javax.servlet.http.HttpServletResponse) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Before(org.junit.Before)

Example 2 with AuthorizationExtension

use of com.thoughtworks.go.plugin.access.authorization.AuthorizationExtension 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 3 with AuthorizationExtension

use of com.thoughtworks.go.plugin.access.authorization.AuthorizationExtension 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 4 with AuthorizationExtension

use of com.thoughtworks.go.plugin.access.authorization.AuthorizationExtension 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 5 with AuthorizationExtension

use of com.thoughtworks.go.plugin.access.authorization.AuthorizationExtension in project gocd by gocd.

the class PreAuthenticatedRequestsProcessingFilterTest method setUp.

@Before
public void setUp() throws Exception {
    request = mock(HttpServletRequest.class);
    response = mock(HttpServletResponse.class);
    filterChain = mock(FilterChain.class);
    authenticationManager = mock(AuthenticationManager.class);
    authorizationExtension = mock(AuthorizationExtension.class);
    configService = mock(GoConfigService.class);
    filter = new PreAuthenticatedRequestsProcessingFilter(authorizationExtension, configService);
    securityConfig = new SecurityConfig();
    filter.setAuthenticationManager(authenticationManager);
    filter.setFilterProcessesUrl("^/go/plugin/([\\w\\-.]+)/authenticate$");
    stub(configService.security()).toReturn(securityConfig);
    stub(request.getHeaderNames()).toReturn(Collections.emptyEnumeration());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AuthenticationManager(org.springframework.security.AuthenticationManager) SecurityConfig(com.thoughtworks.go.config.SecurityConfig) AuthorizationExtension(com.thoughtworks.go.plugin.access.authorization.AuthorizationExtension) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Before(org.junit.Before)

Aggregations

AuthorizationExtension (com.thoughtworks.go.plugin.access.authorization.AuthorizationExtension)5 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)5 SecurityConfig (com.thoughtworks.go.config.SecurityConfig)4 AuthorityGranter (com.thoughtworks.go.server.security.AuthorityGranter)3 PluginRoleService (com.thoughtworks.go.server.service.PluginRoleService)3 UserService (com.thoughtworks.go.server.service.UserService)3 Before (org.junit.Before)3 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)2 SecurityService (com.thoughtworks.go.server.service.SecurityService)2 TestingClock (com.thoughtworks.go.util.TestingClock)2 FilterChain (javax.servlet.FilterChain)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)1 AuthenticationResponse (com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse)1 User (com.thoughtworks.go.plugin.access.authorization.models.User)1 SiteUrlProvider (com.thoughtworks.go.server.web.SiteUrlProvider)1 Arrays.asList (java.util.Arrays.asList)1