db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1627831 [2/4] - in /db/derby/code/trunk/java: drda/org/apache/derby/drda/ drda/org/apache/derby/impl/drda/ engine/org/apache/derby/iapi/jdbc/ engine/org/apache/derby/iapi/services/context/ engine/org/apache/derby/iapi/services/monitor/ eng...
Date Fri, 26 Sep 2014 17:12:33 GMT
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmx/JMXManagementService.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmx/JMXManagementService.java?rev=1627831&r1=1627830&r2=1627831&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmx/JMXManagementService.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmx/JMXManagementService.java Fri Sep 26 17:12:31 2014
@@ -43,6 +43,7 @@ import org.apache.derby.iapi.reference.P
 import org.apache.derby.iapi.services.info.Version;
 import org.apache.derby.iapi.services.jmx.ManagementService;
 import org.apache.derby.iapi.services.monitor.ModuleControl;
+import org.apache.derby.iapi.services.monitor.ModuleFactory;
 import org.apache.derby.iapi.services.monitor.Monitor;
 import org.apache.derby.iapi.services.property.PropertyUtil;
 import org.apache.derby.mbeans.ManagementMBean;
@@ -113,7 +114,7 @@ public final class JMXManagementService 
         registeredMbeans = new HashMap<ObjectName,StandardMBean>();
         
         systemIdentifier =
-            Monitor.getMonitor().getUUIDFactory().createUUID().toString();
+            getMonitor().getUUIDFactory().createUUID().toString();
         
         findServer();
              
@@ -124,7 +125,7 @@ public final class JMXManagementService 
         
         registerMBean(
                 new Version(
-                        Monitor.getMonitor().getEngineVersion(),
+                        getMonitor().getEngineVersion(),
                         SystemPermission.ENGINE),
                 VersionMBean.class,
                 "type=Version,jar=derby.jar");
@@ -429,4 +430,23 @@ public final class JMXManagementService 
     public String quotePropertyValue(String value) {
         return ObjectName.quote(value);
     }
+    
+    /**
+     * Privileged Monitor lookup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  ModuleFactory  getMonitor()
+    {
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<ModuleFactory>()
+             {
+                 public ModuleFactory run()
+                 {
+                     return Monitor.getMonitor();
+                 }
+             }
+             );
+    }
+
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java?rev=1627831&r1=1627830&r2=1627831&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java Fri Sep 26 17:12:31 2014
@@ -201,7 +201,6 @@ abstract class BaseMonitor
 		(services.get(0)).shutdown();
 
 		stopContextService();
-		Monitor.clearMonitor();
 	}
 
 	/**
@@ -245,8 +244,7 @@ abstract class BaseMonitor
 
 		// if monitor is already set then the system is already
 		// booted or in the process of booting or shutting down.
-		if (!Monitor.setMonitor(this))
-			return;
+		if ( setMonitor( this ) ) { return; }
 
 		MessageService.setFinder(this);
 
@@ -2088,23 +2086,16 @@ nextModule:
      */
     private  static  ContextService    getContextService()
     {
-        if ( System.getSecurityManager() == null )
-        {
-            return ContextService.getFactory();
-        }
-        else
-        {
-            return AccessController.doPrivileged
-                (
-                 new PrivilegedAction<ContextService>()
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<ContextService>()
+             {
+                 public ContextService run()
                  {
-                     public ContextService run()
-                     {
-                         return ContextService.getFactory();
-                     }
+                     return ContextService.getFactory();
                  }
-                 );
-        }
+             }
+             );
     }    
 
     /**
@@ -2113,27 +2104,40 @@ nextModule:
      */
     private  static  void    stopContextService()
     {
-        if ( System.getSecurityManager() == null )
-        {
-            ContextService.stop();
-        }
-        else
-        {
-            AccessController.doPrivileged
-                (
-                 new PrivilegedAction<Object>()
+        AccessController.doPrivileged
+            (
+             new PrivilegedAction<Object>()
+             {
+                 public Object run()
                  {
-                     public Object run()
-                     {
-                         ContextService.stop();
-                         return null;
-                     }
+                     ContextService.stop();
+                     Monitor.clearMonitor();
+                     return null;
                  }
-                 );
-        }
+             }
+             );
     }    
 
-	/**
+    /**
+     * Privileged startup. Must be private so that user code
+     * can't call this entry point. Returns true if the system is
+     * already booted or in the process of shutting down.
+     */
+    private  static  boolean    setMonitor( final BaseMonitor baseMonitor )
+    {
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<Boolean>()
+             {
+                 public Boolean run()
+                 {
+                     return !Monitor.setMonitor( baseMonitor );
+                 }
+             }
+             ).booleanValue();
+    }
+
+    /**
 		Initialize the monitor wrt the current environemnt.
 		Returns false if the monitor cannot be initialized, true otherwise.
 	*/

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java?rev=1627831&r1=1627830&r2=1627831&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java Fri Sep 26 17:12:31 2014
@@ -26,6 +26,7 @@ import org.apache.derby.iapi.reference.S
 
 import org.apache.derby.iapi.services.i18n.MessageService;
 
+import org.apache.derby.iapi.services.monitor.ModuleFactory;
 import org.apache.derby.iapi.services.monitor.Monitor;
 import org.apache.derby.iapi.services.monitor.PersistentService;
 import org.apache.derby.shared.common.sanity.SanityManager;
@@ -87,7 +88,7 @@ final class StorageFactoryService implem
         this.subSubProtocol = subSubProtocol;
         this.storageFactoryClass = storageFactoryClass;
 
-        Object monitorEnv = Monitor.getMonitor().getEnvironment();
+        Object monitorEnv = getMonitor().getEnvironment();
 		if (monitorEnv instanceof File)
         {
             final File relativeRoot = (File) monitorEnv;
@@ -1046,6 +1047,24 @@ final class StorageFactoryService implem
         }
     }
     
+    /**
+     * Privileged Monitor lookup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  ModuleFactory  getMonitor()
+    {
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<ModuleFactory>()
+             {
+                 public ModuleFactory run()
+                 {
+                     return Monitor.getMonitor();
+                 }
+             }
+             );
+    }
+
     final class DirectoryList implements Enumeration, PrivilegedAction<DirectoryList>
     {
         private String[] contents;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/DatabaseClasses.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/DatabaseClasses.java?rev=1627831&r1=1627830&r2=1627831&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/DatabaseClasses.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/DatabaseClasses.java Fri Sep 26 17:12:31 2014
@@ -26,6 +26,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.ObjectStreamClass;
 import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 import java.util.Properties;
@@ -38,6 +39,7 @@ import org.apache.derby.iapi.services.lo
 import org.apache.derby.iapi.services.loader.ClassInspector;
 import org.apache.derby.iapi.services.loader.GeneratedClass;
 import org.apache.derby.iapi.services.monitor.ModuleControl;
+import org.apache.derby.iapi.services.monitor.ModuleFactory;
 import org.apache.derby.iapi.services.monitor.Monitor;
 import org.apache.derby.shared.common.sanity.SanityManager;
 import org.apache.derby.iapi.services.stream.HeaderPrintWriter;
@@ -168,7 +170,7 @@ abstract class DatabaseClasses
         int lastDot = fullyQualifiedName.lastIndexOf((int)'.');
         String filename = fullyQualifiedName.substring(lastDot+1,fullyQualifiedName.length()).concat(".class");
 
-		Object env = Monitor.getMonitor().getEnvironment();
+		Object env = getMonitor().getEnvironment();
 		File dir = env instanceof File ? (File) env : null;
 
         final File classFile = new File(dir, filename);
@@ -304,4 +306,23 @@ abstract class DatabaseClasses
 	*/
 
 	abstract LoadedGeneratedClass loadGeneratedClassFromData(String fullyQualifiedName, ByteArray classDump); 
