Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • Spring Security allows to specify the actual user of a request in multiple ways. You should also be able to annotate the test method with something like @WithMockUser(roles="ADMIN") as explained in the referenced documentation Commented Aug 4, 2015 at 16:23
  • 1
    The thing is - @WithMockUser(roles = "USER") didn't work with the method, contrary to with(user(...)). Also, mockMvc.perform(get("/admin/health").with(user("user").roles("ADMIN"))).andExpect(status().isOk()); doesn't work either. I totally don't get it Commented Aug 4, 2015 at 16:27
  • 1
    Where is the static user() defined (Eclipse fails totally on including static) Commented Jun 16, 2016 at 13:58
  • 1
    Hey, it's org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user, most likely from the spring-security-test library. Commented Jun 16, 2016 at 22:58
  • .with(user("user")) ignores any kind of permission or role based security Commented Mar 27, 2018 at 11:05