欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
WebService開(kāi)發(fā)筆記 3 -- 增強訪(fǎng)問(wèn) WebService 的安全性
WebService開(kāi)發(fā)筆記 1中我們創(chuàng )建了一個(gè)WebService簡(jiǎn)單實(shí)例,下面我們通過(guò)一個(gè)簡(jiǎn)單的用戶(hù)口令驗證機制來(lái)加強一下WebService的安全性:

1.修改WebService 服務(wù)端 spring 配置文件 ws-context.xml
Xml代碼
 
  1. <beans xmlns="http://www.springframework.org/schema/beans"  
  2.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.     xmlns:jaxws="http://cxf.apache.org/jaxws"  
  4.     xsi:schemaLocation="http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans.xsd"  
  5.     default-autowire="byName" default-lazy-init="true">  
  6.        
  7.     <jaxws:endpoint id="webServiceSample"  
  8.         address="/WebServiceSample" implementor="cn.org.coral.biz.examples.webservice.WebServiceSampleImpl">  
  9.   
  10.         <jaxws:inInterceptors>  
  11.             <bean class="org.apache.cxf.binding.soap.saaj.SAAJInInterceptor" />  
  12.             <bean class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor">  
  13.                 <constructor-arg>  
  14.                     <map>  
  15.                         <entry key="action" value="UsernameToken" />  
  16.                         <entry key="passwordType" value="PasswordText" />  
  17.                         <entry key="passwordCallbackClass" value="cn.org.coral.biz.examples.webservice.handler.WsAuthHandler" />  
  18.                     </map>  
  19.                 </constructor-arg>  
  20.             </bean>  
  21.         </jaxws:inInterceptors>      
  22.   
  23.     </jaxws:endpoint>  
  24.        
  25. </beans>  


2.服務(wù)端添加passwordCallbackClass回調類(lèi),該類(lèi)進(jìn)行用戶(hù)口令驗證:
Java代碼
 
  1. package cn.org.coral.biz.examples.webservice.handler;   
  2.   
  3. import java.io.IOException;   
  4.   
  5. import javax.security.auth.callback.Callback;   
  6. import javax.security.auth.callback.CallbackHandler;   
  7. import javax.security.auth.callback.UnsupportedCallbackException;   
  8.   
  9. import org.apache.ws.security.WSPasswordCallback;   
  10.   
  11. public class WsAuthHandler  implements CallbackHandler{   
  12.   
  13.     public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {   
  14.         WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];   
  15.         if (pc.getIdentifer().equals("ws-client")){   
  16.             if (!pc.getPassword().equals("admin")) {   
  17.                 throw new SecurityException("wrong password");   
  18.            }   
  19.         }else{   
  20.             throw new SecurityException("wrong username");   
  21.         }   
  22.     }   
  23.   
  24. }  


3.客戶(hù)端修改spring 配置文件 wsclient-context.xml 如下:
Xml代碼
 
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.     xmlns:jaxws="http://cxf.apache.org/jaxws"  
  5.     xsi:schemaLocation="http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans.xsd"  
  6.     default-autowire="byName" default-lazy-init="true">  
  7.   
  8.   
  9.     <!-- ws clinet -->  
  10.     <bean id="webServiceSampleClient" class="cn.org.coral.biz.examples.webservice.WebServiceSample"  
  11.         factory-bean="webServiceSampleClientFactory" factory-method="create" />  
  12.   
  13.   
  14.     <bean id="webServiceSampleClientFactory"  
  15.         class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">  
  16.         <property name="serviceClass"  
  17.             value="cn.org.coral.biz.examples.webservice.WebServiceSample" />  
  18.         <property name="address"  
  19.             value="http://88.148.29.54:8080/aio/services/WebServiceSample" />  
  20.         <property name="outInterceptors">  
  21.             <list>  
  22.                 <bean  
  23.                     class="org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor" />  
  24.                 <ref bean="wss4jOutConfiguration" />  
  25.             </list>  
  26.         </property>  
  27.     </bean>  
  28.   
  29.     <bean id="wss4jOutConfiguration"  
  30.         class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">  
  31.         <property name="properties">  
  32.             <map>  
  33.                 <entry key="action" value="UsernameToken" />  
  34.                 <entry key="user" value="ws-client" />  
  35.                 <entry key="passwordType" value="PasswordText" />  
  36.                 <entry>  
  37.                     <key>  
  38.                         <value>passwordCallbackRef</value>  
  39.                     </key>  
  40.                     <ref bean="passwordCallback" />  
  41.                 </entry>  
  42.             </map>  
  43.         </property>  
  44.     </bean>  
  45.     <bean id="passwordCallback"  
  46.         class="cn.org.coral.biz.examples.webservice.handler.WsClinetAuthHandler">  
  47.     </bean>  
  48.   
  49. </beans>  