+    
+    /**
+     * Privileged Monitor lookup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  ModuleFactory  getMonitor()
+    {
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<ModuleFactory>()
+             {
+                 public ModuleFactory run()
+                 {
+                     return Monitor.getMonitor();
+                 }
+             }
+             );
+    }
+
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/UpdateLoader.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/UpdateLoader.java?rev=1627831&r1=1627830&r2=1627831&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/UpdateLoader.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/UpdateLoader.java Fri Sep 26 17:12:31 2014
@@ -102,7 +102,7 @@ final class UpdateLoader implements Lock
 
         this.normalizeToUpper = normalizeToUpper;
 		this.parent = parent;
-		lf = (LockFactory) Monitor.getServiceModule(parent, Module.LockFactory);
+		lf = (LockFactory) getServiceModule(parent, Module.LockFactory);
 		compat = (lf != null) ? lf.createCompatibilitySpace(this) : null;
 
 		if (verbose) {
@@ -434,24 +434,36 @@ final class UpdateLoader implements Lock
      */
     private  static  Context    getContextOrNull( final String contextID )
     {
-        if ( System.getSecurityManager() == null )
-        {
-            return ContextService.getContextOrNull( contextID );
-        }
-        else
-        {
-            return AccessController.doPrivileged
-                (
-                 new PrivilegedAction<Context>()
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<Context>()
+             {
+                 public Context run()
                  {
-                     public Context run()
-                     {
-                         return ContextService.getContextOrNull( contextID );
-                     }
+                     return ContextService.getContextOrNull( contextID );
                  }
-                 );
-        }
+             }
+             );
     }
+    
+    /**
+     * Privileged module lookup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private static  Object getServiceModule( final Object serviceModule, final String factoryInterface )
+    {
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<Object>()
+             {
+                 public Object run()
+                 {
+                     return Monitor.getServiceModule( serviceModule, factoryInterface );
+                 }
+             }
+             );
+    }
+
 }
 
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/stream/SingleStream.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/stream/SingleStream.java?rev=1627831&r1=1627830&r2=1627831&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/stream/SingleStream.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/stream/SingleStream.java Fri Sep 26 17:12:31 2014
@@ -26,6 +26,7 @@ import org.apache.derby.iapi.services.st
 import org.apache.derby.iapi.services.stream.PrintWriterGetHeader;
 
 import org.apache.derby.iapi.services.monitor.ModuleControl;
+import org.apache.derby.iapi.services.monitor.ModuleFactory;
 import org.apache.derby.iapi.services.monitor.Monitor;
 
 import org.apache.derby.iapi.reference.Property;
@@ -38,6 +39,9 @@ import java.io.OutputStream;
 import java.io.File;
 import java.io.Writer;
 
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
 import java.util.Properties;
 
 import java.lang.reflect.Method;
@@ -189,7 +193,7 @@ implements InfoStreams, ModuleControl, j
 
 		// See if this needs to be made relative to something ...
 		if (!streamFile.isAbsolute()) {
-			Object monitorEnv = Monitor.getMonitor().getEnvironment();
+			Object monitorEnv = getMonitor().getEnvironment();
 			if (monitorEnv instanceof File)
 				streamFile = new File((File) monitorEnv, fileName);
 		}
@@ -400,5 +404,24 @@ implements InfoStreams, ModuleControl, j
         // SECURITY PERMISSION - OP4, OP5
         return PBmakeFileHPW(PBfileName, PBheader);
     }
+    
+    /**
+     * Privileged Monitor lookup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  ModuleFactory  getMonitor()
+    {
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<ModuleFactory>()
+             {
+                 public ModuleFactory run()
+                 {
+                     return Monitor.getMonitor();
+                 }
+             }
+             );
+    }
+
 }
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/uuid/BasicUUIDFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/uuid/BasicUUIDFactory.java?rev=1627831&r1=1627830&r2=1627831&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/uuid/BasicUUIDFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/uuid/BasicUUIDFactory.java Fri Sep 26 17:12:31 2014
@@ -21,6 +21,10 @@
 
 package org.apache.derby.impl.services.uuid;
 
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import org.apache.derby.iapi.services.monitor.ModuleFactory;
 import org.apache.derby.iapi.services.monitor.Monitor;
 import org.apache.derby.catalog.UUID;
 import org.apache.derby.iapi.services.uuid.UUIDFactory;
@@ -66,7 +70,7 @@ public final class BasicUUIDFactory
 	private long timemillis;
 
 	public BasicUUIDFactory() {
-		Object env = Monitor.getMonitor().getEnvironment();
+		Object env = getMonitor().getEnvironment();
 		if (env != null) {
 			String s = env.toString();
 			if (s != null)
@@ -154,5 +158,24 @@ public final class BasicUUIDFactory
 		timemillis = System.currentTimeMillis();
 		currentValue = INITIAL_VALUE;
 	}
+    
+    /**
+     * Privileged Monitor lookup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  ModuleFactory  getMonitor()
+    {
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<ModuleFactory>()
+             {
+                 public ModuleFactory run()
+                 {
+                     return Monitor.getMonitor();
+                 }
+             }
+             );
+    }
+
 }
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericLanguageFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericLanguageFactory.java?rev=1627831&r1=1627830&r2=1627831&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericLanguageFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericLanguageFactory.java Fri Sep 26 17:12:31 2014
@@ -39,6 +39,9 @@ import org.apache.derby.iapi.services.lo
 
 import org.apache.derby.iapi.services.io.FormatIdUtil;
 
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.Properties;
 
 /**
@@ -69,7 +72,7 @@ public class GenericLanguageFactory impl
 	 */
 	public void boot(boolean create, Properties startParams) throws StandardException 
 	{		
-		LanguageConnectionFactory lcf = (LanguageConnectionFactory)  Monitor.findServiceModule(this, LanguageConnectionFactory.MODULE);
+		LanguageConnectionFactory lcf = (LanguageConnectionFactory)  findServiceModule(this, LanguageConnectionFactory.MODULE);
 		PropertyFactory pf = lcf.getPropertyFactory();
 		if (pf != null)
 			pf.addPropertySetNotification(new LanguageDbPropertySetter());
@@ -140,4 +143,29 @@ public class GenericLanguageFactory impl
 	** when we make putResultSets available for users'
 	** server-side JDBC methods.
 	*/
+    /**
+     * Privileged startup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  Object findServiceModule( final Object serviceModule, final String factoryInterface)
+        throws StandardException
+    {
+        try {
+            return AccessController.doPrivileged
+                (
+                 new PrivilegedExceptionAction<Object>()
+                 {
+                     public Object run()
+                         throws StandardException
+                     {
+                         return Monitor.findServiceModule( serviceModule, factoryInterface );
+                     }
+                 }
+                 );
+        } catch (PrivilegedActionException pae)
+        {
+            throw StandardException.plainWrapException( pae );
+        }
+    }
+
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java?rev=1627831&r1=1627830&r2=1627831&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java Fri Sep 26 17:12:31 2014
@@ -38,6 +38,7 @@ import org.apache.derby.iapi.services.co
 import org.apache.derby.iapi.services.context.ContextService;
 import org.apache.derby.iapi.services.io.ArrayUtil;
 import org.apache.derby.iapi.services.loader.GeneratedClass;
+import org.apache.derby.iapi.services.monitor.ModuleFactory;
 import org.apache.derby.iapi.services.monitor.Monitor;
 import org.apache.derby.shared.common.sanity.SanityManager;
 import org.apache.derby.iapi.services.stream.HeaderPrintWriter;
@@ -182,7 +183,7 @@ public class GenericPreparedStatement
 	GenericPreparedStatement() {
 		/* Get the UUID for this prepared statement */
 		UUIDFactory uuidFactory = 
-			Monitor.getMonitor().getUUIDFactory();
+			getMonitor().getUUIDFactory();
 
 		UUIDValue = uuidFactory.createUUID();
 		UUIDString = UUIDValue.toString();
@@ -1401,23 +1402,35 @@ recompileOutOfDatePlan:
      */
     private  static  ContextService    getContextService()
     {
-        if ( System.getSecurityManager() == null )
-        {
-            return ContextService.getFactory();
-        }
-        else
-        {
-            return AccessController.doPrivileged
-                (
-                 new PrivilegedAction<ContextService>()
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<ContextService>()
+             {
+                 public ContextService run()
                  {
-                     public ContextService run()
-                     {
-                         return ContextService.getFactory();
-                     }
+                     return ContextService.getFactory();
                  }
-                 );
-        }
+             }
+             );
+    }
+
+    
+    /**
+     * Privileged Monitor lookup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  ModuleFactory  getMonitor()
+    {
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<ModuleFactory>()
+             {
+                 public ModuleFactory run()
+                 {
+                     return Monitor.getMonitor();
+                 }
+             }
+             );
     }
 
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DD_Version.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DD_Version.java?rev=1627831&r1=1627830&r2=1627831&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DD_Version.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DD_Version.java Fri Sep 26 17:12:31 2014
@@ -40,6 +40,9 @@ import org.apache.derby.iapi.util.IdUtil
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.HashSet;
 import java.util.Properties;
 
@@ -192,7 +195,7 @@ public	class DD_Version implements	Forma
 
 		} else {
            
-			if (Monitor.isFullUpgrade(startParams, dictionaryVersion.toString())) {
+			if (isFullUpgrade(startParams, dictionaryVersion.toString())) {
 				performMajorUpgrade = true;
 			} else {
 				softUpgradeRun = true;
@@ -724,7 +727,7 @@ public	class DD_Version implements	Forma
 	 */
 	private int getJBMSMinorVersionNumber() 
 	{
-		ProductVersionHolder jbmsVersion = Monitor.getMonitor().getEngineVersion();
+		ProductVersionHolder jbmsVersion = DataDictionaryImpl.getMonitor().getEngineVersion();
 
 		return jbmsVersion.getMinorVersion()*100 +jbmsVersion.getMaintVersion() + (jbmsVersion.isBeta() ? 0 : 1) + 2;
 	}
