Java 登录Spring security后保持相同的URL
我想在登录后保持在同一页面,但spring强制您重定向到Java 登录Spring security后保持相同的URL,java,spring,spring-security,Java,Spring,Spring Security,我想在登录后保持在同一页面,但spring强制您重定向到defaultSuccessUrl 我的代码是这样的 @Override protected void configure(HttpSecurity http) throws Exception { http .csrf().disable() .authorizeRequests() .antMatchers("/css/**","/fonts
defaultSuccessUrl
我的代码是这样的
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/css/**","/fonts/**","/js/**","/app/**","/images/**","/partials/**").permitAll()
.anyRequest()
.authenticated()
.and()
.formLogin()
.loginPage("/login")
.defaultSuccessUrl("/index.html")
.failureUrl("/login?error=true")
.permitAll()
.and().logout().logoutSuccessUrl("/login?logout")
.and().exceptionHandling().accessDeniedPage("/pages/303.html");
}
设置
始终使用默认的target=“true”
这将迫使spring security转到/index.html我认为您应该添加一个身份验证成功处理程序
@Override
protected void configure(HttpSecurity http) throws Exception {
SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
successHandler.setUseReferer(true);//redirect to the previous page
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/css/**","/fonts/**","/js/**","/app/**","/images/**","/partials/**").permitAll()
.anyRequest()
.authenticated()
.and()
.formLogin()
.loginPage("/login")
.defaultSuccessUrl("/index.html")
.failureUrl("/login?error=true")
.permitAll()
.successHandler(successHandler)//enable success handler
.and().logout().logoutSuccessUrl("/login?logout")
.and().exceptionHandling().accessDeniedPage("/pages/303.html");
}
禁止将其设置为true此链接可能会根据您的问题帮助您:)您是否尝试过
.loginPage(“/login”).defaultSuccessUrl(“/login”)
?您输入的URL是什么?它是单页应用程序吗?我可以注意到url中的“#”是的,我正在使用angularjs,所以当我单击url时,我会在同一页面中包含一个模板页面。你解决了吗