Java Code Examples for org.springframework.boot.context.properties.source.ConfigurationPropertySources#attach()

The following examples show how to use org.springframework.boot.context.properties.source.ConfigurationPropertySources#attach() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OAuth2AutoConfigurationTests.java    From spring-security-oauth2-boot with Apache License 2.0 6 votes vote down vote up
@Test
public void testCanUseClientCredentialsWithEnableOAuth2Client() {
	this.context = new AnnotationConfigServletWebServerApplicationContext();
	this.context.register(ClientConfiguration.class, MinimalSecureWebApplication.class);
	TestPropertyValues
			.of("security.oauth2.client.clientId=client", "security.oauth2.client.grantType=client_credentials")
			.applyTo(this.context);
	ConfigurationPropertySources.attach(this.context.getEnvironment());
	this.context.refresh();
	// The primary context is fine (not session scoped):
	OAuth2ClientContext bean = this.context.getBean(OAuth2ClientContext.class);
	assertThat(bean.getAccessTokenRequest()).isNotNull();
	assertThat(countBeans(ClientCredentialsResourceDetails.class)).isEqualTo(1);
	// Kind of a bug (should ideally be 1), but the cause is in Spring OAuth2 (there
	// is no need for the extra session-scoped bean). What this test proves is that
	// even if the user screws up and does @EnableOAuth2Client for client
	// credentials,
	// it will still just about work (because of the @Primary annotation on the
	// Boot-created instance of OAuth2ClientContext).
	assertThat(countBeans(OAuth2ClientContext.class)).isEqualTo(2);
}
 
Example 2
Source File: EurekaConfigurationListener.java    From summerframework with Apache License 2.0 5 votes vote down vote up
private HostInfo getFirstNonLoopbackHostInfo(ConfigurableEnvironment environment) {
    InetUtilsProperties target = new InetUtilsProperties();
    ConfigurationPropertySources.attach(environment);
    Binder.get(environment).bind(InetUtilsProperties.PREFIX, Bindable.ofInstance(target));
    try (InetUtils utils = new InetUtils(target)) {
        return utils.findFirstNonLoopbackHostInfo();
    }
}
 
Example 3
Source File: SpringApplication.java    From spring-javaformat with Apache License 2.0 5 votes vote down vote up
private ConfigurableEnvironment prepareEnvironment(
		SpringApplicationRunListeners listeners,
		ApplicationArguments applicationArguments) {
	// Create and configure the environment
	ConfigurableEnvironment environment = getOrCreateEnvironment();
	configureEnvironment(environment, applicationArguments.getSourceArgs());
	listeners.environmentPrepared(environment);
	bindToSpringApplication(environment);
	if (this.webApplicationType == WebApplicationType.NONE) {
		environment = new EnvironmentConverter(getClassLoader())
				.convertToStandardEnvironmentIfNecessary(environment);
	}
	ConfigurationPropertySources.attach(environment);
	return environment;
}
 
Example 4
Source File: DubboRelaxedBinding2AutoConfiguration.java    From dubbo-spring-boot-project with Apache License 2.0 5 votes vote down vote up
@Bean(name = BASE_PACKAGES_PROPERTY_RESOLVER_BEAN_NAME)
public PropertyResolver dubboScanBasePackagesPropertyResolver(ConfigurableEnvironment environment) {
    ConfigurableEnvironment propertyResolver = new AbstractEnvironment() {
        @Override
        protected void customizePropertySources(MutablePropertySources propertySources) {
            Map<String, Object> dubboScanProperties = getSubProperties(environment.getPropertySources(), DUBBO_SCAN_PREFIX);
            propertySources.addLast(new MapPropertySource("dubboScanProperties", dubboScanProperties));
        }
    };
    ConfigurationPropertySources.attach(propertyResolver);
    return new DelegatingPropertyResolver(propertyResolver);
}
 
