webService 下得 攔截

來源:互聯網
上載者:User

標籤:message   actor   else   content   point   資訊   org   contents   exce   

當我們 對webservice 介面的 攔截 更具許可權  來 判斷 是否可以調用  一下是我的 一個demo

   首先 我們寫一個 攔截類  

       

import javax.xml.soap.SOAPException;

import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageContentsList;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
import org.springframework.beans.factory.annotation.Autowired;

import com.sinotrans.eaiconsole.model.EsUserModel;
import com.sinotrans.eaiconsole.user.service.LoginManager;

public class WebServiceUserAuthorityInterceptor extends AbstractPhaseInterceptor<Message> {

@Autowired
LoginManager loginManager;

public WebServiceUserAuthorityInterceptor() {
super(Phase.PRE_INVOKE);

}

public void handleMessage(Message message) throws Fault { // 指定CXF擷取用戶端的HttpServletRequest
// :
// http-request;

MessageContentsList contents = MessageContentsList
.getContentsList(message);

String userName = "", pwd = "";

if (contents != null && contents.size() > 0) {

userName = (String) contents.get(0);

pwd = (String) contents.get(1);

EsUserModel eum = loginManager.longinWebServiceUserAuthority(
userName, pwd);

if (null == eum) {

SOAPException soapExc = new SOAPException("使用者名稱密碼認證失敗");
throw new Fault(soapExc);
}
} else {
SOAPException soapExc = new SOAPException("未輸入參數資訊");
throw new Fault(soapExc);
}
}

}

 

接著我們在  cxf 裡配置如下

//我們的攔截類 注入進去  

<bean id="inMessageInterceptor"
class="com.sinotrans.eaiconsole.Interceptor.WebServiceUserAuthorityInterceptor">

</bean>

 

//給需要攔截的  方法 注入 我們的攔截類

<jaxws:endpoint id="lMSWebService"
implementor="com.sinotrans.eaiconsole.service.impl.LMSWebServiceImpl"
address="/lMSWebService">

<jaxws:inInterceptors>
<ref bean="inMessageInterceptor" />
</jaxws:inInterceptors>

</jaxws:endpoint>

 

webService 下得 攔截

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.