[jboss-cvs] JBossAS SVN: r100854 - in trunk: tomcat/src/main/java/org/jboss/web/tomcat/service/ondemand and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Feb 11 00:40:20 EST 2010


Author: bstansberry at jboss.com
Date: 2010-02-11 00:40:19 -0500 (Thu, 11 Feb 2010)
New Revision: 100854

Modified:
   trunk/testsuite/src/main/org/jboss/test/web/test/OnDemandContextProfileManagerUnitTestCase.java
   trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/ondemand/OnDemandContextProfileManager.java
Log:
[JBAS-7713] Activate the profile in a privileged block

Modified: trunk/testsuite/src/main/org/jboss/test/web/test/OnDemandContextProfileManagerUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/web/test/OnDemandContextProfileManagerUnitTestCase.java	2010-02-11 05:21:56 UTC (rev 100853)
+++ trunk/testsuite/src/main/org/jboss/test/web/test/OnDemandContextProfileManagerUnitTestCase.java	2010-02-11 05:40:19 UTC (rev 100854)
@@ -49,6 +49,7 @@
 import org.jboss.profileservice.spi.ProfileService;
 import org.jboss.profileservice.spi.metadata.ProfileMetaData;
 import org.jboss.profileservice.spi.metadata.ProfileSourceMetaData;
+import org.jboss.web.tomcat.service.ondemand.ContextDemandListener;
 import org.jboss.web.tomcat.service.ondemand.OnDemandContextIntegrator;
 import org.jboss.web.tomcat.service.ondemand.OnDemandContextProfileManager;
 
@@ -236,7 +237,8 @@
       Capture<ProfileMetaData> capture = new Capture<ProfileMetaData>();
       expect(ts.profileFactory.createProfile(eq(ts.testee.getProfileKey()), capture(capture))).andReturn(profile);
       ts.profileService.registerProfile(profile);
-      ts.integrator.registerContextDemandListener(ts.testee);
+      ContextDemandListener cdl = anyObject();
+      ts.integrator.registerContextDemandListener(cdl);
       ts.integrator.registerOnDemandContext("service", "host", "/context");
       
       replay(ts.profileFactory);
@@ -314,7 +316,8 @@
       expect(ts.profileService.getActiveProfileKeys()).andReturn(keys);
       ts.profileService.deactivateProfile(ts.testee.getProfileKey());
       ts.profileService.unregisterProfile(ts.testee.getProfileKey());
-      ts.integrator.removeContextDemandListener(ts.testee);
+      ContextDemandListener cdl = anyObject();
+      ts.integrator.removeContextDemandListener(cdl);
       
       replay(ts.profileService);
       replay(ts.integrator);
@@ -340,7 +343,8 @@
       Collection<ProfileKey> keys = Collections.emptyList();
       expect(ts.profileService.getActiveProfileKeys()).andReturn(keys);
       ts.profileService.unregisterProfile(ts.testee.getProfileKey());
-      ts.integrator.removeContextDemandListener(ts.testee);
+      ContextDemandListener cdl = anyObject();
+      ts.integrator.removeContextDemandListener(cdl);
       
       replay(ts.profileService);
       replay(ts.integrator);

Modified: trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/ondemand/OnDemandContextProfileManager.java
===================================================================
--- trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/ondemand/OnDemandContextProfileManager.java	2010-02-11 05:21:56 UTC (rev 100853)
+++ trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/ondemand/OnDemandContextProfileManager.java	2010-02-11 05:40:19 UTC (rev 100854)
@@ -23,6 +23,8 @@
 
 import java.io.IOException;
 import java.net.URI;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -60,7 +62,7 @@
  * @author Brian Stansberry
  * @version $Revision$
  */
-public class OnDemandContextProfileManager implements ContextDemandListener
+public class OnDemandContextProfileManager
 {   
    public static final String DEFAULT_SERVICE_NAME = "jboss.web";
    public static final String DEFAULT_HOST_NAME = "localhost";
@@ -103,6 +105,8 @@
    private String contextPath; // TODO do something smarter
    
    private boolean activateOnDemand = true;
+   
+   private final ContextDemandListener contextDemandListener = new Listener();
 
    // ----------------------------------------------------------- Constructors
    
@@ -420,27 +424,8 @@
    public void setActivateOnDemand(boolean activateOnDemand)
    {
       this.activateOnDemand = activateOnDemand;
-   }   
+   }  
 
-   // --------------------------------------------------  ContextDemandListener
-
-   public void contextDemanded(String serviceName, String hostName, String contextName)
-   {
-      if (this.contextPath.equals(contextName) 
-            && this.hostName.equals(hostName) 
-            && this.serviceName.equals(serviceName))
-      {
-         try
-         {
-            activateProfile();
-         }
-         catch (Exception e)
-         {
-            log.error("Unable to activate profile " + getProfileKey(), e);
-         }
-      }
-   }
-
    // -----------------------------------------------------------------  Public
 
    /**
@@ -496,7 +481,7 @@
       
       if (this.activateOnDemand)
       {
-         contextIntegrator.registerContextDemandListener(this);
+         contextIntegrator.registerContextDemandListener(contextDemandListener);
          contextPath = (contextName.length() == 0 || '/' == contextName.charAt(0) ? contextName : "/" + contextName);
          contextIntegrator.registerOnDemandContext(serviceName, hostName, contextPath);  
       }
@@ -543,7 +528,7 @@
          {
             if (this.contextIntegrator != null)
             {
-               this.contextIntegrator.removeContextDemandListener(this);
+               this.contextIntegrator.removeContextDemandListener(contextDemandListener);
             }
          }
       }
@@ -693,4 +678,31 @@
       }
    }
    
+   private class Listener implements ContextDemandListener
+   {
+      public void contextDemanded(String serviceName, String hostName, String contextName)
+      {
+         if (OnDemandContextProfileManager.this.contextPath.equals(contextName) 
+               && OnDemandContextProfileManager.this.hostName.equals(hostName) 
+               && OnDemandContextProfileManager.this.serviceName.equals(serviceName))
+         {
+            AccessController.doPrivileged(new PrivilegedAction<Object>()                  
+            {
+               public Object run()
+               {
+                  try
+                  {
+                     OnDemandContextProfileManager.this.activateProfile();
+                  }
+                  catch (Exception e)
+                  {
+                     log.error("Unable to activate profile " + getProfileKey(), e);
+                  }
+                  return null;
+               }
+            });
+         }
+      }
+   }
+   
 }




More information about the jboss-cvs-commits mailing list