国产chinesehdxxxx野外,国产av无码专区亚洲av琪琪,播放男人添女人下边视频,成人国产精品一区二区免费看,chinese丰满人妻videos

8.3.為Webservice添加Security認(rèn)證

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

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

修改我們的UserServiceEndpoint類,讓其實(shí)現(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,可以在右邊響應(yīng)窗口當(dāng)中看到如下圖所示信息:

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

再點(diǎn)用SoapUI請(qǐng)求服務(wù),可以看到已經(jīng)能正確得到響應(yīng)結(jié)果了。

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

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

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)