Spring Boot: 2 different login pages for 2 URLs
<p>I have a Spring Boot application. I have 2 login pages for 2 different sets of users in the system. </p>

<ol>
<li><p>Any URL starting with <code>/expert</code>, the user should have the role of either <code>EXPERT</code> or <code>ADMIN</code>. The user uses form login to login into the system, and the login page path is <code>/login</code>. </p></li>
<li><p>For some URLs, such as <code>css</code>, <code>js</code>, etc, no authentication is required. </p></li>
<li><p>For all other URLs, the user needs no special role, an authentication is enough. The login page for the user should be <code>/loginTwo</code>. </p></li>
</ol>

<p>I looked at <a href="https://stackoverflow.com/questions/39575907/spring-boot-and-spring-security-multiple-login-pages">this</a> stackoverflow question and <a href="http://docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/#multiple-httpsecurity" rel="nofollow noreferrer">this</a> documentation to implement this. However, when I access a URL that contains <code>/expert</code>, it takes me to the login page <code>/loginTwo</code>, instead of <code>/login</code>. </p>

<p>Here is my code below: </p>

<pre><code>@Autowired
@Qualifier("userService")
UserDetailsService userDetailsService;

@Bean
public PasswordEncoder passwordEncoder() {
    PasswordEncoder encoder = new Md5PasswordEncoder();
    return encoder;
}

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
}

@Configuration
@Order(1)
public static class ExpertWebSecurity extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http
            .authorizeRequests()
                .antMatchers("/login/**").permitAll();
        http
            .antMatcher("/expert/**")
            .authorizeRequests()
                .anyRequest().access("hasRole('ROLE_ADMIN') or hasRole('ROLE_EXPERT')")
                .and()
            .formLogin()
                .loginPage("/login").permitAll();
    }
}

@Configuration
public static class StudentWebSecurity extends WebSecurityConfigurerAdapter{

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        System.out.println("Here in stu");

        http
            .authorizeRequests()
                .antMatchers("/css/**,/js/**").permitAll()
                .antMatchers("/error/**").permitAll()
                .antMatchers("/student/**").permitAll()
                .antMatchers("/filter/**").permitAll()
                .antMatchers("/loginTwo").permitAll()
                .antMatchers("/admin/**").access("hasRole('ROLE_ADMIN') or hasRole('ROLE_EXPERT')")
                .antMatchers("/").permitAll()
                .anyRequest().authenticated()
                .and()
            .csrf();
        http
            .formLogin()
                .loginPage("/loginTwo").permitAll()
                .and()
            .logout().permitAll();
        http
            .sessionManagement()
                .maximumSessions(20)
                .expiredUrl("/loginTwo")
                .maxSessionsPreventsLogin(false);
        http
            .headers().addHeaderWriter(new XFrameOptionsHeaderWriter(XFrameOptionsMode.SAMEORIGIN));
    }
}
</code></pre>

<p>Request you to help me with this. </p>