我正在嘗試在 下開發(fā) SOAP Web 服務(wù)Apache CXF 3.0.4,但我無法UsernameToken使用 WS-SecurityPolicy驗證每個 SOAP 消息頭中包含的 SOAP 消息。根據(jù)文檔,如果cxf-rt-ws-policy和cxf-rt-ws-security模塊在classpath. 在正確配置后,它會完成處理安全性的必要工作。我通過端點屬性注釋進行配置,方式如下:@WebService(targetNamespace = "http://tempuri.org/", name = "MyService")@EndpointProperties(value = { @EndpointProperty(key = "ws-security.callback-handler", value = "org.tempuri.ServerPasswordCallback") //@EndpointProperty(key = "ws-security.validate.token", value = "false") })public interface MyService {...}ServerPasswordCallback 是:public class ServerPasswordCallback implements CallbackHandler { public ServerPasswordCallback() { System.out.println("Instantiating ServerPasswordCallback"); } public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { System.out.println("Validating on ServerPasswordCallback"); WSPasswordCallback pc = (WSPasswordCallback) callbacks[0]; if (pc.getIdentifier().equals("joe")) { // set the password on the callback. This will be compared to the // password which was sent from the client. pc.setPassword("password"); } }}奇怪的是,它似乎ServerPasswordCallback從未被實例化,handle()也從未被調(diào)用。如果在端點屬性注釋中我設(shè)置ws-security.validate.token為false,則拋出前一個異常,即使此屬性應(yīng)阻止令牌驗證。這個事實讓我認為注釋不起作用,但我不知道為什么。這是驗證 a 的正確方法UsernameToken嗎?端點屬性注釋是否正確?注意我無法像文檔中建議的那樣設(shè)置端點屬性,因為我無法訪問端點實例。這里有一個示例項目
添加回答
舉報
0/150
提交
取消