Author: dkulp Date: Thu Dec 20 20:08:10 2012 New Revision: 1424661 URL: http://svn.apache.org/viewvc?rev=1424661&view=rev Log: Merged revisions 1424658 via git cherry-pick from https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes
........ r1424658 | dkulp | 2012-12-20 15:05:26 -0500 (Thu, 20 Dec 2012) | 10 lines Merged revisions 1424642 via git cherry-pick from https://svn.apache.org/repos/asf/cxf/trunk ........ r1424642 | dkulp | 2012-12-20 14:11:41 -0500 (Thu, 20 Dec 2012) | 2 lines [CXF-4715] If an element is being looked up for encryption only, don't put a wsu-Id on it. ........ ........ Modified: cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractBindingBuilder.java cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/TransportBindingHandler.java Modified: cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractBindingBuilder.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractBindingBuilder.java?rev=1424661&r1=1424660&r2=1424661&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractBindingBuilder.java (original) +++ cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractBindingBuilder.java Thu Dec 20 20:08:10 2012 @@ -1221,7 +1221,7 @@ public abstract class AbstractBindingBui // Handle sign/enc elements try { - result.addAll(this.getElements("Element", xpaths, namespaces, found)); + result.addAll(this.getElements("Element", xpaths, namespaces, found, sign)); } catch (XPathExpressionException e) { LOG.log(Level.FINE, e.getMessage(), e); // REVISIT @@ -1229,7 +1229,7 @@ public abstract class AbstractBindingBui // Handle content encrypted elements try { - result.addAll(this.getElements("Content", contentXpaths, cnamespaces, found)); + result.addAll(this.getElements("Content", contentXpaths, cnamespaces, found, sign)); } catch (XPathExpressionException e) { LOG.log(Level.FINE, e.getMessage(), e); // REVISIT @@ -1332,6 +1332,8 @@ public abstract class AbstractBindingBui * signing/encryption. Populated with additional matches found by * this method and used to prevent including the same element * twice under the same operation. + * @param forceId + * force adding a wsu:Id onto the elements. Recommended for signatures. * @return a configured list of {@code WSEncryptionPart}s suitable for * processing by WSS4J * @throws XPathExpressionException @@ -1342,7 +1344,8 @@ public abstract class AbstractBindingBui */ protected List<WSEncryptionPart> getElements(String encryptionModifier, List<String> xpaths, Map<String, String> namespaces, - List<Element> found) throws XPathExpressionException, SOAPException { + List<Element> found, + boolean forceId) throws XPathExpressionException, SOAPException { List<WSEncryptionPart> result = new ArrayList<WSEncryptionPart>(); @@ -1360,8 +1363,21 @@ public abstract class AbstractBindingBui Element el = (Element)list.item(x); if (!found.contains(el)) { - final String id = this.addWsuIdToElement(el); - + String id = null; + if (forceId) { + id = this.addWsuIdToElement(el); + } else { + //not forcing an ID on this. Use one if there is one + //there already, but don't force one + Attr idAttr = el.getAttributeNode("Id"); + if (idAttr == null) { + //then try the wsu:Id value + idAttr = el.getAttributeNodeNS(PolicyConstants.WSU_NAMESPACE_URI, "Id"); + } + if (idAttr != null) { + id = idAttr.getValue(); + } + } WSEncryptionPart part = new WSEncryptionPart(id, encryptionModifier); part.setElement(el); Modified: cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/TransportBindingHandler.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/TransportBindingHandler.java?rev=1424661&r1=1424660&r2=1424661&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/TransportBindingHandler.java (original) +++ cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/TransportBindingHandler.java Thu Dec 20 20:08:10 2012 @@ -590,7 +590,7 @@ public class TransportBindingHandler ext result.addAll( this.getElements( "Element", signedElements.getXPathExpressions(), - signedElements.getDeclaredNamespaces(), found + signedElements.getDeclaredNamespaces(), found, true ) ); } catch (XPathExpressionException e) {
