[英]Java Web Service client with keystore
也许我可以在这里找到一些帮助。 我需要访问Web服务,但首先需要使用密钥库对客户端进行身份验证。 我不能用弹簧。 在spring-ws.xml中,这种配置适用于我的同事的客户:
<bean class="org.springframework.ws.soap.security.wss4j.support.CryptoFactoryBean" id="clientCrypto">
<property name="configuration">
<util:properties>
<prop key="org.apache.ws.security.crypto.provider">org.apache.ws.security.components.crypto.Merlin</prop>
<prop key="org.apache.ws.security.crypto.merlin.keystore.type">jks</prop>
<prop key="org.apache.ws.security.crypto.merlin.keystore.password">${esb.keystore.password}</prop>
<prop key="org.apache.ws.security.crypto.merlin.keystore.alias">${esb.keystore.user}</prop>
<prop key="org.apache.ws.security.crypto.merlin.file">src\main\resources\${esb.keystore.location}</prop>
</util:properties>
</property>
</bean>
我的客户是这样的:
PortalCustomerService service = new PortalCustomerService();
PortalCustomerPortType port = service.getSomethingHttpPort();
BindingProvider bindingProvider = (BindingProvider) port;
Binding binding = bindingProvider.getBinding();
List<Handler> handlerList = binding.getHandlerChain();
handlerList.add(new MyHandler());
binding.setHandlerChain(handlerList);
//calling webmethod
MyResponse response = port.checkClients(getRequest());
MyHandler具有如下方法handleMessage:
public boolean handleMessage(SOAPMessageContext messageContext) {
Boolean outboundProperty = (Boolean) messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outboundProperty.booleanValue()) {
// I think I need to add something here but I dont know what
} else {}
return true;
}
我有私钥:myportal.key,公钥:portal.cer。
未经身份验证,我得到:
javax.xml.ws.soap.SOAPFaultException: An error was discovered processing the <wsse:Security> header
您可以通过以下方式获得一些帮助
System.setProperty("javax.net.debug","all");
如果密钥是自签名的,那么您可能还需要设置TrustStore
属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.