當前位置: 首頁>>代碼示例>>Java>>正文


Java ConditionContext.getEnvironment方法代碼示例

本文整理匯總了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();
}
 
開發者ID:holon-platform,項目名稱:holon-jaxrs,代碼行數:22,代碼來源:SwaggerApiAutoDetectCondition.java

示例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));
}
 
開發者ID:lord-of-code,項目名稱:loc-framework,代碼行數:18,代碼來源:PrefixPropertyCondition.java

示例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;
    }
 
開發者ID:juiser,項目名稱:juiser,代碼行數:22,代碼來源:JuiserSpringSecurityCondition.java

示例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.");
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:22,代碼來源:JCacheCacheConfiguration.java

示例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"));
}
 
開發者ID:cereebro,項目名稱:cereebro,代碼行數:13,代碼來源:OnEnabledDetectorCondition.java

示例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"));
	}
}
 
開發者ID:vpavic,項目名稱:simple-openid-provider,代碼行數:16,代碼來源:LogoutConfiguration.java

示例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]);
    }
}
 
開發者ID:alibaba,項目名稱:jetcache,代碼行數:10,代碼來源:JetCacheConditon.java

示例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);
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:12,代碼來源:ResourceCondition.java

示例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")));
}
 
開發者ID:mazhaoyong,項目名稱:api-server-seed,代碼行數:12,代碼來源:BasicServiceConfigCondition.java

示例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;
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:12,代碼來源:OnEnabledEndpointElementCondition.java

示例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;
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:13,代碼來源:OnEnabledEndpointCondition.java


注:本文中的org.springframework.context.annotation.ConditionContext.getEnvironment方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。