私は春のブートで新しく、私は小さなアプリケーションで春のブートと春のセキュリティを使用しています。ログインに成功すると、ページは/ loginに再度リダイレクトされます。私はそれを修正する方法を知らない。ログインに成功すると、URLは/ loginに再度リダイレクトされます
ログイン成功後:
これは、セキュリティの設定:
は@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.antMatchers("/", "/login").permitAll()//设置SpringSecurity对"/"和"/login"路径不拦截
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")//设置Spring Security的登录页面访问路径为/login
.defaultSuccessUrl("/chat")//登录成功后转向/chat路径
.permitAll()
.and()
.logout()
.permitAll();
}
/**
* 在内存中分别配置两个用户xin.luo和king.luo,密码和用户名一致,角色是USER
* @param auth
* @throws Exception
*/
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("xin").password("xin").roles("USER")
.and()
.withUser("king").password("king").roles("USER");
}
/**
* /resources/static/目录下的静态资源文件,Spring Security不拦截
* @param web
* @throws Exception
*/
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/resources/static/**");
}
}
を使用すると、クライアント側では何がありますか?認証が成功したかどうかは確かに分かりますか? –
ここに私のログインページがあり、認証が成功したと思います。しかし、ページは上の図のように、/ loginから/ chatにリダイレクトされた後に再び/ loginにリダイレクトされます。