[英]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,但它可能在內存中。
對不起,如果問題不合適,但我總是發現相互矛盾的方法,並且由於我缺乏知識而很快迷失了方向:
formLogin()
是正確的選擇,還是我應該使用其他東西?SessionRepository
class or session cookie name, then you should add it.formLogin
是正確的選擇之一,但您需要對其進行配置以替換默認的 spring 安全行為。 與入門指南一樣,配置HttpSecurity
bean 以使用您的/auth/login
和/auth/logout
值更改默認的/login
和/logout
端點路徑。 您可能還想在此 bean 中配置其他內容,例如在exceptionHandling配置中添加authenticationEntryPoint ,因此您的 API 服務器響應 401 http 狀態而不是重定向到登錄頁面。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.