我有一个始终以动态前缀开头的 Spring 应用程序。这是因为我需要该前缀来进行一些内部配置。问题是,当我尝试设置登录页面时,无法传递该前缀并使其工作。如何为我的登录页面设置动态前缀?
这是我的 AppController 的一部分,我在其中分配请求映射以具有我的前缀。
AppCotroler.java
@Controller
@RequestMapping("/{myDynamicPrefix}")
public class AppController {
...... @PathVariable String myDynamicPrefix // To ascces to the variable
}
这是我的 WebSecurityConfigurerAdapter 的一部分,其中分配了登录页面。
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");
}
想法是.antMatchers("/{myDynamicPrefix}/login")
and .antMatchers("/","/{myDynamicPrefix}/**")
工作正常但是.loginPage("/{myDynamicPrefix}/login")
根本不起作用。
这是我想要的 URL 的示例
http://localhost:8080/MyApp/MyPrefix/MyPage
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)