This is an automated email from the ASF dual-hosted git repository. coheigea pushed a commit to branch 3.2.x-fixes in repository https://gitbox.apache.org/repos/asf/cxf.git
commit b0b946e3271fd581eb0c1738ab6866366c858b60 Author: Colm O hEigeartaigh <[email protected]> AuthorDate: Fri Jul 19 11:08:02 2019 +0100 CXF-8077 - WSS4JInInterceptor is not thread safe (cherry picked from commit 9ab0d2766695a2ba9f1ed1ca042b5d2a42eb4fd9) # Conflicts: # rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java --- .../cxf/ws/security/wss4j/WSS4JInInterceptor.java | 53 +++++++++++++++------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java index 9b47702..f40ddd1 100644 --- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java +++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java @@ -104,7 +104,8 @@ public class WSS4JInInterceptor extends AbstractWSS4JInterceptor { /** * */ - private WSSecurityEngine secEngineOverride; + private WSSConfig defaultConfig; + public WSS4JInInterceptor() { super(); @@ -121,19 +122,42 @@ public class WSS4JInInterceptor extends AbstractWSS4JInterceptor { public WSS4JInInterceptor(Map<String, Object> properties) { this(); setProperties(properties); + WSSConfig config = WSSConfig.getNewInstance(); + + // Set any custom WSS4J Processor instances that are configured final Map<QName, Object> processorMap = CastUtils.cast( (Map<?, ?>)properties.get(PROCESSOR_MAP)); - final Map<QName, Object> validatorMap = CastUtils.cast( - (Map<?, ?>)properties.get(VALIDATOR_MAP)); - if (processorMap != null) { - if (validatorMap != null) { - processorMap.putAll(validatorMap); + for (Map.Entry<QName, Object> entry : processorMap.entrySet()) { + Object val = entry.getValue(); + if (val instanceof Class<?>) { + config.setProcessor(entry.getKey(), (Class<?>)val); + } else if (val instanceof Processor) { + config.setProcessor(entry.getKey(), (Processor)val); + } else if (val == null) { + config.setProcessor(entry.getKey(), (Class<?>)null); + } + } + } + + // Set any custom WSS4J Validator instances that are configured + Map<QName, Object> validatorMap = CastUtils.cast( + (Map<?, ?>)properties.get(VALIDATOR_MAP)); + if (validatorMap == null) { + validatorMap = CastUtils.cast((Map<?, ?>)properties.get(ConfigurationConstants.VALIDATOR_MAP)); + } + if (validatorMap != null) { + for (Map.Entry<QName, Object> entry : validatorMap.entrySet()) { + Object val = entry.getValue(); + if (val instanceof Class<?>) { + config.setValidator(entry.getKey(), (Class<?>)val); + } else if (val instanceof Validator) { + config.setValidator(entry.getKey(), (Validator)val); + } } - secEngineOverride = createSecurityEngine(processorMap); - } else if (validatorMap != null) { - secEngineOverride = createSecurityEngine(validatorMap); } + + defaultConfig = config; } public void setIgnoreActions(boolean i) { @@ -636,15 +660,12 @@ public class WSS4JInInterceptor extends AbstractWSS4JInterceptor { /** * @return the WSSecurityEngine in use by this interceptor. - * This engine is defined to be the secEngineOverride - * instance, if defined in this class (and supplied through - * construction); otherwise, it is taken to be the default - * WSSecEngine instance (currently defined in the WSHandler - * base class). */ protected WSSecurityEngine getSecurityEngine(boolean utWithCallbacks) { - if (secEngineOverride != null) { - return secEngineOverride; + if (defaultConfig != null) { + WSSecurityEngine engine = new WSSecurityEngine(); + engine.setWssConfig(defaultConfig); + return engine; } if (!utWithCallbacks) {
