Skip to content

Pageable resolver breaks annotation WithUserDetails [DATACMNS-954] #1409

@spring-projects-issues

Description

@spring-projects-issues

kane zhu opened DATACMNS-954 and commented

I am testing a rest api with security enabled which bases on spring boot 1.4.2/spring security/spring security test.

I have a protected api looking like below,

@Secured("ROLE_STAFF")
    @RequestMapping(value = "/videoclips", method = RequestMethod.GET)
    @ResponseBody
    @JsonView({View.Staff.class})
    public ResponseEntity<Page<VideoClip>> listClips(@AuthenticationPrincipal UserDetails activeUser,
                                                     Pageable pageable) throws IllegalRequest {

Then the test method looks like,

@RunWith(SpringRunner.class)
@EnableSpringDataWebSupport
@ActiveProfiles("integTest")
@ContextConfiguration(classes = {MongoClientTestConfiguration.class, SecurityTestConfiguration.class,
        JacksonConfiguration.class, StaffController.class})
@WebMvcTest({StaffController.class})
public class StaffControllerTest implements ApplicationContextAware {

    @Test
    @WithUserDetails(value = "staffUsername")
    public void listVideoClips() throws Exception {
      mvc.perform(MockMvcRequestBuilders.get("/staff/videoclips")
                .param("page", "0").param("size", String.valueOf(pageable.getPageSize())))
                .andExpect(status().isOk());
    }

When running above test method, the runtime variable activeUser of controller's listClips is an empty hashmap, not the expected UserDetail.
If removing the annotation EnableSpringDataWebSupport, the activeUser of controller is the expected value when running the test case. But the pageable of controller would not be resolved any more if the SpringDataWebSupport is removed.

Looks like the arguments resolver of request introduced by spring data web support breaks the annotation WithUserDetails of spring security test


Affects: 1.12.5 (Hopper SR5)

Issue Links:

  • DATACMNS-776 ProxyingHandlerMethodArgumentResolver handles interfaces not intended for projection
    ("duplicates")

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions