我尝试测试注入(inject) UserPrincipal 的 mvcControllers 的访问:
restPockMockMvc .perform(get("/pocs").principal(authToken)) .andReturn();
这是我尝试测试的 Controller 方法:
@PreAuthorize(value = "hasRole('AK_ADMIN')") @RequestMapping(method = RequestMethod.GET, produces = "application/json; charset=utf-8") 公共(public) PagedResources 集合列表(HttpServletRequest httpServletRequest){ ........................
httpServletRequest.getUserPrincipal() 始终为空,而我注入(inject)了 userPrincipal,但我不明白为什么...
欢迎您的帮助。 谢谢
最佳答案
尝试
MockHttpServletRequest request = new MockHttpServletRequest();
request.getUserPrincipal();
关于spring - MockMvc 和用户主体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29340971/