How to set role in MockHttpServletRequest?

为君一笑 提交于 2019-12-25 02:44:46

问题


I have read following topic:

https://stackoverflow.com/a/18487953/2674303

But it is a bit not my variant.

Inside my method controller which I need to test I have following line:

httpServletRequest.isUserInRole("ROLE_OWNER");

How can I set role in MockHttpServletRequest ?


回答1:


 mockMvc.perform(post("/owner/terminals/edit").principal(principal).with(new RequestPostProcessor() {
            public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) {
                request.addUserRole("ROLE_OWNER");
                return request;
            }


来源:https://stackoverflow.com/questions/32772151/how-to-set-role-in-mockhttpservletrequest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!