Java Code Examples for org.springframework.boot.autoconfigure.condition.ConditionOutcome#match()

The following examples show how to use org.springframework.boot.autoconfigure.condition.ConditionOutcome#match() . 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: OSSCondition.java    From jeecg-boot-with-activiti with MIT License 6 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
	String sourceClass = "";
	if (metadata instanceof ClassMetadata) {
		sourceClass = ((ClassMetadata) metadata).getClassName();
	}
	ConditionMessage.Builder message = ConditionMessage.forCondition("OSS", sourceClass);
	Environment environment = context.getEnvironment();
	try {
		BindResult<OSSType> specified = Binder.get(environment).bind("oss.type", OSSType.class);
		if (!specified.isBound()) {
			return ConditionOutcome.match(message.because("automatic OSS type"));
		}
		OSSType required = OSSConfigurations.getType(((AnnotationMetadata) metadata).getClassName());
		if (specified.get() == required) {
			return ConditionOutcome.match(message.because(specified.get() + " OSS type"));
		}
	}
	catch (BindException ex) {
	}
	return ConditionOutcome.noMatch(message.because("unknown OSS type"));
}
 
Example 2
Source File: VelocityLayoutCondition.java    From velocity-spring-boot-project with Apache License 2.0 6 votes vote down vote up
protected ConditionOutcome getMatchOutcome(Environment environment) {

        boolean velocityEnabled = environment.getProperty(VELOCITY_ENABLED_PROPERTY_NAME, boolean.class, true);

        if (!velocityEnabled) {
            return ConditionOutcome.noMatch("The velocity layout is disabled , caused by " +
                    VELOCITY_ENABLED_PROPERTY_NAME + " = false");
        }

        boolean velocityLayoutEnabled = environment.getProperty(VELOCITY_LAYOUT_ENABLED_PROPERTY_NAME, boolean.class,
                DEFAULT_VELOCITY_LAYOUT_ENABLED_VALUE);

        if (!velocityLayoutEnabled) {
            return ConditionOutcome.noMatch("The velocity layout is disabled , caused by " +
                    VELOCITY_LAYOUT_ENABLED_PROPERTY_NAME + " = false");
        }

        return ConditionOutcome.match("The velocity layout is enabled !");

    }
 
Example 3
Source File: EnableWebSecurityCondition.java    From cola-cloud with MIT License 6 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    String[] enablers = context.getBeanFactory()
            .getBeanNamesForAnnotation(EnableWebSecurity.class);
    ConditionMessage.Builder message = ConditionMessage
            .forCondition("@EnableWebSecurity Condition");
    if (enablers != null && enablers.length > 0) {
        return ConditionOutcome.match(message
                .found("@EnableWebSecurity annotation on Application")
                .items(enablers));
    }

    return ConditionOutcome.noMatch(message.didNotFind(
            "@EnableWebSecurity annotation " + "on Application")
            .atAll());
}
 
Example 4
Source File: EnableResourceServerCondition.java    From cola-cloud with MIT License 6 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    String[] enablers = context.getBeanFactory()
            .getBeanNamesForAnnotation(EnableResourceServer.class);
    ConditionMessage.Builder message = ConditionMessage
            .forCondition("@EnableResourceServer Condition");
    if (enablers != null && enablers.length > 0) {
        return ConditionOutcome.match(message
                .found("@EnableResourceServer annotation on Application")
                .items(enablers));
    }

    return ConditionOutcome.noMatch(message.didNotFind(
            "@EnableResourceServer annotation " + "on Application")
            .atAll());
}
 
Example 5
Source File: ZipkinSQSCredentialsConfiguration.java    From zipkin-aws with Apache License 2.0 5 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata a) {

  String queueUrl = context.getEnvironment().getProperty(PROPERTY_NAME);

  return isEmpty(queueUrl)
      ? ConditionOutcome.noMatch(PROPERTY_NAME + " isn't set")
      : ConditionOutcome.match();
}
 
Example 6
Source File: AuthorizationServerTokenServicesConfiguration.java    From spring-security-oauth2-boot with Apache License 2.0 5 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
	ConditionMessage.Builder message = ConditionMessage.forCondition("OAuth JWT KeyStore Condition");
	Environment environment = context.getEnvironment();
	String keyStore = environment.getProperty("security.oauth2.authorization.jwt.key-store");
	if (StringUtils.hasText(keyStore)) {
		return ConditionOutcome.match(message.foundExactly("provided key store location"));
	}
	return ConditionOutcome.noMatch(message.didNotFind("provided key store location").atAll());
}
 