@@ -815,4 +818,29 @@ public	class DD_Version implements	Forma
 		return true;
 	}
 
+    /**
+     * Privileged startup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  boolean isFullUpgrade( final Properties startParams, final String oldVersionInfo )
+        throws StandardException
+    {
+        try {
+            return AccessController.doPrivileged
+                (
+                 new PrivilegedExceptionAction<Boolean>()
+                 {
+                     public Boolean run()
+                         throws StandardException
+                     {
+                         return Monitor.isFullUpgrade( startParams, oldVersionInfo );
+                     }
+                 }
+                 ).booleanValue();
+        } catch (PrivilegedActionException pae)
+        {
+            throw StandardException.plainWrapException( pae );
+        }
+    }
+
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java?rev=1627831&r1=1627830&r2=1627831&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java Fri Sep 26 17:12:31 2014
@@ -24,7 +24,9 @@ package org.apache.derby.impl.sql.catalo
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.security.PrivilegedActionException;
 import java.security.PrivilegedAction;
+import java.security.PrivilegedExceptionAction;
 import java.security.AccessController;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
@@ -75,6 +77,7 @@ import org.apache.derby.iapi.services.lo
 import org.apache.derby.iapi.services.locks.ShExLockable;
 import org.apache.derby.iapi.services.locks.ShExQual;
 import org.apache.derby.iapi.services.monitor.ModuleControl;
+import org.apache.derby.iapi.services.monitor.ModuleFactory;
 import org.apache.derby.iapi.services.monitor.ModuleSupportable;
 import org.apache.derby.iapi.services.monitor.Monitor;
 import org.apache.derby.iapi.services.property.PropertyUtil;
@@ -517,7 +520,7 @@ public final class	DataDictionaryImpl
 
 		startupParameters = startParams;
 
-		uuidFactory = Monitor.getMonitor().getUUIDFactory();
+		uuidFactory = getMonitor().getUUIDFactory();
 
 		engineType = Monitor.getEngineType( startParams );
 
@@ -534,11 +537,11 @@ public final class	DataDictionaryImpl
 		// REMIND: actually, we're supposed to get the DataValueFactory
 		// out of the connection context...this is a bit of a shortcut.
 		// We get the DataValueFactory early in order to help bootstrap the system catalogs.
-		LanguageConnectionFactory langConnFactory = (LanguageConnectionFactory) Monitor.bootServiceModule(
+		LanguageConnectionFactory langConnFactory = (LanguageConnectionFactory) bootServiceModule(
 			create, this, LanguageConnectionFactory.MODULE, startParams);
 
 		dvf = langConnFactory.getDataValueFactory();
-		exFactory = (ExecutionFactory) Monitor.bootServiceModule(
+		exFactory = (ExecutionFactory) bootServiceModule(
 														create, this,
 														ExecutionFactory.MODULE,
 														startParams);
@@ -662,7 +665,7 @@ public final class	DataDictionaryImpl
 		 * Get the table descriptor cache.
 		 */
 		CacheFactory cf =
