@Override protected void configure(HttpSecurity http) throws Exception { logger.debug("Configuring web security"); http.headers().cacheControl().disable(); http.authorizeRequests() // TODO (move img to images) // TODO (move intl to js/intl) .antMatchers("/intl/*", "/img/*", "/fonts/*", "/webjars/**", "/cli/**").permitAll() .regexMatchers("/login\\?.*").permitAll() .anyRequest().fullyAuthenticated() .and() .formLogin() .loginPage("/login").permitAll() .successHandler(new ShowPageAuthenticationSuccessHandler()) .and() .logout().logoutSuccessUrl("/login?logout").permitAll(); http.exceptionHandling().defaultAuthenticationEntryPointFor(new Http401AuthenticationEntryPoint("API_UNAUTHORIZED"), new AntPathRequestMatcher("/api/*")); http.exceptionHandling().defaultAuthenticationEntryPointFor(new LoginUrlAuthenticationEntryPoint("/login"), new AntPathRequestMatcher("/*")); }
@Override protected void configure(HttpSecurity http) throws Exception { http.addFilterBefore(corsFilter, UsernamePasswordAuthenticationFilter.class) .exceptionHandling() .authenticationEntryPoint(new Http401AuthenticationEntryPoint("TBD")) .and() .csrf() .disable() .headers() .frameOptions() .disable() .and() .sessionManagement() .sessionCreationPolicy(SessionCreationPolicy.STATELESS) .and() .authorizeRequests() .antMatchers("/api/register") .permitAll() .antMatchers("/api/activate") .permitAll() .antMatchers("/api/authenticate") .permitAll() .antMatchers("/api/account/reset_password/init") .permitAll() .antMatchers("/api/account/reset_password/finish") .permitAll() .antMatchers("/api/**") .authenticated() .and() .apply(securityConfigurerAdapter()); }
@Override protected void configure(HttpSecurity http) throws Exception { http.antMatcher("/api/**").authorizeRequests().anyRequest().authenticated(); // Applying CAS security on current HttpSecurity (FilterChain) // I'm not using .apply() from HttpSecurity due to following issue // https://github.com/spring-projects/spring-security/issues/4422 CasHttpSecurityConfigurer.cas().configure(http); http.exceptionHandling().authenticationEntryPoint(new Http401AuthenticationEntryPoint("CAS")); }
@Bean public Http401AuthenticationEntryPoint securityException401EntryPoint() { return new Http401AuthenticationEntryPoint("401 Authentification Exception"); }