国产gaysexchina男同gay,japanrcep老熟妇乱子伦视频,吃奶呻吟打开双腿做受动态图,成人色网站,国产av一区二区三区最新精品

8.3.為Webservice添加Security認證

2023-07-03 17:26 更新
前面我們介紹過,要為在BDF2-SERVICE模塊當中發(fā)布的Webservice添加WS-Secrutiy認證,可以覆蓋bdf2.webservice.useSecurity屬性值,將這個屬性值設置為true即可,這樣所以的發(fā)布的Webservice就全部需要WS-Security認證了。但實際應用當中,我們發(fā)布的Webservice當中可能有些需要進行認證,但還有一些我們是希望用戶不用任何認證就可以直接訪問的,這樣就要求我們發(fā)布的Webservice可以獨立控制自己是否需要進行WS-Security認證。

在BDF2-SERVICE模塊當中,要想讓發(fā)布的Webservice自已決定是否添加WS-Security認證,我們只需要我們的Endpoint類實現(xiàn)IWebservice接口即可,這個接口源碼如下:
IWebService接口源碼
package com.bstek.bdf2.webservice.jaxb;
/**
 * @author Jacky.gao
 * @since 2013-3-6
 */
public interface IWebservice {
 Class<?>[] bindClasses();
 boolean useSecurity();
}
可以看到,這個接口非常簡單,只有兩個方法需要我們實現(xiàn),第一個bindClasses用于將需要進行XML與JavaBean之間進行相互轉換的類返回(unmarshaller與marshaller);第二個方法useSecurity就用來標明當前Webservice是否需要WS-Security認證,返回true表示需要,false表示不需要。

修改我們的UserServiceEndpoint類,讓其實現(xiàn)IWebservice接口,修改后的代碼如下:
修改后的UserServiceEndpoint類源碼
package ws;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
import org.springframework.ws.soap.addressing.server.annotation.Action;
import com.bstek.bdf2.webservice.jaxb.IWebservice;
@Endpoint
public class UserServiceEndpoint implements IWebservice{
 @PayloadRoot(localPart="UserRequest",namespace="http://www.bstek.com/ws")
 public @ResponsePayload UserResponse getUsers(@RequestPayload UserRequest request){
 int userCount=request.getUserCount();
 String targetCompanyId=request.getTargetCompany();
 UserResponse response=new UserResponse();
 List<User> users=new ArrayList<User>();
 for(int i=0;i<userCount;i++){
 User user=new User();
 user.setBirthday(new Date());
 user.setCompanyId(targetCompanyId);
 user.setGender(true);
 user.setUsername("user"+i);
 users.add(user);
 }
 response.setUsers(users);
 return response;
 }
 public Class<?>[] bindClasses() {
 return new Class[]{UserResponse.class,UserRequest.class,User.class};
 }
 public boolean useSecurity() {
 return true;
 }
}
重啟我們的工程,再次通過SoapUI調(diào)用我們的Webservice,可以在右邊響應窗口當中看到如下圖所示信息:

提示我們需要在調(diào)用目標Webservice時添加WS-Security的header,否則目標Webservice不允許調(diào)用。對于SoapUI來說,它支持標準的WS-Security認證,我們需要做就是雙擊左邊樹形導航的DemoUserRequestSoap11節(jié)點,在彈出的窗口當中定義相應的用戶名及密碼,同時需要將WSS-Type屬性值改為PasswordDigest,表示Soap消息的header當中采用加密方式傳遞用戶名及密碼信息,如下圖所示:

再點用SoapUI請求服務,可以看到已經(jīng)能正確得到響應結果了。

這里需要特別指出的是,這里定義的username及password一定要與bdf2.webservice.userServiceBean屬性定義的UserDetailsService實現(xiàn)類訪問的用戶信息對應,同時其中的password也必須是用戶的實際存儲的密碼,比如,如果用戶的密碼是以密文形式存放的,這里也要輸入具體的密文,而不能是加密之前的密碼。

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號