AXIS2访问权限控制利用TOMCAT用户
2011-09-08 17:35
375 查看
1.找到TOMCAT安装目录,找到CONFIG文件夹,查找到Tomcat_Home\conf\tomcat-users.xml文件,添加角色
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>… <role rolename="department-manager"/>
<user username="test" password="test" roles="department-manager"/>
…
</tomcat-users>
上面配置代码在tomcat配置文件中添加了一个department-manager角色,并且在此角色中添加了一个名为hellking的用户。要使tomcat-users.xml中配置的角色和用户生效,需要配置tomcat使用UserDatabaseRealm。打开Tomcat_Home\conf\server.xml配置文件,在GlobalNamingResources中添加以下描述:
2.在tomcat中添加UserDatabaseRealm
然后再web应用的部署描述符中指定Web服务资源的访问控制,如下所示:
3.
<security-constraint>
<web-resource-collection>
<web-resource-name>Tax Web service </web-resource-name>
<url-pattern>/services/PersonalTaxService</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>department-manager</role-name> <
/auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Axis Basic Authentication Area</realm-name>
</login-config>
<security-role>
<role-name>department-manager</role-name>
</security-role>
url-pattern指定了需要通过角色验证的URL样式,在这里是"/services/PersonalTaxService";role-name是能够访问制定URL的角色,这里是department-manager。以上配置的意思是只有角色类型是"department-manager"的用户才能访问URL样式为"/services/PersonalTaxService"Web服务。
4.客户端调用:
public String ClientAccount(CDto abDto){
RPCServiceClient serviceClient = null;
String para=null;
String xmlString = null;
try {
serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
EndpointReference targetEPR = new EndpointReference(ClientReadProperties.getInstence().getProperty("Select"));
options.setTo(targetEPR);
HttpTransportProperties.Authenticator authenticator = new HttpTransportProperties.Authenticator();
authenticator.setPreemptiveAuthentication(true);
authenticator.setUsername("test");
authenticator.setPassword("test");
options.setProperty(HTTPConstants.AUTHENTICATE, authenticator);
QName qname = new QName(ClientReadProperties.getInstence().getProperty("Qurl"),"Select");
para=ObjectToXML.ObjectToXMLString(abDto);//封装成XML格式字符串
xmlString = (String) serviceClient.invokeBlocking(qname,new Object[] { para },new Class[] { String.class })[0];
} catch (Exception e) {
e.getStackTrace();
}
return xmlString;
}
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>… <role rolename="department-manager"/>
<user username="test" password="test" roles="department-manager"/>
…
</tomcat-users>
上面配置代码在tomcat配置文件中添加了一个department-manager角色,并且在此角色中添加了一个名为hellking的用户。要使tomcat-users.xml中配置的角色和用户生效,需要配置tomcat使用UserDatabaseRealm。打开Tomcat_Home\conf\server.xml配置文件,在GlobalNamingResources中添加以下描述:
2.在tomcat中添加UserDatabaseRealm
<GlobalNamingResources>... <Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved"> </Resource> <ResourceParams name="UserDatabase"> <parameter> <name>factory</name> <value>org.apache.catalina.users.MemoryUserDatabaseFactory</value> </parameter><parameter><name>pathname</name> <value>conf/tomcat-users.xml</value> </parameter> </ResourceParams> </GlobalNamingResources> |
3.
<security-constraint>
<web-resource-collection>
<web-resource-name>Tax Web service </web-resource-name>
<url-pattern>/services/PersonalTaxService</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>department-manager</role-name> <
/auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Axis Basic Authentication Area</realm-name>
</login-config>
<security-role>
<role-name>department-manager</role-name>
</security-role>
url-pattern指定了需要通过角色验证的URL样式,在这里是"/services/PersonalTaxService";role-name是能够访问制定URL的角色,这里是department-manager。以上配置的意思是只有角色类型是"department-manager"的用户才能访问URL样式为"/services/PersonalTaxService"Web服务。
4.客户端调用:
public String ClientAccount(CDto abDto){
RPCServiceClient serviceClient = null;
String para=null;
String xmlString = null;
try {
serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
EndpointReference targetEPR = new EndpointReference(ClientReadProperties.getInstence().getProperty("Select"));
options.setTo(targetEPR);
HttpTransportProperties.Authenticator authenticator = new HttpTransportProperties.Authenticator();
authenticator.setPreemptiveAuthentication(true);
authenticator.setUsername("test");
authenticator.setPassword("test");
options.setProperty(HTTPConstants.AUTHENTICATE, authenticator);
QName qname = new QName(ClientReadProperties.getInstence().getProperty("Qurl"),"Select");
para=ObjectToXML.ObjectToXMLString(abDto);//封装成XML格式字符串
xmlString = (String) serviceClient.invokeBlocking(qname,new Object[] { para },new Class[] { String.class })[0];
} catch (Exception e) {
e.getStackTrace();
}
return xmlString;
}
相关文章推荐
- Oracle GoldenGate 安全性配置系列:利用 CMDSEC 文件控制 GoldenGate 命令的用户访问权限
- Tomcat7.0.40 基于DataSourceRealm的和JDBCRealm的资源用户访问控制
- SQL Server 2005 控制用户权限访问表
- SQLServer控制用户访问权限表
- SharePoint【用户访问控制】-- sharepoint 判断当前用户在当前页面是否有某项权限
- Struts2 利用拦截器 interceptor 控制登陆和访问权限
- Asp.net 权限控制 利用用户控件include到页面
- SQL Server 2005控制用户权限访问表
- 防止用户直接访问url的权限控制
- SQL Server 2005/2008 控制用户权限访问表
- RBAC(用户权限管理) 基于角色的访问控制
- SQL Server 2005 控制用户权限访问表
- 控制用户访问--用户和权限
- mysql的用户管理和权限管理(访问控制)
- Asp.net 权限控制 利用用户控件include到页面
- SpringSecurity实战! 详细讲解如何通过SpringSecurity控制用户访问权限。
- SQLServer控制用户访问权限表
- SQLServer控制用户访问权限表
- sharepoint:拥有完全控制权限的用户依然“拒绝访问” -- 金大昊(jindahao)