cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject svn commit: r1148446 - in /cxf/branches/2.4.x-fixes: ./ rt/core/src/main/java/org/apache/cxf/interceptor/security/NamePasswordCallbackHandler.java rt/core/src/test/java/org/apache/cxf/interceptor/security/NamePasswordCallbackHandlerTest.java
Date Tue, 19 Jul 2011 16:54:58 GMT
Author: ay
Date: Tue Jul 19 16:54:57 2011
New Revision: 1148446

URL: http://svn.apache.org/viewvc?rev=1148446&view=rev
Log:
Merged revisions 1148281 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1148281 | ay | 2011-07-19 13:54:51 +0200 (Tue, 19 Jul 2011) | 1 line
  
  [CXF-3658] Make NamePasswordCallback used for JAAS login more flexible...
........

Added:
    cxf/branches/2.4.x-fixes/rt/core/src/test/java/org/apache/cxf/interceptor/security/NamePasswordCallbackHandlerTest.java
      - copied unchanged from r1148281, cxf/trunk/rt/core/src/test/java/org/apache/cxf/interceptor/security/NamePasswordCallbackHandlerTest.java
Modified:
    cxf/branches/2.4.x-fixes/   (props changed)
    cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/security/NamePasswordCallbackHandler.java

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jul 19 16:54:57 2011
@@ -1 +1 @@
-/cxf/trunk:1144977,1145682,1146773,1147504,1148067,1148077,1148235,1148257
+/cxf/trunk:1144977,1145682,1146773,1147504,1148067,1148077,1148235,1148257,1148281

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/security/NamePasswordCallbackHandler.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/security/NamePasswordCallbackHandler.java?rev=1148446&r1=1148445&r2=1148446&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/security/NamePasswordCallbackHandler.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/security/NamePasswordCallbackHandler.java
Tue Jul 19 16:54:57 2011
@@ -19,6 +19,7 @@
 package org.apache.cxf.interceptor.security;
 
 import java.io.IOException;
+import java.lang.reflect.Method;
 import java.util.ResourceBundle;
 import java.util.logging.Logger;
 
@@ -35,15 +36,25 @@ public class NamePasswordCallbackHandler
     
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(NamePasswordCallbackHandler.class);
     private static final Logger LOG = LogUtils.getL7dLogger(NamePasswordCallbackHandler.class);
+    private static final String PASSWORD_CALLBACK_NAME = "setObject";
+    private static final Class[] PASSWORD_CALLBACK_TYPES = 
+        new Class[]{Object.class, char[].class, String.class};
     
     private String username;  
     private String password;  
-     
+    
+    private String passwordCallbackName;
+    
     public NamePasswordCallbackHandler(String username, String password) {  
-        this.username = username;  
-        this.password = password;  
+        this(username, password, null);  
     }  
      
+    public NamePasswordCallbackHandler(String username, String password, String passwordCallbackName)
{  
+        this.username = username;  
+        this.password = password;
+        this.passwordCallbackName = passwordCallbackName;
+    }  
+
     public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException
{  
         for (int i = 0; i < callbacks.length; i++) {  
             Callback callback = callbacks[i];
@@ -53,8 +64,8 @@ public class NamePasswordCallbackHandler
                 ((NameCallback) callback).setName(username);  
             } else if (callback instanceof PasswordCallback) {  
                 PasswordCallback pwCallback = (PasswordCallback) callback;  
-                pwCallback.setPassword(password.toCharArray());  
-            } else {
+                pwCallback.setPassword(password.toCharArray());
+            } else if (!invokePasswordCallback(callback)) {
                 org.apache.cxf.common.i18n.Message errorMsg = 
                     new org.apache.cxf.common.i18n.Message("UNSUPPORTED_CALLBACK_TYPE", 
                                                            BUNDLE, 
@@ -68,4 +79,28 @@ public class NamePasswordCallbackHandler
     protected boolean handleCallback(Callback callback) {
         return false;
     }
+    
+    /*
+     * This method is called from the handle(Callback[]) method when the specified callback

+     * did not match any of the known callback classes. It looks for the callback method

+     * having the specified method name with one of the suppported parameter types.
+     * If found, it invokes the callback method on the object and returns true. 
+     * If not, it returns false.
+     */
+    private boolean invokePasswordCallback(Callback callback) {
+        String cbname = passwordCallbackName == null
+                        ? PASSWORD_CALLBACK_NAME : passwordCallbackName;
+        for (Class<?> arg : PASSWORD_CALLBACK_TYPES) {
+            try {
+                Method method = callback.getClass().getMethod(cbname, arg);
+                method.invoke(callback, arg == String.class ? password : password.toCharArray());
+                return true;
+            } catch (Exception e) {
+                // ignore and continue
+                LOG.warning(e.toString());
+            }
+        }
+        return false;
+    }
+ 
 }



Mime
View raw message