【发布时间】:2018-06-27 02:03:07
【问题描述】:
我有一个看起来像这样的休息端点:
@RequestMapping(path = "api/profile/majors", method = RequestMethod.GET)
public String getMajors() {
//return profileDAO.getMajors();
return "abc";
}
由于某种原因,每次我去浏览器访问:http://localhost:8080/api/profile/majors
似乎请求总是被重定向到http://localhost:8080
当我在return "abc" 处设置断点时,程序确实停在那里,但发送回浏览器的响应仍然是http://localhost:8080/ 处的任何内容
知道为什么吗??
(更多背景知识:我确实运行了 Spring Security 过滤器,我确实调用了filterChain.doFilter(request, response);,但这个问题仍然存在..)
任何提示都会有所帮助!
我的安全配置是这样的:
http.cors()
.and()
.csrf()
.disable()
.authorizeRequests()
.antMatchers(Endpoints.PROTECTED_API_PATTERN)
.authenticated()
.and()
.addFilterBefore(
new JWTLoginFilter(loginRequestMatcher, authenticationManager(), successHandler),
UsernamePasswordAuthenticationFilter.class
)
.addFilterBefore(
new JWTAPIFilter(protectedAPIMatcher, authenticationManager(), cookieService),
UsernamePasswordAuthenticationFilter.class
);
【问题讨论】:
-
访问
http://localhost:8080/api/profile/majors时得到的响应码是什么? -
找到了 302
-
请求 URL:localhost:8080/api/profile/majors 请求方法:GET 状态码:302 找到远程地址:[::1]:8080 推荐人策略:no-referrer-when-downgrade
-
我记错了。但这可能是在登录成功后,您被定向到此页面。也许也可以在这里分享 spring 安全配置。
-
我有一个扩展
AbstractAuthenticationProcessingFilter的自定义过滤器,我将"/api/**"传递给了它的构造函数defaultFilterProcessesUrl。如果我将其设置为任何其他值,例如"/"一切都会正常工作......有什么想法吗?
标签: java spring spring-mvc spring-boot