@Bean public MockMvcBuilderCustomizer mockMvcBuilderCustomizer(ListableBeanFactory beanFactory) { Filter springSecurityFilterChain = beanFactory.getBean("springSecurityFilterChain", Filter.class); return builder -> builder.addFilters(springSecurityFilterChain) .defaultRequest(get("/").with(csrf()).with(user(123L).roles("ADMIN"))) .build(); }