You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by do...@apache.org on 2009/04/30 02:58:04 UTC

svn commit: r770025 - in /ofbiz/trunk: framework/base/src/org/ofbiz/base/util/ framework/common/src/META-INF/ framework/common/src/META-INF/services/ framework/common/src/org/ofbiz/common/authentication/ specialpurpose/crowd/src/META-INF/ specialpurpos...

Author: doogie
Date: Thu Apr 30 00:58:04 2009
New Revision: 770025

URL: http://svn.apache.org/viewvc?rev=770025&view=rev
Log:
Remove the Resolving classes; instead, make use of ServiceRegistry,
which simplifies the code quite nicely.  However, this means that
the system will *not* walk the classpath, converting everything to
a file/jar, and trying to load *all* org.ofbiz.* classes.  Instead,
it only will load those classes that have been configured to be
looked at, by way of the services text files.

Added:
    ofbiz/trunk/framework/common/src/META-INF/
    ofbiz/trunk/framework/common/src/META-INF/services/
    ofbiz/trunk/framework/common/src/META-INF/services/org.ofbiz.common.authentication.api.Authenticator
    ofbiz/trunk/specialpurpose/crowd/src/META-INF/
    ofbiz/trunk/specialpurpose/crowd/src/META-INF/services/
    ofbiz/trunk/specialpurpose/crowd/src/META-INF/services/org.ofbiz.common.authentication.api.Authenticator
Removed:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/AbstractResolver.java
    ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/AuthInterfaceResolver.java
Modified:
    ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/AuthHelper.java

Added: ofbiz/trunk/framework/common/src/META-INF/services/org.ofbiz.common.authentication.api.Authenticator
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/META-INF/services/org.ofbiz.common.authentication.api.Authenticator?rev=770025&view=auto
==============================================================================
--- ofbiz/trunk/framework/common/src/META-INF/services/org.ofbiz.common.authentication.api.Authenticator (added)
+++ ofbiz/trunk/framework/common/src/META-INF/services/org.ofbiz.common.authentication.api.Authenticator Thu Apr 30 00:58:04 2009
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.ofbiz.common.authentication.example.TestFailAuthenticator
+org.ofbiz.common.authentication.example.TestPassAuthenticator

Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/AuthHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/AuthHelper.java?rev=770025&r1=770024&r2=770025&view=diff
==============================================================================
--- ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/AuthHelper.java (original)
+++ ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/AuthHelper.java Thu Apr 30 00:58:04 2009
@@ -19,9 +19,13 @@
 
 package org.ofbiz.common.authentication;
 
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Iterator;
+import javax.imageio.spi.ServiceRegistry;
 
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.common.authentication.api.Authenticator;
@@ -87,20 +91,14 @@
     @SuppressWarnings("unchecked")
     private synchronized static void loadAuthenticators_internal(LocalDispatcher dispatcher) {
         if (!authenticatorsLoaded) {
-            AuthInterfaceResolver resolver = new AuthInterfaceResolver();
-            List<Class> implementations = resolver.getImplementations();
-
-            for (Class c : implementations) {
+            Iterator<Authenticator> it = ServiceRegistry.lookupProviders(Authenticator.class, getContextClassLoader());
+            while (it.hasNext()) {
                 try {
-                    Authenticator auth = (Authenticator) c.newInstance();
+                    Authenticator auth = it.next();
                     if (auth.isEnabled()) {
                         auth.initialize(dispatcher);                    
                         authenticators.add(auth);
                     }
-                } catch (InstantiationException e) {
-                    Debug.logError(e, module);
-                } catch (IllegalAccessException e) {
-                    Debug.logError(e, module);
                 } catch (ClassCastException e) {
                     Debug.logError(e, module);
                 }
@@ -110,4 +108,23 @@
             authenticatorsLoaded = true;
         }
     }
+
+    /* Do not move this into a shared global util class; doing so
+     * would mean the method would have to be public, and then it
+     * could be called by any other non-secure source.
+     */
+    private static ClassLoader getContextClassLoader() {
+        return AccessController.doPrivileged(
+                new PrivilegedAction<ClassLoader>() {
+                    public ClassLoader run() {
+                        ClassLoader cl = null;
+                        try {
+                            cl = Thread.currentThread().getContextClassLoader();
+                        } catch (SecurityException e) {
+                            Debug.logError(e, e.getMessage(), module);
+                        }
+                        return cl;
+                    }
+                });
+    }
 }

Added: ofbiz/trunk/specialpurpose/crowd/src/META-INF/services/org.ofbiz.common.authentication.api.Authenticator
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/crowd/src/META-INF/services/org.ofbiz.common.authentication.api.Authenticator?rev=770025&view=auto
==============================================================================
--- ofbiz/trunk/specialpurpose/crowd/src/META-INF/services/org.ofbiz.common.authentication.api.Authenticator (added)
+++ ofbiz/trunk/specialpurpose/crowd/src/META-INF/services/org.ofbiz.common.authentication.api.Authenticator Thu Apr 30 00:58:04 2009
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.ofbiz.crowd.CrowdAuthenticator