Search in sources :

Example 16 with User

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

the class PluginAuthenticationProviderTest method shouldRelyOnTheAuthConfigOrderWhileAuthenticatingUser.

@Test
public void shouldRelyOnTheAuthConfigOrderWhileAuthenticatingUser() throws Exception {
    SecurityAuthConfig sha1Passwords = new SecurityAuthConfig("sha1Passwords", "file");
    SecurityAuthConfig corporateLDAP = new SecurityAuthConfig("corporateLDAP", "ldap");
    SecurityAuthConfig bcryptPasswords = new SecurityAuthConfig("bcryptPasswords", "file");
    SecurityAuthConfig internalLDAP = new SecurityAuthConfig("internalLDAP", "ldap");
    addPluginSupportingPasswordBasedAuthentication("file");
    addPluginSupportingPasswordBasedAuthentication("ldap");
    securityConfig.securityAuthConfigs().add(sha1Passwords);
    securityConfig.securityAuthConfigs().add(corporateLDAP);
    securityConfig.securityAuthConfigs().add(bcryptPasswords);
    securityConfig.securityAuthConfigs().add(internalLDAP);
    InOrder inOrder = inOrder(authorizationExtension);
    when(authorizationExtension.authenticateUser("ldap", "username", "password", Collections.singletonList(internalLDAP), Collections.emptyList())).thenReturn(new AuthenticationResponse(new User("username", null, null), Collections.emptyList()));
    provider.retrieveUser("username", authenticationToken);
    inOrder.verify(authorizationExtension).authenticateUser("file", "username", "password", Collections.singletonList(sha1Passwords), Collections.emptyList());
    inOrder.verify(authorizationExtension).authenticateUser("ldap", "username", "password", Collections.singletonList(corporateLDAP), Collections.emptyList());
    inOrder.verify(authorizationExtension).authenticateUser("file", "username", "password", Collections.singletonList(bcryptPasswords), Collections.emptyList());
    inOrder.verify(authorizationExtension).authenticateUser("ldap", "username", "password", Collections.singletonList(internalLDAP), Collections.emptyList());
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) InOrder(org.mockito.InOrder) User(com.thoughtworks.go.plugin.access.authorization.models.User) AuthenticationResponse(com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse) Test(org.junit.Test)

Example 17 with User

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

the class PreAuthenticatedAuthenticationProviderTest method authenticate_shouldEnsureUserDetailsInAuthTokenHasDisplayName.

@Test
public void authenticate_shouldEnsureUserDetailsInAuthTokenHasDisplayName() {
    Map<String, String> credentials = Collections.singletonMap("access_token", "some_token");
    PreAuthenticatedAuthenticationToken authenticationToken = new PreAuthenticatedAuthenticationToken(null, credentials, pluginId);
    AuthenticationResponse authenticationResponse = new AuthenticationResponse(new User("username", null, "email"), asList("admin"));
    when(authorizationExtension.authenticateUser(any(String.class), any(Map.class), any(List.class), any(List.class))).thenReturn(authenticationResponse);
    PreAuthenticatedAuthenticationToken authenticate = (PreAuthenticatedAuthenticationToken) authenticationProvider.authenticate(authenticationToken);
    GoUserPrinciple principal = (GoUserPrinciple) authenticate.getPrincipal();
    assertThat(principal.getDisplayName(), is(authenticationResponse.getUser().getUsername()));
}
Also used : User(com.thoughtworks.go.plugin.access.authorization.models.User) PreAuthenticatedAuthenticationToken(com.thoughtworks.go.server.security.tokens.PreAuthenticatedAuthenticationToken) Arrays.asList(java.util.Arrays.asList) List(java.util.List) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) GoUserPrinciple(com.thoughtworks.go.server.security.userdetail.GoUserPrinciple) AuthenticationResponse(com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse) Map(java.util.Map) Test(org.junit.Test)

Example 18 with User

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

the class AuthenticationResponseTest method shouldAbleToDeserializeJSON.

@Test
public void shouldAbleToDeserializeJSON() throws Exception {
    String json = "{\n" + "  \"user\": {\n" + "      \"username\":\"gocd\",\n" + "      \"display_name\": \"GoCD Admin\",\n" + "      \"email\": \"gocd@go.cd\"\n" + "  },\n" + "  \"roles\": [\"admin\",\"blackbird\"]\n" + "}";
    AuthenticationResponse authenticationResponse = AuthenticationResponse.fromJSON(json);
    assertThat(authenticationResponse.getUser(), is(new User("gocd", "GoCD Admin", "gocd@go.cd")));
    assertThat(authenticationResponse.getRoles(), hasSize(2));
    assertThat(authenticationResponse.getRoles(), containsInAnyOrder("admin", "blackbird"));
}
Also used : User(com.thoughtworks.go.plugin.access.authorization.models.User) AuthenticationResponse(com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse) Test(org.junit.Test)

Aggregations

User (com.thoughtworks.go.plugin.access.authorization.models.User)18 AuthenticationResponse (com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse)15 Test (org.junit.Test)15 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)14 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)10 UserDetails (org.springframework.security.userdetails.UserDetails)7 GoUserPrinciple (com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)5 UsernamePasswordAuthenticationToken (org.springframework.security.providers.UsernamePasswordAuthenticationToken)5 PluginRoleConfig (com.thoughtworks.go.config.PluginRoleConfig)4 DefaultGoPluginApiResponse (com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse)3 SecurityAuthConfigs (com.thoughtworks.go.config.SecurityAuthConfigs)2 PreAuthenticatedAuthenticationToken (com.thoughtworks.go.server.security.tokens.PreAuthenticatedAuthenticationToken)2 Arrays.asList (java.util.Arrays.asList)2 List (java.util.List)2 Map (java.util.Map)2 InOrder (org.mockito.InOrder)2 UsernameNotFoundException (org.springframework.security.userdetails.UsernameNotFoundException)2 SecurityConfig (com.thoughtworks.go.config.SecurityConfig)1 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)1 AuthorizationExtension (com.thoughtworks.go.plugin.access.authorization.AuthorizationExtension)1