I have a spring application that always start with a dynamic prefix. This is because I need that prefix to make some internal configurations. The problem is that when I try to set my login page, it is imposible to pass that prefixe and making work. How can I set the dymanic prefix to my login page?
This is part of my AppController where I am assigning the Request Mapping to have my prefix.
AppCotroler.java
@Controller
@RequestMapping("/{myDynamicPrefix}")
public class AppController {
...... @PathVariable String myDynamicPrefix // To ascces to the variable
}
And this is part of my WebSecurityConfigurerAdapter where the login page is asigned.
WebSecurityConfig.java
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
MyDBAuthenticationService myDBAauthenticationService;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http.authorizeRequests().antMatchers("/{myDynamicPrefix}/login").permitAll();
// If no login, it will redirect to /login page.
http.authorizeRequests().antMatchers("/","/{myDynamicPrefix}/**").access("hasAnyRole('ROLE_USER')");
http.authorizeRequests().and().exceptionHandling().accessDeniedPage("/403");
// Config for Login Form
http.authorizeRequests().and().formLogin()//
// Submit URL of login page.
.loginProcessingUrl("/j_spring_security_check") // Submit URL
.loginPage("/{myDynamicPrefix}/login")//
.defaultSuccessUrl("/userInfo")//
.failureUrl("/{myDynamicPrefix}/login?error=true")//
.usernameParameter("username")//
.passwordParameter("password")
// Config for Logout Page
.and().logout().logoutUrl("/{myDynamicPrefix}/logout").logoutSuccessUrl("/{myDynamicPrefix}/logoutSuccessful");
}
The think is that .antMatchers("/{myDynamicPrefix}/login") and .antMatchers("/","/{myDynamicPrefix}/**") are working normally but .loginPage("/{myDynamicPrefix}/login") is not working at all.
This is an example of how I want the URL
http://localhost:8080/MyApp/MyPrefix/MyPage