This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag 
org.apache.sling.extensions.webconsolesecurityprovider-1.1.2
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-extensions-webconsolesecurityprovider.git

commit 8a904648d23105a44e2ff1a6bb631520f9fc2cfa
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Tue Dec 10 04:40:48 2013 +0000

    SLING-3272 : Only register security provider 2 if startup is finished
    
    git-svn-id: 
https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/webconsolesecurityprovider@1549757
 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            |  6 ++++
 .../internal/Activator.java                        |  9 ++++++
 .../internal/ServicesListener.java                 | 35 ++++++++++++++++++++--
 3 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index 31c1f3a..68b98d5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -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>
diff --git 
a/src/main/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/Activator.java
 
b/src/main/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/Activator.java
index 018ee6d..be6e303 100644
--- 
a/src/main/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/Activator.java
+++ 
b/src/main/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/Activator.java
@@ -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;
diff --git 
a/src/main/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/ServicesListener.java
 
b/src/main/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/ServicesListener.java
index 4dda83f..99d93d3 100644
--- 
a/src/main/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/ServicesListener.java
+++ 
b/src/main/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/ServicesListener.java
@@ -21,11 +21,14 @@ package 
org.apache.sling.extensions.webconsolesecurityprovider.internal;
 
 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.ManagedService;
  * 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 ) {

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to