本文整理汇总了Java中org.springframework.context.annotation.ConditionContext.getEnvironment方法的典型用法代码示例。如果您正苦于以下问题:Java ConditionContext.getEnvironment方法的具体用法?Java ConditionContext.getEnvironment怎么用?Java ConditionContext.getEnvironment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.context.annotation.ConditionContext
的用法示例。
在下文中一共展示了ConditionContext.getEnvironment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMatchOutcome
import org.springframework.context.annotation.ConditionContext; //导入方法依赖的package包/类
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
ConditionMessage.Builder message = ConditionMessage
.forCondition("OAuth JWT Condition");
Environment environment = context.getEnvironment();
String keyValue = environment
.getProperty("security.oauth2.resource.jwt.key-value");
String keyUri = environment
.getProperty("security.oauth2.resource.jwt.key-uri");
if (StringUtils.hasText(keyValue) || StringUtils.hasText(keyUri)) {
return ConditionOutcome
.match(message.foundExactly("provided public key"));
}
return ConditionOutcome
.noMatch(message.didNotFind("provided public key").atAll());
}
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:18,代码来源:ResourceServerTokenServicesConfiguration.java
示例2: getMatchOutcome
import org.springframework.context.annotation.ConditionContext; //导入方法依赖的package包/类
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
final RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(context.getEnvironment(),
"holon.swagger.");
if (!resolver.getProperty("holon.swagger.enabled", boolean.class, true)) {
return ConditionOutcome.noMatch(ConditionMessage.forCondition("SwaggerApiAutoDetectCondition")
.because("holon.swagger.enabled is false"));
}
if (resolver.containsProperty("resourcePackage")) {
return ConditionOutcome.noMatch(
ConditionMessage.forCondition("SwaggerApiAutoDetectCondition").available("resourcePackage"));
}
Map<String, Object> ag = resolver.getSubProperties("apiGroups");
if (ag != null && ag.size() > 0) {
return ConditionOutcome
.noMatch(ConditionMessage.forCondition("SwaggerApiAutoDetectCondition").available("apiGroups"));
}
return ConditionOutcome.match();
}
示例3: getMatchOutcome
import org.springframework.context.annotation.ConditionContext; //导入方法依赖的package包/类
@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));
}
示例4: isSpringSecurityEnabled
import org.springframework.context.annotation.ConditionContext; //导入方法依赖的package包/类
private boolean isSpringSecurityEnabled(ConditionContext ctx) {
boolean enabled = true;
Environment env = ctx.getEnvironment();
for (String propName : props) {
if (env.containsProperty(propName)) {
if (!Boolean.parseBoolean(env.getProperty(propName))) {
enabled = false;
break;
}
}
}
if (enabled) {
enabled = ClassUtils.isPresent(SPRING_SEC_CLASS_NAME, ctx.getClassLoader());
}
return enabled;
}
示例5: getMatchOutcome
import org.springframework.context.annotation.ConditionContext; //导入方法依赖的package包/类
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
ConfigurableEnvironment environment = (ConfigurableEnvironment) context
.getEnvironment();
ResourceProperties properties = new ResourceProperties();
RelaxedDataBinder binder = new RelaxedDataBinder(properties, "spring.resources");
binder.bind(new PropertySourcesPropertyValues(environment.getPropertySources()));
Boolean match = properties.getChain().getEnabled();
if (match == null) {
boolean webJarsLocatorPresent = ClassUtils.isPresent(WEBJAR_ASSERT_LOCATOR,
getClass().getClassLoader());
return new ConditionOutcome(webJarsLocatorPresent,
"Webjars locator (" + WEBJAR_ASSERT_LOCATOR + ") is "
+ (webJarsLocatorPresent ? "present" : "absent"));
}
return new ConditionOutcome(match,
"Resource chain is " + (match ? "enabled" : "disabled"));
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:OnEnabledResourceChainCondition.java
示例6: getMatchOutcome
import org.springframework.context.annotation.ConditionContext; //导入方法依赖的package包/类
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
Environment environment = context.getEnvironment();
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment,
"security.oauth2.resource.");
Boolean preferTokenInfo = resolver.getProperty("prefer-token-info",
Boolean.class);
if (preferTokenInfo == null) {
preferTokenInfo = environment
.resolvePlaceholders("${OAUTH2_RESOURCE_PREFERTOKENINFO:true}")
.equals("true");
}
String tokenInfoUri = resolver.getProperty("token-info-uri");
String userInfoUri = resolver.getProperty("user-info-uri");
if (!StringUtils.hasLength(userInfoUri)) {
return ConditionOutcome.match("No user info provided");
}
if (StringUtils.hasLength(tokenInfoUri) && preferTokenInfo) {
return ConditionOutcome.match(
"Token info endpoint " + "is preferred and user info provided");
}
return ConditionOutcome.noMatch("Token info endpoint is not provided");
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:25,代码来源:ResourceServerTokenServicesConfiguration.java
示例7: getMatchOutcome
import org.springframework.context.annotation.ConditionContext; //导入方法依赖的package包/类
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(
context.getEnvironment(), "spring.session.");
StoreType sessionStoreType = SessionStoreMappings
.getType(((AnnotationMetadata) metadata).getClassName());
if (!resolver.containsProperty("store-type")) {
if (sessionStoreType == StoreType.REDIS && redisPresent) {
return ConditionOutcome
.match("Session store type default to redis (deprecated)");
}
return ConditionOutcome.noMatch("Session store type not set");
}
String value = resolver.getProperty("store-type").replace("-", "_").toUpperCase();
if (value.equals(sessionStoreType.name())) {
return ConditionOutcome.match("Session store type " + sessionStoreType);
}
return ConditionOutcome.noMatch("Session store type " + value);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:21,代码来源:SessionCondition.java
示例8: getMatchOutcome
import org.springframework.context.annotation.ConditionContext; //导入方法依赖的package包/类
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(
context.getEnvironment(), "spring.cache.jcache.");
if (resolver.containsProperty("provider")) {
return ConditionOutcome.match("JCache provider specified");
}
Iterator<CachingProvider> providers = Caching.getCachingProviders()
.iterator();
if (!providers.hasNext()) {
return ConditionOutcome.noMatch("No JSR-107 compliant providers");
}
providers.next();
if (providers.hasNext()) {
return ConditionOutcome.noMatch(
"Multiple default JSR-107 compliant " + "providers found");
}
return ConditionOutcome.match("Default JSR-107 compliant provider found.");
}
示例9: getMatchOutcome
import org.springframework.context.annotation.ConditionContext; //导入方法依赖的package包/类
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
AnnotationAttributes attributes = AnnotationAttributes
.fromMap(metadata.getAnnotationAttributes(ConditionalOnEnabledDetector.class.getName()));
final String name = attributes.getString("value");
final String prefix = attributes.getString("prefix");
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(context.getEnvironment(),
prefix + "." + name + ".");
Boolean enabled = resolver.getProperty("enabled", Boolean.class, true);
return new ConditionOutcome(enabled, ConditionMessage.forCondition(ConditionalOnEnabledDetector.class, name)
.because(enabled ? "enabled" : "disabled"));
}
示例10: getMatchOutcome
import org.springframework.context.annotation.ConditionContext; //导入方法依赖的package包/类
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
ConditionMessage.Builder message = ConditionMessage.forCondition("OpenID Session Management Condition");
Environment environment = context.getEnvironment();
boolean enabled = environment.getProperty("op.session-management.enabled", Boolean.class, false);
if (enabled) {
return ConditionOutcome.match(message.found("property", "properties")
.items(ConditionMessage.Style.QUOTE, "op.session-management.enabled"));
}
else {
return ConditionOutcome.noMatch(message.didNotFind("property", "properties")
.items(ConditionMessage.Style.QUOTE, "op.session-management.enabled"));
}
}
示例11: getMatchOutcome
import org.springframework.context.annotation.ConditionContext; //导入方法依赖的package包/类
@Override
public ConditionOutcome getMatchOutcome(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
ConfigTree ct = new ConfigTree((ConfigurableEnvironment) conditionContext.getEnvironment(), "jetcache.");
if (match(ct, "local.") || match(ct, "remote.")) {
return ConditionOutcome.match();
} else {
return ConditionOutcome.noMatch("no match for " + cacheTypes[0]);
}
}
示例12: getMatchOutcome
import org.springframework.context.annotation.ConditionContext; //导入方法依赖的package包/类
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(
context.getEnvironment(), this.prefix);
if (resolver.containsProperty(this.propertyName)) {
return ConditionOutcome.match("A '" + this.prefix + this.propertyName + "' "
+ "property is specified");
}
return getResourceOutcome(context, metadata);
}
示例13: matches
import org.springframework.context.annotation.ConditionContext; //导入方法依赖的package包/类
/**
* match [motan.basicservice.exportPort, motan.basicservice.export] config property
*
* @see org.springframework.context.annotation.Condition#matches(org.springframework.context.annotation.ConditionContext, org.springframework.core.type.AnnotatedTypeMetadata)
*/
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
Environment env = context.getEnvironment();
return (!StringUtils.isEmpty(env.getProperty("motan.basicservice.exportPort"))
|| !StringUtils.isEmpty(env.getProperty("motan.basicservice.export")));
}
示例14: getEndpointOutcome
import org.springframework.context.annotation.ConditionContext; //导入方法依赖的package包/类
protected ConditionOutcome getEndpointOutcome(ConditionContext context,
String endpointName) {
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(
context.getEnvironment(), this.prefix + endpointName + ".");
if (resolver.containsProperty("enabled")) {
boolean match = resolver.getProperty("enabled", Boolean.class, true);
return new ConditionOutcome(match,
getEndpointElementOutcomeMessage(endpointName, match));
}
return null;
}
示例15: determineEndpointOutcome
import org.springframework.context.annotation.ConditionContext; //导入方法依赖的package包/类
private ConditionOutcome determineEndpointOutcome(String endpointName,
boolean enabledByDefault, ConditionContext context) {
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(
context.getEnvironment(), "endpoints." + endpointName + ".");
if (resolver.containsProperty("enabled") || !enabledByDefault) {
boolean match = resolver.getProperty("enabled", Boolean.class,
enabledByDefault);
return new ConditionOutcome(match, "The endpoint " + endpointName + " is "
+ (match ? "enabled" : "disabled"));
}
return null;
}