jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r904415 - /jackrabbit/sandbox/jackrabbit2-bundle/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/osgi/security/PluggableDefaultLoginModule.java
Date Fri, 29 Jan 2010 08:30:23 GMT
Author: fmeschbe
Date: Fri Jan 29 08:30:21 2010
New Revision: 904415

URL: http://svn.apache.org/viewvc?rev=904415&view=rev
Log:
* Have to implement supportsCredentials checking with plugin factories for
  support. Otherwise getCredentials returns null and login fails
* commit and abort have to clear the activePlugin field only after calling
  the base class implementation. Reason: the base class implementation might
  call back into the plugin (e.g. the addPrincipals method)

Modified:
    jackrabbit/sandbox/jackrabbit2-bundle/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/osgi/security/PluggableDefaultLoginModule.java

Modified: jackrabbit/sandbox/jackrabbit2-bundle/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/osgi/security/PluggableDefaultLoginModule.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit2-bundle/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/osgi/security/PluggableDefaultLoginModule.java?rev=904415&r1=904414&r2=904415&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit2-bundle/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/osgi/security/PluggableDefaultLoginModule.java
(original)
+++ jackrabbit/sandbox/jackrabbit2-bundle/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/osgi/security/PluggableDefaultLoginModule.java
Fri Jan 29 08:30:21 2010
@@ -71,27 +71,23 @@
             Map options) throws LoginException {
         super.doInit(callbackHandler, session, options);
 
+        // get the credentials, this should call supportsCredentials which
+        // in turn will set the activePlugin field (as a side effect)
         final Credentials credentials = getCredentials();
-        if (credentials != null) {
-            LoginModulePluginFactory[] modules = Activator.getLoginModules();
-            for (LoginModulePluginFactory loginModulePluginFactory : modules) {
-                LoginModulePlugin plugin = loginModulePluginFactory.create(credentials);
-                if (plugin != null) {
-                    try {
-                        plugin.init(callbackHandler, session, options);
-                        activePlugin = plugin;
-                        break;
-                    } catch (LoginException le) {
-                        // TODO: log
-                    }
-                }
-            }
+
+        // if we got credentials, but no active plugin (yet), lets try again
+        // and find one (I would assume this is unrealstic, yet, lets try)
+        if (credentials != null && activePlugin == null) {
+            activePlugin = getActivePlugin(credentials);
         }
 
         // if no custom plugin is provided, use a default instance
         if (activePlugin == null) {
             activePlugin = NULL_PLUGIN;
         }
+
+        // initialize the selected plugin
+        activePlugin.init(callbackHandler, session, options);
     }
 
     @Override
@@ -104,8 +100,6 @@
             result = activePlugin.commit();
         } catch (Exception e) {
             failure = e;
-        } finally {
-            activePlugin = null;
         }
 
         try {
@@ -117,6 +111,9 @@
             }
         }
 
+        // drop the active plugin after commit
+        activePlugin = null;
+
         if (failure != null) {
             if (failure instanceof RuntimeException) {
                 throw (RuntimeException) failure;
@@ -138,8 +135,6 @@
             result = activePlugin.abort();
         } catch (Exception e) {
             failure = e;
-        } finally {
-            activePlugin = null;
         }
 
         try {
@@ -151,6 +146,9 @@
             }
         }
 
+        // drop the active plugin after abort
+        activePlugin = null;
+
         if (failure != null) {
             if (failure instanceof RuntimeException) {
                 throw (RuntimeException) failure;
@@ -162,6 +160,18 @@
         return result;
     }
 
+    @Override
+    protected boolean supportsCredentials(Credentials creds) {
+        // find a plugin for the credentials
+        activePlugin = getActivePlugin(creds);
+        if (activePlugin != null) {
+            return true;
+        }
+
+        // if none, call the default implementation
+        return super.supportsCredentials(creds);
+    }
+
     /**
      * Overwrites the <code>AbstractLoginModule</code> implementation to check
      * whether one of the plugins can provide the user ID for the given
@@ -241,4 +251,16 @@
 
         return super.impersonate(principal, creds);
     }
+
+    private LoginModulePlugin getActivePlugin(final Credentials credentials) {
+        LoginModulePluginFactory[] modules = Activator.getLoginModules();
+        for (LoginModulePluginFactory loginModulePluginFactory : modules) {
+            LoginModulePlugin plugin = loginModulePluginFactory.create(credentials);
+            if (plugin != null) {
+                return plugin;
+            }
+        }
+
+        return null;
+    }
 }



Mime
View raw message