@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);
}
java类org.springframework.boot.context.properties.source.ConfigurationPropertySources的实例源码
OAuth2AutoConfigurationTests.java 文件源码
项目:spring-security-oauth2-boot
阅读 33
收藏 0
点赞 0
评论 0
OAuth2AutoConfigurationTests.java 文件源码
项目:spring-security-oauth2-boot
阅读 35
收藏 0
点赞 0
评论 0
@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);
}
PrefixPropertyCondition.java 文件源码
项目:loc-framework
阅读 35
收藏 0
点赞 0
评论 0
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
String prefix = (String) attribute(metadata, "prefix");
Class<?> value = (Class<?>) attribute(metadata, "value");
ConfigurableEnvironment environment = (ConfigurableEnvironment) context.getEnvironment();
try {
new Binder(ConfigurationPropertySources.from(environment.getPropertySources()))
.bind(prefix, Bindable.of(value))
.orElseThrow(
() -> new FatalBeanException("Could not bind DataSourceSettings properties"));
return new ConditionOutcome(true, String.format("Map property [%s] is not empty", prefix));
} catch (Exception e) {
//ignore
}
return new ConditionOutcome(false, String.format("Map property [%s] is empty", prefix));
}
OAuth2AutoConfigurationTests.java 文件源码
项目:spring-security-oauth2-boot
阅读 39
收藏 0
点赞 0
评论 0
@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);
}
EnvironmentEntryInitializingTreeMap.java 文件源码
项目:spring-cloud-stream
阅读 34
收藏 0
点赞 0
评论 0
@Override
public T get(Object key) {
if (!this.delegate.containsKey(key) && key instanceof String) {
T entry = BeanUtils.instantiateClass(entryClass);
Binder binder = new Binder(ConfigurationPropertySources.get(environment),new PropertySourcesPlaceholdersResolver(environment),this.conversionService);
binder.bind(defaultsPrefix, Bindable.ofInstance(entry));
this.delegate.put((String) key, entry);
}
return this.delegate.get(key);
}
EnvironmentEntryInitializingTreeMap.java 文件源码
项目:spring-cloud-stream
阅读 38
收藏 0
点赞 0
评论 0
@Override
public T put(String key, T value) {
// boot 2 call this first
Binder binder = new Binder(ConfigurationPropertySources.get(environment),new PropertySourcesPlaceholdersResolver(environment),this.conversionService);
binder.bind(defaultsPrefix, Bindable.ofInstance(value));
return this.delegate.put(key, value);
}
HostInfoEnvironmentPostProcessor.java 文件源码
项目:spring-cloud-commons
阅读 42
收藏 0
点赞 0
评论 0
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();
}
}
EurekaClientAutoConfigurationTests.java 文件源码
项目:spring-cloud-netflix
阅读 44
收藏 0
点赞 0
评论 0
private void setupContext(Class<?>... config) {
ConfigurationPropertySources.attach(this.context.getEnvironment());
this.context.register(PropertyPlaceholderAutoConfiguration.class, EurekaDiscoveryClientConfiguration.class);
for (Class<?> value : config) {
this.context.register(value);
}
this.context.register(TestConfiguration.class);
this.context.refresh();
}
LocBaseAutoConfiguration.java 文件源码
项目:loc-framework
阅读 35
收藏 0
点赞 0
评论 0
protected <T> T resolverSetting(Class<T> clazz, MutablePropertySources propertySources) {
return new Binder(ConfigurationPropertySources.from(propertySources))
.bind("loc", Bindable.of(clazz))
.orElseThrow(() -> new FatalBeanException("Could not bind DataSourceSettings properties"));
}
SpringBootAdminClientEnabledCondition.java 文件源码
项目:spring-boot-admin
阅读 45
收藏 0
点赞 0
评论 0
private ClientProperties getClientProperties(ConditionContext context) {
Iterable<ConfigurationPropertySource> sources = ConfigurationPropertySources.get(context.getEnvironment());
ClientProperties clientProperties = new ClientProperties();
new Binder(sources).bind("spring.boot.admin.client", Bindable.ofInstance(clientProperties));
return clientProperties;
}