简体   繁体   English

Apache CXF-JAX-RS安全

[英]Apache CXF - JAX-RS Security

Working towards getting a Kerberos authenticated Web Service up and running and while Apache CXF seems to meet my requirements I'm struggling to get things started. 努力使Kerberos身份验证的Web服务启动并运行,并且在Apache CXF似乎满足我的要求的同时,我仍在努力启动。

Hosting on Tomcat 7 and my super simple test service works but I can't figure out how to get CXF to provide security: 托管在Tomcat 7上,我的超级简单测试服务可以运行,但是我不知道如何获得CXF来提供安全性:

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

    @Path("test")
    public class ItemResource {

        public ItemResource() {
        }


        @GET
        @Produces("application/json")
        public String getJson(@QueryParam("name") int test) {

            return "test";

        }
    }

Web.xml 在web.xml

    <servlet>
            <init-param>
                <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
                <param-value>true</param-value>
            </init-param>
    <servlet-name>jersey-serlvet</servlet-name>
    <servlet-class>
                 com.sun.jersey.spi.container.servlet.ServletContainer
            </servlet-class>
    <init-param>
         <param-name>com.sun.jersey.config.property.packages</param-name>
         <param-value>net.example.test/param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

The documentation says I can protect the Rest service with the org.apache.cxf.jaxrs.security.KerberosAuthenticationFilter but I'm unsure as to how to do this. 该文档说我可以使用org.apache.cxf.jaxrs.security.KerberosAuthenticationFilter保护Rest服务,但是我不确定如何做到这一点。

Any help would be appreciated. 任何帮助,将不胜感激。

If you want to use CXF's KerberosAuthenticationFilter you have to use CXF as JAX-RS implementation, instead of Jersey. 如果要使用CXF的KerberosAuthenticationFilter ,则必须使用CXF作为JAX-RS实现,而不是Jersey。

You can find out how to do that on CXF JAX-RS help pages or in this tutorial . 您可以在CXF JAX-RS帮助页面或本教程中找到如何做到这一点 First you have to remove all configuration from web.xml because it is valid only for Jersey. 首先,您必须从web.xml删除所有配置,因为它仅对Jersey有效。 Then follow the tutorial to create the service. 然后按照教程创建服务。

Finally you have to add mentioned KerberosAuthenticationFilter to CXF spring configuration like in the cited documentation. 最后,您必须像引用的文档中一样将提到的KerberosAuthenticationFilter添加到CXF弹簧配置中。

EDIT: 编辑:

Because linked tutorial indeed does not run I fixed it. 因为链接的教程确实无法运行,所以我对其进行了修复。 You can download it from my github project RestWithCXF . 您可以从我的github项目RestWithCXF下载它。

You might also find useful samples in samples\\jax_rs of CXF distro. 您可能还会在CXF发行版的samples\\jax_rs中找到有用的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM