this.oauth2Login.configure(this);
protected void configure(ServerHttpSecurity http) { ReactiveClientRegistrationRepository clientRegistrationRepository = getClientRegistrationRepository(); ServerOAuth2AuthorizedClientRepository authorizedClientRepository = getAuthorizedClientRepository(); OAuth2AuthorizationRequestRedirectWebFilter oauthRedirectFilter = getRedirectWebFilter(); ReactiveAuthenticationManager manager = getAuthenticationManager(); AuthenticationWebFilter authenticationFilter = new OAuth2LoginAuthenticationWebFilter(manager, authorizedClientRepository); authenticationFilter.setRequiresAuthenticationMatcher(getAuthenticationMatcher()); authenticationFilter.setServerAuthenticationConverter(getAuthenticationConverter(clientRegistrationRepository)); RedirectServerAuthenticationSuccessHandler redirectHandler = new RedirectServerAuthenticationSuccessHandler(); authenticationFilter.setAuthenticationSuccessHandler(redirectHandler); authenticationFilter.setAuthenticationFailureHandler(new ServerAuthenticationFailureHandler() { @Override public Mono<Void> onAuthenticationFailure(WebFilterExchange webFilterExchange, AuthenticationException exception) { return Mono.error(exception); } }); authenticationFilter.setSecurityContextRepository(new WebSessionServerSecurityContextRepository()); MediaTypeServerWebExchangeMatcher htmlMatcher = new MediaTypeServerWebExchangeMatcher( MediaType.TEXT_HTML); htmlMatcher.setIgnoredMediaTypes(Collections.singleton(MediaType.ALL)); Map<String, String> urlToText = http.oauth2Login.getLinks(); if (urlToText.size() == 1) { http.defaultEntryPoints.add(new DelegateEntry(htmlMatcher, new RedirectServerAuthenticationEntryPoint(urlToText.keySet().iterator().next()))); } else { http.defaultEntryPoints.add(new DelegateEntry(htmlMatcher, new RedirectServerAuthenticationEntryPoint("/login"))); } http.addFilterAt(oauthRedirectFilter, SecurityWebFiltersOrder.HTTP_BASIC); http.addFilterAt(authenticationFilter, SecurityWebFiltersOrder.AUTHENTICATION); }
this.oauth2Login.configure(this);
protected void configure(ServerHttpSecurity http) { ReactiveClientRegistrationRepository clientRegistrationRepository = getClientRegistrationRepository(); ServerOAuth2AuthorizedClientRepository authorizedClientRepository = getAuthorizedClientRepository(); OAuth2AuthorizationRequestRedirectWebFilter oauthRedirectFilter = new OAuth2AuthorizationRequestRedirectWebFilter(clientRegistrationRepository); ReactiveAuthenticationManager manager = getAuthenticationManager(); AuthenticationWebFilter authenticationFilter = new OAuth2LoginAuthenticationWebFilter(manager, authorizedClientRepository); authenticationFilter.setRequiresAuthenticationMatcher(createAttemptAuthenticationRequestMatcher()); authenticationFilter.setServerAuthenticationConverter(getAuthenticationConverter(clientRegistrationRepository)); RedirectServerAuthenticationSuccessHandler redirectHandler = new RedirectServerAuthenticationSuccessHandler(); authenticationFilter.setAuthenticationSuccessHandler(redirectHandler); authenticationFilter.setAuthenticationFailureHandler(new ServerAuthenticationFailureHandler() { @Override public Mono<Void> onAuthenticationFailure(WebFilterExchange webFilterExchange, AuthenticationException exception) { return Mono.error(exception); } }); authenticationFilter.setSecurityContextRepository(new WebSessionServerSecurityContextRepository()); MediaTypeServerWebExchangeMatcher htmlMatcher = new MediaTypeServerWebExchangeMatcher( MediaType.TEXT_HTML); htmlMatcher.setIgnoredMediaTypes(Collections.singleton(MediaType.ALL)); Map<String, String> urlToText = http.oauth2Login.getLinks(); if (urlToText.size() == 1) { http.defaultEntryPoints.add(new DelegateEntry(htmlMatcher, new RedirectServerAuthenticationEntryPoint(urlToText.keySet().iterator().next()))); } else { http.defaultEntryPoints.add(new DelegateEntry(htmlMatcher, new RedirectServerAuthenticationEntryPoint("/login"))); } http.addFilterAt(oauthRedirectFilter, SecurityWebFiltersOrder.HTTP_BASIC); http.addFilterAt(authenticationFilter, SecurityWebFiltersOrder.AUTHENTICATION); }
private ServerOAuth2AuthorizedClientRepository getAuthorizedClientRepository() { ServerOAuth2AuthorizedClientRepository result = this.authorizedClientRepository; if (result == null) { result = getBeanOrNull(ServerOAuth2AuthorizedClientRepository.class); } if (result == null) { ReactiveOAuth2AuthorizedClientService authorizedClientService = getAuthorizedClientService(); if (authorizedClientService != null) { result = new AuthenticatedPrincipalServerOAuth2AuthorizedClientRepository( authorizedClientService); } } return result; }
/** * Gets the {@link ReactiveAuthenticationManager} to use. First tries an explicitly configured manager, and * defaults to {@link OAuth2AuthorizationCodeReactiveAuthenticationManager} * * @return the {@link ReactiveAuthenticationManager} to use */ private ReactiveAuthenticationManager getAuthenticationManager() { if (this.authenticationManager == null) { this.authenticationManager = createDefault(); } return this.authenticationManager; }
private ReactiveOAuth2AuthorizedClientService getAuthorizedClientService() { ReactiveOAuth2AuthorizedClientService service = getBeanOrNull(ReactiveOAuth2AuthorizedClientService.class); if (service == null) { service = new InMemoryReactiveOAuth2AuthorizedClientService(getClientRegistrationRepository()); } return service; }
public OAuth2LoginSpec oauth2Login() { if (this.oauth2Login == null) { this.oauth2Login = new OAuth2LoginSpec(); } return this.oauth2Login; }
this.oauth2Login.configure(this);
protected void configure(ServerHttpSecurity http) { ReactiveClientRegistrationRepository clientRegistrationRepository = getClientRegistrationRepository(); ServerOAuth2AuthorizedClientRepository authorizedClientRepository = getAuthorizedClientRepository(); OAuth2AuthorizationRequestRedirectWebFilter oauthRedirectFilter = new OAuth2AuthorizationRequestRedirectWebFilter(clientRegistrationRepository); ReactiveAuthenticationManager manager = getAuthenticationManager(); AuthenticationWebFilter authenticationFilter = new OAuth2LoginAuthenticationWebFilter(manager, authorizedClientRepository); authenticationFilter.setRequiresAuthenticationMatcher(createAttemptAuthenticationRequestMatcher()); authenticationFilter.setServerAuthenticationConverter(getAuthenticationConverter(clientRegistrationRepository)); RedirectServerAuthenticationSuccessHandler redirectHandler = new RedirectServerAuthenticationSuccessHandler(); authenticationFilter.setAuthenticationSuccessHandler(redirectHandler); authenticationFilter.setAuthenticationFailureHandler(new ServerAuthenticationFailureHandler() { @Override public Mono<Void> onAuthenticationFailure(WebFilterExchange webFilterExchange, AuthenticationException exception) { return Mono.error(exception); } }); authenticationFilter.setSecurityContextRepository(new WebSessionServerSecurityContextRepository()); MediaTypeServerWebExchangeMatcher htmlMatcher = new MediaTypeServerWebExchangeMatcher( MediaType.TEXT_HTML); htmlMatcher.setIgnoredMediaTypes(Collections.singleton(MediaType.ALL)); Map<String, String> urlToText = http.oauth2Login.getLinks(); if (urlToText.size() == 1) { http.defaultEntryPoints.add(new DelegateEntry(htmlMatcher, new RedirectServerAuthenticationEntryPoint(urlToText.keySet().iterator().next()))); } else { http.defaultEntryPoints.add(new DelegateEntry(htmlMatcher, new RedirectServerAuthenticationEntryPoint("/login"))); } http.addFilterAt(oauthRedirectFilter, SecurityWebFiltersOrder.HTTP_BASIC); http.addFilterAt(authenticationFilter, SecurityWebFiltersOrder.AUTHENTICATION); }
private ServerOAuth2AuthorizedClientRepository getAuthorizedClientRepository() { ServerOAuth2AuthorizedClientRepository result = this.authorizedClientRepository; if (result == null) { result = getBeanOrNull(ServerOAuth2AuthorizedClientRepository.class); } if (result == null) { ReactiveOAuth2AuthorizedClientService authorizedClientService = getAuthorizedClientService(); if (authorizedClientService != null) { result = new AuthenticatedPrincipalServerOAuth2AuthorizedClientRepository( authorizedClientService); } } return result; }
private ReactiveOAuth2AuthorizedClientService getAuthorizedClientService() { ReactiveOAuth2AuthorizedClientService service = getBeanOrNull(ReactiveOAuth2AuthorizedClientService.class); if (service == null) { service = new InMemoryReactiveOAuth2AuthorizedClientService(getClientRegistrationRepository()); } return service; }
/** * Gets the {@link ReactiveAuthenticationManager} to use. First tries an explicitly configured manager, and * defaults to {@link OAuth2AuthorizationCodeReactiveAuthenticationManager} * * @return the {@link ReactiveAuthenticationManager} to use */ private ReactiveAuthenticationManager getAuthenticationManager() { if (this.authenticationManager == null) { this.authenticationManager = createDefault(); } return this.authenticationManager; }
public OAuth2LoginSpec oauth2Login() { if (this.oauth2Login == null) { this.oauth2Login = new OAuth2LoginSpec(); } return this.oauth2Login; }
private ServerOAuth2AuthorizedClientRepository getAuthorizedClientRepository() { ServerOAuth2AuthorizedClientRepository result = this.authorizedClientRepository; if (result == null) { result = getBeanOrNull(ServerOAuth2AuthorizedClientRepository.class); } if (result == null) { ReactiveOAuth2AuthorizedClientService authorizedClientService = getAuthorizedClientService(); if (authorizedClientService != null) { result = new AuthenticatedPrincipalServerOAuth2AuthorizedClientRepository( authorizedClientService); } } return result; }
/** * Gets the {@link ReactiveAuthenticationManager} to use. First tries an explicitly configured manager, and * defaults to {@link OAuth2AuthorizationCodeReactiveAuthenticationManager} * * @return the {@link ReactiveAuthenticationManager} to use */ private ReactiveAuthenticationManager getAuthenticationManager() { if (this.authenticationManager == null) { this.authenticationManager = createDefault(); } return this.authenticationManager; }
private ServerWebExchangeMatcher getAuthenticationMatcher() { if (this.authenticationMatcher == null) { this.authenticationMatcher = createAttemptAuthenticationRequestMatcher(); } return this.authenticationMatcher; }
private ReactiveOAuth2AuthorizedClientService getAuthorizedClientService() { ReactiveOAuth2AuthorizedClientService service = getBeanOrNull(ReactiveOAuth2AuthorizedClientService.class); if (service == null) { service = new InMemoryReactiveOAuth2AuthorizedClientService(getClientRegistrationRepository()); } return service; }
private OAuth2AuthorizationRequestRedirectWebFilter getRedirectWebFilter() { OAuth2AuthorizationRequestRedirectWebFilter oauthRedirectFilter; if (this.authorizationRequestResolver == null) { oauthRedirectFilter = new OAuth2AuthorizationRequestRedirectWebFilter(getClientRegistrationRepository()); } else { oauthRedirectFilter = new OAuth2AuthorizationRequestRedirectWebFilter(this.authorizationRequestResolver); } return oauthRedirectFilter; }
public OAuth2LoginSpec oauth2Login() { if (this.oauth2Login == null) { this.oauth2Login = new OAuth2LoginSpec(); } return this.oauth2Login; }