在 Apache Geronimo 应用程序中实现和部署 Web 服务
2010-03-26 00:00:00 来源:WEB开发网清单 9 中的片段展示如何从安全处理程序接收主体的凭证,并以这个主体的身份调用 EJB 方法:
清单 9. 作为某个安全主体调用业务逻辑
// username and password are obtained from the security handler
LoginContext ctx = createLoginContext(username, password);
ctx.login();
try {
Set set = ctx.getSubject().getPrincipals(
org.apache.geronimo.security.IdentificationPrincipal.class);
IdentificationPrincipal idp = (IdentificationPrincipal) set.iterator().next();
Subject subject =
org.apache.geronimo.security.ContextManager.getRegisteredSubject(idp.getId());
org.apache.geronimo.security.ContextManager.setCurrentCaller(subject);
return (Order[])Subject.doAs(subject, new PrivilegedExceptionAction() {
public Object run() throws Exception {
BusinessLogic logic = BusinessLogicUtil.getHome().create();
return logic.getOrders();
}
});
} finally {
ctx.logout();
}
这个片段不能转移到处理程序代码中,因为业务方法(在这个例子中是 getOrders)应该以另一个主体的身份运行(doAs 调用),而处理程序在调用服务方法之前执行。
清单 10 展示了为这个应用程序开发的示例 Web 服务部署描述符:
清单 10. Web 服务部署描述符
<?xml version="1.0" encoding="UTF-8"?>
<webservices xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://www.ibm.com/webservices/xsd/j2ee_web_services_1_1.xsd"version="1.1">
<webservice-description>
<webservice-description-name>BusinessLogic</webservice-description-name>
<wsdl-file>WEB-INF/BusinessLogic.wsdl</wsdl-file>
<jaxrpc-mapping-file>WEB-INF/jaxrpc-mapping.xml</jaxrpc-mapping-file>
<port-component>
<port-component-name>BusinessLogicEndpointPort</port-component-name>
<wsdl-port xmlns:ns="http://ibm.com/samples/workdev/v1/wsdl">
ns:BusinessLogicEndpointPort
</wsdl-port>
<service-endpoint-interface>
com.ibm.workdev.v1.interfaces.BusinessLogicEndpoint
</service-endpoint-interface>
<service-impl-bean>
<servlet-link>BusinessLogicServiceServlet</servlet-link>
</service-impl-bean>
<handler>
<handler-name>ServerSecurityHandler</handler-name>
<handler-class>
com.ibm.workdev.v1.web.wssec.WSSecurityServerHandler
</handler-class>
<soap-header xmlns:wssec="http://schemas.xmlsoap.org/ws/2003/06/secext">
wssec:Security
</soap-header>
</handler>
</port-component>
</webservice-description>
</webservices>
- ››apache设置域名绑定 以及绑定不起作用的排查
- ››apache rewrite将指定URL转向指定的几个服务器
- ››apache配置文件httpd.comf部分参数说明
- ››Apache+Mysql+PHP+phpMyAdmin+Mac OS X 10.7 Lion...
- ››apache+tomcat负载均衡_项目实例
- ››apache mysql php 源码编译使用
- ››应用程序的配置管理Poco
- ››Apache添加mod_aspdotnet.so支持ASP.NET配置指南
- ››Apache中改变php.ini的路径
- ››Apache2.2与Tomcat6整合及虚拟主机配置
- ››Apache+php+mysql在windows下的安装与配置图解
- ››Apache+Subversion完美结合,CentOS下实现版本控制...
更多精彩
赞助商链接