Search in sources :

Example 1 with ClientDetailsUserDetailsService

use of org.springframework.security.oauth2.provider.client.ClientDetailsUserDetailsService in project spring-security-oauth by spring-projects.

the class ClientDetailsUserDetailsServiceTests method shouldConductOriginalException.

@SuppressWarnings("unchecked")
@Test(expected = ClientRegistrationException.class)
public void shouldConductOriginalException() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put(UserAuthenticationConverter.USERNAME, "test_user");
    ClientDetailsService clientDetailsService = Mockito.mock(ClientDetailsService.class);
    Mockito.when(clientDetailsService.loadClientByClientId("test_user")).thenThrow(ClientRegistrationException.class);
    ClientDetailsUserDetailsService testee = new ClientDetailsUserDetailsService(clientDetailsService);
    testee.loadUserByUsername("test_user");
}
Also used : HashMap(java.util.HashMap) ClientDetailsService(org.springframework.security.oauth2.provider.ClientDetailsService) Test(org.junit.Test)

Example 2 with ClientDetailsUserDetailsService

use of org.springframework.security.oauth2.provider.client.ClientDetailsUserDetailsService in project spring-security-oauth by spring-projects.

the class AuthorizationServerSecurityConfigurer method init.

@Override
public void init(HttpSecurity http) throws Exception {
    registerDefaultAuthenticationEntryPoint(http);
    if (passwordEncoder != null) {
        ClientDetailsUserDetailsService clientDetailsUserDetailsService = new ClientDetailsUserDetailsService(clientDetailsService());
        clientDetailsUserDetailsService.setPasswordEncoder(passwordEncoder());
        http.getSharedObject(AuthenticationManagerBuilder.class).userDetailsService(clientDetailsUserDetailsService).passwordEncoder(passwordEncoder());
    } else {
        http.userDetailsService(new ClientDetailsUserDetailsService(clientDetailsService()));
    }
    http.securityContext().securityContextRepository(new NullSecurityContextRepository()).and().csrf().disable().httpBasic().realmName(realm);
}
Also used : NullSecurityContextRepository(org.springframework.security.web.context.NullSecurityContextRepository) ClientDetailsUserDetailsService(org.springframework.security.oauth2.provider.client.ClientDetailsUserDetailsService)

Example 3 with ClientDetailsUserDetailsService

use of org.springframework.security.oauth2.provider.client.ClientDetailsUserDetailsService in project spring-security-oauth by spring-projects.

the class ClientDetailsUserDetailsServiceTests method shouldThrowUsernameNotFoundExceptionWhenNoSuchClient.

@SuppressWarnings("unchecked")
@Test(expected = UsernameNotFoundException.class)
public void shouldThrowUsernameNotFoundExceptionWhenNoSuchClient() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put(UserAuthenticationConverter.USERNAME, "test_user");
    ClientDetailsService clientDetailsService = Mockito.mock(ClientDetailsService.class);
    Mockito.when(clientDetailsService.loadClientByClientId("test_user")).thenThrow(NoSuchClientException.class);
    ClientDetailsUserDetailsService testee = new ClientDetailsUserDetailsService(clientDetailsService);
    testee.loadUserByUsername("test_user");
}
Also used : HashMap(java.util.HashMap) ClientDetailsService(org.springframework.security.oauth2.provider.ClientDetailsService) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)2 Test (org.junit.Test)2 ClientDetailsService (org.springframework.security.oauth2.provider.ClientDetailsService)2 ClientDetailsUserDetailsService (org.springframework.security.oauth2.provider.client.ClientDetailsUserDetailsService)1 NullSecurityContextRepository (org.springframework.security.web.context.NullSecurityContextRepository)1