下面列出了org.springframework.boot.autoconfigure.condition.ConditionMessage#Builder ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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"));
}
@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());
}
@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());
}
@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());
}
@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 + "'"));
}
}
@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"));
}
@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"));
}
@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"));
}
@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());
}
@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());
}
@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());
}
@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());
}
@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());
}
@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());
}
@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());
}
@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());
}
@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());
}
@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"));
}
@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))));
}
@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))));
}