MockMvc和用户负责人

时间:2015-03-30 07:52:13

标签: spring security principal mockmvc

我尝试测试注入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,我不明白为什么......

欢迎您的帮助。 谢谢

1 个答案:

答案 0 :(得分:1)

尝试

MockHttpServletRequest request = new MockHttpServletRequest();
request.getUserPrincipal();