Search in sources :

Example 1 with UserInfoTokenServices

use of org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoTokenServices in project spring-boot-quick by vector4wang.

the class WebSecurityConfig method sso.

private Filter sso() {
    OAuth2ClientAuthenticationProcessingFilter githubFilter = new OAuth2ClientAuthenticationProcessingFilter("/login/github");
    OAuth2RestTemplate githubTemplate = new OAuth2RestTemplate(github(), oauth2ClientContext);
    githubFilter.setRestTemplate(githubTemplate);
    githubFilter.setTokenServices(new UserInfoTokenServices(githubResource().getUserInfoUri(), github().getClientId()));
    return githubFilter;
}
Also used : UserInfoTokenServices(org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoTokenServices) OAuth2ClientAuthenticationProcessingFilter(org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter) OAuth2RestTemplate(org.springframework.security.oauth2.client.OAuth2RestTemplate)

Example 2 with UserInfoTokenServices

use of org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoTokenServices in project spring-cloud-security by spring-cloud.

the class ResourceServerTokenRelayAutoConfigurationTests method clientConfigured.

@Test
public void clientConfigured() throws Exception {
    this.context = new SpringApplicationBuilder(ClientConfiguration.class).properties("spring.config.name=test", "server.port=0", "security.oauth2.resource.userInfoUri:http://example.com", "security.oauth2.client.clientId=foo").run();
    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(new MockHttpServletRequest()));
    OAuth2ClientContext client = this.context.getBean(OAuth2ClientContext.class);
    assertNull(client.getAccessToken());
    UserInfoTokenServices services = context.getBean(UserInfoTokenServices.class);
    OAuth2RestTemplate template = (OAuth2RestTemplate) ReflectionTestUtils.getField(services, "restTemplate");
    MockRestServiceServer server = MockRestServiceServer.createServer(template);
    server.expect(requestTo("http://example.com")).andRespond(withSuccess("{\"id\":\"user\"}", MediaType.APPLICATION_JSON));
    services.loadAuthentication("FOO");
    assertEquals("FOO", client.getAccessToken().getValue());
    server.verify();
}
Also used : UserInfoTokenServices(org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoTokenServices) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) OAuth2ClientContext(org.springframework.security.oauth2.client.OAuth2ClientContext) MockRestServiceServer(org.springframework.test.web.client.MockRestServiceServer) OAuth2RestTemplate(org.springframework.security.oauth2.client.OAuth2RestTemplate) Test(org.junit.Test)

Aggregations

UserInfoTokenServices (org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoTokenServices)2 OAuth2RestTemplate (org.springframework.security.oauth2.client.OAuth2RestTemplate)2 Test (org.junit.Test)1 SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 OAuth2ClientContext (org.springframework.security.oauth2.client.OAuth2ClientContext)1 OAuth2ClientAuthenticationProcessingFilter (org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter)1 MockRestServiceServer (org.springframework.test.web.client.MockRestServiceServer)1 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)1