Search in sources :

Example 1 with PluginRoleService

use of com.thoughtworks.go.server.service.PluginRoleService in project gocd by gocd.

the class AuthorizationRequestProcessorTest method shouldProcessInvalidateCacheRequest.

@Test
public void shouldProcessInvalidateCacheRequest() throws Exception {
    PluginRoleService pluginRoleService = mock(PluginRoleService.class);
    when(authorizationExtension.getMessageConverter(AuthorizationMessageConverterV1.VERSION)).thenReturn(new AuthorizationMessageConverterV1());
    GoApiRequest request = new DefaultGoApiRequest(INVALIDATE_CACHE_REQUEST.requestName(), "1.0", null);
    AuthorizationRequestProcessor authorizationRequestProcessor = new AuthorizationRequestProcessor(registry, null, authorizationExtension, pluginRoleService);
    GoApiResponse response = authorizationRequestProcessor.process(pluginDescriptor, request);
    assertThat(response.responseCode(), is(200));
    verify(pluginRoleService).invalidateRolesFor("cd.go.authorization.github");
}
Also used : GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) AuthorizationMessageConverterV1(com.thoughtworks.go.plugin.access.authorization.AuthorizationMessageConverterV1) DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest) GoApiRequest(com.thoughtworks.go.plugin.api.request.GoApiRequest) PluginRoleService(com.thoughtworks.go.server.service.PluginRoleService) DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest) Test(org.junit.Test)

Example 2 with PluginRoleService

use of com.thoughtworks.go.server.service.PluginRoleService 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)

Aggregations

PluginRoleService (com.thoughtworks.go.server.service.PluginRoleService)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)1 SecurityConfig (com.thoughtworks.go.config.SecurityConfig)1 AuthorizationExtension (com.thoughtworks.go.plugin.access.authorization.AuthorizationExtension)1 AuthorizationMessageConverterV1 (com.thoughtworks.go.plugin.access.authorization.AuthorizationMessageConverterV1)1 AuthenticationResponse (com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse)1 User (com.thoughtworks.go.plugin.access.authorization.models.User)1 DefaultGoApiRequest (com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest)1 GoApiRequest (com.thoughtworks.go.plugin.api.request.GoApiRequest)1 GoApiResponse (com.thoughtworks.go.plugin.api.response.GoApiResponse)1 AuthorityGranter (com.thoughtworks.go.server.security.AuthorityGranter)1 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)1 UserService (com.thoughtworks.go.server.service.UserService)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 Map (java.util.Map)1 Before (org.junit.Before)1 Test (org.junit.Test)1