-				(CacheFactory) Monitor.startSystemModule(org.apache.derby.iapi.reference.Module.CacheFactory);
+				(CacheFactory) startSystemModule(org.apache.derby.iapi.reference.Module.CacheFactory);
 		OIDTdCache =
 			cf.newCacheManager(this,
 				"TableDescriptorOIDCache",
@@ -694,7 +697,7 @@ public final class	DataDictionaryImpl
 		cacheCoordinator = new ShExLockable();
 
 		/* Get AccessFactory in order to transaction stuff */
-		af = (AccessFactory)  Monitor.findServiceModule(this, AccessFactory.MODULE);
+		af = (AccessFactory)  findServiceModule(this, AccessFactory.MODULE);
 
 		/* Get the lock factory */
 		lockFactory = af.getLockFactory();
@@ -931,7 +934,7 @@ public final class	DataDictionaryImpl
         if( permissionsCache == null)
         {
             CacheFactory cf =
-              (CacheFactory) Monitor.startSystemModule(org.apache.derby.iapi.reference.Module.CacheFactory);
+              (CacheFactory) startSystemModule(org.apache.derby.iapi.reference.Module.CacheFactory);
             LanguageConnectionContext lcc = getLCC();
             TransactionController tc = lcc.getTransactionExecute();
             permissionsCacheSize = PropertyUtil.getServiceInt( tc,
@@ -14578,22 +14581,115 @@ public final class	DataDictionaryImpl
      */
     private  static  Context    getContext( final String contextID )
     {
-        if ( System.getSecurityManager() == null )
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<Context>()
+             {
+                 public Context run()
+                 {
+                     return ContextService.getContext( contextID );
+                 }
+             }
+             );
+    }
+    
+    /**
+     * Privileged Monitor lookup. Must be package private so that user code
+     * can't call this entry point.
+     */
+    static  ModuleFactory  getMonitor()
+    {
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<ModuleFactory>()
+             {
+                 public ModuleFactory run()
+                 {
+                     return Monitor.getMonitor();
+                 }
+             }
+             );
+    }
+
+    
+    /**
+     * Privileged startup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  Object  startSystemModule( final String factoryInterface )
+        throws StandardException
+    {
+        try {
+            return AccessController.doPrivileged
+                (
+                 new PrivilegedExceptionAction<Object>()
+                 {
+                     public Object run()
+                         throws StandardException
+                     {
+                         return Monitor.startSystemModule( factoryInterface );
+                     }
+                 }
+                 );
+        } catch (PrivilegedActionException pae)
         {
-            return ContextService.getContext( contextID );
+            throw StandardException.plainWrapException( pae );
         }
-        else
+    }
+
+    
+    /**
+     * Privileged startup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  Object bootServiceModule
+        (
+         final boolean create, final Object serviceModule,
+         final String factoryInterface, final Properties properties
+         )
+        throws StandardException
+    {
+        try {
+            return AccessController.doPrivileged
+                (
+                 new PrivilegedExceptionAction<Object>()
+                 {
+                     public Object run()
+                         throws StandardException
+                     {
+                         return Monitor.bootServiceModule( create, serviceModule, factoryInterface, properties );
+                     }
+                 }
+                 );
+        } catch (PrivilegedActionException pae)
         {
+            throw StandardException.plainWrapException( pae );
+        }
+    }
+
+    /**
+     * Privileged startup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  Object findServiceModule( final Object serviceModule, final String factoryInterface)
+        throws StandardException
+    {
+        try {
             return AccessController.doPrivileged
                 (
-                 new PrivilegedAction<Context>()
+                 new PrivilegedExceptionAction<Object>()
                  {
-                     public Context run()
+                     public Object run()
+                         throws StandardException
                      {
-                         return ContextService.getContext( contextID );
+                         return Monitor.findServiceModule( serviceModule, factoryInterface );
                      }
                  }
                  );
+        } catch (PrivilegedActionException pae)
+        {
+            throw StandardException.plainWrapException( pae );
         }
     }
+    
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DropDependencyFilter.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DropDependencyFilter.java?rev=1627831&r1=1627830&r2=1627831&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DropDependencyFilter.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DropDependencyFilter.java Fri Sep 26 17:12:31 2014
@@ -140,7 +140,7 @@ public class DropDependencyFilter implem
 	{
 		if ( uuidFactory == null )
 		{
-			uuidFactory = Monitor.getMonitor().getUUIDFactory();
+			uuidFactory = DataDictionaryImpl.getMonitor().getUUIDFactory();
 		}
 		return	uuidFactory;
 	}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConstraintDefinitionNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConstraintDefinitionNode.java?rev=1627831&r1=1627830&r2=1627831&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConstraintDefinitionNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConstraintDefinitionNode.java Fri Sep 26 17:12:31 2014
@@ -21,11 +21,14 @@
 
 package	org.apache.derby.impl.sql.compile;
 
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.Properties;
 import org.apache.derby.catalog.UUID;
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.services.context.ContextManager;
+import org.apache.derby.iapi.services.monitor.ModuleFactory;
 import org.apache.derby.iapi.services.monitor.Monitor;
 import org.apache.derby.shared.common.sanity.SanityManager;
 import org.apache.derby.iapi.services.uuid.UUIDFactory;
@@ -497,7 +500,7 @@ public class ConstraintDefinitionNode ex
 	{
 		if ( uuidFactory == null )
 		{
-			uuidFactory = Monitor.getMonitor().getUUIDFactory();
+			uuidFactory = getMonitor().getUUIDFactory();
 		}
 		return	uuidFactory;
 	}
@@ -539,4 +542,23 @@ public class ConstraintDefinitionNode ex
 
         constraintText = sb.toString();
     }
+    
+    /**
+     * Privileged Monitor lookup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  ModuleFactory  getMonitor()
+    {
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<ModuleFactory>()
+             {
+                 public ModuleFactory run()
+                 {
+                     return Monitor.getMonitor();
+                 }
+             }
+             );
+    }
+
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionFactory.java?rev=1627831&r1=1627830&r2=1627831&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionFactory.java Fri Sep 26 17:12:31 2014
@@ -54,6 +54,7 @@ import org.apache.derby.shared.common.sa
 
 import org.apache.derby.iapi.services.monitor.Monitor;
 import org.apache.derby.iapi.services.monitor.ModuleControl;
+import org.apache.derby.iapi.services.monitor.ModuleFactory;
 import org.apache.derby.iapi.services.monitor.ModuleSupportable;
 import org.apache.derby.iapi.services.context.ContextManager;
 
@@ -69,6 +70,10 @@ import org.apache.derby.iapi.reference.S
 import org.apache.derby.iapi.reference.Property;
 import org.apache.derby.iapi.reference.EngineType;
 
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedExceptionAction;
 import java.util.Properties;
 import java.util.Dictionary;
 import java.io.Serializable;
@@ -286,26 +291,26 @@ public class GenericLanguageConnectionFa
 		//booted DVF (DVF got booted by BasicDatabase's boot method. 
 		//BasicDatabase also set the correct Locale in the DVF. There after,
 		//DVF with correct Locale is available to rest of the Derby code.
-		dvf = (DataValueFactory) Monitor.bootServiceModule(create, this, org.apache.derby.iapi.reference.ClassName.DataValueFactory, startParams);
-		javaFactory = (JavaFactory) Monitor.startSystemModule(org.apache.derby.iapi.reference.Module.JavaFactory);
-		uuidFactory = Monitor.getMonitor().getUUIDFactory();
-		classFactory = (ClassFactory) Monitor.getServiceModule(this, org.apache.derby.iapi.reference.Module.ClassFactory);
+		dvf = (DataValueFactory) bootServiceModule(create, this, org.apache.derby.iapi.reference.ClassName.DataValueFactory, startParams);
+		javaFactory = (JavaFactory) startSystemModule(org.apache.derby.iapi.reference.Module.JavaFactory);
+		uuidFactory = getMonitor().getUUIDFactory();
+		classFactory = (ClassFactory) getServiceModule(this, org.apache.derby.iapi.reference.Module.ClassFactory);
 		if (classFactory == null)
- 			classFactory = (ClassFactory) Monitor.findSystemModule(org.apache.derby.iapi.reference.Module.ClassFactory);
+ 			classFactory = (ClassFactory) findSystemModule(org.apache.derby.iapi.reference.Module.ClassFactory);
 
 		//set the property validation module needed to do propertySetCallBack
 		//register and property validation
 		setValidation();
 
-		ef = (ExecutionFactory) Monitor.bootServiceModule(create, this, ExecutionFactory.MODULE, startParams);
-		of = (OptimizerFactory) Monitor.bootServiceModule(create, this, OptimizerFactory.MODULE, startParams);
+		ef = (ExecutionFactory) bootServiceModule(create, this, ExecutionFactory.MODULE, startParams);
+		of = (OptimizerFactory) bootServiceModule(create, this, OptimizerFactory.MODULE, startParams);
 		tcf =
-		   (TypeCompilerFactory) Monitor.startSystemModule(TypeCompilerFactory.MODULE);
+		   (TypeCompilerFactory) startSystemModule(TypeCompilerFactory.MODULE);
 
 		// If the system supports statement caching boot the CacheFactory module.
 		int cacheSize = statementCacheSize(startParams);
 		if (cacheSize > 0) {
-			CacheFactory cacheFactory = (CacheFactory) Monitor.startSystemModule(org.apache.derby.iapi.reference.Module.CacheFactory);
+			CacheFactory cacheFactory = (CacheFactory) startSystemModule(org.apache.derby.iapi.reference.Module.CacheFactory);
 			singleStatementCache = cacheFactory.newCacheManager(this,
 												"StatementCache",
 												cacheSize/4,
@@ -314,7 +319,7 @@ public class GenericLanguageConnectionFa
             // Start a management bean for the statement cache to allow
             // monitoring through JMX, if it is available and enabled.
             DataFactory df = (DataFactory)
-                    Monitor.findServiceModule(this, DataFactory.MODULE);
+                    findServiceModule(this, DataFactory.MODULE);
             singleStatementCache.registerMBean(df.getRootDirectory());
 		}
 
@@ -413,7 +418,7 @@ public class GenericLanguageConnectionFa
 	}
 
 	protected void setValidation() throws StandardException {
-		pf = (PropertyFactory) Monitor.findServiceModule(this,
+		pf = (PropertyFactory) findServiceModule(this,
 			org.apache.derby.iapi.reference.Module.PropertyFactory);
 		pf.addPropertySetNotification(this);
 	}
@@ -435,4 +440,148 @@ public class GenericLanguageConnectionFa
 	{
 		return nextLCCInstanceNumber++;
 	}
+    
+    /**
+     * Privileged Monitor lookup. Must be package private so that user code
+     * can't call this entry point.
+     */
+    static  ModuleFactory  getMonitor()
+    {
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<ModuleFactory>()
+             {
+                 public ModuleFactory run()
+                 {
+                     return Monitor.getMonitor();
+                 }
+             }
+             );
+    }
+
+    
+    /**
+     * Privileged startup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  Object  startSystemModule( final String factoryInterface )
+        throws StandardException
+    {
+        try {
+            return AccessController.doPrivileged
+                (
+                 new PrivilegedExceptionAction<Object>()
+                 {
+                     public Object run()
+                         throws StandardException
+                     {
+                         return Monitor.startSystemModule( factoryInterface );
+                     }
+                 }
+                 );
+        } catch (PrivilegedActionException pae)
+        {
+            throw StandardException.plainWrapException( pae );
+        }
+    }
+
+    
+    /**
+     * Privileged lookup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  Object  findSystemModule( final String factoryInterface )
+        throws StandardException
+    {
+        try {
+            return AccessController.doPrivileged
+                (
+                 new PrivilegedExceptionAction<Object>()
+                 {
+                     public Object run()
+                         throws StandardException
+                     {
+                         return Monitor.findSystemModule( factoryInterface );
+                     }
+                 }
+                 );
+        } catch (PrivilegedActionException pae)
+        {
+            throw StandardException.plainWrapException( pae );
+        }
+    }
+
+    
+    /**
+     * Privileged startup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  Object bootServiceModule
+        (
+         final boolean create, final Object serviceModule,
+         final String factoryInterface, final Properties properties
+         )
+        throws StandardException
+    {
+        try {
+            return AccessController.doPrivileged
+                (
+                 new PrivilegedExceptionAction<Object>()
+                 {
+                     public Object run()
+                         throws StandardException
+                     {
+                         return Monitor.bootServiceModule( create, serviceModule, factoryInterface, properties );
+                     }
+                 }
+                 );
+        } catch (PrivilegedActionException pae)
+        {
+            throw StandardException.plainWrapException( pae );
+        }
+    }
+
+    /**
+     * Privileged startup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  Object findServiceModule( final Object serviceModule, final String factoryInterface)
+        throws StandardException
+    {
+        try {
+            return AccessController.doPrivileged
+                (
+                 new PrivilegedExceptionAction<Object>()
+                 {
+                     public Object run()
+                         throws StandardException
+                     {
+                         return Monitor.findServiceModule( serviceModule, factoryInterface );
+                     }
+                 }
+                 );
+        } catch (PrivilegedActionException pae)
+        {
+            throw StandardException.plainWrapException( pae );
+        }
+    }
+
+    /**
+     * Privileged module lookup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private static  Object getServiceModule( final Object serviceModule, final String factoryInterface )
+    {
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<Object>()
+             {
+                 public Object run()
+                 {
+                     return Monitor.getServiceModule( serviceModule, factoryInterface );
+                 }
+             }
+             );
+    }
+
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericStatementContext.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericStatementContext.java?rev=1627831&r1=1627830&r2=1627831&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericStatementContext.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericStatementContext.java Fri Sep 26 17:12:31 2014
@@ -188,7 +188,7 @@ final class GenericStatementContext 
     }
 
     private static TimerFactory getTimerFactory() {
-        return Monitor.getMonitor().getTimerFactory();
+        return GenericLanguageConnectionFactory.getMonitor().getTimerFactory();
     }
 
 	// StatementContext Interface

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java?rev=1627831&r1=1627830&r2=1627831&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java Fri Sep 26 17:12:31 2014
@@ -21,6 +21,8 @@
 
 package org.apache.derby.impl.sql.execute;
 
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.sql.SQLWarning;
@@ -44,6 +46,7 @@ import org.apache.derby.iapi.services.io
 import org.apache.derby.iapi.services.loader.GeneratedByteCode;
 import org.apache.derby.iapi.services.loader.GeneratedClass;
 import org.apache.derby.iapi.services.loader.GeneratedMethod;
+import org.apache.derby.iapi.services.monitor.ModuleFactory;
 import org.apache.derby.iapi.services.monitor.Monitor;
 import org.apache.derby.iapi.services.property.PropertyUtil;
 import org.apache.derby.iapi.services.uuid.UUIDFactory;
@@ -254,7 +257,7 @@ public abstract class BaseActivation imp
 
 		/* Get the UUID for this activation */
 		UUIDFactory uuidFactory =
