I have a spring application that always starts with a dynamic prefix. This is because I need this prefix to create some internal configurations. The problem is that when I try to set my login page, it is not possible to pass this prefix and get the job done. How to set a dummy prefix on my login page?
This is part of my AppController where I assign the Mapping Request to have my prefix.
Appcotroler.java
@Controller
@RequestMapping("/{myDynamicPrefix}")
public class AppController {
...... @PathVariable String myDynamicPrefix
}
And this is part of my WebSecurityConfigurerAdapter adapter, which introduces the login page.
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();
http.authorizeRequests().antMatchers("/","/{myDynamicPrefix}/**").access("hasAnyRole('ROLE_USER')");
http.authorizeRequests().and().exceptionHandling().accessDeniedPage("/403");
http.authorizeRequests().and().formLogin()
.loginProcessingUrl("/j_spring_security_check")
.loginPage("/{myDynamicPrefix}/login")
.defaultSuccessUrl("/userInfo")
.failureUrl("/{myDynamicPrefix}/login?error=true")
.usernameParameter("username")
.passwordParameter("password")
.and().logout().logoutUrl("/{myDynamicPrefix}/logout").logoutSuccessUrl("/{myDynamicPrefix}/logoutSuccessful");
}
I think that .antMatchers("/{myDynamicPrefix}/login")they .antMatchers("/","/{myDynamicPrefix}/**")work fine, but .loginPage("/{myDynamicPrefix}/login")they don’t work at all.
This is an example of how I want a URL
http: