我正在開發一個使用Spring Boot的Spring REST應用程序。我正在使用角JS客戶端來使用Spring REST API。Spring CORE Spring CORS安全認證問題
我使用的堆棧:
Spring Boot 1.4.2 , Spring Security , Angular JS , Tomcat 8
我的問題是:
1)登錄時,用戶被成功地認證。自定義認證成功處理程序返回200個狀態碼
2)認證成功之後,當克林特發送另一個請求訪問procted資源,HttpSession的是NULL
3)由於其中當SecurityContextPersistenceFilter
嘗試檢索SecurityContext
從HttpSession
它返回爲空和 和再次服務器發送請求/login
資源
4)所以,我的問題是:
1)爲什麼httpsesion是空的第二個請求?
2)我觀察到,春季安全返回JSESSIONID
作爲第一succesfull認證後的cookie。
3)但是,在此之後,客戶端不在請求因此第二請求發送該JSESSIONID
不會在同一個會話。
4)如果是這樣的話,怎麼SecurityContext
將如果SESSION
檢索是不成立的?
請幫助,因爲我不能夠在這裏
編輯1着手:
我正在使用彈簧安全提供存儲用戶默認設置。我的安全配置是波紋管:
@Configuration
@EnableWebSecurity
@ComponentScan({"com.atul.security"})
public class SecurityConfig extends WebSecurityConfigurerAdapter{
@Autowired
private RESTAuthenticationSuccessHandler authenticationSuccessHandler;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.formLogin().successHandler(authenticationSuccessHandler)
.and()
.csrf().disable()
.authorizeRequests()
.antMatchers(HttpMethod.OPTIONS,"/*").permitAll()
.antMatchers("/index.html", "/home.html", "/login.html", "/").permitAll()
.anyRequest().authenticated()
.and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
}
我得到以下用戶爲認證用戶:
org.sprin[email protected]9055c2bc:
Principal: anonymousUser; Credentials: [PROTECTED];
Authenticated: true;
Details: org.sprin[email protected]b364:
RemoteIpAddress: 0:0:0:0:0:0:0:1;
SessionId: null;
Granted Authorities: ROLE_ANONYMOUS
請求但現在失敗的:AbstractSecurityInterceptor
:AccessDecisionVoter
返回了authenticated
表達和拒絕訪問異常錯誤被拋出
您是否禁用了csrf令牌安全性? –
是的,我在配置spring安全性時做了這個 – Atul
@Atul:你知道這個意思嗎?和()。sessionManagement()。sessionCreationPolicy(SessionCreationPolicy.STATELESS); –