Example 7
Source File: EnableOAuth2SsoCondition.java    From spring-security-oauth2-boot with Apache License 2.0 5 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
	String[] enablers = context.getBeanFactory().getBeanNamesForAnnotation(EnableOAuth2Sso.class);
	ConditionMessage.Builder message = ConditionMessage.forCondition("@EnableOAuth2Sso Condition");
	for (String name : enablers) {
		if (context.getBeanFactory().isTypeMatch(name, WebSecurityConfigurerAdapter.class)) {
			return ConditionOutcome.match(
					message.found("@EnableOAuth2Sso annotation on WebSecurityConfigurerAdapter").items(name));
		}
	}
	return ConditionOutcome.noMatch(
			message.didNotFind("@EnableOAuth2Sso annotation " + "on any WebSecurityConfigurerAdapter").atAll());
}
 
Example 8
Source File: OAuth2RestOperationsConfiguration.java    From spring-security-oauth2-boot with Apache License 2.0 5 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
	String clientId = context.getEnvironment().getProperty("security.oauth2.client.client-id");
	ConditionMessage.Builder message = ConditionMessage.forCondition("OAuth Client ID");
	if (StringUtils.hasLength(clientId)) {
		return ConditionOutcome.match(message.foundExactly("security.oauth2.client.client-id property"));
	}
	return ConditionOutcome.noMatch(message.didNotFind("security.oauth2.client.client-id property").atAll());
}
 
Example 9
Source File: OAuth2ResourceServerConfiguration.java    From spring-security-oauth2-boot with Apache License 2.0 5 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
	ConditionMessage.Builder message = ConditionMessage.forCondition("OAuth ResourceServer Condition");
	Environment environment = context.getEnvironment();
	if (!(environment instanceof ConfigurableEnvironment)) {
		return ConditionOutcome.noMatch(message.didNotFind("A ConfigurableEnvironment").atAll());
	}
	if (hasOAuthClientId(environment)) {
		return ConditionOutcome.match(message.foundExactly("client-id property"));
	}
	Binder binder = Binder.get(environment);
	String prefix = "security.oauth2.resource.";
	if (binder.bind(prefix + "jwt", STRING_OBJECT_MAP).isBound()) {
		return ConditionOutcome.match(message.foundExactly("JWT resource configuration"));
	}
	if (binder.bind(prefix + "jwk", STRING_OBJECT_MAP).isBound()) {
		return ConditionOutcome.match(message.foundExactly("JWK resource configuration"));
	}
	if (StringUtils.hasText(environment.getProperty(prefix + "user-info-uri"))) {
		return ConditionOutcome.match(message.foundExactly("user-info-uri property"));
	}
	if (StringUtils.hasText(environment.getProperty(prefix + "token-info-uri"))) {
		return ConditionOutcome.match(message.foundExactly("token-info-uri property"));
	}
	if (ClassUtils.isPresent(AUTHORIZATION_ANNOTATION, null)) {
		if (AuthorizationServerEndpointsConfigurationBeanCondition.matches(context)) {
			return ConditionOutcome.match(message.found("class").items(AUTHORIZATION_ANNOTATION));
		}
	}
	return ConditionOutcome
			.noMatch(message.didNotFind("client ID, JWT resource or authorization server").atAll());
}
 
Example 10
Source File: OnMissingPropertyCondition.java    From spring-boot-data-geode with Apache License 2.0 5 votes vote down vote up
private ConditionOutcome determineConditionOutcome(Collection<String> matchingProperties) {

		if (!matchingProperties.isEmpty()) {

			return ConditionOutcome.noMatch(ConditionMessage.forCondition(ConditionalOnMissingProperty.class)
				.found("property already defined", "properties already defined")
				.items(matchingProperties));
		}

		return ConditionOutcome.match();
	}
 
Example 11
Source File: OnAwsCloudEnvironmentCondition.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
		AnnotatedTypeMetadata metadata) {
	if (AwsCloudEnvironmentCheckUtils.isRunningOnCloudEnvironment()) {
		return ConditionOutcome.match();
	}
	return ConditionOutcome.noMatch("not running in aws environment");
}
 
Example 12
Source File: ResourceServerTokenServicesConfiguration.java    From spring-security-oauth2-boot with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 13
Source File: FunctionDetectorCondition.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
	if (context != null &&  context.getBeanFactory() != null) {

		String[] functionTypes = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(context.getBeanFactory(), Function.class, true, false);
		String[] consumerTypes = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(context.getBeanFactory(), Consumer.class, true, false);
		String[] biFunctionTypes = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(context.getBeanFactory(), BiFunction.class, true, false);
		String[] biConsumerTypes = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(context.getBeanFactory(), BiConsumer.class, true, false);

		List<String> functionComponents = new ArrayList<>();

		functionComponents.addAll(Arrays.asList(functionTypes));
		functionComponents.addAll(Arrays.asList(consumerTypes));
		functionComponents.addAll(Arrays.asList(biFunctionTypes));
		functionComponents.addAll(Arrays.asList(biConsumerTypes));

		List<String> kafkaStreamsFunctions = pruneFunctionBeansForKafkaStreams(functionComponents, context);
		if (!CollectionUtils.isEmpty(kafkaStreamsFunctions)) {
			return ConditionOutcome.match("Matched. Function/BiFunction/Consumer beans found");
		}
		else {
			return ConditionOutcome.noMatch("No match. No Function/BiFunction/Consumer beans found");
		}
	}
	return ConditionOutcome.noMatch("No match. No Function/BiFunction/Consumer beans found");
}
 
