Search in sources :

Example 1 with DefaultUserAuthenticationConverter

use of org.springframework.security.oauth2.provider.token.DefaultUserAuthenticationConverter in project cloud-sea-towerman by huadahuang1983.

the class WebSecurityConfig method remoteTokenServices.

@Bean
public RemoteTokenServices remoteTokenServices() {
    RemoteTokenServices services = new RemoteTokenServices();
    services.setCheckTokenEndpointUrl(this.resource.getTokenInfoUri());
    services.setClientId(this.resource.getClientId());
    services.setClientSecret(this.resource.getClientSecret());
    DefaultUserAuthenticationConverter userTokenConverter = new DefaultUserAuthenticationConverter();
    userTokenConverter.setUserDetailsService(userDetailsService());
    DefaultAccessTokenConverter tokenConverter = new DefaultAccessTokenConverter();
    tokenConverter.setUserTokenConverter(userTokenConverter);
    services.setAccessTokenConverter(tokenConverter);
    return services;
}
Also used : DefaultAccessTokenConverter(org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter) DefaultUserAuthenticationConverter(org.springframework.security.oauth2.provider.token.DefaultUserAuthenticationConverter) RemoteTokenServices(org.springframework.security.oauth2.provider.token.RemoteTokenServices) Bean(org.springframework.context.annotation.Bean)

Example 2 with DefaultUserAuthenticationConverter

use of org.springframework.security.oauth2.provider.token.DefaultUserAuthenticationConverter in project spring-security-oauth2-google by skate056.

the class GoogleTokenServicesTest method shouldLoadAuthenticationAndTransformValuesToStandardValuesAndAddDomainRole.

@Test
public void shouldLoadAuthenticationAndTransformValuesToStandardValuesAndAddDomainRole() throws Exception {
    Map<String, String> body = new HashMap<>();
    body.put("issued_to", "blh");
    body.put("user_id", "user@domain.google.com");
    body.put("email", "user@domain.google.com");
    given(response.getBody()).willReturn(body);
    given(restTemplate.exchange(anyString(), any(HttpMethod.class), any(HttpEntity.class), any(ParameterizedTypeReference.class))).willReturn(response);
    googleTokenServices.setRestTemplate(restTemplate);
    googleTokenServices.setCheckTokenEndpointUrl("//");
    DefaultUserAuthenticationConverter defaultUserAuthenticationConverter = new DefaultUserAuthenticationConverter();
    defaultUserAuthenticationConverter.setAuthorityGranter(authorityGranter);
    GoogleAccessTokenConverter realAccessTokenConverter = new GoogleAccessTokenConverter();
    realAccessTokenConverter.setUserTokenConverter(defaultUserAuthenticationConverter);
    googleTokenServices.setAccessTokenConverter(realAccessTokenConverter);
    OAuth2Authentication authentication = googleTokenServices.loadAuthentication(null);
    assertThat(authentication, notNullValue());
    verify(authorityGranter).getAuthorities(anyMap());
}
Also used : HttpEntity(org.springframework.http.HttpEntity) HashMap(java.util.HashMap) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Matchers.anyString(org.mockito.Matchers.anyString) HttpMethod(org.springframework.http.HttpMethod) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Bean (org.springframework.context.annotation.Bean)1 ParameterizedTypeReference (org.springframework.core.ParameterizedTypeReference)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpMethod (org.springframework.http.HttpMethod)1 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)1 DefaultAccessTokenConverter (org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter)1 DefaultUserAuthenticationConverter (org.springframework.security.oauth2.provider.token.DefaultUserAuthenticationConverter)1 RemoteTokenServices (org.springframework.security.oauth2.provider.token.RemoteTokenServices)1