Author: dkulp
Date: Thu Jan 8 09:58:26 2009
New Revision: 732773
URL: http://svn.apache.org/viewvc?rev=732773&view=rev
Log:
[CXF-1964] Patch from Colm applied to allow processors to be registered as
objects instead of just class names.
Added:
cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/CustomProcessor.java
(with props)
Modified:
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java
cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/WSS4JInOutTest.java
Modified:
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java?rev=732773&r1=732772&r2=732773&view=diff
==============================================================================
---
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java
(original)
+++
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java
Thu Jan 8 09:58:26 2009
@@ -67,6 +67,7 @@
import org.apache.ws.security.handler.WSHandlerResult;
import org.apache.ws.security.message.token.SecurityTokenReference;
import org.apache.ws.security.message.token.Timestamp;
+import org.apache.ws.security.processor.Processor;
import org.apache.ws.security.util.WSSecurityUtil;
/**
@@ -108,7 +109,7 @@
public WSS4JInInterceptor(Map<String, Object> properties) {
this();
setProperties(properties);
- final Map<QName, String> map = CastUtils.cast(
+ final Map<QName, Object> map = CastUtils.cast(
(Map)properties.get(PROCESSOR_MAP));
if (map != null) {
secEngineOverride = createSecurityEngine(map);
@@ -462,20 +463,25 @@
*/
private WSSecurityEngine
createSecurityEngine(
- final Map<QName, String> map
+ final Map<QName, Object> map
) {
assert map != null;
final WSSConfig config = WSSConfig.getNewInstance();
- for (Map.Entry<QName, String> entry : map.entrySet()) {
+ for (Map.Entry<QName, Object> entry : map.entrySet()) {
final QName key = entry.getKey();
- String val = entry.getValue();
- if (val != null) {
- val = val.trim();
- if ("null".equals(val) || val.length() == 0) {
- val = null;
+ Object val = entry.getValue();
+
+ if (val instanceof String) {
+ String valStr = ((String)val).trim();
+ if ("null".equals(valStr) || valStr.length() == 0) {
+ valStr = null;
}
+ config.setProcessor(key, valStr);
+ } else if (val instanceof Processor) {
+ config.setProcessor(key, (Processor)val);
+ } else if (val == null) {
+ config.setProcessor(key, (String)val);
}
- config.setProcessor(key, val);
}
final WSSecurityEngine ret = new WSSecurityEngine();
ret.setWssConfig(config);
Added:
cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/CustomProcessor.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/CustomProcessor.java?rev=732773&view=auto
==============================================================================
---
cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/CustomProcessor.java
(added)
+++
cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/CustomProcessor.java
Thu Jan 8 09:58:26 2009
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.ws.security.wss4j;
+
+import org.apache.ws.security.WSConstants;
+import org.apache.ws.security.WSDocInfo;
+import org.apache.ws.security.WSSConfig;
+import org.apache.ws.security.WSSecurityEngineResult;
+import org.apache.ws.security.WSSecurityException;
+import org.apache.ws.security.components.crypto.Crypto;
+import org.apache.ws.security.message.token.SecurityContextToken;
+import org.apache.ws.security.processor.Processor;
+
+/**
+ * a custom processor that inserts itself into the results vector
+ */
+public class CustomProcessor implements Processor {
+
+ public final void
+ handleToken(
+ final org.w3c.dom.Element elem,
+ final Crypto crypto,
+ final Crypto decCrypto,
+ final javax.security.auth.callback.CallbackHandler cb,
+ final WSDocInfo wsDocInfo,
+ final java.util.Vector returnResults,
+ final WSSConfig config
+ ) throws WSSecurityException {
+ final java.util.Map result =
+ new WSSecurityEngineResult(
+ WSConstants.SIGN,
+ (SecurityContextToken) null
+ );
+ result.put("foo", this);
+ returnResults.add(result);
+ }
+
+ public final String getId() {
+ return getClass().getName();
+ }
+}
Propchange:
cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/CustomProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/CustomProcessor.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/WSS4JInOutTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/WSS4JInOutTest.java?rev=732773&r1=732772&r2=732773&view=diff
==============================================================================
---
cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/WSS4JInOutTest.java
(original)
+++
cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/WSS4JInOutTest.java
Thu Jan 8 09:58:26 2009
@@ -374,6 +374,83 @@
assertNull(result);
}
+
+ @Test
+ public void testCustomProcessorObject() throws Exception {
+ Document doc = readDocument("wsse-request-clean.xml");
+
+ WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
+ PhaseInterceptor<SoapMessage> handler =
ohandler.createEndingInterceptor();
+
+ SoapMessage msg = new SoapMessage(new MessageImpl());
+ Exchange ex = new ExchangeImpl();
+ ex.setInMessage(msg);
+
+ SOAPMessage saajMsg = MessageFactory.newInstance().createMessage();
+ SOAPPart part = saajMsg.getSOAPPart();
+ part.setContent(new DOMSource(doc));
+ saajMsg.saveChanges();
+
+ msg.setContent(SOAPMessage.class, saajMsg);
+
+ msg.put(WSHandlerConstants.ACTION, WSHandlerConstants.SIGNATURE);
+ msg.put(WSHandlerConstants.SIG_PROP_FILE,
"META-INF/cxf/outsecurity.properties");
+ msg.put(WSHandlerConstants.USER, "myalias");
+ msg.put("password", "myAliasPassword");
+
+ handler.handleMessage(msg);
+
+ doc = part;
+
+ assertValid("//wsse:Security", doc);
+ assertValid("//wsse:Security/ds:Signature", doc);
+
+ byte[] docbytes = getMessageBytes(doc);
+ XMLStreamReader reader = StaxUtils.createXMLStreamReader(new
ByteArrayInputStream(docbytes));
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+
+ dbf.setValidating(false);
+ dbf.setIgnoringComments(false);
+ dbf.setIgnoringElementContentWhitespace(true);
+ dbf.setNamespaceAware(true);
+
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ db.setEntityResolver(new NullResolver());
+ doc = StaxUtils.read(db, reader, false);
+
+ final Map<String, Object> properties = new HashMap<String, Object>();
+ final Map<QName, Object> customMap = new HashMap<QName, Object>();
+ customMap.put(
+ new QName(
+ WSConstants.SIG_NS,
+ WSConstants.SIG_LN
+ ),
+ new CustomProcessor()
+ );
+ properties.put(
+ WSS4JInInterceptor.PROCESSOR_MAP,
+ customMap
+ );
+ WSS4JInInterceptor inHandler = new WSS4JInInterceptor(properties);
+
+ SoapMessage inmsg = new SoapMessage(new MessageImpl());
+ ex.setInMessage(inmsg);
+ inmsg.setContent(SOAPMessage.class, saajMsg);
+
+ inHandler.setProperty(WSHandlerConstants.ACTION,
WSHandlerConstants.SIGNATURE);
+
+ inHandler.handleMessage(inmsg);
+
+ WSSecurityEngineResult result =
+ (WSSecurityEngineResult)
inmsg.get(WSS4JInInterceptor.SIGNATURE_RESULT);
+ assertNotNull(result);
+
+ Object obj = result.get("foo");
+ assertNotNull(obj);
+ assertEquals(obj.getClass().getName(),
CustomProcessor.class.getName());
+ }
+
private byte[] getMessageBytes(Document doc) throws Exception {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
XMLStreamWriter byteArrayWriter =
StaxUtils.createXMLStreamWriter(outputStream);