@Override
 public ConditionOutcome getMatchOutcome(
     ConditionContext context, AnnotatedTypeMetadata metadata) {
   String managementEnabled =
       context.getEnvironment().getProperty("management.security.enabled", "true");
   String basicEnabled = context.getEnvironment().getProperty("security.basic.enabled", "true");
   return new ConditionOutcome(
       "true".equalsIgnoreCase(managementEnabled) && !"true".equalsIgnoreCase(basicEnabled),
       "Management security enabled and basic disabled");
 }
 /**
  * Returns the class loader for the {@link DataSource} class. Used to ensure that the driver
  * class can actually be loaded by the data source.
  */
 private ClassLoader getDataSourceClassLoader(ConditionContext context) {
   Class<?> dataSourceClass = new DataSourceBuilder(context.getClassLoader()).findType();
   if (dataSourceClass == null) {
     return null;
   }
   return dataSourceClass.getClassLoader();
 }
 private boolean isEnabled(
     org.springframework.context.annotation.ConditionContext context,
     java.lang.String prefix,
     boolean defaultValue) {
   RelaxedPropertyResolver resolver =
       new RelaxedPropertyResolver(context.getEnvironment(), prefix);
   return resolver.getProperty("enabled", Boolean.class, defaultValue);
 }
 @Override
 public ConditionOutcome getMatchOutcome(
     ConditionContext context, AnnotatedTypeMetadata metadata) {
   for (String className : CLASS_NAMES) {
     if (ClassUtils.isPresent(className, context.getClassLoader())) {
       return ConditionOutcome.match("found HibernateEntityManager class");
     }
   }
   return ConditionOutcome.noMatch("did not find HibernateEntityManager class");
 }
 @Override
 public ConditionOutcome getMatchOutcome(
     ConditionContext context, AnnotatedTypeMetadata metadata) {
   RelaxedPropertyResolver resolver =
       new RelaxedPropertyResolver(context.getEnvironment(), "security.oauth2.resource.jwt.");
   String keyValue = resolver.getProperty("key-value");
   String keyUri = resolver.getProperty("key-uri");
   if (StringUtils.hasText(keyValue) || StringUtils.hasText(keyUri)) {
     return ConditionOutcome.match("public key is provided");
   }
   return ConditionOutcome.noMatch("public key is not provided");
 }
 @Override
 public ConditionOutcome getMatchOutcome(
     ConditionContext context, AnnotatedTypeMetadata metadata) {
   if (anyMatches(context, metadata, this.nonEmbedded)) {
     return ConditionOutcome.noMatch("existing non-embedded database detected");
   }
   EmbeddedDatabaseType type =
       EmbeddedDatabaseConnection.get(context.getClassLoader()).getType();
   if (type == null) {
     return ConditionOutcome.noMatch("no embedded database detected");
   }
   return ConditionOutcome.match("embedded database " + type + " detected");
 }
    @Override
    public Outcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {

      ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
      String[] beans = beanFactory.getBeanNamesForType(DispatcherServlet.class, false, false);
      if (beans.length == 0) {
        return Outcome.match("no DispatcherServlet found");
      }
      if (Arrays.asList(beans).contains(DEFAULT_DISPATCHER_SERVLET_BEAN_NAME)) {
        return Outcome.noMatch(
            "found DispatcherServlet named " + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
      }
      return Outcome.match(
          "multiple DispatcherServlets found and none is named "
              + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
    }
    @Override
    public ConditionOutcome getMatchOutcome(
        ConditionContext context, AnnotatedTypeMetadata metadata) {

      if (anyMatches(context, metadata, this.nonEmbedded, this.embeddedCondition)) {
        return ConditionOutcome.match("existing auto database detected");
      }

      if (BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
                  context.getBeanFactory(), DataSource.class, true, false)
              .length
          > 0) {
        return ConditionOutcome.match("Existing bean configured database detected");
      }

      return ConditionOutcome.noMatch("no existing bean configured database");
    }
 @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");
 }
 private boolean hasBean(ConditionContext context, Class<?> type) {
   return BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
               context.getBeanFactory(), type, true, false)
           .length
       > 0;
 }
 /**
  * Returns the class loader for the {@link DataSource} class. Used to ensure that the driver
  * class can actually be loaded by the data source.
  */
 private ClassLoader getDataSourceClassLoader(ConditionContext context) {
   Class<?> dataSourceClass = new DataSourceBuilder(context.getClassLoader()).findType();
   return (dataSourceClass == null ? null : dataSourceClass.getClassLoader());
 }
 private boolean isEnabled(ConditionContext context, String prefix, boolean defaultValue) {
   RelaxedPropertyResolver resolver =
       new RelaxedPropertyResolver(context.getEnvironment(), prefix);
   return resolver.getProperty("enabled", Boolean.class, defaultValue);
 }
Ejemplo n.º 13
0
 public boolean matches(
     ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
   return conditionContext.getEnvironment().getProperty("os.name").contains("Linux");
 }