Spring Security Test and MockMvc supply null custom UserDetails parameter to REST Controller

三世轮回 提交于 2019-12-04 17:51:31

I was finally able to get this to work by explicitly adding my AuthenticationConfig's filter onto the StandaloneMockMvcBuilder. So my setup now looks like:

private MockMvc mockMvc;
@Autowired
private MyController controller;
@Autowired
private AuthenticationConfig authConfig;

@Before
public void setUp() {
  mockMvc = standaloneSetup(controller)
              .setCustomArgumentResolvers(new AuthenticationPrincipalArgumentResolver())
              .addFilters(authConfig.getCustomFilter())
              .build();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!