Java 类org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoTokenServices 实例源码

项目:DAFramework    文件:OAuth2Util.java   
public static Filter general(AuthorizationCodeResourceDetails client, ResourceServerProperties resourceServerProperties, String path, OAuth2ClientContext oauth2ClientContext) {
    OAuth2ClientAuthenticationProcessingFilter oAuth2ClientAuthenticationFilter = new OAuth2ClientAuthenticationProcessingFilter(path){
        protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response,
                                                FilterChain chain, Authentication authResult) throws IOException, ServletException {
            super.successfulAuthentication(request, response, chain, authResult);
            OAuth2AccessToken accessToken = restTemplate.getAccessToken();
            log.warn(new Gson().toJson(authResult));
            log.warn(new Gson().toJson(accessToken));
        }
    };
    OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(client, oauth2ClientContext);
    oAuth2ClientAuthenticationFilter.setRestTemplate(oAuth2RestTemplate);
    UserInfoTokenServices tokenServices = new UserInfoTokenServices(resourceServerProperties.getUserInfoUri(), client.getClientId());
    tokenServices.setRestTemplate(oAuth2RestTemplate);
    oAuth2ClientAuthenticationFilter.setTokenServices(tokenServices);
    return oAuth2ClientAuthenticationFilter;
}
项目:emergentmud    文件:SecurityConfiguration.java   
private Filter ssoFilter() {
    CompositeFilter filter = new CompositeFilter();
    List<Filter> filters = new ArrayList<>();

    OAuth2ClientAuthenticationProcessingFilter facebookFilter = new OAuth2ClientAuthenticationProcessingFilter("/login/facebook");
    OAuth2RestTemplate facebookTemplate = new OAuth2RestTemplate(facebook(), oAuth2ClientContext);
    facebookFilter.setRestTemplate(facebookTemplate);
    facebookFilter.setTokenServices(new UserInfoTokenServices(facebookResource().getUserInfoUri(), facebook().getClientId()));
    filters.add(facebookFilter);

    OAuth2ClientAuthenticationProcessingFilter googleFilter = new OAuth2ClientAuthenticationProcessingFilter("/login/google");
    OAuth2RestTemplate googleTemplate = new OAuth2RestTemplate(google(), oAuth2ClientContext);
    googleFilter.setRestTemplate(googleTemplate);
    googleFilter.setTokenServices(new UserInfoTokenServices(googleResource().getUserInfoUri(), google().getClientId()));
    filters.add(googleFilter);

    filter.setFilters(filters);
    return filter;
}
项目:DAFramework    文件:OAuth2Util.java   
public static Filter wechat(AuthorizationCodeResourceDetails client, ResourceServerProperties resourceServerProperties, String path, OAuth2ClientContext oauth2ClientContext) {
    OAuth2ClientAuthenticationProcessingFilter oAuth2ClientAuthenticationFilter = new OAuth2ClientAuthenticationProcessingFilter(path);

    OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(client, oauth2ClientContext);
    AuthorizationCodeAccessTokenProvider accessTokenProvider = new AuthorizationCodeAccessTokenProvider();
    accessTokenProvider.setAuthorizationRequestEnhancer((request, resource, form, headers) -> {
        form.set("appid", resource.getClientId());
        form.set("secret", resource.getClientSecret());
        form.set("scope", "snsapi_userinfo");
        form.set("response_type", "code");
        form.set("#wechat_redirect", "");
    });
    accessTokenProvider.setMessageConverters(converters());
    oAuth2RestTemplate.setAccessTokenProvider(accessTokenProvider);

    oAuth2RestTemplate.setRetryBadAccessTokens(true);
    oAuth2ClientAuthenticationFilter.setRestTemplate(oAuth2RestTemplate);

    UserInfoTokenServices tokenServices = new UserInfoTokenServices(resourceServerProperties.getUserInfoUri(), client.getClientId());
    tokenServices.setRestTemplate(oAuth2RestTemplate);
    oAuth2ClientAuthenticationFilter.setTokenServices(tokenServices);
    return oAuth2ClientAuthenticationFilter;
}
项目:spring-cloud-security    文件:ResourceServerTokenRelayAutoConfigurationTests.java   
@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();
}
项目:movie-db-java-on-azure    文件:SecurityConfig.java   
private Filter ssoFilter() {
    OAuth2ClientAuthenticationProcessingFilter facebookFilter = new OAuth2ClientAuthenticationProcessingFilter("/login");
    OAuth2RestTemplate facebookTemplate = new OAuth2RestTemplate(facebook(), oauth2ClientContext);
    facebookFilter.setRestTemplate(facebookTemplate);
    UserInfoTokenServices tokenServices = new UserInfoTokenServices(facebookResource().getUserInfoUri(), facebook().getClientId());
    tokenServices.setRestTemplate(facebookTemplate);
    facebookFilter.setTokenServices(tokenServices);
    SavedRequestAwareAuthenticationSuccessHandler authenticationSuccessHandler = new SavedRequestAwareAuthenticationSuccessHandler();
    authenticationSuccessHandler.setUseReferer(true);
    authenticationSuccessHandler.setTargetUrlParameter("continue");
    facebookFilter.setAuthenticationSuccessHandler(authenticationSuccessHandler);
    return facebookFilter;
}
项目:cereebro    文件:AuthorizationServerRelationshipDetector.java   
@Override
public Set<Relationship> detect() {
    if (tokenService instanceof RemoteTokenServices || tokenService instanceof UserInfoTokenServices) {
        return Dependency.on(Component.of(getDefaultName(), ComponentType.HTTP_APPLICATION)).asRelationshipSet();
    }
    return Collections.emptySet();
}
项目:cereebro    文件:AuthorizationServerRelationshipDetectorTest.java   
@Test
public void usingUserInfoTokenServicesShouldReturnDependency() {
    ResourceServerTokenServices tokenService = new UserInfoTokenServices("/info", "nope");
    detector = new AuthorizationServerRelationshipDetector(tokenService);
    Set<Relationship> expected = new HashSet<>(Arrays
            .asList(Dependency.on(Component.of("oauth2-authorization-server", ComponentType.HTTP_APPLICATION))));
    Set<Relationship> result = detector.detect();
    Assertions.assertThat(result).isEqualTo(expected);
}
项目:referenceapp    文件:OAuthService.java   
private Filter ssoFilter() {
    OAuth2ClientAuthenticationProcessingFilter facebookFilter = new OAuth2ClientAuthenticationProcessingFilter(
            "/login/facebook");
    OAuth2RestTemplate facebookTemplate = new OAuth2RestTemplate(facebook(), oauth2ClientContext);
    facebookFilter.setRestTemplate(facebookTemplate);
    UserInfoTokenServices tokenServices = new UserInfoTokenServices(facebookResource().getUserInfoUri(),
            facebook().getClientId());
    tokenServices.setRestTemplate(facebookTemplate);
    facebookFilter.setTokenServices(
            new UserInfoTokenServices(facebookResource().getUserInfoUri(), facebook().getClientId()));
    return facebookFilter;
}
项目:restbucks-member    文件:WebSecurityConfiguration.java   
private OAuth2ClientAuthenticationProcessingFilter ssoFilter(String provideName,
                                                             ClientResources clientResources) {
    OAuth2ClientAuthenticationProcessingFilter filter =
            new OAuth2ClientAuthenticationProcessingFilter(format("/login/%s", provideName));
    filter.setRestTemplate(new OAuth2RestTemplate(clientResources.getClient(), oauth2ClientContext));
    filter.setTokenServices(new UserInfoTokenServices(clientResources.getResource().getUserInfoUri(),
            clientResources.getClient().getClientId()));
    filter.setApplicationEventPublisher(applicationEventPublisher);
    return filter;
}
项目:spring_boot    文件:ApplicationConfiguration.java   
private Filter ssoFilter(ClientResources client, String path) {
    OAuth2ClientAuthenticationProcessingFilter filter
            = new OAuth2ClientAuthenticationProcessingFilter(path);
    OAuth2RestTemplate template = new OAuth2RestTemplate(client.getClient(), oauth2ClientContext);
    filter.setRestTemplate(template);
    filter.setTokenServices(new UserInfoTokenServices(client.getResource().getUserInfoUri(), client.getClient().getClientId()));
    return filter;
}
项目:eve-oauth2-example    文件:EveOAuth2Example.java   
private Filter ssoFilter()
{
  OAuth2ClientAuthenticationProcessingFilter eveFilter = new OAuth2ClientAuthenticationProcessingFilter("/login/eve");
  OAuth2RestTemplate eveTemplate = new OAuth2RestTemplate(eve(), oauth2ClientContext);
  eveFilter.setRestTemplate(eveTemplate);
  eveFilter.setTokenServices(new UserInfoTokenServices(eveResource().getUserInfoUri(), eve().getClientId()));
  return eveFilter;
}
项目:marketplace    文件:WebSecurityConfig.java   
/**
 * ## todo : describe.
 *
 * @param client     {@link ClientResources}
 * @param processUrl {@link String}
 * @return {@link Filter}
 */
