org.springframework.security.web.server.ServerAuthenticationEntryPoint Java Examples
The following examples show how to use
org.springframework.security.web.server.ServerAuthenticationEntryPoint.
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: ReactiveConfig.java From errors-spring-boot-starter with Apache License 2.0 | 6 votes |
@Bean public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http, ServerAccessDeniedHandler accessDeniedHandler, ServerAuthenticationEntryPoint authenticationEntryPoint) { return http .csrf() .accessDeniedHandler(accessDeniedHandler) .and() .exceptionHandling() .authenticationEntryPoint(authenticationEntryPoint) .accessDeniedHandler(accessDeniedHandler) .and() .authorizeExchange() .pathMatchers(GET, "/test/protected").authenticated() .pathMatchers(POST, "/test/protected").hasRole("ADMIN") .anyExchange().permitAll() .and().build(); }
Example #2
Source File: OAuth2SecurityConfigUtils.java From syncope with Apache License 2.0 | 5 votes |
public static void forLogin( final ServerHttpSecurity http, final AMType amType, final ApplicationContext ctx) { ReactiveClientRegistrationRepository clientRegistrationRepository = ctx.getBean(ReactiveClientRegistrationRepository.class); ReactiveOAuth2AuthorizedClientService authorizedClientService = new InMemoryReactiveOAuth2AuthorizedClientService(clientRegistrationRepository); ServerOAuth2AuthorizedClientRepository authorizedClientRepository = new AuthenticatedPrincipalServerOAuth2AuthorizedClientRepository(authorizedClientService); OAuth2AuthorizationRequestRedirectWebFilter authRequestRedirectFilter = new OAuth2AuthorizationRequestRedirectWebFilter(clientRegistrationRepository); AuthenticationWebFilter authenticationFilter = new OAuth2LoginAuthenticationWebFilter(authenticationManager(amType), authorizedClientRepository); authenticationFilter.setRequiresAuthenticationMatcher( new PathPatternParserServerWebExchangeMatcher("/login/oauth2/code/{registrationId}")); authenticationFilter.setServerAuthenticationConverter( new ServerOAuth2AuthorizationCodeAuthenticationTokenConverter(clientRegistrationRepository)); authenticationFilter.setAuthenticationSuccessHandler(new RedirectServerAuthenticationSuccessHandler()); authenticationFilter.setAuthenticationFailureHandler((exchange, ex) -> Mono.error(ex)); authenticationFilter.setSecurityContextRepository(new WebSessionServerSecurityContextRepository()); MediaTypeServerWebExchangeMatcher htmlMatcher = new MediaTypeServerWebExchangeMatcher(MediaType.TEXT_HTML); htmlMatcher.setIgnoredMediaTypes(Collections.singleton(MediaType.ALL)); ServerAuthenticationEntryPoint entrypoint = new RedirectServerAuthenticationEntryPoint("/oauth2/authorization/" + amType.name()); http.exceptionHandling().authenticationEntryPoint(new DelegateEntry(htmlMatcher, entrypoint).getEntryPoint()); http.addFilterAt(authRequestRedirectFilter, SecurityWebFiltersOrder.HTTP_BASIC); http.addFilterAt(authenticationFilter, SecurityWebFiltersOrder.AUTHENTICATION); }
Example #3
Source File: ReactiveSecurityErrorsAutoConfiguration.java From errors-spring-boot-starter with Apache License 2.0 | 2 votes |
/** * Responsible for catching all authentication exceptions and delegating them to typical web error handlers * to perform the actual exception handling procedures. * * @param errorWebExceptionHandler Spring Boot's default exception handler which in turn would delegate to our * typical error handlers. * @return The registered authentication entry point. */ @Bean @ConditionalOnClass(name = "org.springframework.security.web.server.ServerAuthenticationEntryPoint") public ServerAuthenticationEntryPoint authenticationEntryPoint(ErrorWebExceptionHandler errorWebExceptionHandler) { return errorWebExceptionHandler::handle; }