当通过使用飞碟(Itext)ReplacedElementFactory实现的筛选器调用Spring@Secured方法时,该方法不起作用

当通过使用飞碟(Itext)ReplacedElementFactory实现的筛选器调用Spring@Secured方法时,该方法不起作用,spring,security,authentication,filter,itext,Spring,Security,Authentication,Filter,Itext,当我通过普通的@Controller类调用@Service类上的Spring@Secured方法时,身份验证工作正常 当我使用org.xhtmlrenderer.extend.ReplacedElementFactory实现通过IText PDF过滤器调用相同的方法时,我得到以下堆栈跟踪: org.springframework.security.authentication.AuthenticationCredentialsNotFoundException: An Authenticatio

当我通过普通的@Controller类调用@Service类上的Spring@Secured方法时,身份验证工作正常

当我使用org.xhtmlrenderer.extend.ReplacedElementFactory实现通过IText PDF过滤器调用相同的方法时,我得到以下堆栈跟踪:

org.springframework.security.authentication.AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext
    at org.springframework.security.access.intercept.AbstractSecurityInterceptor.credentialsNotFound(AbstractSecurityInterceptor.java:325)
    at org.springframework.security.access.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:196)
    at org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:64)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
安全性显然是有效的,因为没有所需角色的用户会收到拒绝访问异常,而具有正确角色的其他用户则根本没有问题

以下是my web.xml中的一个片段:

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter>
    <filter-name>pdfFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>pdfFilter</filter-name>
    <url-pattern>/reports/pdf/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
</filter-mapping>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
以下是我的ImageService类方法:

@Secured({"ROLE_MY_ROLE_READ"})
    public Image getPersonImageByImageId(Long imageId) {
        return imageDao.findOne(imageId);
    }
失败发生在调用映像服务方法时,这可能是因为它是安全的,并且ReplacedElementFactory实现没有访问安全上下文的权限,但是如何进行身份验证


我是一个新手,所以如果还需要什么,请告诉我。

不确定您是如何配置安全性的。但如果您也使用过,请检查过滤器的顺序。安全筛选器应该在您的pdffilter之前。

我已编辑了问题和数据,以更准确地反映问题。目前,我刚刚创建了第二个非安全方法,该方法仅在ReplacedElementFactory实现中调用。我不喜欢这个解决方案,但是URL也有一些安全性,所以它不是完全不安全的。我只是想要一个比我目前的解决方案更好的答案。
@Secured({"ROLE_MY_ROLE_READ"})
    public Image getPersonImageByImageId(Long imageId) {
        return imageDao.findOne(imageId);
    }