cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asold...@apache.org
Subject [1/2] cxf git commit: [CXF-6295] create Validator instance when a string with class name is provided
Date Fri, 13 Mar 2015 07:49:59 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 4d7bae999 -> 2aa1f7a2f


[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/58f924e9
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/58f924e9
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/58f924e9

Branch: refs/heads/3.0.x-fixes
Commit: 58f924e9a0957083bcbb97aca5985e6fde2b74f9
Parents: 4d7bae9
Author: Alessio Soldano <asoldano@redhat.com>
Authored: Thu Mar 12 22:57:33 2015 +0100
Committer: Alessio Soldano <asoldano@redhat.com>
Committed: Fri Mar 13 08:46:35 2015 +0100

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


http://git-wip-us.apache.org/repos/asf/cxf/blob/58f924e9/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