4.客戶(hù)端添加passwordCallback類(lèi),通過(guò)該類(lèi)設置訪(fǎng)問(wèn)口令
Java代碼
 
  1. package cn.org.coral.biz.examples.webservice.handler;   
  2.   
  3. import java.io.IOException;   
  4.   
  5. import javax.security.auth.callback.Callback;   
  6. import javax.security.auth.callback.CallbackHandler;   
  7. import javax.security.auth.callback.UnsupportedCallbackException;   
  8.   
  9. import org.apache.ws.security.WSPasswordCallback;   
  10.   
  11. public class WsClinetAuthHandler  implements CallbackHandler{   
  12.   
  13.   
  14.     public void handle(Callback[] callbacks) throws IOException,    
  15.                     UnsupportedCallbackException {    
  16.             for (int i = 0; i < callbacks.length; i++) {    
  17.                     WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];    
  18.                     int usage = pc.getUsage();    
  19.   
  20.   
  21.                     System.out.println("identifier: " + pc.getIdentifer());    
  22.                     System.out.println("usage: " + pc.getUsage());    
  23.                     if (usage == WSPasswordCallback.USERNAME_TOKEN) {    
  24.                             // username token pwd...    
  25.                             pc.setPassword("admin");    
  26.   
  27.                     } else if (usage == WSPasswordCallback.SIGNATURE) {    
  28.                             // set the password for client's keystore.keyPassword    
  29.                             pc.setPassword("keyPassword");    
  30.                     }    
  31.             }    
  32.     }    
  33.   
  34. }  


5.junit單元測試程序:
Java代碼
 
  1. package cn.org.coral.biz.examples.webservice;   
  2.   
  3. import org.springframework.test.AbstractDependencyInjectionSpringContextTests;   
  4. import org.springframework.util.Assert;   
  5.   
  6. public class TestWebService extends AbstractDependencyInjectionSpringContextTests {   
  7.     WebServiceSample webServiceSampleClient;   
  8.        
  9.     @Override  
  10.     protected String[] getConfigLocations() {   
  11.         setAutowireMode(AUTOWIRE_BY_NAME);   
  12.         return new String[] { "classpath:/cn/org/coral/biz/examples/webservice/wsclient-context.xml" };   
  13.     }   
  14.   
  15.     /**  
  16.      * @param webServiceSampleClient the webServiceSampleClient to set  
  17.      */  
  18.     public void setWebServiceSampleClient(WebServiceSample webServiceSampleClient) {   
  19.         this.webServiceSampleClient = webServiceSampleClient;   
  20.     }   
  21.   
  22.     public void testSay(){   
  23.         String result = webServiceSampleClient.say(" world");   
  24.         Assert.hasText(result);        
  25.     }   
  26. }  
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
使用cxf3.0.4搭建webservice服務(wù)需要的最精簡(jiǎn)jar包
Spring和CXF整合發(fā)布WebService(服務(wù)端、客戶(hù)端)最詳細
webservice cxf 學(xué)習
簡(jiǎn)單的Jax-WS WebService實(shí)現
CXF創(chuàng )建webservice客戶(hù)端和服務(wù)端
CXF MyEclipse 開(kāi)發(fā)webservice入門(mén)實(shí)例之HelloWorld
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久