Default RequestCache as @Bean

Fixes: gh-5583
This commit is contained in:
Rob Winch
2018-07-26 14:09:22 -05:00
parent 8ce244f5d2
commit 7b2b1a877d
2 changed files with 39 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ package org.springframework.security.config.annotation.web.configurers;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@@ -69,4 +70,25 @@ public class FormLoginConfigurerTests {
.requestCache(this.requestCache);
}
}
@Test
public void requestCacheAsBean() throws Exception {
this.spring.register(RequestCacheBeanConfig.class,
AuthenticationTestConfiguration.class).autowire();
RequestCache requestCache = this.spring.getContext().getBean(RequestCache.class);
this.mockMvc.perform(formLogin())
.andExpect(authenticated());
verify(requestCache).getRequest(any(), any());
}
@EnableWebSecurity
static class RequestCacheBeanConfig {
@Bean
RequestCache requestCache() {
return mock(RequestCache.class);
}
}
}