Code example for MockMvcConfigurerAdapter

0
    private Filter springSecurityFilterChain; 
 
    /** 
     * Creates a new instance 
     */ 
    SecurityMockMvcConfigurer() {} 
 
    /** 
     * Creates a new instance with the provided {@link javax.servlet.Filter} 
     * @param springSecurityFilterChain the {@link javax.servlet.Filter} to use 
     */ 
    SecurityMockMvcConfigurer(Filter springSecurityFilterChain) { 
        this.springSecurityFilterChain = springSecurityFilterChain; 
    } 
 
    @Override 
    public RequestPostProcessor beforeMockMvcCreated(ConfigurableMockMvcBuilder<?> builder, WebApplicationContext context) { 
        String securityBeanId = BeanIds.SPRING_SECURITY_FILTER_CHAIN; 
        if(springSecurityFilterChain == null && context.containsBean(securityBeanId)) { 
            springSecurityFilterChain = context.getBean(securityBeanId, Filter.class);