0
我試圖爲Web應用程序包含身份驗證。 用戶通過登錄頁面成功,但他們仍然無法訪問任何其他頁面。春季安全 - 成功身份驗證後無法訪問
最初我認爲這個問題與Active Directory有關,但在切換到內存驗證進行調試後,我發現這兩個方法都不能正常工作。
這是我的安全配置:
@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf()
.disable()
.authorizeRequests()
.antMatchers("/css/**").permitAll()
.antMatchers("/js/**").permitAll()
.antMatchers("/img/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.and()
.logout()
.permitAll();
}
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("user").password("test").roles("USER");
}
}
登錄後,我得到驗證成功在日誌中:
Authentication event AuthenticationSuccessEvent: user; details: org.sprin[email protected]b364: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: null
Authentication event InteractiveAuthenticationSuccessEvent: user; details: org.sprin[email protected]b364: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: null
但是我重定向回到登錄頁面,而不是到請求資源。手動導航到資源仍然讓我重定向回登錄頁面。
我的錯誤是否明顯,或者我錯過了什麼?