I'm trying to use Spring Security, and I have a use case where I want different login pages and a different set of URLs to be protected.
Here is my configuration:
@Configuration @Order(1) public static class ProviderSecurity extends WebSecurityConfigurerAdapter{ @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/", "/home").permitAll() .antMatchers("/admin/login").permitAll() .antMatchers("/admin/**").access("hasRole('BASE_USER')") .and() .formLogin() .loginPage("/admin/login").permitAll() .defaultSuccessUrl("/admin/home") .failureUrl("/admin/login?error=true").permitAll() .usernameParameter("username") .passwordParameter("password") .and() .csrf() .and() .exceptionHandling().accessDeniedPage("/Access_Denied"); } } @Configuration @Order(2) public static class ConsumerSecurity extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/consumer/login").permitAll() .antMatchers("/consumer/**").access("hasRole('BASE_USER')") .anyRequest().authenticated() .and() .formLogin() .loginPage("/consumer/login").permitAll() .defaultSuccessUrl("/consumer/home") .failureUrl("/consumer/login?error=true").permitAll() .usernameParameter("username") .passwordParameter("password") .and().csrf() .and() .exceptionHandling().accessDeniedPage("/Access_Denied"); } }
These classes are inner classes of another MultipleHttpSecurityConfig class, which has the @EnableWebSecurity annotation.
Security for admin/** working fine, but none of the consumer/** pages is secure, redirection does not occur for the login page. I was looking for other answers, but no one worked.
source share