@Test
public void testCustomAuthenticationDoesNotAuthenticateWithBootSecurityUser()
throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(AuthenticationManagerCustomizer.class,
SecurityAutoConfiguration.class, ServerPropertiesAutoConfiguration.class);
this.context.refresh();
SecurityProperties security = this.context.getBean(SecurityProperties.class);
AuthenticationManager manager = this.context.getBean(AuthenticationManager.class);
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
security.getUser().getName(), security.getUser().getPassword());
try {
manager.authenticate(token);
fail("Expected Exception");
}
catch (AuthenticationException success) {
// Expected
}
token = new UsernamePasswordAuthenticationToken("foo", "bar");
assertThat(manager.authenticate(token)).isNotNull();
}
java类org.springframework.web.context.support.AnnotationConfigWebApplicationContext的实例源码
SecurityAutoConfigurationTests.java 文件源码
项目:spring-boot-concourse
阅读 17
收藏 0
点赞 0
评论 0
HypermediaAutoConfigurationTests.java 文件源码
项目:spring-boot-concourse
阅读 16
收藏 0
点赞 0
评论 0
@Test
public void customizationOfSupportedMediaTypesCanBeDisabled() {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(BaseConfig.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.hateoas.use-hal-as-default-json-media-type:false");
this.context.refresh();
RequestMappingHandlerAdapter handlerAdapter = this.context
.getBean(RequestMappingHandlerAdapter.class);
for (HttpMessageConverter<?> converter : handlerAdapter.getMessageConverters()) {
if (converter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) {
assertThat(converter.getSupportedMediaTypes())
.containsExactly(MediaTypes.HAL_JSON);
}
}
}
SecurityAutoConfigurationTests.java 文件源码
项目:https-github.com-g0t4-jenkins2-course-spring-boot
阅读 24
收藏 0
点赞 0
评论 0
@Test
public void testDefaultUsernamePassword() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(SecurityAutoConfiguration.class,
ServerPropertiesAutoConfiguration.class);
this.context.refresh();
SecurityProperties security = this.context.getBean(SecurityProperties.class);
AuthenticationManager manager = this.context.getBean(AuthenticationManager.class);
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
security.getUser().getName(), security.getUser().getPassword());
assertThat(manager.authenticate(token)).isNotNull();
}
FormInitializer.java 文件源码
项目:singular-server
阅读 15
收藏 0
点赞 0
评论 0
public void init(ServletContext ctx, AnnotationConfigWebApplicationContext applicationContext) {
Class<?> documentFactory = documentFactory();
if (documentFactory != null) {
applicationContext.register(documentFactory);
} else {
logger.info(SINGULAR_FORM, " Null Form Document Factory, skipping Form Document Factory configuration. ");
}
Class<?> typeLoader = typeLoader();
if (typeLoader != null) {
applicationContext.register(typeLoader);
} else {
logger.info(SINGULAR_FORM, " Null Form Type Loader, skipping Form Type Loader configuration. ");
}
Class<?> formConfigFactory = formConfigFactory();
if (formConfigFactory != null) {
applicationContext.register(formConfigFactory);
} else {
logger.info(SINGULAR_FORM, " Null Form Config Factory, skipping Form Config Factory configuration. ");
}
}
MultipleResourceServerConfigurationTests.java 文件源码
项目:spring-security-oauth2-boot
阅读 22
收藏 0
点赞 0
评论 0
@Test
public void orderIsUnchangedWhenThereAreMultipleResourceServerConfigurations() {
this.context = new AnnotationConfigWebApplicationContext();
this.context.register(DoubleResourceConfiguration.class);
TestPropertyValues.of("security.oauth2.resource.tokenInfoUri:http://example.com",
"security.oauth2.client.clientId=acme").applyTo(this.context);
this.context.refresh();
assertThat(this.context
.getBean("adminResources", ResourceServerConfiguration.class).getOrder())
.isEqualTo(3);
assertThat(this.context
.getBean("otherResources", ResourceServerConfiguration.class).getOrder())
.isEqualTo(4);
}
SpringWebinitializer.java 文件源码
项目:Spring-5.0-Cookbook
阅读 23
收藏 0
点赞 0
评论 0
private void addRootContext(ServletContext container) {
// Create the application context
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register(SpringContextConfig.class);
// Register application context with ContextLoaderListener
container.addListener(new ContextLoaderListener(rootContext));
}
SpringWebinitializer.java 文件源码
项目:Spring-5.0-Cookbook
阅读 29
收藏 0
点赞 0
评论 0
private void addDispatcherContext(ServletContext container) {
// Create the dispatcher servlet's Spring application context
AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
dispatcherContext.register(SpringDispatcherConfig.class);
// Declare <servlet> and <servlet-mapping> for the DispatcherServlet
ServletRegistration.Dynamic dispatcher = container.addServlet("ch06-servlet",
new DispatcherServlet(dispatcherContext));
dispatcher.addMapping("/");
dispatcher.setLoadOnStartup(1);
}
SpringWebInitializer.java 文件源码
项目:Spring-5.0-Cookbook
阅读 21
收藏 0
点赞 0
评论 0
private void addRootContext(ServletContext container) {
// Create the application context
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register(SpringContextConfig.class);
// Register application context with ContextLoaderListener
container.addListener(new ContextLoaderListener(rootContext));
container.addListener(new AppSessionListener());
container.setInitParameter("contextConfigLocation", "org.packt.secured.mvc.core");
container.setSessionTrackingModes(EnumSet.of(SessionTrackingMode.COOKIE)); // if URL, enable sessionManagement URL rewriting
}
SpringWebInitializer.java 文件源码
项目:Spring-5.0-Cookbook
阅读 16
收藏 0
点赞 0
评论 0
private void addDispatcherContext(ServletContext container) {
// Create the dispatcher servlet's Spring application context
AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
dispatcherContext.register(SpringDispatcherConfig.class);
// Declare <servlet> and <servlet-mapping> for the DispatcherServlet
ServletRegistration.Dynamic dispatcher = container.addServlet("ch04-servlet",
new DispatcherServlet(dispatcherContext));
dispatcher.addMapping("/");
dispatcher.setLoadOnStartup(1);
}
SpringWebinitializer.java 文件源码
项目:Spring-5.0-Cookbook
阅读 29
收藏 0
点赞 0
评论 0
private void addRootContext(ServletContext container) {
// Create the application context
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register(SpringContextConfig.class);
// Register application context with ContextLoaderListener
container.addListener(new ContextLoaderListener(rootContext));
container.setInitParameter("contextConfigLocation", "org.packt.web.reactor.security.config");
container.setSessionTrackingModes(EnumSet.of(SessionTrackingMode.COOKIE)); // if URL, enable sessionManagement URL rewriting
}