Search in sources :

Example 31 with SpringApplicationBuilder

use of org.springframework.boot.builder.SpringApplicationBuilder in project spring-boot by spring-projects.

the class ResourceServerTokenServicesConfigurationTests method userInfoWithClient.

@Test
public void userInfoWithClient() {
    EnvironmentTestUtils.addEnvironment(this.environment, "security.oauth2.client.client-id=acme", "security.oauth2.resource.userInfoUri:http://example.com", "server.port=-1", "debug=true");
    this.context = new SpringApplicationBuilder(ResourceNoClientConfiguration.class).environment(this.environment).web(WebApplicationType.SERVLET).run();
    BeanDefinition bean = ((BeanDefinitionRegistry) this.context).getBeanDefinition("scopedTarget.oauth2ClientContext");
    assertThat(bean.getScope()).isEqualTo("request");
}
Also used : SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) Test(org.junit.Test)

Example 32 with SpringApplicationBuilder

use of org.springframework.boot.builder.SpringApplicationBuilder in project spring-boot by spring-projects.

the class ResourceServerTokenServicesConfigurationTests method springSocialUserInfo.

@Test
public void springSocialUserInfo() {
    EnvironmentTestUtils.addEnvironment(this.environment, "security.oauth2.resource.userInfoUri:http://example.com", "spring.social.facebook.app-id=foo", "spring.social.facebook.app-secret=bar");
    this.context = new SpringApplicationBuilder(SocialResourceConfiguration.class).environment(this.environment).web(WebApplicationType.SERVLET).run();
    ConnectionFactoryLocator connectionFactory = this.context.getBean(ConnectionFactoryLocator.class);
    assertThat(connectionFactory).isNotNull();
    SpringSocialTokenServices services = this.context.getBean(SpringSocialTokenServices.class);
    assertThat(services).isNotNull();
}
Also used : SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) ConnectionFactoryLocator(org.springframework.social.connect.ConnectionFactoryLocator) Test(org.junit.Test)

Example 33 with SpringApplicationBuilder

use of org.springframework.boot.builder.SpringApplicationBuilder in project spring-boot by spring-projects.

the class ResourceServerTokenServicesConfigurationTests method jwkConfiguration.

@Test
public void jwkConfiguration() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.environment, "security.oauth2.resource.jwk.key-set-uri=http://my-auth-server/token_keys");
    this.context = new SpringApplicationBuilder(ResourceConfiguration.class).environment(this.environment).web(false).run();
    DefaultTokenServices services = this.context.getBean(DefaultTokenServices.class);
    assertThat(services).isNotNull();
    this.thrown.expect(NoSuchBeanDefinitionException.class);
    this.context.getBean(RemoteTokenServices.class);
}
Also used : SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) DefaultTokenServices(org.springframework.security.oauth2.provider.token.DefaultTokenServices) Test(org.junit.Test)

Example 34 with SpringApplicationBuilder

use of org.springframework.boot.builder.SpringApplicationBuilder in project spring-boot by spring-projects.

the class ResourceServerTokenServicesConfigurationTests method switchToJwt.

@Test
public void switchToJwt() {
    EnvironmentTestUtils.addEnvironment(this.environment, "security.oauth2.resource.jwt.keyValue=FOOBAR");
    this.context = new SpringApplicationBuilder(ResourceConfiguration.class).environment(this.environment).web(WebApplicationType.NONE).run();
    DefaultTokenServices services = this.context.getBean(DefaultTokenServices.class);
    assertThat(services).isNotNull();
    this.thrown.expect(NoSuchBeanDefinitionException.class);
    this.context.getBean(RemoteTokenServices.class);
}
Also used : SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) DefaultTokenServices(org.springframework.security.oauth2.provider.token.DefaultTokenServices) Test(org.junit.Test)

Example 35 with SpringApplicationBuilder

use of org.springframework.boot.builder.SpringApplicationBuilder in project spring-boot by spring-projects.

the class SpringApplicationAdminJmxAutoConfigurationTests method onlyRegisteredOnceWhenThereIsAChildContext.

@Test
public void onlyRegisteredOnceWhenThereIsAChildContext() throws Exception {
    SpringApplicationBuilder parentBuilder = new SpringApplicationBuilder().web(WebApplicationType.NONE).sources(JmxAutoConfiguration.class, SpringApplicationAdminJmxAutoConfiguration.class);
    SpringApplicationBuilder childBuilder = parentBuilder.child(JmxAutoConfiguration.class, SpringApplicationAdminJmxAutoConfiguration.class).web(WebApplicationType.NONE);
    ConfigurableApplicationContext parent = null;
    ConfigurableApplicationContext child = null;
    try {
        parent = parentBuilder.run("--" + ENABLE_ADMIN_PROP);
        child = childBuilder.run("--" + ENABLE_ADMIN_PROP);
        BeanFactoryUtils.beanOfType(parent.getBeanFactory(), SpringApplicationAdminMXBeanRegistrar.class);
        this.thrown.expect(NoSuchBeanDefinitionException.class);
        BeanFactoryUtils.beanOfType(child.getBeanFactory(), SpringApplicationAdminMXBeanRegistrar.class);
    } finally {
        if (parent != null) {
            parent.close();
        }
        if (child != null) {
            child.close();
        }
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) JmxAutoConfiguration(org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration) Test(org.junit.Test)

Aggregations

SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)36 Test (org.junit.Test)32 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)17 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)13 DefaultTokenServices (org.springframework.security.oauth2.provider.token.DefaultTokenServices)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 URI (java.net.URI)1 RoutesCollector (org.apache.camel.spring.boot.RoutesCollector)1 Logger (org.slf4j.Logger)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)1 Banner (org.springframework.boot.Banner)1 SpringApplication (org.springframework.boot.SpringApplication)1 JmxAutoConfiguration (org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration)1 ParentContextApplicationContextInitializer (org.springframework.boot.builder.ParentContextApplicationContextInitializer)1 ApplicationStartingEvent (org.springframework.boot.context.event.ApplicationStartingEvent)1 ServerPortInfoApplicationContextInitializer (org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer)1 AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ApplicationListener (org.springframework.context.ApplicationListener)1