Hessian 访问权限设置

 

 Hessian  设置访问用户名和密码

1: web.xml文件增加如下代码

 <!-- 定义hessian认证 -->
 <security-constraint>
     <web-resource-collection>
       <web-resource-name>Hessian Security</web-resource-name>
       <url-pattern>/esb/hessian/TransferService</url-pattern>
     </web-resource-collection>
     <auth-constraint>
        <role-name>Hessian</role-name>
     </auth-constraint>   
 </security-constraint>
 
 <!-- Define the Login Configuration for this Application -->
 <login-config>
     <auth-method>BASIC</auth-method>
     <realm-name>Hessian Security</realm-name>
 </login-config>
 
 <!-- Security roles referenced by this web application -->
 <security-role>
     <description></description>
     <role-name>Hessian</role-name>
 </security-role>

2:设置tomcat  配置文件下tomcat-users.xml

<role rolename="tomcat"/>
  <role rolename="role1"/>
  <role rolename="Hessian"/>
  <user username="tomcat" password="tomcat" roles="tomcat"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
  <user username="role1" password="tomcat" roles="role1"/>
  <user username="Hessianuser" password="password" roles="Hessian"/>

3:增加客户端代码

  String url = "http://192.168.0.236:8080/test/esb/hessian/TransferService";

  HessianProxyFactory factory = new HessianProxyFactory();
  factory.setUser("aig");
  factory.setPassword("password");
  

这样就可以给hessian 增加权限了.

如果密码不正确会出现以下错误:

Exception in thread "main" com.caucho.hessian.client.HessianRuntimeException: com.caucho.hessian.io.HessianProtocolException: 401: java.io.IOException: Server returned HTTP response code: 401 for URL: http://192.168.0.236:8080/test/esb/hessian/TransferService
 at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:213)
 at $Proxy0.transferInfoAig(Unknown Source)
 at test.TransferInofTest.main(TransferInofTest.java:87)
Caused by: com.caucho.hessian.io.HessianProtocolException: 401: java.io.IOException: Server returned HTTP response code: 401 for URL: http://192.168.0.236:8080/test/esb/hessian/sapTransferService
 at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:185)
 ... 2 more
Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: http://192.168.0.236:8080/test/esb/hessian/TransferService
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
 at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1360)
 at java.security.AccessController.doPrivileged(Native Method)
 at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1354)
 at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1008)
 at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:167)
 ... 2 more
Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: http://192.168.0.236:8080/CHJ_G4/esb/hessian/TransferService
 at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1305)
 at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:373)
 at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:158)
 ... 2 more
 

 

 Hessian  设置访问用户名和密码

1: web.xml文件增加如下代码

 <!-- 定义hessian认证 -->
 <security-constraint>
     <web-resource-collection>
       <web-resource-name>Hessian Security</web-resource-name>
       <url-pattern>/esb/hessian/TransferService</url-pattern>
     </web-resource-collection>
     <auth-constraint>
        <role-name>Hessian</role-name>
     </auth-constraint>   
 </security-constraint>
 
 <!-- Define the Login Configuration for this Application -->
 <login-config>
     <auth-method>BASIC</auth-method>
     <realm-name>Hessian Security</realm-name>
 </login-config>
 
 <!-- Security roles referenced by this web application -->
 <security-role>
     <description></description>
     <role-name>Hessian</role-name>
 </security-role>

2:设置tomcat  配置文件下tomcat-users.xml

<role rolename="tomcat"/>
  <role rolename="role1"/>
  <role rolename="Hessian"/>
  <user username="tomcat" password="tomcat" roles="tomcat"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
  <user username="role1" password="tomcat" roles="role1"/>
  <user username="Hessianuser" password="password" roles="Hessian"/>

3:增加客户端代码

  String url = "http://192.168.0.236:8080/test/esb/hessian/TransferService";

  HessianProxyFactory factory = new HessianProxyFactory();
  factory.setUser("aig");
  factory.setPassword("password");
  

这样就可以给hessian 增加权限了.

如果密码不正确会出现以下错误:

Exception in thread "main" com.caucho.hessian.client.HessianRuntimeException: com.caucho.hessian.io.HessianProtocolException: 401: java.io.IOException: Server returned HTTP response code: 401 for URL: http://192.168.0.236:8080/test/esb/hessian/TransferService
 at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:213)
 at $Proxy0.transferInfoAig(Unknown Source)
 at test.TransferInofTest.main(TransferInofTest.java:87)
Caused by: com.caucho.hessian.io.HessianProtocolException: 401: java.io.IOException: Server returned HTTP response code: 401 for URL: http://192.168.0.236:8080/test/esb/hessian/sapTransferService
 at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:185)
 ... 2 more
Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: http://192.168.0.236:8080/test/esb/hessian/TransferService
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
 at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1360)
 at java.security.AccessController.doPrivileged(Native Method)
 at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1354)
 at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1008)
 at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:167)
 ... 2 more
Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: http://192.168.0.236:8080/CHJ_G4/esb/hessian/TransferService
 at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1305)
 at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:373)
 at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:158)
 ... 2 more
 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值