我已经为Jersey创建了LoggingFilter,并在web.xml中对其进行了正确配置。一切正常。当我执行“ GET”时,我得到了userPrincipal(request.getUserPrincipal()),但对于POST,它返回null。我已经在Websphere上的Java 1.4中编写了几个REST服务,并且总是可以访问到userPrincipal,但是在Tomcat / 1.6上我得到了上面的内容。我正在使用基本身份验证。泽西岛正在这样做吗?还是Tomcat?

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Lookup Resources</web-resource-name>
        <description>A set of secured resources.</description>
        <url-pattern>/rest/lookup/*</url-pattern>
        <http-method>GET</http-method>
    </web-resource-collection>
    <auth-constraint>
        <role-name>DataServ_Lookup</role-name>
        <role-name>DataServ_Admin</role-name>
    </auth-constraint>
    <!-- Comment this out for Dev.  It is a MUST for Prod...
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>-->

</security-constraint>

最佳答案

为什么创建自己的LoggingFilter?您知道泽西岛开箱即用吗?
您的过滤器是否以任何方式修改了请求?尝试将HttpServletRequest注入您的资源,并获取该主体的形式-看看是否已设置。如果不是,请查看您的请求是否确实包含基本的auth标头。

10-06 14:24
查看更多