【发布时间】:2018-03-11 23:27:08
【问题描述】:
所以我有一个 Spring Boot 应用程序,我正在使用 PostMan 向它发送一个请求。它使用 Spring Security 和 JWT 进行身份验证。我正在尝试获得工作授权,但遇到了问题。 Spring能够登录用户并返回一个令牌罚款。但是当我将令牌放在标题中时,它根本不起作用。我没有得到服务器的响应。删除令牌后,它可以正常工作。现在无论是否登录,所有请求都应该能够通过。
我的 Spring Web 配置:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurity extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and().csrf().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.addFilter(new JWTAuthenticationFilter(authenticationManager()))
.addFilter(new JWTAuthorizationFilter(authenticationManager()));
}
}
我尝试访问的 REST 路径:
@RestController("threadService")
@RequestMapping("/api/thread")
public class ThreadService {
@RequestMapping(value="/list", method=RequestMethod.GET)
public List<ThreadDetails> getThreadList() {
logger.info("getThreadList");
return threadDao.getThreadList();
}
}
我在登录并获得令牌后发出的失败的 GET 请求:
GET /api/thread/list HTTP/1.1
Host: localhost:8080
Authorization : Bearer (JWT token here)
Cache-Control: no-cache
Postman-Token: 69565839-4806-b4f6-9a03-11382a80c7da
当标头中没有授权时,上述请求可以正常工作。
【问题讨论】:
标签: spring rest spring-boot spring-security