我正在开发一个 REST 应用程序,它使用 Jersey 框架。我想知道如何控制用户身份验证。我查了很多地方,找到最接近的文章是这样的:http://weblogs.java.net/blog/2008/03/07/authentication-jersey.
但是,本文只能与 GlassFish 服务器和附加数据库一起使用。无论如何,我可以在 Jersey 中实现一个接口,并在到达请求的 REST 资源之前将其用作过滤器吗?
我现在想使用基本身份验证,但它应该足够灵活,以便我可以稍后更改。
我成功地使用 Spring Security 来保护我的基于 Jersey 的 API。它具有可插入的身份验证方案,允许您稍后从基本身份验证切换到其他身份验证。我一般不使用Spring,只是安全方面的东西。
这是我的 web.xml 中的相关部分
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/security-applicationContext.xml,
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<!-- Enables Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>
org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
<init-param>
<param-name>targetBeanName</param-name>
<param-value>springSecurityFilterChain</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
您可以将 applicationContext.xml 留空 ()。可以找到 security-applicationContext.xml 的示例here
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)