Spring security @带有自定义方法的预授权注释不';行不通

Spring security @带有自定义方法的预授权注释不';行不通,spring-security,Spring Security,我试图在服务层的方法级别使用Spring@PreAuthorize调用一个自定义方法,但是没有调用我的自定义方法。我的代码: spring-application-context.xml: <context:component-scan base-package="com.dice" /> <sec:global-method-security pre-post-annotations="enabled"/> 调用util类的控制器: @InjectParam Cust

我试图在服务层的方法级别使用Spring@PreAuthorize调用一个自定义方法,但是没有调用我的自定义方法。我的代码:

spring-application-context.xml:

<context:component-scan base-package="com.dice" />
<sec:global-method-security pre-post-annotations="enabled"/>
调用util类的控制器:

@InjectParam
CustomerUtil customerUtil;

@GET
@Path("/{customerId}/")
@Produces(MediaType.APPLICATION_JSON)
public Response getCustomerInfo(@PathParam("customerId") Integer customerId,
    @DefaultValue("") @QueryParam("fields") String partialResponseFields) {

    logger.debug("getCustomerInfo called: id: " + customerId + ", uriInfo = " + uriInfo.getPath());
    try {
        return buildOKResourceResponse(new CustomerActionResource(customerUtil.getCustomerInfo(uriInfo, customerId)),partialResponseFields);
组件的使用:

@InjectParam
AuthorizationService svc;

@PreAuthorize("@authorizationService.test('special')")
public Customer getCustomerInfo(UriInfo uriInfo, Integer id) {
    logger.debug("svc: " + svc.hasPermission("x"));
    return populateCustomerInfo(uriInfo, PstUserModelServiceUtil.getPstUserModelByPstUserId(id));
}
我包含InjectParam只是为了确保AuthorizationService类被Spring识别。果然,“AUTHORIZATION CALLED”调试语句在我通过注入类调用时出现,但在通过@PreAuthorization调用调用时不会出现

我的弹簧罐:

spring-aop-3.2.0.RELEASE.jar
spring-beans-3.2.0.RELEASE.jar
spring-context-3.2.0.RELEASE.jar
spring-context-support-3.2.2.RELEASE.jar
spring-core-3.2.0.RELEASE.jar
spring-data-commons-1.5.0.RELEASE.jar
spring-data-solr-1.0.0.RELEASE.jar
spring-expression-3.2.0.RELEASE.jar
spring-jdbc-3.2.0.RELEASE.jar
spring-orm-3.2.0.RELEASE.jar
spring-security-acl-3.1.4.RELEASE.jar
spring-security-config-3.1.4.RELEASE.jar
spring-security-core-3.1.4.RELEASE.jar
spring-security-oauth2-1.1.0.BUILD-SNAPSHOT.jar
spring-security-taglibs-3.1.4.RELEASE.jar
spring-security-web-3.1.4.RELEASE.jar
spring-tx-3.2.0.RELEASE.jar
spring-web-3.2.2.RELEASE.jar
spring-webmvc-3.2.2.RELEASE.jar

我做错了什么?我在component类和使用该组件的类上都有接口,正如我读到的关于aop的内容一样,Spring装饰了impl类,即Spring需要一个接口来查看底层实现。

Spring安全性通过创建一个用安全性注释注释的类的代理来工作(即
@PreAuthorize
)。为了代理它,必须由Spring创建具有安全注释的类,并且必须对Spring创建的实例进行任何调用


验证带有
public Customer getCustomerInfo
的类是由Spring创建的,而不是以其他方式创建的。

我使用对getCustomerInfo()方法的Spring控制器调用更新了原始帖子。我有点转向了不相关的领域,但我们必须使用InjectParam来“修复”尝试使用Autowired时引发异常。使用jersey InjectParam注入CustomerUtil对象是问题吗?在使用该注释而不是Autowired时,该对象不是由Spring创建的?谢谢!我相信问题出在“@InjectParam CustomerUtil”上。我们计划将CustomerUtil c移动到lass进入服务层,通过spring-context.xml注入bean,然后使用一个servlce定位器类来查找bean。所以我继续这样做,一旦我这样做了(并允许spring创建bean),预授权注释开始像一个符咒一样启动。
spring-aop-3.2.0.RELEASE.jar
spring-beans-3.2.0.RELEASE.jar
spring-context-3.2.0.RELEASE.jar
spring-context-support-3.2.2.RELEASE.jar
spring-core-3.2.0.RELEASE.jar
spring-data-commons-1.5.0.RELEASE.jar
spring-data-solr-1.0.0.RELEASE.jar
spring-expression-3.2.0.RELEASE.jar
spring-jdbc-3.2.0.RELEASE.jar
spring-orm-3.2.0.RELEASE.jar
spring-security-acl-3.1.4.RELEASE.jar
spring-security-config-3.1.4.RELEASE.jar
spring-security-core-3.1.4.RELEASE.jar
spring-security-oauth2-1.1.0.BUILD-SNAPSHOT.jar
spring-security-taglibs-3.1.4.RELEASE.jar
spring-security-web-3.1.4.RELEASE.jar
spring-tx-3.2.0.RELEASE.jar
spring-web-3.2.2.RELEASE.jar
spring-webmvc-3.2.2.RELEASE.jar