DATAGEODE-310 - Use Environment accessible properties to enable/disable Apache Shiro and Authentication Auto-configuration.

This commit is contained in:
John Blum
2020-03-19 13:36:55 -07:00
parent 9a85b4e54a
commit e1ad232f79
2 changed files with 25 additions and 3 deletions

View File

@@ -43,6 +43,7 @@ import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.OrderComparator;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.data.gemfire.config.annotation.support.AbstractAnnotationConfigSupport;
import org.springframework.data.gemfire.util.CollectionUtils;
@@ -238,13 +239,24 @@ public class ApacheShiroSecurityConfiguration extends AbstractAnnotationConfigSu
protected static final String APACHE_SHIRO_LIFECYCLE_BEAN_POST_PROCESSOR_CLASS_NAME =
"org.apache.shiro.spring.LifecycleBeanPostProcessor";
public static final String SPRING_DATA_GEMFIRE_SECURITY_SHIRO_ENABLED =
"spring.data.gemfire.security.shiro.enabled";
private boolean isApacheShiroPresent(ConditionContext context) {
return ClassUtils.isPresent(APACHE_SHIRO_LIFECYCLE_BEAN_POST_PROCESSOR_CLASS_NAME,
context.getClassLoader());
}
private boolean isEnabled(Environment environment) {
return environment.getProperty(SPRING_DATA_GEMFIRE_SECURITY_SHIRO_ENABLED, Boolean.class, true);
}
/**
* @inheritDoc
*/
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
return ClassUtils.isPresent(APACHE_SHIRO_LIFECYCLE_BEAN_POST_PROCESSOR_CLASS_NAME,
context.getClassLoader());
return isEnabled(context.getEnvironment()) && isApacheShiroPresent(context);
}
}
}

View File

@@ -206,9 +206,19 @@ public class AutoConfiguredAuthenticationConfiguration {
public static class AutoConfiguredAuthenticationCondition implements Condition {
public static final String SPRING_DATA_GEMFIRE_SECURITY_AUTH_ENABLED =
"spring.data.gemfire.security.auth.auto-configure.enabled";
private static boolean isEnabled(Environment environment) {
return environment.getProperty(SPRING_DATA_GEMFIRE_SECURITY_AUTH_ENABLED, Boolean.class, true);
}
@Override
public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
return isMatch(conditionContext.getEnvironment());
Environment environment = conditionContext.getEnvironment();
return isEnabled(environment) && isMatch(environment);
}
}
}