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

The following examples show how to use org.springframework.boot.autoconfigure.condition.ConditionOutcome#noMatch() . 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: SpringBootAdminClientEnabledCondition.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata annotatedTypeMetadata) {
	ClientProperties clientProperties = getClientProperties(context);

	if (!clientProperties.isEnabled()) {
		return ConditionOutcome
				.noMatch("Spring Boot Client is disabled, because 'spring.boot.admin.client.enabled' is false.");
	}

	if (clientProperties.getUrl().length == 0) {
		return ConditionOutcome
				.noMatch("Spring Boot Client is disabled, because 'spring.boot.admin.client.url' is empty.");
	}

	return ConditionOutcome.match();
}
 
Example 2
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 3
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 4
Source File: ZipkinSenderCondition.java    From spring-cloud-sleuth with Apache License 2.0 6 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
		AnnotatedTypeMetadata md) {
	String sourceClass = "";
	if (md instanceof ClassMetadata) {
		sourceClass = ((ClassMetadata) md).getClassName();
	}
	ConditionMessage.Builder message = ConditionMessage.forCondition("ZipkinSender",
			sourceClass);
	String property = context.getEnvironment()
			.getProperty("spring.zipkin.sender.type");
	if (StringUtils.isEmpty(property)) {
		return ConditionOutcome.match(message.because("automatic sender type"));
	}
	String senderType = getType(((AnnotationMetadata) md).getClassName());
	if (property.equalsIgnoreCase(senderType)) {
		return ConditionOutcome.match(message.because(property + " sender type"));
	}
	return ConditionOutcome.noMatch(message.because(property + " sender type"));
}
 
Example 5
Source File: MissingSpringCloudRegistryConfigPropertyCondition.java    From spring-cloud-alibaba with Apache License 2.0 5 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
		AnnotatedTypeMetadata metadata) {
	ConfigurableEnvironment environment = (ConfigurableEnvironment) context
			.getEnvironment();

	String protocol = environment.getProperty("dubbo.registry.protocol");

	if (PROTOCOL.equals(protocol)) {
		return ConditionOutcome.noMatch(
				"'spring-cloud' protocol was found from 'dubbo.registry.protocol'");
	}

	String address = environment.getProperty("dubbo.registry.address");

	if (StringUtils.startsWithIgnoreCase(address, PROTOCOL)) {
		return ConditionOutcome.noMatch(
				"'spring-cloud' protocol was found from 'dubbo.registry.address'");
	}

	Map<String, Object> properties = getSubProperties(
			environment.getPropertySources(), "dubbo.registries.");

	boolean found = properties.entrySet().stream().anyMatch(entry -> {
		String key = entry.getKey();
		String value = String.valueOf(entry.getValue());
		return (key.endsWith(".address") && value.startsWith(PROTOCOL))
				|| (key.endsWith(".protocol") && PROTOCOL.equals(value));

	});

	return found
			? ConditionOutcome.noMatch(
					"'spring-cloud' protocol was found in 'dubbo.registries.*'")
			: ConditionOutcome.match();
}
 
Example 6
Source File: CamelSSLAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata annotatedTypeMetadata) {
    Binder binder = Binder.get(context.getEnvironment());
    Map<String, Object> sslProperties = binder.bind("camel.ssl.config", Bindable.mapOf(String.class, Object.class)).orElse(Collections.emptyMap());
    ConditionMessage.Builder message = ConditionMessage.forCondition("camel.ssl.config");
    if (sslProperties.size() > 0) {
        return ConditionOutcome.match(message.because("enabled"));
    }

    return ConditionOutcome.noMatch(message.because("not enabled"));
}
 
Example 7
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 8
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 Condition");
	Environment environment = context.getEnvironment();
	String keyValue = environment.getProperty("security.oauth2.authorization.jwt.key-value");
	if (StringUtils.hasText(keyValue)) {
		return ConditionOutcome.match(message.foundExactly("provided private or symmetric key"));
	}
	return ConditionOutcome.noMatch(message.didNotFind("provided private or symmetric key").atAll());
}
 
Example 9
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 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: JuiserSpringSecurityCondition.java    From juiser with Apache License 2.0 5 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {

    ConditionMessage matchMessage = ConditionMessage.empty();

    boolean enabled = isSpringSecurityEnabled(context);

    if (metadata.isAnnotated(ConditionalOnJuiserSpringSecurityEnabled.class.getName())) {
        if (!enabled) {
            return ConditionOutcome.noMatch(
                ConditionMessage.forCondition(ConditionalOnJuiserSpringSecurityEnabled.class)
                    .didNotFind("spring security enabled").atAll());
        }
        matchMessage = matchMessage.andCondition(ConditionalOnJuiserSpringSecurityEnabled.class)
            .foundExactly("spring security enabled");
    }

    if (metadata.isAnnotated(ConditionalOnJuiserSpringSecurityDisabled.class.getName())) {
        if (enabled) {
            return ConditionOutcome.noMatch(
                ConditionMessage.forCondition(ConditionalOnJuiserSpringSecurityDisabled.class)
                    .didNotFind("spring security disabled").atAll());
        }
        matchMessage = matchMessage.andCondition(ConditionalOnJuiserSpringSecurityDisabled.class)
            .didNotFind("spring security disabled").atAll();
    }

    return ConditionOutcome.match(matchMessage);
}
 
