Java Code Examples for org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter#setRestTemplate()
The following examples show how to use
org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter#setRestTemplate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpringSecurityConfiguration.java From crnk-example with Apache License 2.0 | 6 votes |
private OAuth2ClientAuthenticationProcessingFilter ssoFilter(ClientResources client, String path) { OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(client.getClient(), oauth2ClientContext); UserInfoTokenServices tokenServices = new UserInfoTokenServices(client.getResource().getUserInfoUri(), client.getClient().getClientId()); tokenServices.setRestTemplate(oAuth2RestTemplate); OAuth2ClientAuthenticationProcessingFilter oAuth2ClientAuthenticationFilter = new OAuth2ClientAuthenticationProcessingFilter(path); oAuth2ClientAuthenticationFilter.setRestTemplate(oAuth2RestTemplate); oAuth2ClientAuthenticationFilter.setTokenServices(tokenServices); oAuth2ClientAuthenticationFilter.setAuthenticationSuccessHandler(new SimpleUrlAuthenticationSuccessHandler() { @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { // TODO switch to tokens or find a way to return to last page on client this.setDefaultTargetUrl("/"); super.onAuthenticationSuccess(request, response, authentication); } }); return oAuth2ClientAuthenticationFilter; }
Example 2
Source File: OAuth2Util.java From DAFramework with MIT License | 6 votes |
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; }
Example 3
Source File: OAuth2Util.java From DAFramework with MIT License | 6 votes |
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; }
Example 4
Source File: WebSecurityConfig.java From mojito with Apache License 2.0 | 6 votes |
private Filter oauthFilter() { logger.debug("Setup SSO filter for oauth"); OAuth2ClientAuthenticationProcessingFilter oauth2Filter = new OAuth2ClientAuthenticationProcessingFilter( "/login/oauth"); OAuth2RestTemplate auth2RestTemplate = new OAuth2RestTemplate(oauth2(), oauth2ClientContext); oauth2Filter.setRestTemplate(auth2RestTemplate); UserInfoTokenServices tokenServices = new UserInfoTokenServices( oauth2Resource().getUserInfoUri(), oauth2().getClientId()); tokenServices.setRestTemplate(auth2RestTemplate); oauth2Filter.setTokenServices(new MyUserInfoTokenServices( oauth2Resource().getUserInfoUri(), oauth2().getClientId())); return oauth2Filter; }
Example 5
Source File: SsoSecurityConfigurer.java From spring-security-oauth2-boot with Apache License 2.0 | 5 votes |
private OAuth2ClientAuthenticationProcessingFilter oauth2SsoFilter(OAuth2SsoProperties sso) { OAuth2RestOperations restTemplate = this.applicationContext.getBean(UserInfoRestTemplateFactory.class) .getUserInfoRestTemplate(); ResourceServerTokenServices tokenServices = this.applicationContext.getBean(ResourceServerTokenServices.class); OAuth2ClientAuthenticationProcessingFilter filter = new OAuth2ClientAuthenticationProcessingFilter( sso.getLoginPath()); filter.setRestTemplate(restTemplate); filter.setTokenServices(tokenServices); filter.setApplicationEventPublisher(this.applicationContext); return filter; }
Example 6
Source File: SecurityConfig.java From movie-db-java-on-azure with MIT License | 5 votes |
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; }