Java Code Examples for org.springframework.boot.autoconfigure.condition.ConditionMessage#Builder

The following examples show how to use org.springframework.boot.autoconfigure.condition.ConditionMessage#Builder . 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: 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: ResourceServerTokenServicesConfiguration.java    From spring-security-oauth2-boot with Apache License 2.0 6 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
	ConditionMessage.Builder message = ConditionMessage.forCondition("OAuth TokenInfo Condition");
	Environment environment = context.getEnvironment();
	Boolean preferTokenInfo = environment.getProperty("security.oauth2.resource.prefer-token-info",
			Boolean.class);
	if (preferTokenInfo == null) {
		preferTokenInfo = environment.resolvePlaceholders("${OAUTH2_RESOURCE_PREFERTOKENINFO:true}")
				.equals("true");
	}
	String tokenInfoUri = environment.getProperty("security.oauth2.resource.token-info-uri");
	String userInfoUri = environment.getProperty("security.oauth2.resource.user-info-uri");
	if (!StringUtils.hasLength(userInfoUri) && !StringUtils.hasLength(tokenInfoUri)) {
		return ConditionOutcome.match(message.didNotFind("user-info-uri property").atAll());
	}
	if (StringUtils.hasLength(tokenInfoUri) && preferTokenInfo) {
		return ConditionOutcome.match(message.foundExactly("preferred token-info-uri property"));
	}
	return ConditionOutcome.noMatch(message.didNotFind("token info").atAll());
}
 
Example 5
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 6
Source File: RedissonAutoConfiguration.java    From redisson-spring-boot with Apache License 2.0 6 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    String type = context.getEnvironment().getProperty("redisson.type");
    if (type == null || type.isEmpty() || type.trim().isEmpty()) {
        type = RedissonType.SINGLE.name();
    }
    ConditionMessage.Builder condition = ConditionMessage.forCondition("RedissonCondition",
            String.format("(redisson.type=%s)", type));
    if (type.equalsIgnoreCase(RedissonType.NONE.name())) {
        return noMatch(condition.found("matched value").items(Style.QUOTE, type));
    }
    Set<String> relaxedTypes = Arrays.stream(RedissonType.values())
            .filter(t -> t != RedissonType.NONE)
            .map(Enum::name)
            .map(name -> Arrays.asList(name, name.toLowerCase(), name.toUpperCase()))
            .flatMap(List::stream)
            .collect(toSet());
    if (relaxedTypes.contains(type)) {
        return match(condition.found("matched value").items(Style.QUOTE, type));
    } else {
        return noMatch(condition.because("has unrecognized value '" + type + "'"));
    }
}
 
Example 7
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 8
Source File: MySQLAutoconfiguration.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    ConditionMessage.Builder message = ConditionMessage.forCondition("Hibernate");

    return Arrays.stream(CLASS_NAMES).filter(className -> ClassUtils.isPresent(className, context.getClassLoader())).map(className -> ConditionOutcome.match(message.found("class").items(Style.NORMAL, className))).findAny()
            .orElseGet(() -> ConditionOutcome.noMatch(message.didNotFind("class", "classes").items(Style.NORMAL, Arrays.asList(CLASS_NAMES))));
}
 
Example 9
Source File: MySQLAutoconfiguration.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    ConditionMessage.Builder message = ConditionMessage.forCondition("Hibernate");

    return Arrays.stream(CLASS_NAMES).filter(className -> ClassUtils.isPresent(className, context.getClassLoader())).map(className -> ConditionOutcome.match(message.found("class").items(Style.NORMAL, className))).findAny()
            .orElseGet(() -> ConditionOutcome.noMatch(message.didNotFind("class", "classes").items(Style.NORMAL, Arrays.asList(CLASS_NAMES))));
}
 
Example 10
Source File: BasicClientSecurityConfigured.java    From microservices-dashboard with Apache License 2.0 5 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
		AnnotatedTypeMetadata metadata) {
	ConditionMessage.Builder message = ConditionMessage
			.forCondition("Basic Client Security Configured Condition");
	BasicClientSecurityProperties basicClientSecurityProperties =
			getBasicClientSecurityProperties(context.getEnvironment());
	if (basicClientSecurityProperties.isConfigured()) {
		return ConditionOutcome.match(message.because("Both the username and password have been configured"));
	}
	return ConditionOutcome.noMatch(message.because("Both the username and password should be configured"));
}
 
Example 11
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 12
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 13
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 14
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 15
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 16
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 17
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 KeyStore Condition");
	Environment environment = context.getEnvironment();
	String keyStore = environment.getProperty("security.oauth2.resource.jwt.key-store");
	if (StringUtils.hasText(keyStore)) {
		return ConditionOutcome.match(message.foundExactly("provided key store location"));
	}
	return ConditionOutcome.noMatch(message.didNotFind("key store location not provided").atAll());
}
 
Example 18
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 19
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 20
Source File: GroupCondition.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
    final ConditionMessage.Builder message = ConditionMessage.forCondition(this.single);
    final Environment environment = conditionContext.getEnvironment();

    return HierarchicalPropertiesEvaluator.evaluate(environment, this.group, this.single)
        ? ConditionOutcome.match(message.because("enabled"))
        : ConditionOutcome.noMatch(message.because("not enabled"));
}