- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
开始这个问题的上下文很少,我在 springboot 中做了前端与后端实现的 react 。
当我开发时,我在 package.json 中设置了 "proxy": "http://localhost:8080/",
这样它就可以将我的请求代理到 localhost:8080,这是 spring 的tomcat 服务器。
对于生产,我使用 frontend-maven-plugin 构建 React 应用程序,使用 maven-antrun-plugin 将 React 生产构建复制到后端目录 (target/classes/public),最后部署到 heroku。
在我的项目中添加 spring security 后,我意识到它添加了对“/login”上的登录页面的支持,我通过更改 http.loginPage()
将其更改为“/my-login”
@Override
protected void configure(HttpSecurity http) throws Exception{
http.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.formLogin()
.loginPage("/my-login")
.permitAll(true)
.and()
.logout()
.logoutSuccessUrl("/my-login?logout")
.permitAll();
http.cors();
现在的问题是我的登录页面在 react 应用程序目录中,我不能在 spring boot 目录中有另一个登录页面。我尝试将 .jsp 登录页面作为中间件,它会与 Spring Security 对话并从 React 端发出发布请求,但实际上无法用这种方法做任何事情。
那么有没有其他方法可以让登录页面由 react 提供,它仍然可以与 spring security 交互?
谢谢,
段落
最佳答案
我刚刚开始使用 spring ...但通常对于 React 应用程序,身份验证是无状态的...我们设置包含 token 的授权 header (例如:jwt)并且我们有一个注销端点使 token 。因此,注销请求中的 200 =“/my-login?logout”。任何路由中的 403 都被“客户端”路由器重定向到“/my-login”
您采用的方法要求 View 是“服务器端”呈现的……据我所知,React SSR(服务器端呈现)是 NodeJS 服务器独有的。
关于java - 我如何将 Spring Security 与我的 React-Spring Boot 应用程序一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59025961/
我是一名优秀的程序员,十分优秀!