我尝试测试注入UserPrincipal的mvcControllers的访问权限:
的 restPockMockMvc .perform(获取( “/ POCS”)。委托人(的authToken)) .andReturn();
这是我尝试测试的控制器的方法:
@PreAuthorize(value =“hasRole('AK_ADMIN')”) @RequestMapping(method = RequestMethod.GET,produce =“application / json; charset = utf-8”) public PagedResources collectionList(HttpServletRequest httpServletRequest){ ............}
httpServletRequest.getUserPrincipal()我总是为null,而我注入了userPrincipal,我不明白为什么......
欢迎您的帮助。 谢谢
答案 0 :(得分:1)
尝试
MockHttpServletRequest request = new MockHttpServletRequest();
request.getUserPrincipal();