簡體   English   中英

Spring 具有自定義身份驗證和 session 存儲的引導安全性

[英]Spring Boot Security with custom auth & session storage

I'm trying simple Spring Boot applications for a Single Page Application, Vue, where the web server is supposed to answer all /api , /auth/login and /auth/logout requests without any views, just JSON responses, like a REST API .

現在為了簡單起見,我想要一個用戶名和密碼驗證,但由 Vue 前端調用。 當我使用.formLogin()時, Spring 安全創建一個帶有JSESSIONID的 cookie,但它可能在內存中。

對不起,如果問題不合適,但我總是發現相互矛盾的方法,並且由於我缺乏知識而很快迷失了方向:

  1. 是否需要 Spring Session,或者如何擴展它以存儲在我擁有的自定義存儲庫中?
  2. formLogin()是正確的選擇,還是我應該使用其他東西?
  1. Spring Session dependency ( org.springframework.session:spring-session-core ) is not required to be manually added to classpath, because it is done by Spring Security. However, if you would like to customize session management, for example change default in memory SessionRepository class or session cookie name, then you should add it.
  2. formLogin是正確的選擇之一,但您需要對其進行配置以替換默認的 spring 安全行為。 入門指南一樣,配置HttpSecurity bean 以使用您的/auth/login/auth/logout值更改默認的/login/logout端點路徑。 您可能還想在此 bean 中配置其他內容,例如在exceptionHandling配置中添加authenticationEntryPoint ,因此您的 API 服務器響應 401 http 狀態而不是重定向到登錄頁面。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM