我如何在Spring Security 4中实现AffirmativeBased对象?

时间:2015-07-14 13:40:00

标签: spring spring-security

Spring 3中,构造函数看起来像这样:

public AffirmativeBased(List<AccessDecisionVoter> decisionVoters)

Spring 4中,构造函数添加一个类型:

public AffirmativeBased(List<AccessDecisionVoter<? extends Object>> decisionVoters)

有人可以帮我理解它在寻找什么吗?

3 个答案:

答案 0 :(得分:3)

这一切都很好。如果您使用的是spring boot / java config,只需更改您的声明(添加?类型),如下所示,编译器不会抱怨。无论如何,所有类型的信息都将被删除

List<AccessDecisionVoter<?>> voters = new ArrayList<>();

答案 1 :(得分:2)

我遇到了以下异常:

  

org.springframework.beans.factory.NoSuchBeanDefinitionException:没有   为依赖项找到类型[java.util.List]的限定bean   [java.util.List的&GT]:   预计至少有1个豆有资格成为autowire候选人   这种依赖。依赖注释:{}

我能够通过将属性更改为构造函数参数来修复它。

var latedifference = 0;
    latedifference += late-lates
     if (late > lates && latedifference <= 2){
        $('#lateedge').text('Your Team has the Edge');
    }else if (late > lates && latedifference > 2){
        $('#lateedge').text('Your Team has a Big Edge');   
    }else if (lates > late && latedifference < -2){
        $('#lateedge').text('Opposing Team has a Big Edge');   
    }else if (lates === late){
        $('#lateedge').text('Teams are Even');
    }else {
        $('#lateedge').text('Opposing Team has the Edge');
    }

答案 2 :(得分:0)

阅读源代码..看看GlobalMethodSecurityConfiguration

protected AccessDecisionManager accessDecisionManager() {
    List<AccessDecisionVoter<? extends Object>> decisionVoters = new ArrayList<AccessDecisionVoter<? extends Object>>();
    ExpressionBasedPreInvocationAdvice expressionAdvice = new ExpressionBasedPreInvocationAdvice();
    expressionAdvice.setExpressionHandler(getExpressionHandler());
    if (prePostEnabled()) {
        decisionVoters
                .add(new PreInvocationAuthorizationAdviceVoter(expressionAdvice));
    }
    if (jsr250Enabled()) {
        decisionVoters.add(new Jsr250Voter());
    }
    decisionVoters.add(new RoleVoter());
    decisionVoters.add(new AuthenticatedVoter());
    return new AffirmativeBased(decisionVoters);
}