cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asold...@apache.org
Subject cxf git commit: [CXF-6295] create Validator instance when a string with class name is provided
Date Thu, 12 Mar 2015 21:58:50 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 037aab058 -> c5dbb84ac


[CXF-6295] create Validator instance when a string with class name is provided


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/c5dbb84a
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/c5dbb84a
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/c5dbb84a

Branch: refs/heads/master
Commit: c5dbb84ac4e5bf73555e85ae1e65a5065393c602
Parents: 037aab0
Author: Alessio Soldano <asoldano@redhat.com>
Authored: Thu Mar 12 22:57:33 2015 +0100
Committer: Alessio Soldano <asoldano@redhat.com>
Committed: Thu Mar 12 22:57:33 2015 +0100

----------------------------------------------------------------------
 .../wss4j/UsernameTokenInterceptor.java         | 29 ++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/c5dbb84a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/UsernameTokenInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/UsernameTokenInterceptor.java
b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/UsernameTokenInterceptor.java
index 96f0ac8..e9e3c52 100644
--- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/UsernameTokenInterceptor.java
+++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/UsernameTokenInterceptor.java
@@ -31,6 +31,7 @@ import javax.xml.namespace.QName;
 
 import org.w3c.dom.Element;
 import org.apache.cxf.binding.soap.SoapMessage;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.headers.Header;
 import org.apache.cxf.helpers.CastUtils;
@@ -205,8 +206,7 @@ public class UsernameTokenInterceptor extends AbstractTokenInterceptor
{
                 return getCallback(message);
             }
             public Validator getValidator(QName qName) throws WSSecurityException {
-                Object validator = 
-                        message.getContextualProperty(SecurityConstants.USERNAME_TOKEN_VALIDATOR);
+                Object validator = loadValidator(SecurityConstants.USERNAME_TOKEN_VALIDATOR,
message);
                 if (validator == null) {
                     return super.getValidator(qName);
                 }
@@ -236,6 +236,31 @@ public class UsernameTokenInterceptor extends AbstractTokenInterceptor
{
             throw WSS4JUtils.createSoapFault(message, message.getVersion(), ex);
         }
     }
+    
+    private Validator loadValidator(String validatorKey, SoapMessage message) throws WSSecurityException
{
+        Object o = message.getContextualProperty(validatorKey);
+        if (o == null) {
+            return null;
+        }
+        try {
+            if (o instanceof Validator) {
+                return (Validator)o;
+            } else if (o instanceof Class) {
+                return (Validator)((Class<?>)o).newInstance();
+            } else if (o instanceof String) {
+                return (Validator)ClassLoaderUtils.loadClass(o.toString(),
+                                                             UsernameTokenInterceptor.class)
+                                                             .newInstance();
+            } else {
+                throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, 
+                                                  "Cannot load Validator: " + o);
+            }
+        } catch (RuntimeException t) {
+            throw t;
+        } catch (Exception ex) {
+            throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, ex);
+        }
+    }
 
     protected UsernameTokenPrincipal parseTokenAndCreatePrincipal(Element tokenElement, boolean
bspCompliant) 
         throws WSSecurityException, Base64DecodingException {


Mime
View raw message