Rest Tomcat/Jersey:客户端证书身份验证

Rest Tomcat/Jersey:客户端证书身份验证,rest,tomcat,jersey,authentication,Rest,Tomcat,Jersey,Authentication,我正在使用Jersey/Tomcat开发一个RESTful服务 我需要支持两套API公共和私有。公共API对所有人开放,并使用API密钥进行身份验证。私有API将仅从我自己的Web服务器层调用,以执行某些内部操作 我更喜欢在同一台服务器上托管这两组API,以便有效地管理/扩展它们 The URIs for the APIs will look some thing like this: https://myapis/v1.0/* --> for public APIs

我正在使用Jersey/Tomcat开发一个RESTful服务

我需要支持两套API公共和私有。公共API对所有人开放,并使用API密钥进行身份验证。私有API将仅从我自己的Web服务器层调用,以执行某些内部操作

我更喜欢在同一台服务器上托管这两组API,以便有效地管理/扩展它们

The URIs for the APIs will look some thing like this:
    https://myapis/v1.0/*  --> for public APIs 
    and
    https://myapis/v1.0/secure/*  --> for public APIs
出于安全原因,我想使用客户端证书对私有API进行身份验证。也就是说,web服务器必须使用安装在Tomcat的trustStore上的自签名证书调用secure/*API调用

根据我的研究,我认为这可以通过或实现

但就我而言,两者都不起作用

如果我选择web.xml路径(我根据证书属性在tomcat-user.xml中添加了一个tomcat用户)两个API都不可访问(错误403)

如果我采用注释路径,两个API都可以在无需身份验证的情况下访问

我遇到了几篇关于这个主题的文章,并且做了几次尝试和错误尝试。但似乎都不管用

正确的方法是什么

这是我的web.xml

泽西塞尔维特酒店 com.sun.jersey.spi.container.servlet.ServletContainer com.sun.jersey.config.property.packages com.mycompany.reststuff 1.


泽西塞尔维特酒店
/v1.0/*
蛹
/v1.0/*
得到
邮递
私蜂
/v1.0/secure/*
得到
邮递
网络播客
网络播客
客户端身份验证
...

您是否打开了Tomcat SSL?这可能是一个明显的问题,但是,您是否将Tomcat-user.xml中的Tomcat用户添加到WebCaller角色?403(禁止)使我认为身份验证成功,但身份验证用户无权访问资源。
<servlet-mapping>
    <servlet-name>jersey-serlvet</servlet-name>
    <url-pattern>/v1.0/*</url-pattern>
</servlet-mapping>

<security-constraint>
    <web-resource-collection>
        <web-resource-name>PuplicAPIs</web-resource-name>
        <url-pattern>/v1.0/*</url-pattern>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
    </web-resource-collection>
    <!-- no auth-constraint -->
</security-constraint>

<security-constraint>
    <web-resource-collection>
        <web-resource-name>PrivateAPIs</web-resource-name>
        <url-pattern>/v1.0/secure/*</url-pattern>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
    </web-resource-collection>
    <auth-constraint>
         <role-name>WebCaller</role-name>    
    </auth-constraint>
</security-constraint>

<security-role>
  <role-name>WebCaller</role-name>
</security-role>
<login-config>
  <auth-method>CLIENT-AUTH</auth-method>
</login-config> ...