3

我尝试测试注入 UserPrincipal 的 mvcControllers 的访问权限:

restPockMockMvc .perform(get("/pocs").principal(authToken)) .andReturn();

这是我尝试测试的控制器的方法:

@PreAuthorize(value = "hasRole('AK_ADMIN')") @RequestMapping(method = RequestMethod.GET,produces = "application/json; charset=utf-8") public PagedResources collectionList(HttpServletRequest httpServletRequest){ ..... .......}

httpServletRequest.getUserPrincipal() 始终为空,而我注入 userPrincipal 但我不明白为什么......

欢迎您的帮助。谢谢

4

1 回答 1

1

尝试

MockHttpServletRequest request = new MockHttpServletRequest();
request.getUserPrincipal();
于 2015-07-17T04:34:17.143 回答