Skip to content

Commit

Permalink
Update to latest 1.3 code
Browse files Browse the repository at this point in the history
  • Loading branch information
dsyer committed May 26, 2015
1 parent 53f67a4 commit 5468949
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public Authentication authenticate(Authentication authentication)

@Bean
public AccessDecisionManager shellAccessDecisionManager() {
List<AccessDecisionVoter<? extends Object>> voters = new ArrayList<AccessDecisionVoter<? extends Object>>();
List<AccessDecisionVoter> voters = new ArrayList<AccessDecisionVoter>();
RoleVoter voter = new RoleVoter();
voter.setRolePrefix("");
voters.add(voter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Conditional;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.MethodMetadata;
import org.springframework.core.type.StandardAnnotationMetadata;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;

Expand All @@ -37,6 +41,18 @@
public abstract class SpringBootCondition implements Condition {

private final Log logger = LogFactory.getLog(getClass());

public static boolean evaluateForClass(Class<?> annotated, ConditionContext context) {
Conditional conditional = AnnotationUtils.findAnnotation(annotated, Conditional.class);
StandardAnnotationMetadata metadata = new StandardAnnotationMetadata(annotated);
for (Class<? extends Condition> type : conditional.value()) {
Condition condition = BeanUtils.instantiateClass(type);
if (condition.matches(context, metadata)) {
return true;
}
}
return false;
}

@Override
public final boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.OnBeanCondition;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.boot.autoconfigure.security.oauth2.ClientCredentialsProperties;
Expand All @@ -36,7 +35,6 @@
import org.springframework.context.annotation.Import;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.core.type.StandardAnnotationMetadata;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerEndpointsConfiguration;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
Expand Down Expand Up @@ -111,11 +109,6 @@ public void configure(HttpSecurity http) throws Exception {
protected static class ResourceServerCondition extends SpringBootCondition implements
ConfigurationCondition {

private OnBeanCondition condition = new OnBeanCondition();

private StandardAnnotationMetadata beanMetaData = new StandardAnnotationMetadata(
ResourceServerCondition.class);

@Override
public ConfigurationPhase getConfigurationPhase() {
return ConfigurationPhase.REGISTER_BEAN;
Expand Down Expand Up @@ -143,9 +136,9 @@ public ConditionOutcome getMatchOutcome(ConditionContext context,
.isPresent(
"org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerEndpointsConfiguration",
null)) {
if (this.condition.matches(context, this.beanMetaData)) {
if (SpringBootCondition.evaluateForClass(ResourceServerCondition.class, context)) {
return ConditionOutcome
.match("found authorization server configuration");
.match("found authorization server endpoints configuration");
}
}
return ConditionOutcome
Expand Down

0 comments on commit 5468949

Please sign in to comment.