java - 生成令牌 JWT 后 Spring Security 302 重定向
问题描述
我有一个 POST,它在请求的标头中生成 jwt 令牌,但是在邮递员发出请求的那一刻,它以 302 响应并重定向到“localhost”。
查看邮递员控制台,POST 具有令牌。
http.authorizeRequests()
.and().csrf().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and().authorizeRequests().antMatchers("/", "/css/**", "/js/**", "/images/**", "/listar/**", "/api/**").permitAll()
.anyRequest().authenticated()
.and().addFilter(new JWTAuthenticationFilter(authenticationManager()))
.httpBasic();
public JWTAuthenticationFilter(AuthenticationManager authenticationManager) {
this.authenticationManager = authenticationManager;
this.setRequiresAuthenticationRequestMatcher(new AntPathRequestMatcher("/api/login", "POST"));
}
在调试模式下检查,您可以看到“AbstractAuthenticationTargetUrlRequestHandler.defaultTargetUrl”的值为“/”,因此为 302。
我怎么能定义它根本不重定向?
解决方案
推荐阅读
- node.js - 当库有 index.d.ts 文件时,为什么我的应用程序代码会显示“找不到模块的声明文件...”?
- c# - 如何将插入符号添加到表单控件?
- c++ - 标量类型的初始化程序中的错误指示符
- c# - Windows 窗体测验跟踪单选按钮
- python - 如何使用“upsert”使用 SQLAlchemy 执行批量插入,因此现有密钥被忽略(或更新)并且不会使执行崩溃?
- python - 先前初始化的变量声称“未定义”
- flutter - 如何在不设置路由的情况下导航到新屏幕
- ios - 如何在 Swift 中显示这个 html 结构的 json 响应
- javascript - 将匹配重音字符并将 - 替换为 ' ' 的正则表达式
- python - 带有OOP的python中的KMeans实现?