private void registerDefaultEntryPoint(H http) { ExceptionHandlingConfigurer<H> exceptionHandling = http .getConfigurer(ExceptionHandlingConfigurer.class); if (exceptionHandling == null) { return; } exceptionHandling.defaultAuthenticationEntryPointFor( this.authenticationEntryPoint, this.requestMatcher); }
private void registerDefaultCsrfOverride(H http) { CsrfConfigurer<H> csrf = http .getConfigurer(CsrfConfigurer.class); if (csrf == null) { return; } csrf.ignoringRequestMatchers(this.requestMatcher); }
private void registerDefaultAccessDeniedHandler(H http) { ExceptionHandlingConfigurer<H> exceptionHandling = http .getConfigurer(ExceptionHandlingConfigurer.class); if (exceptionHandling == null) { return; } exceptionHandling.defaultAccessDeniedHandlerFor( this.accessDeniedHandler, this.requestMatcher); }
/** * Gets the default {@link InvalidSessionStrategy} from the * {@link SessionManagementConfigurer#getInvalidSessionStrategy()} or null if not * available. * * @param http the {@link HttpSecurityBuilder} * @return the {@link InvalidSessionStrategy} */ @SuppressWarnings("unchecked") private InvalidSessionStrategy getInvalidSessionStrategy(H http) { SessionManagementConfigurer<H> sessionManagement = http .getConfigurer(SessionManagementConfigurer.class); if (sessionManagement == null) { return null; } return sessionManagement.getInvalidSessionStrategy(); }
private void registerDefaultEntryPoint(B http, RequestMatcher preferredMatcher) { ExceptionHandlingConfigurer<B> exceptionHandling = http .getConfigurer(ExceptionHandlingConfigurer.class); if (exceptionHandling == null) { return; } exceptionHandling.defaultAuthenticationEntryPointFor( postProcess(this.authenticationEntryPoint), preferredMatcher); }
/** * Gets the default {@link AccessDeniedHandler} from the * {@link ExceptionHandlingConfigurer#getAccessDeniedHandler()} or create a * {@link AccessDeniedHandlerImpl} if not available. * * @param http the {@link HttpSecurityBuilder} * @return the {@link AccessDeniedHandler} */ @SuppressWarnings("unchecked") private AccessDeniedHandler getDefaultAccessDeniedHandler(H http) { ExceptionHandlingConfigurer<H> exceptionConfig = http .getConfigurer(ExceptionHandlingConfigurer.class); AccessDeniedHandler handler = null; if (exceptionConfig != null) { handler = exceptionConfig.getAccessDeniedHandler(); } if (handler == null) { handler = new AccessDeniedHandlerImpl(); } return handler; }
@SuppressWarnings("unchecked") protected final void registerAuthenticationEntryPoint(B http, AuthenticationEntryPoint authenticationEntryPoint) { ExceptionHandlingConfigurer<B> exceptionHandling = http .getConfigurer(ExceptionHandlingConfigurer.class); if (exceptionHandling == null) { return; } exceptionHandling.defaultAuthenticationEntryPointFor( postProcess(authenticationEntryPoint), getAuthenticationEntryPointMatcher(http)); }
private void registerDefaultLogoutSuccessHandler(B http, RequestMatcher preferredMatcher) { LogoutConfigurer<B> logout = http .getConfigurer(LogoutConfigurer.class); if (logout == null) { return; } LogoutConfigurer<B> handler = logout.defaultLogoutSuccessHandlerFor( postProcess(new HttpStatusReturningLogoutSuccessHandler(HttpStatus.NO_CONTENT)), preferredMatcher); }
@SuppressWarnings("unchecked") public static void permitAll( HttpSecurityBuilder<? extends HttpSecurityBuilder<?>> http, RequestMatcher... requestMatchers) { ExpressionUrlAuthorizationConfigurer<?> configurer = http .getConfigurer(ExpressionUrlAuthorizationConfigurer.class); if (configurer == null) { throw new IllegalStateException( "permitAll only works with HttpSecurity.authorizeRequests()"); } for (RequestMatcher matcher : requestMatchers) { if (matcher != null) { configurer .getRegistry() .addMapping( 0, new UrlMapping( matcher, SecurityConfig .createList(ExpressionUrlAuthorizationConfigurer.permitAll))); } } }
@Override @SuppressWarnings("unchecked") public void configure(H http) throws Exception { AuthenticationEntryPoint authenticationEntryPoint = null; ExceptionHandlingConfigurer<?> exceptionConf = http .getConfigurer(ExceptionHandlingConfigurer.class); if (exceptionConf != null) { authenticationEntryPoint = exceptionConf.getAuthenticationEntryPoint(); } if (loginPageGeneratingFilter.isEnabled() && authenticationEntryPoint == null) { loginPageGeneratingFilter = postProcess(loginPageGeneratingFilter); http.addFilter(loginPageGeneratingFilter); http.addFilter(this.logoutPageGeneratingFilter); } }
/** * Updates the default values for authentication. * * @throws Exception */ protected final void updateAuthenticationDefaults() { if (loginProcessingUrl == null) { loginProcessingUrl(loginPage); } if (failureHandler == null) { failureUrl(loginPage + "?error"); } final LogoutConfigurer<B> logoutConfigurer = getBuilder().getConfigurer( LogoutConfigurer.class); if (logoutConfigurer != null && !logoutConfigurer.isCustomLogoutSuccess()) { logoutConfigurer.logoutSuccessUrl(loginPage + "?logout"); } }
new RequestHeaderRequestMatcher("X-Requested-With", "XMLHttpRequest")); boolean isCsrfEnabled = http.getConfigurer(CsrfConfigurer.class) != null;
.getSharedObject(AuthenticationManager.class)); ExceptionHandlingConfigurer<H> exceptionConf = http .getConfigurer(ExceptionHandlingConfigurer.class); AuthenticationEntryPoint authenticationEntryPoint = exceptionConf == null ? null : exceptionConf.getAuthenticationEntryPoint(http); securityContextRequestFilter .setAuthenticationEntryPoint(authenticationEntryPoint); LogoutConfigurer<H> logoutConf = http.getConfigurer(LogoutConfigurer.class); List<LogoutHandler> logoutHandlers = logoutConf == null ? null : logoutConf .getLogoutHandlers();
@SuppressWarnings("unchecked") @Override public void configure(H http) throws Exception { CsrfFilter filter = new CsrfFilter(this.csrfTokenRepository); RequestMatcher requireCsrfProtectionMatcher = getRequireCsrfProtectionMatcher(); if (requireCsrfProtectionMatcher != null) { filter.setRequireCsrfProtectionMatcher(requireCsrfProtectionMatcher); } AccessDeniedHandler accessDeniedHandler = createAccessDeniedHandler(http); if (accessDeniedHandler != null) { filter.setAccessDeniedHandler(accessDeniedHandler); } LogoutConfigurer<H> logoutConfigurer = http.getConfigurer(LogoutConfigurer.class); if (logoutConfigurer != null) { logoutConfigurer .addLogoutHandler(new CsrfLogoutHandler(this.csrfTokenRepository)); } SessionManagementConfigurer<H> sessionConfigurer = http .getConfigurer(SessionManagementConfigurer.class); if (sessionConfigurer != null) { sessionConfigurer.addSessionAuthenticationStrategy( new CsrfAuthenticationStrategy(this.csrfTokenRepository)); } filter = postProcess(filter); http.addFilter(filter); }
@Override @SuppressWarnings("unchecked") public void configure(H http) throws Exception { SecurityContextRepository securityContextRepository = http .getSharedObject(SecurityContextRepository.class); if (securityContextRepository == null) { securityContextRepository = new HttpSessionSecurityContextRepository(); } SecurityContextPersistenceFilter securityContextFilter = new SecurityContextPersistenceFilter( securityContextRepository); SessionManagementConfigurer<?> sessionManagement = http .getConfigurer(SessionManagementConfigurer.class); SessionCreationPolicy sessionCreationPolicy = sessionManagement == null ? null : sessionManagement.getSessionCreationPolicy(); if (SessionCreationPolicy.ALWAYS == sessionCreationPolicy) { securityContextFilter.setForceEagerSessionCreation(true); } securityContextFilter = postProcess(securityContextFilter); http.addFilter(securityContextFilter); } }
@SuppressWarnings("unchecked") @Override public void init(H http) throws Exception { validateInput(); String key = getKey(); RememberMeServices rememberMeServices = getRememberMeServices(http, key); http.setSharedObject(RememberMeServices.class, rememberMeServices); LogoutConfigurer<H> logoutConfigurer = http.getConfigurer(LogoutConfigurer.class); if (logoutConfigurer != null && this.logoutHandler != null) { logoutConfigurer.addLogoutHandler(this.logoutHandler); } RememberMeAuthenticationProvider authenticationProvider = new RememberMeAuthenticationProvider( key); authenticationProvider = postProcess(authenticationProvider); http.authenticationProvider(authenticationProvider); initDefaultLoginFilter(http); }
@SuppressWarnings("unchecked") private RequestMatcher getLogoutRequestMatcher(H http) { if (logoutRequestMatcher != null) { return logoutRequestMatcher; } if (http.getConfigurer(CsrfConfigurer.class) != null) { this.logoutRequestMatcher = new AntPathRequestMatcher(this.logoutUrl, "POST"); } else { this.logoutRequestMatcher = new OrRequestMatcher( new AntPathRequestMatcher(this.logoutUrl, "GET"), new AntPathRequestMatcher(this.logoutUrl, "POST"), new AntPathRequestMatcher(this.logoutUrl, "PUT"), new AntPathRequestMatcher(this.logoutUrl, "DELETE") ); } return this.logoutRequestMatcher; } }
private void registerDefaultAccessDeniedHandler(H http) { ExceptionHandlingConfigurer<H> exceptionHandling = http .getConfigurer(ExceptionHandlingConfigurer.class); if (exceptionHandling == null) { return; } exceptionHandling.defaultAccessDeniedHandlerFor( this.accessDeniedHandler, this.requestMatcher); }
private void registerDefaultCsrfOverride(H http) { CsrfConfigurer<H> csrf = http .getConfigurer(CsrfConfigurer.class); if (csrf == null) { return; } csrf.ignoringRequestMatchers(this.requestMatcher); }
private void registerDefaultLogoutSuccessHandler(B http, RequestMatcher preferredMatcher) { LogoutConfigurer<B> logout = http .getConfigurer(LogoutConfigurer.class); if (logout == null) { return; } LogoutConfigurer<B> handler = logout.defaultLogoutSuccessHandlerFor( postProcess(new HttpStatusReturningLogoutSuccessHandler(HttpStatus.NO_CONTENT)), preferredMatcher); }