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());
}
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()));
}
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"));
}
Aggregations