Repository: cxf Updated Branches: refs/heads/master 7ac69b005 -> 341507ae7
Simply Crypto loading for streaming code Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/341507ae Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/341507ae Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/341507ae Branch: refs/heads/master Commit: 341507ae77002786170a0d135dce3d257cf814c7 Parents: 7ac69b0 Author: Colm O hEigeartaigh <[email protected]> Authored: Tue Apr 15 23:23:50 2014 +0100 Committer: Colm O hEigeartaigh <[email protected]> Committed: Wed Apr 16 00:15:02 2014 +0100 ---------------------------------------------------------------------- .../PolicyBasedWSS4JStaxInInterceptor.java | 31 ++++-------- .../PolicyBasedWSS4JStaxOutInterceptor.java | 31 ++++-------- .../security/wss4j/WSS4JStaxInInterceptor.java | 2 +- .../security/wss4j/WSS4JStaxOutInterceptor.java | 53 ++++++++++++-------- 4 files changed, 54 insertions(+), 63 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/341507ae/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWSS4JStaxInInterceptor.java ---------------------------------------------------------------------- diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWSS4JStaxInInterceptor.java b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWSS4JStaxInInterceptor.java index f05081b..2fb0a9d 100644 --- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWSS4JStaxInInterceptor.java +++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWSS4JStaxInInterceptor.java @@ -47,7 +47,6 @@ import org.apache.cxf.ws.security.SecurityConstants; import org.apache.wss4j.common.WSSPolicyException; import org.apache.wss4j.common.crypto.Crypto; import org.apache.wss4j.common.ext.WSSecurityException; -import org.apache.wss4j.dom.handler.WSHandlerConstants; import org.apache.wss4j.policy.SP12Constants; import org.apache.wss4j.policy.SPConstants; import org.apache.wss4j.policy.model.AlgorithmSuite; @@ -112,16 +111,13 @@ public class PolicyBasedWSS4JStaxInInterceptor extends WSS4JStaxInInterceptor { } if (signCrypto != null) { - message.put(WSHandlerConstants.DEC_PROP_REF_ID, "RefId-" + signCrypto.hashCode()); - message.put("RefId-" + signCrypto.hashCode(), signCrypto); + securityProperties.setDecryptionCrypto(signCrypto); } if (encrCrypto != null) { - message.put(WSHandlerConstants.SIG_VER_PROP_REF_ID, "RefId-" + encrCrypto.hashCode()); - message.put("RefId-" + encrCrypto.hashCode(), (Crypto)encrCrypto); + securityProperties.setSignatureVerificationCrypto(encrCrypto); } else if (signCrypto != null) { - message.put(WSHandlerConstants.SIG_VER_PROP_REF_ID, "RefId-" + signCrypto.hashCode()); - message.put("RefId-" + signCrypto.hashCode(), (Crypto)signCrypto); + securityProperties.setSignatureVerificationCrypto(signCrypto); } } @@ -171,16 +167,13 @@ public class PolicyBasedWSS4JStaxInInterceptor extends WSS4JStaxInInterceptor { } if (signCrypto != null) { - message.put(WSHandlerConstants.DEC_PROP_REF_ID, "RefId-" + signCrypto.hashCode()); - message.put("RefId-" + signCrypto.hashCode(), signCrypto); + securityProperties.setDecryptionCrypto(signCrypto); } if (encrCrypto != null) { - message.put(WSHandlerConstants.SIG_VER_PROP_REF_ID, "RefId-" + encrCrypto.hashCode()); - message.put("RefId-" + encrCrypto.hashCode(), (Crypto)encrCrypto); + securityProperties.setSignatureVerificationCrypto(encrCrypto); } else if (signCrypto != null) { - message.put(WSHandlerConstants.SIG_VER_PROP_REF_ID, "RefId-" + signCrypto.hashCode()); - message.put("RefId-" + signCrypto.hashCode(), (Crypto)signCrypto); + securityProperties.setSignatureVerificationCrypto(signCrypto); } } @@ -228,8 +221,7 @@ public class PolicyBasedWSS4JStaxInInterceptor extends WSS4JStaxInInterceptor { crypto = signCrypto; } if (crypto != null) { - message.put(WSHandlerConstants.SIG_VER_PROP_REF_ID, "RefId-" + crypto.hashCode()); - message.put("RefId-" + crypto.hashCode(), crypto); + securityProperties.setSignatureCrypto(crypto); } crypto = signCrypto; @@ -237,8 +229,7 @@ public class PolicyBasedWSS4JStaxInInterceptor extends WSS4JStaxInInterceptor { crypto = encrCrypto; } if (crypto != null) { - message.put(WSHandlerConstants.DEC_PROP_REF_ID, "RefId-" + crypto.hashCode()); - message.put("RefId-" + crypto.hashCode(), crypto); + securityProperties.setDecryptionCrypto(crypto); } } else { Crypto crypto = signCrypto; @@ -246,8 +237,7 @@ public class PolicyBasedWSS4JStaxInInterceptor extends WSS4JStaxInInterceptor { crypto = encrCrypto; } if (crypto != null) { - message.put(WSHandlerConstants.SIG_VER_PROP_REF_ID, "RefId-" + crypto.hashCode()); - message.put("RefId-" + crypto.hashCode(), crypto); + securityProperties.setSignatureVerificationCrypto(crypto); } crypto = encrCrypto; @@ -255,8 +245,7 @@ public class PolicyBasedWSS4JStaxInInterceptor extends WSS4JStaxInInterceptor { crypto = signCrypto; } if (crypto != null) { - message.put(WSHandlerConstants.DEC_PROP_REF_ID, "RefId-" + crypto.hashCode()); - message.put("RefId-" + crypto.hashCode(), crypto); + securityProperties.setDecryptionCrypto(crypto); } } } http://git-wip-us.apache.org/repos/asf/cxf/blob/341507ae/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWSS4JStaxOutInterceptor.java ---------------------------------------------------------------------- diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWSS4JStaxOutInterceptor.java b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWSS4JStaxOutInterceptor.java index 5530e38..a3befb3 100644 --- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWSS4JStaxOutInterceptor.java +++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWSS4JStaxOutInterceptor.java @@ -32,7 +32,6 @@ import org.apache.cxf.ws.security.wss4j.policyhandlers.StaxSymmetricBindingHandl import org.apache.cxf.ws.security.wss4j.policyhandlers.StaxTransportBindingHandler; import org.apache.wss4j.common.crypto.Crypto; import org.apache.wss4j.common.ext.WSSecurityException; -import org.apache.wss4j.dom.handler.WSHandlerConstants; import org.apache.wss4j.policy.SPConstants; import org.apache.wss4j.policy.model.AsymmetricBinding; import org.apache.wss4j.policy.model.SymmetricBinding; @@ -83,16 +82,13 @@ public class PolicyBasedWSS4JStaxOutInterceptor extends WSS4JStaxOutInterceptor } if (signCrypto != null) { - message.put(WSHandlerConstants.SIG_PROP_REF_ID, "RefId-" + signCrypto.hashCode()); - message.put("RefId-" + signCrypto.hashCode(), signCrypto); + securityProperties.setSignatureCrypto(signCrypto); } if (encrCrypto != null) { - message.put(WSHandlerConstants.ENC_PROP_REF_ID, "RefId-" + encrCrypto.hashCode()); - message.put("RefId-" + encrCrypto.hashCode(), (Crypto)encrCrypto); + securityProperties.setEncryptionCrypto(encrCrypto); } else if (signCrypto != null) { - message.put(WSHandlerConstants.ENC_PROP_REF_ID, "RefId-" + signCrypto.hashCode()); - message.put("RefId-" + signCrypto.hashCode(), (Crypto)signCrypto); + securityProperties.setEncryptionCrypto(signCrypto); } } @@ -117,16 +113,13 @@ public class PolicyBasedWSS4JStaxOutInterceptor extends WSS4JStaxOutInterceptor } if (signCrypto != null) { - message.put(WSHandlerConstants.SIG_PROP_REF_ID, "RefId-" + signCrypto.hashCode()); - message.put("RefId-" + signCrypto.hashCode(), signCrypto); + securityProperties.setSignatureCrypto(signCrypto); } if (encrCrypto != null) { - message.put(WSHandlerConstants.ENC_PROP_REF_ID, "RefId-" + encrCrypto.hashCode()); - message.put("RefId-" + encrCrypto.hashCode(), (Crypto)encrCrypto); + securityProperties.setEncryptionCrypto(encrCrypto); } else if (signCrypto != null) { - message.put(WSHandlerConstants.ENC_PROP_REF_ID, "RefId-" + signCrypto.hashCode()); - message.put("RefId-" + signCrypto.hashCode(), (Crypto)signCrypto); + securityProperties.setEncryptionCrypto(signCrypto); } } @@ -156,8 +149,7 @@ public class PolicyBasedWSS4JStaxOutInterceptor extends WSS4JStaxOutInterceptor crypto = signCrypto; } if (crypto != null) { - message.put(WSHandlerConstants.ENC_PROP_REF_ID, "RefId-" + crypto.hashCode()); - message.put("RefId-" + crypto.hashCode(), crypto); + securityProperties.setEncryptionCrypto(crypto); } crypto = signCrypto; @@ -165,8 +157,7 @@ public class PolicyBasedWSS4JStaxOutInterceptor extends WSS4JStaxOutInterceptor crypto = encrCrypto; } if (crypto != null) { - message.put(WSHandlerConstants.SIG_PROP_REF_ID, "RefId-" + crypto.hashCode()); - message.put("RefId-" + crypto.hashCode(), crypto); + securityProperties.setSignatureCrypto(crypto); } } else { Crypto crypto = signCrypto; @@ -174,8 +165,7 @@ public class PolicyBasedWSS4JStaxOutInterceptor extends WSS4JStaxOutInterceptor crypto = encrCrypto; } if (crypto != null) { - message.put(WSHandlerConstants.ENC_PROP_REF_ID, "RefId-" + crypto.hashCode()); - message.put("RefId-" + crypto.hashCode(), crypto); + securityProperties.setEncryptionCrypto(crypto); } crypto = encrCrypto; @@ -183,8 +173,7 @@ public class PolicyBasedWSS4JStaxOutInterceptor extends WSS4JStaxOutInterceptor crypto = signCrypto; } if (crypto != null) { - message.put(WSHandlerConstants.SIG_PROP_REF_ID, "RefId-" + crypto.hashCode()); - message.put("RefId-" + crypto.hashCode(), crypto); + securityProperties.setSignatureCrypto(crypto); } } } http://git-wip-us.apache.org/repos/asf/cxf/blob/341507ae/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxInInterceptor.java ---------------------------------------------------------------------- diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxInInterceptor.java b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxInInterceptor.java index 73886bb..f0a4a79 100644 --- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxInInterceptor.java +++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxInInterceptor.java @@ -236,7 +236,7 @@ public class WSS4JStaxInInterceptor extends AbstractWSS4JStaxInterceptor { // Crypto loading only applies for Map Map<String, Object> config = getProperties(); - if (config != null) { + if (config != null && !config.isEmpty()) { Crypto sigVerCrypto = loadCrypto( msg, http://git-wip-us.apache.org/repos/asf/cxf/blob/341507ae/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxOutInterceptor.java ---------------------------------------------------------------------- diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxOutInterceptor.java b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxOutInterceptor.java index bb825e1..4c98498 100644 --- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxOutInterceptor.java +++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxOutInterceptor.java @@ -207,23 +207,22 @@ public class WSS4JStaxOutInterceptor extends AbstractWSS4JStaxInterceptor { SoapMessage msg, OutboundSecurityContext outboundSecurityContext, WSSSecurityProperties securityProperties ) throws WSSecurityException { - Map<String, Object> config = getProperties(); + String user = (String)msg.getContextualProperty(SecurityConstants.USERNAME); + if (user != null) { + securityProperties.setTokenUser(user); + } + String sigUser = (String)msg.getContextualProperty(SecurityConstants.SIGNATURE_USERNAME); + if (sigUser != null) { + securityProperties.setSignatureUser(sigUser); + } + String encUser = (String)msg.getContextualProperty(SecurityConstants.ENCRYPT_USERNAME); + if (encUser != null) { + securityProperties.setEncryptionUser(encUser); + } // Crypto loading only applies for Map - if (config != null) { - String user = (String)msg.getContextualProperty(SecurityConstants.USERNAME); - if (user != null) { - securityProperties.setTokenUser(user); - } - String sigUser = (String)msg.getContextualProperty(SecurityConstants.SIGNATURE_USERNAME); - if (sigUser != null) { - securityProperties.setSignatureUser(sigUser); - } - String encUser = (String)msg.getContextualProperty(SecurityConstants.ENCRYPT_USERNAME); - if (encUser != null) { - securityProperties.setEncryptionUser(encUser); - } - + Map<String, Object> config = getProperties(); + if (config != null && !config.isEmpty()) { Crypto sigCrypto = loadCrypto( msg, @@ -256,14 +255,28 @@ public class WSS4JStaxOutInterceptor extends AbstractWSS4JStaxInterceptor { } } ConfigurationConverter.parseCrypto(config, securityProperties); - - if (securityProperties.getSignatureUser() == null && user != null) { - securityProperties.setSignatureUser(user); + } else { + Crypto sigCrypto = securityProperties.getSignatureCrypto(); + if (sigCrypto != null && sigUser == null + && sigCrypto.getDefaultX509Identifier() != null) { + // Fall back to default identifier + securityProperties.setSignatureUser(sigCrypto.getDefaultX509Identifier()); } - if (securityProperties.getEncryptionUser() == null && user != null) { - securityProperties.setEncryptionUser(user); + + Crypto encrCrypto = securityProperties.getEncryptionCrypto(); + if (encrCrypto != null && encUser == null + && encrCrypto.getDefaultX509Identifier() != null) { + // Fall back to default identifier + securityProperties.setEncryptionUser(encrCrypto.getDefaultX509Identifier()); } } + + if (securityProperties.getSignatureUser() == null && user != null) { + securityProperties.setSignatureUser(user); + } + if (securityProperties.getEncryptionUser() == null && user != null) { + securityProperties.setEncryptionUser(user); + } } public final WSS4JStaxOutInterceptorInternal createEndingInterceptor() {