private Filter customSSOFilter(final ClientResources client, final String processUrl) {
    final OAuth2ClientAuthenticationProcessingFilter filter = new OAuth2ClientAuthenticationProcessingFilter(processUrl);

    final OAuth2RestTemplate template = new OAuth2RestTemplate(client.getClient(), oauth2ClientContext);
    filter.setRestTemplate(template);

    final UserInfoTokenServices tokenServices = new UserInfoTokenServices(client.getResource().getUserInfoUri(), client.getClient().getClientId());
    tokenServices.setRestTemplate(template);
    filter.setTokenServices(tokenServices);

    return filter;
}
项目:come2help    文件:CustomOAuthAuthenticationProcessingFilter.java   
public CustomOAuthAuthenticationProcessingFilter(String path, ClientResourceDetails clientResourceDetails, MappingJackson2HttpMessageConverter jsonMessageConverter) {
    super(path);
    this.clientResourceDetails = clientResourceDetails;
    this.tokenService = new UserInfoTokenServices(clientResourceDetails.getResource().getUserInfoUri(), clientResourceDetails.getClient().getClientId());
    this.accessTokenProvider.setStateMandatory(false);
    this.jsonMessageConverter = jsonMessageConverter;
}
项目:spring-oauth2-jwt-minimal    文件:OAuth2ClientConfigurer.java   
private OAuth2ClientAuthenticationProcessingFilter createSsoFilter(ClientResourceDetails clientDetails, AuthenticationSuccessHandler successHandler, String path) {
    OAuth2ClientAuthenticationProcessingFilter ssoFilter = new OAuth2ClientAuthenticationProcessingFilter(path);
    ssoFilter.setAllowSessionCreation(false);
    OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(clientDetails.getClient(), oAuth2ClientContext);
    ssoFilter.setRestTemplate(restTemplate);
    ssoFilter.setTokenServices(new UserInfoTokenServices(clientDetails.getResource().getUserInfoUri(), clientDetails.getClient().getClientId()));
    ssoFilter.setAuthenticationSuccessHandler(successHandler);
    return ssoFilter;
}
项目:codekvast    文件:WebSecurityConfig.java   
private Filter ssoFilter(ClientResources client, String path) {
    OAuth2ClientAuthenticationProcessingFilter filter = new OAuth2ClientAuthenticationProcessingFilter(path);
    OAuth2RestTemplate template = new OAuth2RestTemplate(client.getClient(), oauth2ClientContext);
    filter.setRestTemplate(template);
    UserInfoTokenServices tokenServices =
        new UserInfoTokenServices(client.getResource().getUserInfoUri(), client.getClient().getClientId());
    tokenServices.setRestTemplate(template);
    filter.setTokenServices(tokenServices);
    return filter;
}
项目:JavaSecurity    文件:SsoWithGitHubApplication.java   
private Filter ssoFilter(ClientResources client, String path) {
    OAuth2ClientAuthenticationProcessingFilter oAuth2ClientAuthenticationFilter =
            new OAuth2ClientAuthenticationProcessingFilter(path);
    OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(client.getClient(),
            oAuth2ClientContext);
    oAuth2ClientAuthenticationFilter.setRestTemplate(oAuth2RestTemplate);
    UserInfoTokenServices tokenServices = new UserInfoTokenServices(
            client.getResource().getUserInfoUri(), client.getClient().getClientId());
    tokenServices.setRestTemplate(oAuth2RestTemplate);
    oAuth2ClientAuthenticationFilter.setTokenServices(tokenServices);
    return oAuth2ClientAuthenticationFilter;
}
项目:Facegram    文件:UserApplication.java   
@Bean
@Primary
public ResourceServerTokenServices tokenServices() {
    return new UserInfoTokenServices(resourceServerProperties.getUserInfoUri(), resourceServerProperties.getClientId());
}
项目:WebPLP    文件:OAuthSecurityConfig.java   
private OAuth2ClientAuthenticationProcessingFilter filter() {
    OAuth2ClientAuthenticationProcessingFilter oAuth2Filter = new OAuth2ClientAuthenticationProcessingFilter("/google/login");


    OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(authCodeResourceDetails,
            oauth2ClientContext);
    oAuth2Filter.setRestTemplate(oAuth2RestTemplate);


    oAuth2Filter.setTokenServices(new UserInfoTokenServices(resourceServerProperties.getUserInfoUri(),
            resourceServerProperties.getClientId()));


    return oAuth2Filter;
}