use of org.springframework.security.providers.AuthenticationProvider 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));
}
Aggregations