spring-boot - Spring Security 的默认登录表单可以与 JWT 一起使用吗?
问题描述
我创建了一个 REST API 后端,通过 JWT 对用户进行身份验证和授权。我还向我的应用程序添加了通过电子邮件注册用户的功能。因此,在注册期间,我创建了一个发送给用户的链接,当他点击它时,他被重定向到一个网页,通知他他的帐户已被激活。我现在要做的是合并默认的 spring 安全登录表单,以保护确认链接不被那些可能错误地收到电子邮件的人影响。因此,每当他想访问此链接时,他都需要先登录。
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and().csrf().disable()
.exceptionHandling().authenticationEntryPoint(jwtAuthenticationEntryPoint)
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.headers().frameOptions().sameOrigin()
.and()
.authorizeRequests()
.antMatchers(
"/",
"/favicon.ico",
"/**/*.png",
"/**/*.gif",
"/**/*.svg",
"/**/*.jpg",
"/**/*.html",
"/**/*.css",
"/**/*.js"
)
.permitAll()
.antMatchers(SIGN_UP_URLS).permitAll()
.antMatchers(H2_URL).permitAll()
.anyRequest().authenticated();
http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
}
解决方案
推荐阅读
- spring-integration - Spring Integration:自上次轮询以来仅摄取新文件
- java - 将十进制值转换为二进制时遇到问题
- python - 无法应用一个非常简单的 json.dumps 解决方案,为什么?
- vue.js - Nuxt.js - API 调用的最佳场所
- gitlab-ci - 如何使用 GitLab CI 中的包含从另一个项目中的文件运行脚本?
- node.js - 如何在没有express/multer的节点中处理来自post请求的图像数据?
- javascript - 嵌套数组的 JavaScript 映射和过滤
- c - 如何在结构中分配空间
- javascript - 如何将try catch函数变成promise
- swift - 拖动手势时将矩形限制为屏幕边缘