2
저는 스프링 부트에 새로운데, 저는 작은 응용 프로그램에서 스프링 부트와 스프링 보안을 사용합니다. 로그인에 성공하면 페이지가 다시/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으로 리디렉션됩니다.