Example 12
Source File: OnSearchPathLocatorPresent.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
		AnnotatedTypeMetadata metadata) {
	ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
	List<String> types = CompositeUtils
			.getCompositeTypeList(context.getEnvironment());

	// get EnvironmentRepository types from registered factories
	List<Class<? extends EnvironmentRepository>> repositoryTypes = new ArrayList<>();
	for (String type : types) {
		String factoryName = CompositeUtils.getFactoryName(type, beanFactory);
		Type[] actualTypeArguments = CompositeUtils
				.getEnvironmentRepositoryFactoryTypeParams(beanFactory, factoryName);
		Class<? extends EnvironmentRepository> repositoryType;
		repositoryType = (Class<? extends EnvironmentRepository>) actualTypeArguments[0];
		repositoryTypes.add(repositoryType);
	}

	boolean required = metadata
			.isAnnotated(ConditionalOnSearchPathLocator.class.getName());
	boolean foundSearchPathLocator = repositoryTypes.stream()
			.anyMatch(SearchPathLocator.class::isAssignableFrom);
	if (required && !foundSearchPathLocator) {
		return ConditionOutcome.noMatch(
				ConditionMessage.forCondition(ConditionalOnSearchPathLocator.class)
						.notAvailable(SearchPathLocator.class.getTypeName()));
	}
	if (!required && foundSearchPathLocator) {
		return ConditionOutcome.noMatch(ConditionMessage
				.forCondition(ConditionalOnMissingSearchPathLocator.class)
				.available(SearchPathLocator.class.getTypeName()));
	}
	return ConditionOutcome.match();
}
 
Example 13
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 JWK Condition");
	Environment environment = context.getEnvironment();
	String keyUri = environment.getProperty("security.oauth2.resource.jwk.key-set-uri");
	if (StringUtils.hasText(keyUri)) {
		return ConditionOutcome.match(message.foundExactly("provided jwk key set URI"));
	}
	return ConditionOutcome.noMatch(message.didNotFind("key jwk set URI not provided").atAll());
}
 
Example 14
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 15
Source File: NotEnableOauth2SsoCondition.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
	String ssoClass = "org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso";
	boolean ssoClientAnnotationExists = ClassUtils.isPresent(ssoClass, null);
	if(!ssoClientAnnotationExists){
		return ConditionOutcome.match("EnableOAuth2Sso not exists!");
	}
	String[] beanNames = context.getBeanFactory().getBeanNamesForAnnotation(EnableOAuth2Sso.class);
	if(beanNames==null || beanNames.length==0){
		return ConditionOutcome.match("not @EnableOAuth2Sso bean found!");
	}
	return ConditionOutcome.noMatch("@EnableOAuth2Sso sso client!");
}
 
Example 16
Source File: MsgQueryEnabledCondition.java    From joyqueue with Apache License 2.0 5 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    MsgQueryConfigurationProperties msgQueryConfigurationProperties=getMsgQueryProperties(context);
    if(!msgQueryConfigurationProperties.getEnabled()){
        logger.warn("message query function is disabled, because [message.query.enabled = false]");
        return ConditionOutcome.noMatch("message query function is disabled, because [message.query.enabled = false]");
    }
    logger.info("message query function is enabled");
    return ConditionOutcome.match();
}
 
Example 17
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 18
Source File: HazelcastJetServerConfigAvailableCondition.java    From hazelcast-jet-contrib with Apache License 2.0 5 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    // System property for server configuration found, match
    if (System.getProperty(configSystemProperty) != null) {
        return ConditionOutcome.match(
                startConditionMessage().because("System property '" + configSystemProperty + "' is set."));
    }
    // Environment property for server configuration found, match
    if (context.getEnvironment().containsProperty(CONFIG_ENVIRONMENT_PROPERTY)) {
        return ConditionOutcome.match(startConditionMessage()
                .foundExactly("property " + CONFIG_ENVIRONMENT_PROPERTY));
    }
    // System property for client configuration found, no match
    if (System.getProperty(HazelcastJetClientConfigAvailableCondition.CONFIG_SYSTEM_PROPERTY) != null) {
        return ConditionOutcome.noMatch(startConditionMessage().because("System property '"
                + HazelcastJetClientConfigAvailableCondition.CONFIG_SYSTEM_PROPERTY + "' is set."));
    }
    // Environment property for client configuration found, no match
    if (context.getEnvironment()
               .containsProperty(HazelcastJetClientConfigAvailableCondition.CONFIG_ENVIRONMENT_PROPERTY)) {
        return ConditionOutcome.noMatch(startConditionMessage().because("Environment property '"
                + HazelcastJetClientConfigAvailableCondition.CONFIG_ENVIRONMENT_PROPERTY + "' is set."));
    }
    ConditionOutcome resourceOutcome = getResourceOutcome(context, metadata);
    // Found a configuration file for server, match
    if (resourceOutcome.isMatch()) {
        return resourceOutcome;
    }
    // Found a configuration file for client, no match
    ConditionOutcome clientResourceOutcome = clientConfigAvailableCondition.getMatchOutcome(context, metadata);
    if (clientResourceOutcome.isMatch()) {
        return ConditionOutcome.noMatch(clientResourceOutcome.getConditionMessage());
    }
    return ConditionOutcome.match(startConditionMessage().because(
            "No configuration option found, using default configuration."));
}
 
Example 19
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 20
Source File: MasterSlaveSpringBootCondition.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(), MASTER_SLAVE_PREFIX)
            ? ConditionOutcome.match() : ConditionOutcome.noMatch("Can't find ShardingSphere master-slave rule configuration in local file.");
}