@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { if (!StringUtils.isEmpty(context.getEnvironment().getProperty("fat.titan.url"))) { return true; } else if (!StringUtils.isEmpty(context.getEnvironment().getProperty("uat.titan.url"))) { return true; } else if (!StringUtils.isEmpty(context.getEnvironment().getProperty("pro.titan.url"))) { return true; } return false; }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { String ldapGroupsFile = context.getEnvironment().getProperty("ldap.groups.file"); return ldapGroupsFile == null || ldapGroupsFile.equals("ldap/ldap-groups-null.xml"); } }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { String ldapGroupsFile = context.getEnvironment().getProperty("ldap.groups.file"); return ldapGroupsFile != null && ldapGroupsFile.equals("ldap/ldap-groups-as-scopes.xml"); } }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { String ldapProfileFile = context.getEnvironment().getProperty("ldap.profile.file"); return ldapProfileFile == null || ldapProfileFile.equals("ldap/ldap-simple-bind.xml"); } }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { String ldapProfileFile = context.getEnvironment().getProperty("ldap.profile.file"); return ldapProfileFile != null && ldapProfileFile.equals("ldap/ldap-search-and-bind.xml"); } }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { return Boolean.parseBoolean(context.getEnvironment().getProperty("import.sql.enabled", "true")); }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { return Boolean.parseBoolean(context.getEnvironment().getProperty("demo.import.sql.enabled", "true")); }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { String ldapProfileFile = context.getEnvironment().getProperty("ldap.profile.file"); return ldapProfileFile !=null && ldapProfileFile.equals("ldap/ldap-search-and-compare.xml"); } }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { String ldapGroupsFile = context.getEnvironment().getProperty("ldap.groups.file"); return ldapGroupsFile != null && ldapGroupsFile.equals("ldap/ldap-groups-map-to-scopes.xml"); } }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { Set<String> activeProfiles = Sets.newHashSet(context.getEnvironment().getActiveProfiles()); Set<String> requiredActiveProfiles = retrieveAnnotatedProfiles(metadata, ConditionalOnProfile.class.getName()); Set<String> requiredInactiveProfiles = retrieveAnnotatedProfiles(metadata, ConditionalOnMissingProfile.class .getName()); return Sets.difference(requiredActiveProfiles, activeProfiles).isEmpty() && Sets.intersection(requiredInactiveProfiles, activeProfiles).isEmpty(); }
private ClientProperties getClientProperties(ConditionContext context) { ClientProperties clientProperties = new ClientProperties(context.getEnvironment()); Binder.get(context.getEnvironment()).bind("spring.boot.admin.client", Bindable.ofInstance(clientProperties)); return clientProperties; } }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { MultiValueMap<String, Object> attrs = metadata.getAllAnnotationAttributes(Profile.class.getName()); if (attrs != null) { for (Object value : attrs.get("value")) { if (context.getEnvironment().acceptsProfiles(Profiles.of((String[]) value))) { return true; } } return false; } return true; }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { MultiValueMap<String, Object> attrs = metadata.getAllAnnotationAttributes(Profile.class.getName()); if (attrs != null) { for (Object value : attrs.get("value")) { if (context.getEnvironment().acceptsProfiles(Profiles.of((String[]) value))) { return true; } } return false; } return true; }
@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 = (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(); } }
@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]); } }
@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")); }
public class LinuxCondition implements Condition { @Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { return context.getEnvironment().getProperty("os.name").contains("Linux"); } }
public class MyCondition implements Condition { @Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { Environment env = context.getEnvironment(); return null != env && "true".equals(env.getProperty("createWebSocket")); } }
@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"); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { Environment environment = context.getEnvironment(); if (hasProperty(environment, "encrypt.key-store.location")) { if (hasProperty(environment, "encrypt.key-store.password")) { return ConditionOutcome.match("Keystore found in Environment"); } return ConditionOutcome .noMatch("Keystore found but no password in Environment"); } else if (hasProperty(environment, "encrypt.key")) { return ConditionOutcome.match("Key found in Environment"); } return ConditionOutcome.noMatch("Keystore nor key found in Environment"); }