You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2019/06/11 10:04:44 UTC
[cxf] branch master updated: Adding a test to show how to use
Handler ActionTokens with WS-Security.
This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/master by this push:
new ad557fb Adding a test to show how to use Handler ActionTokens with WS-Security.
ad557fb is described below
commit ad557fb51f2391b449c692ee47cc7856ff9e201a
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Tue Jun 11 11:03:22 2019 +0100
Adding a test to show how to use Handler ActionTokens with WS-Security.
---
.../apache/cxf/systest/ws/action/ActionTest.java | 52 ++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/action/ActionTest.java b/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/action/ActionTest.java
index 1e20c1c..24b7604 100644
--- a/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/action/ActionTest.java
+++ b/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/action/ActionTest.java
@@ -23,6 +23,7 @@ import java.io.StringReader;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -50,8 +51,13 @@ import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
import org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor;
import org.apache.wss4j.common.ConfigurationConstants;
+import org.apache.wss4j.common.SignatureActionToken;
+import org.apache.wss4j.common.crypto.Crypto;
import org.apache.wss4j.common.crypto.CryptoFactory;
import org.apache.wss4j.common.ext.WSSecurityException;
+import org.apache.wss4j.dom.WSConstants;
+import org.apache.wss4j.dom.handler.HandlerAction;
+import org.apache.wss4j.dom.handler.WSHandlerConstants;
import org.apache.wss4j.stax.ext.WSSConstants;
import org.apache.wss4j.stax.ext.WSSSecurityProperties;
import org.apache.wss4j.stax.securityToken.WSSecurityTokenConstants;
@@ -719,4 +725,50 @@ public class ActionTest extends AbstractBusClientServerTestBase {
bus.shutdown(true);
}
+ @org.junit.Test
+ public void testSignatureHandlerActions() throws Exception {
+
+ SpringBusFactory bf = new SpringBusFactory();
+ URL busFile = ActionTest.class.getResource("client.xml");
+
+ Bus bus = bf.createBus(busFile.toString());
+ BusFactory.setDefaultBus(bus);
+ BusFactory.setThreadDefaultBus(bus);
+
+ URL wsdl = ActionTest.class.getResource("DoubleItAction.wsdl");
+ Service service = Service.create(wsdl, SERVICE_QNAME);
+ QName portQName = new QName(NAMESPACE, "DoubleItSignatureConfigPort");
+
+ DoubleItPortType port =
+ service.getPort(portQName, DoubleItPortType.class);
+ updateAddressPort(port, PORT);
+
+ // Programmatic interceptor
+ Map<String, Object> props = new HashMap<>();
+ HandlerAction signatureAction = new HandlerAction();
+ signatureAction.setAction(WSConstants.SIGN);
+
+ SignatureActionToken actionToken = new SignatureActionToken();
+ actionToken.setUser("alice");
+ actionToken.setKeyIdentifierId(WSConstants.BST_DIRECT_REFERENCE);
+
+ Properties cryptoProperties = CryptoFactory.getProperties("alice.properties", this.getClass().getClassLoader());
+ Crypto crypto =
+ CryptoFactory.getInstance(cryptoProperties, this.getClass().getClassLoader(), null);
+ actionToken.setCrypto(crypto);
+ signatureAction.setActionToken(actionToken);
+
+ List<HandlerAction> actions = Collections.singletonList(signatureAction);
+
+ props.put(WSHandlerConstants.HANDLER_ACTIONS, actions);
+ props.put(ConfigurationConstants.PW_CALLBACK_REF, new KeystorePasswordCallback());
+ WSS4JOutInterceptor outInterceptor = new WSS4JOutInterceptor(props);
+ Client client = ClientProxy.getClient(port);
+ client.getOutInterceptors().add(outInterceptor);
+
+ assertEquals(50, port.doubleIt(25));
+
+ ((java.io.Closeable)port).close();
+ bus.shutdown(true);
+ }
}