-			Monitor.getMonitor().getUUIDFactory();
+			getMonitor().getUUIDFactory();
 
 		UUIDValue = uuidFactory.createUUID();
 		UUIDString = UUIDValue.toString();
@@ -1901,4 +1904,23 @@ public abstract class BaseActivation imp
 							 LanguageConnectionContext lcc)
 			throws StandardException {
 	}
+    
+    /**
+     * Privileged Monitor lookup. Must be package private so that user code
+     * can't call this entry point.
+     */
+    static  ModuleFactory  getMonitor()
+    {
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<ModuleFactory>()
+             {
+                 public ModuleFactory run()
+                 {
+                     return Monitor.getMonitor();
+                 }
+             }
+             );
+    }
+
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericExecutionFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericExecutionFactory.java?rev=1627831&r1=1627830&r2=1627831&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericExecutionFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericExecutionFactory.java Fri Sep 26 17:12:31 2014
@@ -56,6 +56,9 @@ import org.apache.derby.iapi.services.lo
 import org.apache.derby.iapi.services.context.ContextManager;
 import org.apache.derby.catalog.UUID;
 import org.apache.derby.iapi.services.io.FormatableBitSet;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.Properties;
 import java.util.Vector;
 
@@ -154,7 +157,7 @@ public class GenericExecutionFactory
                     throws StandardException {
         if (rssFactory == null) {
             rssFactory = (ResultSetStatisticsFactory)
-                Monitor.bootServiceModule(
+                bootServiceModule(
                                     false,
                                     this,
                                     ResultSetStatisticsFactory.MODULE,
@@ -370,7 +373,7 @@ private XPLAINFactoryIF xplainFactory; 
                    throws StandardException {
        if (xplainFactory == null) {
            xplainFactory = (XPLAINFactoryIF)
-               Monitor.bootServiceModule(
+               bootServiceModule(
                                    false,
                                    this,
                                    XPLAINFactoryIF.MODULE,
@@ -379,4 +382,34 @@ private XPLAINFactoryIF xplainFactory; 
        return xplainFactory;
    }
 
+    
+    /**
+     * Privileged startup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  Object bootServiceModule
+        (
+         final boolean create, final Object serviceModule,
+         final String factoryInterface, final Properties properties
+         )
+        throws StandardException
+    {
+        try {
+            return AccessController.doPrivileged
+                (
+                 new PrivilegedExceptionAction<Object>()
+                 {
+                     public Object run()
+                         throws StandardException
+                     {
+                         return Monitor.bootServiceModule( create, serviceModule, factoryInterface, properties );
+                     }
+                 }
+                 );
+        } catch (PrivilegedActionException pae)
+        {
+            throw StandardException.plainWrapException( pae );
+        }
+    }
+
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/JarUtil.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/JarUtil.java?rev=1627831&r1=1627830&r2=1627831&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/JarUtil.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/JarUtil.java Fri Sep 26 17:12:31 2014
@@ -144,7 +144,7 @@ public class JarUtil
         try {
             notifyLoader(false);
             dd.invalidateAllSPSPlans();
-            UUID id = Monitor.getMonitor().getUUIDFactory().createUUID();
+            UUID id = BaseActivation.getMonitor().getUUIDFactory().createUUID();
             final String jarExternalName = JarUtil.mkExternalName(
                 id, schemaName, sqlName, fr.getSeparatorChar());
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/PropertyConglomerate.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/PropertyConglomerate.java?rev=1627831&r1=1627830&r2=1627831&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/PropertyConglomerate.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/PropertyConglomerate.java Fri Sep 26 17:12:31 2014
@@ -53,6 +53,9 @@ import org.apache.derby.iapi.store.raw.R
 import org.apache.derby.iapi.types.DataValueDescriptor;
 
 import java.io.Serializable;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.Hashtable;
@@ -450,7 +453,7 @@ class PropertyConglomerate
 			AccessFactory af = ((TransactionManager)tc).getAccessManager();
 
 			RawStoreFactory rsf = (RawStoreFactory)
-				Monitor.findServiceModule(af, RawStoreFactory.MODULE);
+				findServiceModule(af, RawStoreFactory.MODULE);
 
 			// remove secret key from properties list if possible
 			serviceProperties.remove(Attribute.BOOT_PASSWORD);
@@ -781,6 +784,31 @@ class PropertyConglomerate
 		Object csGroup = cs.getOwner();
 		return lf.isLockHeld(cs, csGroup, cachedLock, ShExQual.EX);
 	}
+    /**
+     * Privileged startup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  Object findServiceModule( final Object serviceModule, final String factoryInterface)
+        throws StandardException
+    {
+        try {
+            return AccessController.doPrivileged
+                (
+                 new PrivilegedExceptionAction<Object>()
+                 {
+                     public Object run()
+                         throws StandardException
+                     {
+                         return Monitor.findServiceModule( serviceModule, factoryInterface );
+                     }
+                 }
+                 );
+        } catch (PrivilegedActionException pae)
+        {
+            throw StandardException.plainWrapException( pae );
+        }
+    }
+
 }
 
 /**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/RAMAccessManager.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/RAMAccessManager.java?rev=1627831&r1=1627830&r2=1627831&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/RAMAccessManager.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/RAMAccessManager.java Fri Sep 26 17:12:31 2014
@@ -35,6 +35,7 @@ import org.apache.derby.iapi.services.co
 import org.apache.derby.iapi.services.daemon.Serviceable;
 import org.apache.derby.iapi.services.locks.LockFactory;
 import org.apache.derby.iapi.services.monitor.ModuleControl;
+import org.apache.derby.iapi.services.monitor.ModuleFactory;
 import org.apache.derby.iapi.services.monitor.Monitor;
 import org.apache.derby.iapi.services.monitor.PersistentService;
 import org.apache.derby.iapi.services.property.PropertySetCallback;
@@ -68,6 +69,8 @@ import org.apache.derby.iapi.reference.S
 import org.apache.derby.iapi.reference.Attribute;
 
 import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.security.AccessController;
 import java.util.Dictionary;
 import java.util.Enumeration;
@@ -436,7 +439,7 @@ public abstract class RAMAccessManager
     {
         // Get a cache factory to create the conglomerate cache.
 		CacheFactory cf = 
-            (CacheFactory) Monitor.startSystemModule(
+            (CacheFactory) startSystemModule(
                  org.apache.derby.iapi.reference.Module.CacheFactory);
 
         // Now create the conglomerate cache.
@@ -642,7 +645,7 @@ public abstract class RAMAccessManager
 
 		try {
 			factory = 
-               (MethodFactory) Monitor.bootServiceModule(
+               (MethodFactory) bootServiceModule(
                     false, this, MethodFactory.MODULE, 
                     impltype, conglomProperties);
 		} catch (StandardException se) {
@@ -866,12 +869,12 @@ public abstract class RAMAccessManager
         rawstore.createDataWarningFile();
 
         //creating readme in log directory
-        LogFactory logFactory =(LogFactory) Monitor.findServiceModule(this, rawstore.getLogFactoryModule());
+        LogFactory logFactory =(LogFactory) findServiceModule(this, rawstore.getLogFactoryModule());
         logFactory.createDataWarningFile();
 
         //creating readme in root database directory
-        DataFactory dataFactory =(DataFactory) Monitor.findServiceModule(this, rawstore.getDataFactoryModule());
-        PersistentService ps = Monitor.getMonitor().getServiceType(rawstore);
+        DataFactory dataFactory =(DataFactory) findServiceModule(this, rawstore.getDataFactoryModule());
+        PersistentService ps = getMonitor().getServiceType(rawstore);
         ps.createDataWarningFile(dataFactory.getStorageFactory());
     }
 	
@@ -1035,7 +1038,7 @@ public abstract class RAMAccessManager
 
         // Access depends on a Raw Store implementations.  Load it.
         //
-        rawstore = (RawStoreFactory) Monitor.bootServiceModule(
+        rawstore = (RawStoreFactory) bootServiceModule(
             create, this, RawStoreFactory.MODULE, serviceProperties);
 
 		// Note: we also boot this module here since we may start Derby
@@ -1044,7 +1047,7 @@ public abstract class RAMAccessManager
 		// /protocol/Database/Storage/Access/Interface/T_AccessFactory.java)
 		// If this module has already been booted by the JDBC layer, this will 
 		// have no effect at all.
-		Monitor.bootServiceModule(
+		bootServiceModule(
             create, this, org.apache.derby.iapi.reference.Module.PropertyFactory, 
             startParams);
 
@@ -1160,7 +1163,7 @@ public abstract class RAMAccessManager
 
         // set up the property validation
         pf = (PropertyFactory) 
-            Monitor.findServiceModule(
+            findServiceModule(
                 this, org.apache.derby.iapi.reference.Module.PropertyFactory);
 
         // set up the transaction properties.  On J9, over NFS, runing on a
@@ -1308,22 +1311,144 @@ public abstract class RAMAccessManager
      */
     private  static  Context    getContext( final String contextID )
     {
-        if ( System.getSecurityManager() == null )
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<Context>()
+             {
+                 public Context run()
+                 {
+                     return ContextService.getContext( contextID );
+                 }
+             }
+             );
+    }
+
+    
+    /**
+     * Privileged Monitor lookup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  ModuleFactory  getMonitor()
+    {
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<ModuleFactory>()
+             {
+                 public ModuleFactory run()
+                 {
+                     return Monitor.getMonitor();
+                 }
+             }
+             );
+    }
+
+    
+    /**
+     * Privileged startup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  Object  startSystemModule( final String factoryInterface )
+        throws StandardException
+    {
+        try {
+            return AccessController.doPrivileged
+                (
+                 new PrivilegedExceptionAction<Object>()
+                 {
+                     public Object run()
+                         throws StandardException
+                     {
+                         return Monitor.startSystemModule( factoryInterface );
+                     }
+                 }
+                 );
+        } catch (PrivilegedActionException pae)
         {
-            return ContextService.getContext( contextID );
+            throw StandardException.plainWrapException( pae );
         }
-        else
+    }
+
+    /**
+     * Privileged startup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  Object bootServiceModule
+        (
+         final boolean create, final Object serviceModule,
+         final String factoryInterface, final Properties properties
+         )
+        throws StandardException
+    {
+        try {
+            return AccessController.doPrivileged
+                (
+                 new PrivilegedExceptionAction<Object>()
+                 {
+                     public Object run()
+                         throws StandardException
+                     {
+                         return Monitor.bootServiceModule( create, serviceModule, factoryInterface, properties );
+                     }
+                 }
+                 );
+        } catch (PrivilegedActionException pae)
+        {
+            throw StandardException.plainWrapException( pae );
+        }
+    }
+
+
+    /**
+     * Privileged startup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  Object bootServiceModule
+        (
+         final boolean create, final Object serviceModule,
+         final String factoryInterface, final String identifier, final Properties properties
+         )
+        throws StandardException
+    {
+        try {
+            return AccessController.doPrivileged
+                (
+                 new PrivilegedExceptionAction<Object>()
+                 {
+                     public Object run()
+                         throws StandardException
+                     {
+                         return Monitor.bootServiceModule( create, serviceModule, factoryInterface, identifier, properties );
+                     }
+                 }
+                 );
+        } catch (PrivilegedActionException pae)
         {
+            throw StandardException.plainWrapException( pae );
+        }
+    }
+
+    /**
+     * Privileged startup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  Object findServiceModule( final Object serviceModule, final String factoryInterface)
+        throws StandardException
+    {
+        try {
             return AccessController.doPrivileged
                 (
-                 new PrivilegedAction<Context>()
+                 new PrivilegedExceptionAction<Object>()
                  {
-                     public Context run()
+                     public Object run()
+                         throws StandardException
                      {
-                         return ContextService.getContext( contextID );
+                         return Monitor.findServiceModule( serviceModule, factoryInterface );
                      }
                  }
                  );
+        } catch (PrivilegedActionException pae)
+        {
+            throw StandardException.plainWrapException( pae );
         }
     }
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/index/B2IFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/index/B2IFactory.java?rev=1627831&r1=1627830&r2=1627831&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/index/B2IFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/index/B2IFactory.java Fri Sep 26 17:12:31 2014
@@ -21,11 +21,14 @@
 
 package org.apache.derby.impl.store.access.btree.index;
 
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.Properties;
 
 import org.apache.derby.iapi.reference.SQLState;
 
 import org.apache.derby.iapi.services.monitor.ModuleControl;
+import org.apache.derby.iapi.services.monitor.ModuleFactory;
 import org.apache.derby.iapi.services.monitor.Monitor;
 import org.apache.derby.shared.common.sanity.SanityManager;
 
@@ -322,7 +325,7 @@ public class B2IFactory implements Congl
 	{
 		// Find the UUID factory.
 		UUIDFactory uuidFactory = 
-            Monitor.getMonitor().getUUIDFactory();
+            getMonitor().getUUIDFactory();
 
 		// Make a UUID that identifies this conglomerate's format.
 		formatUUID = uuidFactory.recreateUUID(FORMATUUIDSTRING);
@@ -331,4 +334,23 @@ public class B2IFactory implements Congl
 	public void	stop()
 	{
 	}
+    
+    /**
+     * Privileged Monitor lookup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  ModuleFactory  getMonitor()
+    {
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<ModuleFactory>()
+             {
+                 public ModuleFactory run()
+                 {
+                     return Monitor.getMonitor();
+                 }
+             }
+             );
+    }
+
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/HeapConglomerateFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/HeapConglomerateFactory.java?rev=1627831&r1=1627830&r2=1627831&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/HeapConglomerateFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/HeapConglomerateFactory.java Fri Sep 26 17:12:31 2014
@@ -24,6 +24,7 @@ package org.apache.derby.impl.store.acce
 import org.apache.derby.iapi.reference.SQLState;
 
 import org.apache.derby.iapi.services.monitor.ModuleControl;
+import org.apache.derby.iapi.services.monitor.ModuleFactory;
 import org.apache.derby.iapi.services.monitor.ModuleSupportable;
 import org.apache.derby.iapi.services.monitor.Monitor;
 import org.apache.derby.shared.common.sanity.SanityManager;
@@ -50,6 +51,8 @@ import org.apache.derby.iapi.services.uu
 
 import org.apache.derby.catalog.UUID;
 
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.Properties;
 
 // For JavaDoc references (i.e. @see)
@@ -309,7 +312,7 @@ public class HeapConglomerateFactory imp
 	{
 		// Find the UUID factory.
 		UUIDFactory uuidFactory = 
-            Monitor.getMonitor().getUUIDFactory();
+            getMonitor().getUUIDFactory();
 		
 		// Make a UUID that identifies this conglomerate's format.
 		formatUUID = uuidFactory.recreateUUID(FORMATUUIDSTRING);
@@ -326,5 +329,24 @@ public class HeapConglomerateFactory imp
 	public HeapConglomerateFactory()
 	{
 	}
+    
+    /**
+     * Privileged Monitor lookup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  ModuleFactory  getMonitor()
+    {
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<ModuleFactory>()
+             {
+                 public ModuleFactory run()
+                 {
+                     return Monitor.getMonitor();
+                 }
+             }
+             );
+    }
+
 }
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/sort/ExternalSortFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/sort/ExternalSortFactory.java?rev=1627831&r1=1627830&r2=1627831&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/sort/ExternalSortFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/sort/ExternalSortFactory.java Fri Sep 26 17:12:31 2014
@@ -21,9 +21,12 @@
 
 package org.apache.derby.impl.store.access.sort;
 
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.Properties;
 
 import org.apache.derby.iapi.services.monitor.ModuleControl;
+import org.apache.derby.iapi.services.monitor.ModuleFactory;
 import org.apache.derby.iapi.services.monitor.ModuleSupportable;
 import org.apache.derby.iapi.services.monitor.Monitor;
 import org.apache.derby.iapi.services.property.PropertyUtil;
@@ -356,7 +359,7 @@ public class ExternalSortFactory impleme
 		throws StandardException
 	{
 		// Find the UUID factory.
-		UUIDFactory uuidFactory = Monitor.getMonitor().getUUIDFactory();
+		UUIDFactory uuidFactory = getMonitor().getUUIDFactory();
 
 		// Make a UUID that identifies this sort's format.
 		formatUUID = uuidFactory.recreateUUID(FORMATUUIDSTRING);
@@ -387,4 +390,23 @@ public class ExternalSortFactory impleme
 	{
 	}
 
+    
+    /**
+     * Privileged Monitor lookup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  ModuleFactory  getMonitor()
+    {
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<ModuleFactory>()
+             {
+                 public ModuleFactory run()
+                 {
+                     return Monitor.getMonitor();
+                 }
+             }
+             );
+    }
+
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java?rev=1627831&r1=1627830&r2=1627831&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java Fri Sep 26 17:12:31 2014
@@ -33,6 +33,7 @@ import org.apache.derby.iapi.services.lo
 import org.apache.derby.iapi.services.locks.LockFactory;
 import org.apache.derby.iapi.services.monitor.Monitor;
 import org.apache.derby.iapi.services.monitor.ModuleControl;
+import org.apache.derby.iapi.services.monitor.ModuleFactory;
 import org.apache.derby.iapi.services.monitor.ModuleSupportable;
 import org.apache.derby.iapi.services.monitor.PersistentService;
 import org.apache.derby.shared.common.sanity.SanityManager;
@@ -70,6 +71,7 @@ import org.apache.derby.iapi.reference.P
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.security.SecureRandom;
 
 import java.util.Date;
@@ -181,14 +183,14 @@ public final class RawStore implements R
         }
 
 		DaemonFactory daemonFactory =
-			(DaemonFactory)Monitor.startSystemModule(org.apache.derby.iapi.reference.Module.DaemonFactory);
+			(DaemonFactory)startSystemModule(org.apache.derby.iapi.reference.Module.DaemonFactory);
 		rawStoreDaemon = daemonFactory.createNewDaemon("rawStoreDaemon");
 		xactFactory = (TransactionFactory)
-					Monitor.bootServiceModule(
+					bootServiceModule(
 						create, this, getTransactionFactoryModule(), properties);
 
 		dataFactory = (DataFactory)
-					Monitor.bootServiceModule(
+					bootServiceModule(
 					  create, this, getDataFactoryModule(), properties);
 		storageFactory = dataFactory.getStorageFactory();
 
@@ -231,7 +233,7 @@ public final class RawStore implements R
         }
         
 		// log factory is booted by the data factory
-		logFactory =(LogFactory) Monitor.findServiceModule(this, getLogFactoryModule());
+		logFactory =(LogFactory) findServiceModule(this, getLogFactoryModule());
 
 		// if this is a restore from backup, restore the jar files.
 		if(restoreFromBackup !=null)
@@ -328,7 +330,7 @@ public final class RawStore implements R
             // Can now start slave replication by booting the
             // SlaveFactory service
             slaveFactory = (SlaveFactory) 
-                Monitor.bootServiceModule(create, this,
+                bootServiceModule(create, this,
                                           getSlaveFactoryModule(),
                                           properties);
             slaveFactory.startSlave(this, logFactory);
@@ -528,7 +530,7 @@ public final class RawStore implements R
                                      replicationMode);
 
         MasterFactory masterFactory = (MasterFactory)
-            Monitor.bootServiceModule(true, this, getMasterFactoryModule(),
+            bootServiceModule(true, this, getMasterFactoryModule(),
                                       replicationProps);
         masterFactory.startMaster(this, dataFactory, logFactory,
                 host, port, dbmaster);
@@ -552,7 +554,7 @@ public final class RawStore implements R
 
         try {
             masterFactory = (MasterFactory) 
-                Monitor.findServiceModule(this, getMasterFactoryModule());
+                findServiceModule(this, getMasterFactoryModule());
         }
         catch (StandardException se) {
             throw StandardException.newException(
@@ -575,7 +577,7 @@ public final class RawStore implements R
 
         try {
             masterFactory = (MasterFactory) 
-                Monitor.findServiceModule(this, getMasterFactoryModule());
+                findServiceModule(this, getMasterFactoryModule());
         }
         catch (StandardException se) {
             throw StandardException.newException
@@ -874,9 +876,9 @@ public final class RawStore implements R
             
             try 
             {
-                String name = Monitor.getMonitor().getServiceName(this);
+                String name = getServiceName(this);
                 PersistentService ps = 
-                    Monitor.getMonitor().getServiceType(this);
+                    getMonitor().getServiceType(this);
                 String fullName = ps.getCanonicalServiceName(name);
                 Properties prop = 
                     ps.getServiceProperties(fullName, (Properties)null);
@@ -1297,8 +1299,8 @@ public final class RawStore implements R
             // for encrypted database, and this takes precedence over the
             // value specified by the user.
 
-            String name = Monitor.getMonitor().getServiceName(this);
-            PersistentService ps = Monitor.getMonitor().getServiceType(this);
+            String name = getServiceName(this);
+            PersistentService ps = getMonitor().getServiceType(this);
             String canonicalName = ps.getCanonicalServiceName(name);
             Properties serviceprops = ps.getServiceProperties(canonicalName,
                                                               (Properties)null);
@@ -1346,7 +1348,7 @@ public final class RawStore implements R
             // properties.
 
             CipherFactoryBuilder cb = (CipherFactoryBuilder)
-                Monitor.startSystemModule(org.apache.derby.iapi.reference.Module.CipherFactoryBuilder);
+                startSystemModule(org.apache.derby.iapi.reference.Module.CipherFactoryBuilder);
 
             // create instance of the cipher factory with the
             // specified encryption properties.
@@ -2859,22 +2861,132 @@ public final class RawStore implements R
      */
     private  static  Context    getContextOrNull( final String contextID )
     {
-        if ( System.getSecurityManager() == null )
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<Context>()
+             {
+                 public Context run()
+                 {
+                     return ContextService.getContextOrNull( contextID );
+                 }
+             }
+             );
+    }
+
+    
+    /**
+     * Privileged Monitor lookup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  ModuleFactory  getMonitor()
+    {
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<ModuleFactory>()
+             {
+                 public ModuleFactory run()
+                 {
+                     return Monitor.getMonitor();
+                 }
+             }
+             );
+    }
+
+
+    /**
+     * Privileged service name lookup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  String getServiceName( final Object serviceModule )
+    {
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<String>()
+             {
+                 public String run()
+                 {
+                     return Monitor.getServiceName( serviceModule );
+                 }
+             }
+             );
+    }
+    
+    /**
+     * Privileged startup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  Object  startSystemModule( final String factoryInterface )
+        throws StandardException
+    {
+        try {
+            return AccessController.doPrivileged
+                (
+                 new PrivilegedExceptionAction<Object>()
+                 {
+                     public Object run()
+                         throws StandardException
+                     {
+                         return Monitor.startSystemModule( factoryInterface );
+                     }
+                 }
+                 );
+        } catch (PrivilegedActionException pae)
         {
-            return ContextService.getContextOrNull( contextID );
+            throw StandardException.plainWrapException( pae );
         }
-        else
+    }
+
+    /**
+     * Privileged startup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  Object bootServiceModule
+        (
+         final boolean create, final Object serviceModule,
+         final String factoryInterface, final Properties properties
+         )
+        throws StandardException
+    {
+        try {
+            return AccessController.doPrivileged
+                (
+                 new PrivilegedExceptionAction<Object>()
+                 {
+                     public Object run()
+                         throws StandardException
+                     {
+                         return Monitor.bootServiceModule( create, serviceModule, factoryInterface, properties );
+                     }
+                 }
+                 );
+        } catch (PrivilegedActionException pae)
         {
+            throw StandardException.plainWrapException( pae );
+        }
+    }
+
+    /**
+     * Privileged startup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  Object findServiceModule( final Object serviceModule, final String factoryInterface)
+        throws StandardException
+    {
+        try {
             return AccessController.doPrivileged
                 (
-                 new PrivilegedAction<Context>()
+                 new PrivilegedExceptionAction<Object>()
                  {
-                     public Context run()
+                     public Object run()
+                         throws StandardException
                      {
-                         return ContextService.getContextOrNull( contextID );
+                         return Monitor.findServiceModule( serviceModule, factoryInterface );
                      }
                  }
                  );
+        } catch (PrivilegedActionException pae)
+        {
+            throw StandardException.plainWrapException( pae );
         }
     }
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java?rev=1627831&r1=1627830&r2=1627831&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java Fri Sep 26 17:12:31 2014
@@ -35,6 +35,7 @@ import org.apache.derby.iapi.services.co
 import org.apache.derby.iapi.services.daemon.DaemonService;
 import org.apache.derby.iapi.services.daemon.Serviceable;
 import org.apache.derby.iapi.services.monitor.ModuleControl;
+import org.apache.derby.iapi.services.monitor.ModuleFactory;
 import org.apache.derby.iapi.services.monitor.ModuleSupportable;
 import org.apache.derby.iapi.services.monitor.Monitor;
 import org.apache.derby.iapi.services.monitor.PersistentService;
@@ -257,7 +258,7 @@ public class BaseDataFileFactory
         throws StandardException 
     {
 
-		jbmsVersion = Monitor.getMonitor().getEngineVersion();
+		jbmsVersion = getMonitor().getEngineVersion();
 		
 		jvmVersion = buildJvmVersion();
 		
@@ -267,11 +268,11 @@ public class BaseDataFileFactory
 
 		dataDirectory = startParams.getProperty(PersistentService.ROOT);
 
-		UUIDFactory uf = Monitor.getMonitor().getUUIDFactory();
+		UUIDFactory uf = getMonitor().getUUIDFactory();
 
 		identifier = uf.createUUID();
 
-        PersistentService ps = Monitor.getMonitor().getServiceType(this);
+        PersistentService ps = getMonitor().getServiceType(this);
 
         try
         {
@@ -415,7 +416,7 @@ public class BaseDataFileFactory
 
 
 		CacheFactory cf = (CacheFactory) 
-            Monitor.startSystemModule(
+            startSystemModule(
                 org.apache.derby.iapi.reference.Module.CacheFactory);
 
         // Initialize the page cache
@@ -1747,7 +1748,7 @@ public class BaseDataFileFactory
         }
 
 		logFactory = (LogFactory)
-			Monitor.bootServiceModule(
+			bootServiceModule(
                 create, this, 
                 rawStoreFactory.getLogFactoryModule(), startParams);
 	}
@@ -1762,7 +1763,7 @@ public class BaseDataFileFactory
         try
         {
             PersistentService ps = 
-                Monitor.getMonitor().getServiceProvider(type);
+                getMonitor().getServiceProvider(type);
             return ps != null && ps.hasStorageFactory();
         }
         catch (StandardException se)
@@ -2930,4 +2931,78 @@ public class BaseDataFileFactory
 		}
         return null;
     } // end of run
+    
+    /**
+     * Privileged Monitor lookup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  ModuleFactory  getMonitor()
+    {
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<ModuleFactory>()
+             {
+                 public ModuleFactory run()
+                 {
+                     return Monitor.getMonitor();
+                 }
+             }
+             );
+    }
+
+    
+    /**
+     * Privileged startup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  Object  startSystemModule( final String factoryInterface )
+        throws StandardException
+    {
+        try {
+            return AccessController.doPrivileged
+                (
+                 new PrivilegedExceptionAction<Object>()
+                 {
+                     public Object run()
+                         throws StandardException
+                     {
+                         return Monitor.startSystemModule( factoryInterface );
+                     }
+                 }
+                 );
+        } catch (PrivilegedActionException pae)
+        {
+            throw StandardException.plainWrapException( pae );
+        }
+    }
+
+    /**
+     * Privileged startup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  Object bootServiceModule
+        (
+         final boolean create, final Object serviceModule,
+         final String factoryInterface, final Properties properties
+         )
+        throws StandardException
+    {
+        try {
+            return AccessController.doPrivileged
+                (
+                 new PrivilegedExceptionAction<Object>()
+                 {
+                     public Object run()
+                         throws StandardException
+                     {
+                         return Monitor.bootServiceModule( create, serviceModule, factoryInterface, properties );
+                     }
+                 }
+                 );
+        } catch (PrivilegedActionException pae)
+        {
+            throw StandardException.plainWrapException( pae );
+        }
+    }
+
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/D_DiagnosticUtil.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/D_DiagnosticUtil.java?rev=1627831&r1=1627830&r2=1627831&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/D_DiagnosticUtil.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/D_DiagnosticUtil.java Fri Sep 26 17:12:31 2014
@@ -21,6 +21,11 @@
 
 package org.apache.derby.impl.store.raw.data;
 
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
 import org.apache.derby.iapi.services.context.ContextService;
 import org.apache.derby.iapi.services.diag.Diagnosticable;
 import org.apache.derby.iapi.services.diag.DiagnosticUtil;
@@ -82,19 +87,19 @@ public class D_DiagnosticUtil
     {
         Object   store_module = null;
 
-		Object db = Monitor.findService(Property.DATABASE_MODULE, db_name);
+		Object db = findService(Property.DATABASE_MODULE, db_name);
 
         // RESOLVE (mikem) - find a single way to find the current 
         // AccessFactory that works both for ij and unit tests.
         if (db == null)
         {
             // maybe it is a module test - try this hack:
-            store_module = Monitor.findService(AccessFactory.MODULE, db_name);
+            store_module = findService(AccessFactory.MODULE, db_name);
         }
         else
         {
             // Find the AccessFactory
-            store_module = Monitor.findServiceModule(db, AccessFactory.MODULE);
+            store_module = findServiceModule(db, AccessFactory.MODULE);
         }
 
         return(store_module);
@@ -241,7 +246,7 @@ public class D_DiagnosticUtil
 			Object module = getModuleFromDbName(db_name);
 
 			RawStoreFactory store_module = (RawStoreFactory)
-				Monitor.findServiceModule(module, RawStoreFactory.MODULE);
+				findServiceModule(module, RawStoreFactory.MODULE);
 
 			xact = store_module.startInternalTransaction
                 (FileContainer.getContextService().getCurrentContextManager());
@@ -325,7 +330,7 @@ public class D_DiagnosticUtil
 
         // Find the AccessFactory
         store_module = (AccessFactory) 
-            Monitor.getServiceModule(module, AccessFactory.MODULE);
+            getServiceModule(module, AccessFactory.MODULE);
 
         if (store_module != null)
         {
@@ -402,7 +407,7 @@ public class D_DiagnosticUtil
 
         // Find the AccessFactory
         store_module = (AccessFactory) 
-            Monitor.getServiceModule(module, AccessFactory.MODULE);
+            getServiceModule(module, AccessFactory.MODULE);
 
         if (store_module != null)
         {
@@ -435,4 +440,65 @@ public class D_DiagnosticUtil
         return(container_id);
     }
 
+    /**
+     * Privileged startup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private  static  Object findServiceModule( final Object serviceModule, final String factoryInterface)
+        throws StandardException
+    {
+        try {
+            return AccessController.doPrivileged
+                (
+                 new PrivilegedExceptionAction<Object>()
+                 {
+                     public Object run()
+                         throws StandardException
+                     {
+                         return Monitor.findServiceModule( serviceModule, factoryInterface );
+                     }
+                 }
+                 );
+        } catch (PrivilegedActionException pae)
+        {
+            throw StandardException.plainWrapException( pae );
+        }
+    }
+
+    /**
+     * Privileged module lookup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private static  Object getServiceModule( final Object serviceModule, final String factoryInterface )
+    {
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<Object>()
+             {
+                 public Object run()
+                 {
+                     return Monitor.getServiceModule( serviceModule, factoryInterface );
+                 }
+             }
+             );
+    }
+
+    /**
+     * Privileged service lookup. Must be private so that user code
+     * can't call this entry point.
+     */
+    private static  Object findService( final String factoryInterface, final String serviceName )
+    {
+        return AccessController.doPrivileged
+            (
+             new PrivilegedAction<Object>()
+             {
+                 public Object run()
+                 {
+                     return Monitor.findService( factoryInterface, serviceName );
+                 }
+             }
+             );
+    }
+    
 }



Mime
View raw message