use of org.springframework.security.providers.UsernamePasswordAuthenticationToken in project gocd by gocd.
the class GoAuthenticationProviderFactoryTest method shouldCreateLicenseEnforcementProviderWithUserServicePassedIn.
@Test
public void shouldCreateLicenseEnforcementProviderWithUserServicePassedIn() throws Exception {
GoAuthenticationProvider licenseEnforcementProvider = (GoAuthenticationProvider) factory.getObject();
AuthenticationProvider underlyingProvider = mock(AuthenticationProvider.class);
licenseEnforcementProvider.setProvider(underlyingProvider);
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("foo", "bar");
UsernamePasswordAuthenticationToken resultantAuthorization = new UsernamePasswordAuthenticationToken(new org.springframework.security.userdetails.User("foo-user", "pass", true, true, true, true, new GrantedAuthority[] { GoAuthority.ROLE_USER.asAuthority() }), "bar");
when(underlyingProvider.authenticate(auth)).thenReturn(resultantAuthorization);
licenseEnforcementProvider.authenticate(auth);
verify(userService).addUserIfDoesNotExist(UserHelper.getUser(resultantAuthorization));
}
use of org.springframework.security.providers.UsernamePasswordAuthenticationToken in project gocd by gocd.
the class GoAuthenticationProviderTest method setUp.
@Before
public void setUp() throws Exception {
userService = mock(UserService.class);
underlyingProvider = mock(AuthenticationProvider.class);
enforcementProvider = new GoAuthenticationProvider(userService, underlyingProvider);
auth = new UsernamePasswordAuthenticationToken(new User("user", "pass", true, true, true, true, new GrantedAuthority[] {}), "credentials");
resultantAuthorization = new UsernamePasswordAuthenticationToken(new User("user-authenticated", "pass", true, true, true, true, new GrantedAuthority[] { GoAuthority.ROLE_GROUP_SUPERVISOR.asAuthority() }), "credentials");
when(underlyingProvider.authenticate(auth)).thenReturn(resultantAuthorization);
}
use of org.springframework.security.providers.UsernamePasswordAuthenticationToken in project gocd by gocd.
the class PluginAuthenticationProviderTest method shouldUpdatePluginRolesForAUserPostAuthentication.
@Test
public void shouldUpdatePluginRolesForAUserPostAuthentication() {
securityConfig.securityAuthConfigs().add(new SecurityAuthConfig("ldap", "cd.go.ldap"));
securityConfig.securityAuthConfigs().add(new SecurityAuthConfig("github", "cd.go.github"));
String pluginId1 = "cd.go.ldap";
String pluginId2 = "cd.go.github";
addPluginSupportingPasswordBasedAuthentication(pluginId1);
addPluginSupportingPasswordBasedAuthentication(pluginId2);
when(authorizationExtension.authenticateUser(pluginId1, "username", "password", securityConfig.securityAuthConfigs().findByPluginId(pluginId1), securityConfig.getPluginRoles(pluginId1))).thenReturn(new AuthenticationResponse(new User("username", "bob", "bob@example.com"), Arrays.asList("blackbird", "admins")));
when(authorizationExtension.authenticateUser(pluginId2, "username", "password", securityConfig.securityAuthConfigs().findByPluginId(pluginId2), securityConfig.getPluginRoles(pluginId2))).thenReturn(NULL_AUTH_RESPONSE);
UserDetails userDetails = provider.retrieveUser("username", new UsernamePasswordAuthenticationToken(null, "password"));
assertNotNull(userDetails);
verify(pluginRoleService).updatePluginRoles("cd.go.ldap", "username", CaseInsensitiveString.caseInsensitiveStrings(Arrays.asList("blackbird", "admins")));
}
use of org.springframework.security.providers.UsernamePasswordAuthenticationToken in project gocd by gocd.
the class PluginAuthenticationProviderTest method reuthenticationUsingAuthorizationPlugins_shouldFallbackOnUserNameInAbsenceOfGoUserPrinciple.
@Test
public void reuthenticationUsingAuthorizationPlugins_shouldFallbackOnUserNameInAbsenceOfGoUserPrinciple() throws Exception {
String pluginId1 = "cd.go.ldap";
securityConfig.securityAuthConfigs().add(new SecurityAuthConfig("ldap", "cd.go.ldap"));
addPluginSupportingPasswordBasedAuthentication(pluginId1);
when(authorizationExtension.authenticateUser(pluginId1, "username", "password", securityConfig.securityAuthConfigs().findByPluginId(pluginId1), securityConfig.getPluginRoles(pluginId1))).thenReturn(new AuthenticationResponse(new User("username", "bob", "bob@example.com"), Arrays.asList("blackbird", "admins")));
UserDetails userDetails = provider.retrieveUser("username", new UsernamePasswordAuthenticationToken(null, "password"));
assertNotNull(userDetails);
verify(pluginRoleService).updatePluginRoles("cd.go.ldap", "username", CaseInsensitiveString.caseInsensitiveStrings(Arrays.asList("blackbird", "admins")));
}
use of org.springframework.security.providers.UsernamePasswordAuthenticationToken in project gocd by gocd.
the class PluginAuthenticationProviderTest method authenticatedUsersUsernameShouldBeUsedToAssignRoles.
@Test
public void authenticatedUsersUsernameShouldBeUsedToAssignRoles() throws Exception {
String pluginId1 = "cd.go.ldap";
securityConfig.securityAuthConfigs().add(new SecurityAuthConfig("ldap", "cd.go.ldap"));
addPluginSupportingPasswordBasedAuthentication(pluginId1);
when(authorizationExtension.authenticateUser(pluginId1, "foo@bar.com", "password", securityConfig.securityAuthConfigs().findByPluginId(pluginId1), securityConfig.getPluginRoles(pluginId1))).thenReturn(new AuthenticationResponse(new User("username", "bob", "bob@example.com"), Arrays.asList("blackbird", "admins")));
UserDetails userDetails = provider.retrieveUser("foo@bar.com", new UsernamePasswordAuthenticationToken(null, "password"));
assertNotNull(userDetails);
verify(pluginRoleService).updatePluginRoles("cd.go.ldap", "username", CaseInsensitiveString.caseInsensitiveStrings(Arrays.asList("blackbird", "admins")));
}
Aggregations