incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1549757 - in /sling/trunk/bundles/extensions/webconsolesecurityprovider: ./ src/main/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/
Date Tue, 10 Dec 2013 04:40:49 GMT
Author: cziegeler
Date: Tue Dec 10 04:40:48 2013
New Revision: 1549757

URL: http://svn.apache.org/r1549757
Log:
SLING-3272 : Only register security provider 2 if startup is finished

Modified:
    sling/trunk/bundles/extensions/webconsolesecurityprovider/pom.xml
    sling/trunk/bundles/extensions/webconsolesecurityprovider/src/main/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/Activator.java
    sling/trunk/bundles/extensions/webconsolesecurityprovider/src/main/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/ServicesListener.java

Modified: sling/trunk/bundles/extensions/webconsolesecurityprovider/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/webconsolesecurityprovider/pom.xml?rev=1549757&r1=1549756&r2=1549757&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/webconsolesecurityprovider/pom.xml (original)
+++ sling/trunk/bundles/extensions/webconsolesecurityprovider/pom.xml Tue Dec 10 04:40:48
2013
@@ -116,6 +116,12 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.launchpad.api</artifactId>
+            <version>1.1.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>javax.servlet</groupId>
             <artifactId>servlet-api</artifactId>
         </dependency>

Modified: sling/trunk/bundles/extensions/webconsolesecurityprovider/src/main/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/Activator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/webconsolesecurityprovider/src/main/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/Activator.java?rev=1549757&r1=1549756&r2=1549757&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/webconsolesecurityprovider/src/main/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/Activator.java
(original)
+++ sling/trunk/bundles/extensions/webconsolesecurityprovider/src/main/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/Activator.java
Tue Dec 10 04:40:48 2013
@@ -16,24 +16,33 @@
  */
 package org.apache.sling.extensions.webconsolesecurityprovider.internal;
 
+import org.apache.sling.launchpad.api.StartupListener;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
 
 public class Activator implements BundleActivator {
 
     private ServicesListener listener;
 
+    private ServiceRegistration registration;
+
     /**
      * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
      */
     public void start(final BundleContext context) throws Exception {
         listener = new ServicesListener(context);
+        registration = context.registerService(StartupListener.class.getName(), listener,
null);
     }
 
     /**
      * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
      */
     public void stop(final BundleContext context) throws Exception {
+        if ( registration != null ) {
+            registration.unregister();
+            registration = null;
+        }
         if ( listener != null ) {
             listener.deactivate();
             listener = null;

Modified: sling/trunk/bundles/extensions/webconsolesecurityprovider/src/main/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/ServicesListener.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/webconsolesecurityprovider/src/main/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/ServicesListener.java?rev=1549757&r1=1549756&r2=1549757&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/webconsolesecurityprovider/src/main/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/ServicesListener.java
(original)
+++ sling/trunk/bundles/extensions/webconsolesecurityprovider/src/main/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/ServicesListener.java
Tue Dec 10 04:40:48 2013
@@ -21,11 +21,14 @@ package org.apache.sling.extensions.webc
 
 import java.util.Dictionary;
 import java.util.Hashtable;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.jcr.Repository;
 
 import org.apache.felix.webconsole.WebConsoleSecurityProvider;
 import org.apache.sling.auth.core.AuthenticationSupport;
+import org.apache.sling.launchpad.api.StartupListener;
+import org.apache.sling.launchpad.api.StartupMode;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.InvalidSyntaxException;
@@ -39,7 +42,7 @@ import org.osgi.service.cm.ManagedServic
  * The <code>ServicesListener</code> listens for the required services
  * and registers the security provider when required services are available
  */
-public class ServicesListener {
+public class ServicesListener implements StartupListener {
 
     private static final String AUTH_SUPPORT_CLASS = AuthenticationSupport.class.getName();
     private static final String REPO_CLASS = Repository.class.getName();
@@ -68,6 +71,9 @@ public class ServicesListener {
     /** The registration for the provider2 */
     private ServiceRegistration provider2Reg;
 
+    /** Flag for marking if startup is finished. */
+    private final AtomicBoolean startupFinished = new AtomicBoolean(false);
+
     /**
      * Start listeners
      */
@@ -80,11 +86,36 @@ public class ServicesListener {
     }
 
     /**
+     * @see org.apache.sling.launchpad.api.StartupListener#inform(org.apache.sling.launchpad.api.StartupMode,
boolean)
+     */
+    public void inform(final StartupMode mode, final boolean finished) {
+        if ( finished && this.startupFinished.compareAndSet(false, true) ) {
+            notifyChange();
+        }
+    }
+
+    /**
+     * @see org.apache.sling.launchpad.api.StartupListener#startupFinished(org.apache.sling.launchpad.api.StartupMode)
+     */
+    public void startupFinished(final StartupMode mode) {
+        if ( this.startupFinished.compareAndSet(false, true) ) {
+            notifyChange();
+        }
+    }
+
+    /**
+     * @see org.apache.sling.launchpad.api.StartupListener#startupProgress(float)
+     */
+    public void startupProgress(float arg0) {
+        // nothing to do
+    }
+
+    /**
      * Notify of service changes from the listeners.
      */
     public synchronized void notifyChange() {
         // check if all services are available
-        final Object authSupport = this.authSupportListener.getService();
+        final Object authSupport = this.startupFinished.get() ? this.authSupportListener.getService()
: null;
         final Object repository = this.repositoryListener.getService();
         if ( registrationState == State.NONE ) {
             if ( authSupport != null ) {



Mime
View raw message