EJB 是怎样通过Resteasy进行验证的
来源:互联网 发布:600756 浪潮软件 编辑:程序博客网 时间:2024/06/05 04:21
今天用SOAPUI发request到后台,给了个401 error,想跟踪下代码来查看如何进行验证的,于是就各种找。
1. 现在的项目用的是EJB3,JBOSS, 查看web.xml 可以看到是用Resteasy 进行验证的:
<web-app>... <context-param> <context-name>resteasy.role.based.security</context-name> <context-value>true</context-value> </context-param></web-app>
以下摘自JBOSS官网(貌似resteasy也是JBOSS的?):
How does Resteasy do authorization? Well, its really simple. It just sees if a method is annotated with @RolesAllowed and then just does HttpServletRequest.isUserInRole. If one of the the @RolesAllowed passes, then allow the request, otherwise, a response is sent back with a 401 (Unauthorized) response code.
所以也就是说只要HttpServletRequest.isUserInRole给个true 就OK了
以下更多的resteasy配置在web.xml中供您参考:
<web-app> <context-param> <context-name>resteasy.role.based.security</context-name> <context-value>true</context-value> </context-param> <listener> <listener-class>org.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class> </listener> <servlet> <servlet-name>Resteasy</servlet-name> <servlet-class>org.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class> </servlet> <servlet-mapping> <servlet-name>Resteasy</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> <security-constraint> <web-resource-collection> <web-resource-name>Resteasy</web-resource-name> <url-pattern>/security</url-pattern> </web-resource-collection> <auth-constraint> <role-name>admin</role-name> <role-name>user</role-name> </auth-constraint> </security-constraint> <login-config> <auth-method>BASIC</auth-method> <realm-name>Test</realm-name> </login-config> <security-role> <role-name>admin</role-name> </security-role> <security-role> <role-name>user</role-name> </security-role></web-app>
Resteasy currently only has simple integration with EJBs. To make an EJB a JAX-RS resource, you must annotate an SLSB's @Remote or @Local interface with JAX-RS annotations:
1)应该有一个@Remote or @Local aannotation在你的EJB里,通常在类名上面,E.G.:
2)Next, in RESTeasy's web.xml file you must manually register the EJB with RESTeasy using the resteasy.jndi.resources <context-param>
<web-app> <display-name>Archetype Created Web Application</display-name> <context-param> <param-name>resteasy.jndi.resources</param-name> <param-value>LibraryBean/local</param-value> </context-param> <listener> <listener-class>org.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class> </listener> <servlet> <servlet-name>Resteasy</servlet-name> <servlet-class>org.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class> </servlet> <servlet-mapping> <servlet-name>Resteasy</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping></web-app>
第一篇博客,也不review一遍了,如果有错误的地方,敬请指出
- EJB 是怎样通过Resteasy进行验证的
- 验证码是怎样形成的
- 手机是怎样通过WIFI定位的!
- 视频标准研发是怎样进行的?
- RESTEasy通过TEXT、XML、JSON进行数据交换
- DAO到底是怎样一种设计模式?EJB是DAO设计模式的一种实现吗?
- 通过JavaScript进行验证
- discuz的验证码是怎样被破解的
- 怎样通过dnspod进行域名解析
- C#文本框怎样验证输入的是纯整数数字
- 微软的是怎样进行测试的(转)
- Spring的依赖注入具体操作是怎样进行的
- Atlassian是怎样进行持续交付的?(上)
- Atlassian是怎样进行持续交付的?(下)
- PDF EXPERT 是怎样进行全屏工作的
- 调用ejb+Resteasy的rest服务报错:Could not find MessageBodyWriter
- RESTEasy通过ApacheAPI或JavaAPI进行TEXT、XML、JSON数据交换
- ssh通过密钥进行验证
- Android中ListView数据使用sAdapter.notifyDataSetChanged();方法不刷新的问题
- 自定义view(一)
- linux 中 kill() 与 signal() 函数
- win7 右键卡死
- [Maven实战]发布maven项目到中央仓库(Central Repository)
- EJB 是怎样通过Resteasy进行验证的
- session和cookie机制
- 自定义简单的Toast,可自行修改文字、图片、样式
- 获取当前运行应用信息的几种方法
- 变量的显示:echo
- 给出两个整数a和b, 求他们的和, 但不能使用 + 等数学运算符。
- Xutils3的使用
- Java在文件尾部追加内容
- The processing instruction target matching "[xX][mM][lL]" is not allowed