Example 14
Source File: ZipkinElasticsearchAwsStorageModule.java    From zipkin-aws with Apache License 2.0 5 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata a) {
  String domain = context.getEnvironment().getProperty(PROPERTY_NAME);
  return domain == null || domain.isEmpty()
      ? ConditionOutcome.noMatch(PROPERTY_NAME + " isn't set")
      : ConditionOutcome.match();
}
 
Example 15
Source File: EnabledKeyCondition.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
	AnnotationAttributes attrubutes = getAnnotationAttributes(metadata);
	
	String mainKey = getMainEnabledKey(context.getEnvironment(), attrubutes);
	if(StringUtils.isNotBlank(mainKey) && !isEnabled(context.getEnvironment(), mainKey)){
		return ConditionOutcome.noMatch("main property ["+mainKey+"] is not enabled");
	}
	
	String key = getEnabledKey(context.getEnvironment(), attrubutes);
	if(!isEnabled(context.getEnvironment(), key)){
		return ConditionOutcome.noMatch("property ["+key+"] is not enabled");
	}
	return ConditionOutcome.match("property ["+key+"] is enabled");
}
 
Example 16
Source File: FlexyPoolConfiguration.java    From spring-boot-data-source-decorator with Apache License 2.0 5 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    ConditionMessage.Builder message = ConditionMessage.forCondition("FlexyPoolConfigurationAvailable");
    String propertiesFilePath = System.getProperty(PropertyLoader.PROPERTIES_FILE_PATH);
    if (propertiesFilePath != null && ClassLoaderUtils.getResource(propertiesFilePath) != null) {
        return ConditionOutcome.match(message.found("FlexyPool configuration file").items(propertiesFilePath));
    }
    if (ClassLoaderUtils.getResource(PropertyLoader.PROPERTIES_FILE_NAME) != null) {
        return ConditionOutcome.match(message.found("FlexyPool configuration file").items(PropertyLoader.PROPERTIES_FILE_NAME));
    }
    return ConditionOutcome.noMatch(message.didNotFind("FlexyPool configuration file").atAll());
}
 
Example 17
Source File: OnMissingBeanCondition.java    From jasypt-spring-boot with MIT License 5 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    Map<String, Object> beanAttributes = metadata.getAnnotationAttributes(Bean.class.getName());
    String beanName = ((String[]) beanAttributes.get("name"))[0];
    if(StringUtils.isEmpty(beanName)) {
        throw new IllegalStateException("OnMissingBeanCondition can't detect bean name!");
    }
    boolean missingBean = !context.getBeanFactory().containsBean(context.getEnvironment().resolveRequiredPlaceholders(beanName));
    return missingBean ? ConditionOutcome.match(beanName + " not found") : ConditionOutcome.noMatch(beanName + " found");
}
 
Example 18
Source File: LocalRulesCondition.java    From shardingsphere with Apache License 2.0 4 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(final ConditionContext conditionContext, final AnnotatedTypeMetadata annotatedTypeMetadata) {
    return PropertyUtil.containPropertyPrefix(conditionContext.getEnvironment(), SHARDING_PREFIX)
        ? ConditionOutcome.match() : ConditionOutcome.noMatch("Can't find ShardingSphere rule configuration in local file.");
}
 
Example 19
Source File: NeedsHistoryAutoConfigurationCondition.java    From camunda-bpm-spring-boot-starter with Apache License 2.0 4 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
  return needsAdditionalConfiguration(context)
    ? ConditionOutcome.match("camunda version needs additional configuration for history level auto")
    : ConditionOutcome.noMatch("camunda version supports history level auto");
}
 
Example 20
Source File: ShadowSpringBootCondition.java    From shardingsphere with Apache License 2.0 4 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(final ConditionContext conditionContext, final AnnotatedTypeMetadata annotatedTypeMetadata) {
    return PropertyUtil.containPropertyPrefix(conditionContext.getEnvironment(), SHADOW_PREFIX)
            ? ConditionOutcome.match() : ConditionOutcome.noMatch("Can't find ShardingSphere shadow rule configuration in local file.");
}