Example 5
Source File: OAuth2AutoConfigurationTests.java    From spring-security-oauth2-boot with Apache License 2.0 5 votes vote down vote up
@Test
public void testCanUseClientCredentials() {
	this.context = new AnnotationConfigServletWebServerApplicationContext();
	this.context.register(TestSecurityConfiguration.class, MinimalSecureWebApplication.class);
	TestPropertyValues
			.of("security.oauth2.client.clientId=client", "security.oauth2.client.grantType=client_credentials")
			.applyTo(this.context);
	ConfigurationPropertySources.attach(this.context.getEnvironment());
	this.context.refresh();
	OAuth2ClientContext bean = this.context.getBean(OAuth2ClientContext.class);
	assertThat(bean.getAccessTokenRequest()).isNotNull();
	assertThat(countBeans(ClientCredentialsResourceDetails.class)).isEqualTo(1);
	assertThat(countBeans(OAuth2ClientContext.class)).isEqualTo(1);
}
 
Example 6
Source File: OAuth2AutoConfigurationTests.java    From spring-security-oauth2-boot with Apache License 2.0 5 votes vote down vote up
@Test
public void testDisablingAuthorizationServer() {
	this.context = new AnnotationConfigServletWebServerApplicationContext();
	this.context.register(ResourceServerConfiguration.class, MinimalSecureWebApplication.class);
	TestPropertyValues.of("security.oauth2.resource.jwt.keyValue:DEADBEEF").applyTo(this.context);
	ConfigurationPropertySources.attach(this.context.getEnvironment());
	this.context.refresh();
	assertThat(countBeans(RESOURCE_SERVER_CONFIG)).isEqualTo(1);
	assertThat(countBeans(AUTHORIZATION_SERVER_CONFIG)).isEqualTo(0);
	assertThat(countBeans(UserApprovalHandler.class)).isEqualTo(0);
	assertThat(countBeans(DefaultTokenServices.class)).isEqualTo(1);
}
 
Example 7
Source File: OAuth2AutoConfigurationTests.java    From spring-security-oauth2-boot with Apache License 2.0 5 votes vote down vote up
@Test
public void authorizationServerWhenUsingJwtConfigurationThenConfiguresJwt() {
	this.context = new AnnotationConfigServletWebServerApplicationContext();
	this.context.register(AuthorizationServerConfiguration.class, MinimalSecureWebApplication.class);
	TestPropertyValues.of("security.oauth2.authorization.jwt.keyValue:DEADBEEF").applyTo(this.context);
	ConfigurationPropertySources.attach(this.context.getEnvironment());
	this.context.refresh();
	assertThat(countBeans(RESOURCE_SERVER_CONFIG)).isEqualTo(0);
	assertThat(countBeans(AUTHORIZATION_SERVER_CONFIG)).isEqualTo(1);
	assertThat(countBeans(JwtAccessTokenConverter.class)).isEqualTo(1);
}
 
Example 8
Source File: HostInfoEnvironmentPostProcessor.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
private HostInfo getFirstNonLoopbackHostInfo(ConfigurableEnvironment environment) {
	InetUtilsProperties target = new InetUtilsProperties();
	ConfigurationPropertySources.attach(environment);
	Binder.get(environment).bind(InetUtilsProperties.PREFIX,
			Bindable.ofInstance(target));
	try (InetUtils utils = new InetUtils(target)) {
		return utils.findFirstNonLoopbackHostInfo();
	}
}
 
Example 9
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
private void setupContext(Class<?>... config) {
	ConfigurationPropertySources.attach(this.context.getEnvironment());
	this.context.register(PropertyPlaceholderAutoConfiguration.class,
			DiscoveryClientOptionalArgsConfiguration.class,
			EurekaDiscoveryClientConfiguration.class);
	for (Class<?> value : config) {
		this.context.register(value);
	}
	this.context.register(TestConfiguration.class);
	this.context.refresh();
}
 
Example 10
Source File: ConsulDiscoveryClientConfigurationTests.java    From spring-cloud-consul with Apache License 2.0 5 votes vote down vote up
private void setupContext(Class<?>... config) {
	ConfigurationPropertySources.attach(this.context.getEnvironment());
	this.context.register(UtilAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class, ConsulAutoConfiguration.class,
			ConsulDiscoveryClientConfiguration.class);
	for (Class<?> value : config) {
		this.context.register(value);
	}
	this.context.refresh();
}