1

我已经实现了一个自定义 PermissionEvaluator 并将其配置如下

<security:http access-denied-page="/" auto-config="true" use-expressions="true">
    <security:anonymous />
    <security:form-login always-use-default-target="false" default-target-url="/people/login/redirect" login-page="/people/login" login-processing-url="/people/login/submit" password-parameter="password" username-parameter="emailAddress" />
    <security:logout delete-cookies="true" invalidate-session="true" logout-success-url="/people/login/redirect" logout-url="/people/logout" />
</security:http>

<security:authentication-manager erase-credentials="false">
    <security:authentication-provider ref="authenticationProvider" />
</security:authentication-manager>

<security:global-method-security jsr250-annotations="enabled" pre-post-annotations="enabled" secured-annotations="enabled" >
    <security:expression-handler ref="expressionHandler"/>
</security:global-method-security>


<bean id="expressionHandler" class="org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler">
     <property name="permissionEvaluator" ref="appPermissionEvaluator"/>
</bean>

<bean class="com.web.security.ApplicationPermissionEvaluator" id="appPermissionEvaluator" />

然后我在我的一个 ControllerClass 上的一种方法上应用了 hasPermissionCheck,如下所示

@PreAuthorize("hasPermission(#accountCode, 'AdministerPosition')")
    @RequestMapping(method = RequestMethod.GET, value =  "/cloud/{account}/position")
    public String list(@PathVariable String account, @RequestParam(required = false, value = URLParameter.ACCOUNT_CODE) final String accountCode, final Model model) {

}

在这种情况下,我在ApplicationPermissionEvaluator课堂上从来没有得到控制。

我发现DenyAllPermissionEvaluator在我的情况下总是会执行以下错误消息

DenyAllPermissionEvaluator - Denying user ****** permission 'AdministerPosition'

请尽快给我建议。我真的坚持这一点。

4

1 回答 1

1

让这个工作的方法是<security:global-method-security ..>在你的 spring mvc 上下文中配置,而不是在主上下文中

即在这里mvc-servlet-context.xml

 <servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:META-INF/spring/mvc-servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
于 2013-02-20T13:44:09.243 回答