Search in sources :

Example 1 with AuthenticationProvider

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));
}
Also used : GrantedAuthority(org.springframework.security.GrantedAuthority) AuthenticationProvider(org.springframework.security.providers.AuthenticationProvider) UsernamePasswordAuthenticationToken(org.springframework.security.providers.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 GrantedAuthority (org.springframework.security.GrantedAuthority)1 AuthenticationProvider (org.springframework.security.providers.AuthenticationProvider)1 UsernamePasswordAuthenticationToken (org.springframework.security.providers.UsernamePasswordAuthenticationToken)1