@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) { 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) { CloudFactory cloudFactory = new CloudFactory(); try { Cloud cloud = cloudFactory.getCloud(); List<ServiceInfo> serviceInfos = cloud.getServiceInfos(); for (ServiceInfo serviceInfo : serviceInfos) { if (serviceInfo instanceof VaultServiceInfo) { return ConditionOutcome.match(String.format( "Found Vault service %s", serviceInfo.getId())); } } return ConditionOutcome.noMatch("No Vault service found"); } catch (CloudException e) { return ConditionOutcome.noMatch("Not running in a Cloud"); } }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { final RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(context.getEnvironment(), "holon.swagger."); if (!resolver.getProperty("holon.swagger.enabled", boolean.class, true)) { return ConditionOutcome.noMatch(ConditionMessage.forCondition("SwaggerApiAutoDetectCondition") .because("holon.swagger.enabled is false")); } if (resolver.containsProperty("resourcePackage")) { return ConditionOutcome.noMatch( ConditionMessage.forCondition("SwaggerApiAutoDetectCondition").available("resourcePackage")); } Map<String, Object> ag = resolver.getSubProperties("apiGroups"); if (ag != null && ag.size() > 0) { return ConditionOutcome .noMatch(ConditionMessage.forCondition("SwaggerApiAutoDetectCondition").available("apiGroups")); } return ConditionOutcome.match(); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ConditionMessage.Builder message = ConditionMessage .forCondition("EmbeddedDataSource"); if (anyMatches(context, metadata, this.pooledCondition)) { return ConditionOutcome .noMatch(message.foundExactly("supported pooled data source")); } EmbeddedDatabaseType type = EmbeddedDatabaseConnection .get(context.getClassLoader()).getType(); if (type == null) { return ConditionOutcome .noMatch(message.didNotFind("embedded database").atAll()); } return ConditionOutcome.match(message.found("embedded database").items(type)); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ConditionMessage.Builder message = ConditionMessage .forCondition("DataSourceAvailable"); if (hasBean(context, DataSource.class) || hasBean(context, XADataSource.class)) { return ConditionOutcome .match(message.foundExactly("existing data source bean")); } if (anyMatches(context, metadata, this.pooledCondition, this.embeddedCondition)) { return ConditionOutcome.match(message .foundExactly("existing auto-configured data source bean")); } return ConditionOutcome .noMatch(message.didNotFind("any existing data source bean").atAll()); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { Map<String, Object> attributes = metadata.getAnnotationAttributes(ConditionalOnPropertyPrefix.class.getName()); if (attributes.containsKey("value")) { String prefix = (String) attributes.get("value"); if (prefix != null && !prefix.trim().equals("")) { final String propertyPrefix = !prefix.endsWith(".") ? prefix + "." : prefix; ConfigPropertyProvider configPropertyProvider = EnvironmentConfigPropertyProvider .create(context.getEnvironment()); Set<String> names = configPropertyProvider.getPropertyNames() .filter((n) -> n.startsWith(propertyPrefix)).collect(Collectors.toSet()); if (!names.isEmpty()) { return ConditionOutcome.match(); } return ConditionOutcome.noMatch( ConditionMessage.forCondition(ConditionalOnPropertyPrefix.class).notAvailable(propertyPrefix)); } } return ConditionOutcome.match(); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { String prefix = (String) attribute(metadata, "prefix"); Class<?> value = (Class<?>) attribute(metadata, "value"); ConfigurableEnvironment environment = (ConfigurableEnvironment) context.getEnvironment(); try { new Binder(ConfigurationPropertySources.from(environment.getPropertySources())) .bind(prefix, Bindable.of(value)) .orElseThrow( () -> new FatalBeanException("Could not bind DataSourceSettings properties")); return new ConditionOutcome(true, String.format("Map property [%s] is not empty", prefix)); } catch (Exception e) { //ignore } return new ConditionOutcome(false, String.format("Map property [%s] is empty", prefix)); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { Environment environment = context.getEnvironment(); String config = environment.resolvePlaceholders("${logging.file:}"); if (StringUtils.hasText(config)) { return ConditionOutcome.match("Found logging.file: " + config); } config = environment.resolvePlaceholders("${logging.path:}"); if (StringUtils.hasText(config)) { return ConditionOutcome.match("Found logging.path: " + config); } config = new RelaxedPropertyResolver(environment, "endpoints.logfile.") .getProperty("external-file"); if (StringUtils.hasText(config)) { return ConditionOutcome .match("Found endpoints.logfile.external-file: " + config); } return ConditionOutcome.noMatch("Found no log file configuration"); }
@PostConstruct public void setupAutoConfigurationReport() { ConditionEvaluationReport report = ConditionEvaluationReport .get(this.context.getBeanFactory()); report.recordConditionEvaluation("a", mock(Condition.class), mock(ConditionOutcome.class)); report.recordExclusions(Arrays.asList("com.foo.Bar")); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ConfigurableEnvironment environment = (ConfigurableEnvironment) context .getEnvironment(); ResourceProperties properties = new ResourceProperties(); RelaxedDataBinder binder = new RelaxedDataBinder(properties, "spring.resources"); binder.bind(new PropertySourcesPropertyValues(environment.getPropertySources())); Boolean match = properties.getChain().getEnabled(); if (match == null) { boolean webJarsLocatorPresent = ClassUtils.isPresent(WEBJAR_ASSERT_LOCATOR, getClass().getClassLoader()); return new ConditionOutcome(webJarsLocatorPresent, "Webjars locator (" + WEBJAR_ASSERT_LOCATOR + ") is " + (webJarsLocatorPresent ? "present" : "absent")); } return new ConditionOutcome(match, "Resource chain is " + (match ? "enabled" : "disabled")); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ConfigurableListableBeanFactory beanFactory = context.getBeanFactory(); List<String> dispatchServletBeans = Arrays.asList(beanFactory .getBeanNamesForType(DispatcherServlet.class, false, false)); if (dispatchServletBeans.contains(DEFAULT_DISPATCHER_SERVLET_BEAN_NAME)) { return ConditionOutcome.noMatch("found DispatcherServlet named " + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME); } if (beanFactory.containsBean(DEFAULT_DISPATCHER_SERVLET_BEAN_NAME)) { return ConditionOutcome.noMatch("found non-DispatcherServlet named " + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME); } if (dispatchServletBeans.isEmpty()) { return ConditionOutcome.match("no DispatcherServlet found"); } return ConditionOutcome .match("one or more DispatcherServlets found and none is named " + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { Environment environment = context.getEnvironment(); RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment, "security.oauth2.resource."); Boolean preferTokenInfo = resolver.getProperty("prefer-token-info", Boolean.class); if (preferTokenInfo == null) { preferTokenInfo = environment .resolvePlaceholders("${OAUTH2_RESOURCE_PREFERTOKENINFO:true}") .equals("true"); } String tokenInfoUri = resolver.getProperty("token-info-uri"); String userInfoUri = resolver.getProperty("user-info-uri"); if (!StringUtils.hasLength(userInfoUri)) { return ConditionOutcome.match("No user info provided"); } if (StringUtils.hasLength(tokenInfoUri) && preferTokenInfo) { return ConditionOutcome.match( "Token info endpoint " + "is preferred and user info provided"); } return ConditionOutcome.noMatch("Token info endpoint is not provided"); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { Environment environment = context.getEnvironment(); RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment, "security.oauth2.resource."); if (hasOAuthClientId(environment)) { return ConditionOutcome.match("found client id"); } if (!resolver.getSubProperties("jwt").isEmpty()) { return ConditionOutcome.match("found JWT resource configuration"); } if (StringUtils.hasText(resolver.getProperty("user-info-uri"))) { return ConditionOutcome .match("found UserInfo " + "URI resource configuration"); } if (ClassUtils.isPresent(AUTHORIZATION_ANNOTATION, null)) { if (AuthorizationServerEndpointsConfigurationBeanCondition .matches(context)) { return ConditionOutcome.match( "found authorization " + "server endpoints configuration"); } } return ConditionOutcome.noMatch("found neither client id nor " + "JWT resource nor authorization server"); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( context.getEnvironment(), "spring.session."); StoreType sessionStoreType = SessionStoreMappings .getType(((AnnotationMetadata) metadata).getClassName()); if (!resolver.containsProperty("store-type")) { if (sessionStoreType == StoreType.REDIS && redisPresent) { return ConditionOutcome .match("Session store type default to redis (deprecated)"); } return ConditionOutcome.noMatch("Session store type not set"); } String value = resolver.getProperty("store-type").replace("-", "_").toUpperCase(); if (value.equals(sessionStoreType.name())) { return ConditionOutcome.match("Session store type " + sessionStoreType); } return ConditionOutcome.noMatch("Session store type " + value); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( context.getEnvironment(), "spring.cache."); if (!resolver.containsProperty("type")) { return ConditionOutcome.match("Automatic cache type"); } CacheType cacheType = CacheConfigurations .getType(((AnnotationMetadata) metadata).getClassName()); String value = resolver.getProperty("type").replace("-", "_").toUpperCase(); if (value.equals(cacheType.name())) { return ConditionOutcome.match("Cache type " + cacheType); } return ConditionOutcome.noMatch("Cache type " + value); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( context.getEnvironment(), "spring.cache.jcache."); if (resolver.containsProperty("provider")) { return ConditionOutcome.match("JCache provider specified"); } Iterator<CachingProvider> providers = Caching.getCachingProviders() .iterator(); if (!providers.hasNext()) { return ConditionOutcome.noMatch("No JSR-107 compliant providers"); } providers.next(); if (providers.hasNext()) { return ConditionOutcome.noMatch( "Multiple default JSR-107 compliant " + "providers found"); } return ConditionOutcome.match("Default JSR-107 compliant provider found."); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { Environment environment = context.getEnvironment(); if ("true".equals(environment .resolvePlaceholders("${spring.sleuth.stream.enabled:}"))) { return ConditionOutcome .noMatch("Found spring.sleuth.stream.enabled=true"); } if (environment instanceof ConfigurableEnvironment) { ConfigurableEnvironment configurable = (ConfigurableEnvironment) environment; configurable.getPropertySources() .addLast( new MapPropertySource("spring.sleuth.stream", Collections.<String, Object>singletonMap( "spring.sleuth.stream.enabled", "false"))); } return ConditionOutcome.match("Not found: spring.sleuth.stream.enabled"); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { Map<String, Object> attributes = metadata.getAnnotationAttributes(ConditionalOnOperatingSystem.class.getName()); OperatingSystem operatingSystem = (OperatingSystem) attributes.get("value"); ConditionMessage.Builder message = ConditionMessage.forCondition(ConditionalOnOperatingSystem.class); String name = operatingSystem.name(); if (operatingSystem == OperatingSystem.WINDOWS && SystemInformation.INSTANCE.isWindows()) { return ConditionOutcome.match(message.foundExactly(name)); } if (operatingSystem == OperatingSystem.UNIX && SystemInformation.INSTANCE.isUnix()) { return ConditionOutcome.match(message.foundExactly(name)); } return ConditionOutcome.noMatch(message.didNotFind(name).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) { 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) { 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) { AnnotationAttributes attributes = AnnotationAttributes .fromMap(metadata.getAnnotationAttributes(ConditionalOnEnabledDetector.class.getName())); final String name = attributes.getString("value"); final String prefix = attributes.getString("prefix"); RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(context.getEnvironment(), prefix + "." + name + "."); Boolean enabled = resolver.getProperty("enabled", Boolean.class, true); return new ConditionOutcome(enabled, ConditionMessage.forCondition(ConditionalOnEnabledDetector.class, name) .because(enabled ? "enabled" : "disabled")); }
@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()); }
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata a) { String eventHubProperty = context.getEnvironment().getProperty(PROPERTY_NAME); ConditionOutcome outcome = eventHubProperty == null || eventHubProperty.isEmpty() ? ConditionOutcome.noMatch(PROPERTY_NAME + " isn't set") : ConditionOutcome.match(); return outcome; }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata a) { String eventHubProperty = context.getEnvironment().getProperty(PROPERTY_NAME); ConditionOutcome outcome = eventHubProperty == null || eventHubProperty.isEmpty() ? ConditionOutcome.noMatch(PROPERTY_NAME + " isn't set") : ConditionOutcome.match(); return outcome; }
@Override public ConditionOutcome getMatchOutcome( ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) { boolean groupEnabled = isEnabled(conditionContext, "camel.component.", true); ConditionMessage.Builder message = ConditionMessage .forCondition("camel.component.syndesis-http"); if (isEnabled(conditionContext, "camel.component.syndesis-http.", groupEnabled)) { return ConditionOutcome.match(message.because("enabled")); } return ConditionOutcome.noMatch(message.because("not enabled")); }
@Override protected ConditionOutcome getResourceOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { if (System.getProperty(configSystemProperty) != null) { return ConditionOutcome.match(startConditionMessage() .because("System property '" + configSystemProperty + "' is set.")); } return super.getResourceOutcome(context, metadata); }
@Test public void testGetResourceOutcomeForSystemProperty() { System.setProperty("anyProperty", "anyValue"); QuickFixJConfigResourceCondition resourceCondition = new ClientConfigAvailableCondition("anyProperty"); ConditionOutcome conditionOutcome = resourceCondition.getResourceOutcome(mock(ConditionContext.class), mock(AnnotatedTypeMetadata.class)); assertThat(conditionOutcome).isNotNull(); assertThat(conditionOutcome.getMessage()).contains("ResourceCondition (QuickFixJ) System property 'anyProperty' is set."); }
@Test public void testGetResourceOutcomeForSystemPropertyNotSet() { QuickFixJConfigResourceCondition resourceCondition = new ClientConfigAvailableCondition("any"); ConditionContext context = mock(ConditionContext.class); AnnotatedTypeMetadata metadata = mock(AnnotatedTypeMetadata.class); ConditionOutcome conditionOutcome = resourceCondition.getResourceOutcome(context, metadata); assertThat(conditionOutcome).isNotNull(); assertThat(conditionOutcome.getMessage()).contains("ResourceCondition (QuickFixJ) did not find resource"); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ConditionMessage.Builder message = ConditionMessage .forCondition("PooledDataSource"); if (getDataSourceClassLoader(context) != null) { return ConditionOutcome .match(message.foundExactly("supported DataSource")); } return ConditionOutcome .noMatch(message.didNotFind("supported DataSource").atAll()); }