Author: tolusha
Date: 2010-06-15 08:47:05 -0400 (Tue, 15 Jun 2010)
New Revision: 2601
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/SimpleFileIOChannel.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/TesterSecurityManager.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedFileHelper.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/jbosscache/ExoJBossCacheFactory.java
Log:
EXOJCR-756: fix
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2010-06-15
10:53:03 UTC (rev 2600)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2010-06-15
12:47:05 UTC (rev 2601)
@@ -56,6 +56,7 @@
import org.exoplatform.services.naming.InitialContextInitializer;
import org.exoplatform.services.transaction.TransactionService;
import org.jboss.cache.Cache;
+import org.jboss.cache.CacheException;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
@@ -68,8 +69,11 @@
import java.io.Serializable;
import java.math.BigInteger;
+import java.security.AccessController;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
@@ -254,11 +258,39 @@
cache = factory.createCache(config.getLockManager());
- cache.create();
- // Add the cache loader needed to prevent TimeoutException
- addCacheLoader();
- cache.start();
+ PrivilegedExceptionAction<Object> action = new
PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ cache.create();
+ // Add the cache loader needed to prevent TimeoutException
+ addCacheLoader();
+ cache.start();
+ return null;
+ }
+ };
+ try
+ {
+ AccessController.doPrivileged(action);
+ }
+ catch (PrivilegedActionException pae)
+ {
+ Throwable cause = pae.getCause();
+ if (cause instanceof CacheException)
+ {
+ throw (CacheException)cause;
+ }
+ else if (cause instanceof RuntimeException)
+ {
+ throw (RuntimeException)cause;
+ }
+ else
+ {
+ throw new RuntimeException(cause);
+ }
+ }
+
createStructuredNode(lockRoot);
// Context recall is a workaround of JDBCCacheLoader starting.
@@ -285,7 +317,7 @@
// detect dialect of data-source
try
{
- DataSource dataSource = (DataSource)new
InitialContext().lookup(dataSourceName);
+ final DataSource dataSource = (DataSource)new
InitialContext().lookup(dataSourceName);
if (dataSource == null)
{
throw new RepositoryException("DataSource (" + dataSourceName +
") can't be null");
@@ -294,7 +326,34 @@
Connection jdbcConn = null;
try
{
- jdbcConn = dataSource.getConnection();
+ PrivilegedExceptionAction<Connection> action = new
PrivilegedExceptionAction<Connection>()
+ {
+ public Connection run() throws Exception
+ {
+ return dataSource.getConnection();
+ }
+ };
+ try
+ {
+ jdbcConn = AccessController.doPrivileged(action);
+ }
+ catch (PrivilegedActionException pae)
+ {
+ Throwable cause = pae.getCause();
+ if (cause instanceof SQLException)
+ {
+ throw (SQLException)cause;
+ }
+ else if (cause instanceof RuntimeException)
+ {
+ throw (RuntimeException)cause;
+ }
+ else
+ {
+ throw new RuntimeException(cause);
+ }
+ }
+
dialect = DialectDetecter.detect(jdbcConn.getMetaData());
}
finally
@@ -489,7 +548,7 @@
}
return true;
}
-
+
/**
* Return new instance of session lock manager.
*/
@@ -912,7 +971,7 @@
{
return getExactNodeOrCloseParentLock(node, true);
}
-
+
private LockData getExactNodeOrCloseParentLock(NodeData node, boolean checkHasLocks)
throws RepositoryException
{
@@ -953,7 +1012,7 @@
{
return getClosedChild(node, true);
}
-
+
private LockData getClosedChild(NodeData node, boolean checkHasLocks) throws
RepositoryException
{
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-06-15
10:53:03 UTC (rev 2600)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-06-15
12:47:05 UTC (rev 2601)
@@ -18,14 +18,6 @@
*/
package org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache;
-import java.io.Serializable;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.transaction.TransactionManager;
-
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.jboss.cache.Cache;
@@ -42,6 +34,17 @@
import org.jboss.cache.interceptors.base.CommandInterceptor;
import org.jgroups.Address;
+import java.io.Serializable;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.transaction.TransactionManager;
+
/**
* Decorator over the JBossCache that stores changes in buffer, then sorts and applies to
JBossCache.
*
@@ -60,9 +63,9 @@
private final ThreadLocal<CompressedChangesBuffer> changesList = new
ThreadLocal<CompressedChangesBuffer>();
private ThreadLocal<Boolean> local = new ThreadLocal<Boolean>();
-
+
private final boolean useExpiration;
-
+
private final long expirationTimeOut;
protected static final Log LOG =
@@ -213,7 +216,34 @@
*/
public void create() throws CacheException
{
- parentCache.create();
+ PrivilegedExceptionAction<Object> action = new
PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ parentCache.create();
+ return null;
+ }
+ };
+ try
+ {
+ AccessController.doPrivileged(action);
+ }
+ catch (PrivilegedActionException pae)
+ {
+ Throwable cause = pae.getCause();
+ if (cause instanceof CacheException)
+ {
+ throw (CacheException)cause;
+ }
+ else if (cause instanceof RuntimeException)
+ {
+ throw (RuntimeException)cause;
+ }
+ else
+ {
+ throw new RuntimeException(cause);
+ }
+ }
}
/* (non-Javadoc)
@@ -584,8 +614,8 @@
public boolean removeNode(Fqn fqn)
{
CompressedChangesBuffer changesContainer = getChangesBufferSafe();
- changesContainer.add(new RemoveNodeContainer(fqn, parentCache,
changesContainer.getHistoryIndex(), local.get(),
- useExpiration, expirationTimeOut));
+ changesContainer.add(new RemoveNodeContainer(fqn, parentCache,
changesContainer.getHistoryIndex(), local.get(),
+ useExpiration, expirationTimeOut));
return true;
}
@@ -618,7 +648,34 @@
*/
public void start() throws CacheException
{
- parentCache.start();
+ PrivilegedExceptionAction<Object> action = new
PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ parentCache.start();
+ return null;
+ }
+ };
+ try
+ {
+ AccessController.doPrivileged(action);
+ }
+ catch (PrivilegedActionException pae)
+ {
+ Throwable cause = pae.getCause();
+ if (cause instanceof CacheException)
+ {
+ throw (CacheException)cause;
+ }
+ else if (cause instanceof RuntimeException)
+ {
+ throw (RuntimeException)cause;
+ }
+ else
+ {
+ throw new RuntimeException(cause);
+ }
+ }
}
/* (non-Javadoc)
@@ -691,9 +748,9 @@
protected final boolean localMode;
protected final boolean useExpiration;
-
+
protected final long timeOut;
-
+
public ChangesContainer(Fqn fqn, ChangesType changesType, Cache<Serializable,
Object> cache, int historicalIndex,
boolean localMode, boolean useExpiration, long timeOut)
{
@@ -750,7 +807,7 @@
{
cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(localMode);
}
-
+
public final void putExpiration(Fqn efqn)
{
setCacheLocalMode();
@@ -780,7 +837,7 @@
{
setCacheLocalMode();
cache.put(fqn, data);
-
+
if (useExpiration)
{
putExpiration(fqn);
@@ -812,7 +869,7 @@
{
putExpiration(fqn);
}
-
+
setCacheLocalMode();
cache.put(fqn, key, value);
}
@@ -853,12 +910,12 @@
newSet.addAll((Set<Object>)existingObject);
}
newSet.add(value);
-
+
if (useExpiration)
{
putExpiration(fqn);
}
-
+
setCacheLocalMode();
cache.put(fqn, key, newSet);
}
@@ -900,12 +957,12 @@
{
Set<Object> newSet = new
HashSet<Object>((Set<Object>)existingObject);
newSet.remove(value);
-
+
if (useExpiration)
{
putExpiration(fqn);
}
-
+
setCacheLocalMode();
cache.put(fqn, key, newSet);
}
@@ -941,8 +998,8 @@
public static class RemoveNodeContainer extends ChangesContainer
{
- public RemoveNodeContainer(Fqn fqn, Cache<Serializable, Object> cache, int
historicalIndex, boolean local,
- boolean useExpiration, long timeOut)
+ public RemoveNodeContainer(Fqn fqn, Cache<Serializable, Object> cache, int
historicalIndex, boolean local,
+ boolean useExpiration, long timeOut)
{
super(fqn, ChangesType.REMOVE, cache, historicalIndex, local, useExpiration,
timeOut);
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/SimpleFileIOChannel.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/SimpleFileIOChannel.java 2010-06-15
10:53:03 UTC (rev 2600)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/SimpleFileIOChannel.java 2010-06-15
12:47:05 UTC (rev 2601)
@@ -20,6 +20,7 @@
import org.exoplatform.services.jcr.impl.storage.value.ValueDataResourceHolder;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
import java.io.File;
import java.io.FileFilter;
@@ -71,6 +72,6 @@
@Override
protected File[] getFiles(String propertyId) throws IOException
{
- return rootDir.listFiles(new PropertyIDFilter(propertyId));
+ return PrivilegedFileHelper.listFiles(rootDir, new PropertyIDFilter(propertyId));
}
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/TesterSecurityManager.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/TesterSecurityManager.java 2010-06-15
10:53:03 UTC (rev 2600)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/TesterSecurityManager.java 2010-06-15
12:47:05 UTC (rev 2601)
@@ -52,28 +52,24 @@
{
StackTraceElement el = traceElements[i];
String cl = el.getClassName();
+ String fn = el.getFileName();
if (cl.startsWith("org.exoplatform"))
{
- int p = cl.lastIndexOf('.');
- if (p != -1)
- {
- cl = cl.substring(p + 1);
- }
-
// TesterSecurityManager is not a part of source code
- if (cl.equals("TesterSecurityManager"))
+ if (fn.equals("TesterSecurityManager.java"))
{
continue;
}
// hide Exception
- if (cl.equals("BaseStandaloneTest"))
+ if (fn.equals("BaseStandaloneTest.java") ||
fn.equals("SLF4JExoLogFactory.java"))
{
return;
}
- if (cl.startsWith("Test") || cl.endsWith("Test") ||
cl.endsWith("TestBase"))
+ if (fn.startsWith("Test") ||
fn.endsWith("Test.java") || fn.endsWith("TestBase.java")
+ || fn.equals("Probe.java"))
{
testCode = true;
}
@@ -82,6 +78,19 @@
srcCode = true;
}
}
+ else if (cl.startsWith("org.apache.jackrabbit.test"))
+ {
+ // hide Exception
+ if (fn.equals("JCRTestResult.java"))
+ {
+ return;
+ }
+ }
+ else if
(cl.startsWith("org.exoplatform.services.log.impl.SLF4JExoLogFactory"))
+ {
+ return;
+ }
+
}
e = e.getCause();
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedFileHelper.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedFileHelper.java 2010-06-15
10:53:03 UTC (rev 2600)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedFileHelper.java 2010-06-15
12:47:05 UTC (rev 2601)
@@ -19,6 +19,7 @@
package org.exoplatform.services.jcr.impl.util.io;
import java.io.File;
+import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@@ -569,4 +570,22 @@
return AccessController.doPrivileged(action);
}
+ /**
+ * Get file's list in privileged mode.
+ *
+ * @param file
+ * @return
+ */
+ public static File[] listFiles(final File file, final FileFilter filter)
+ {
+ PrivilegedAction<File[]> action = new PrivilegedAction<File[]>()
+ {
+ public File[] run()
+ {
+ return file.listFiles(filter);
+ }
+ };
+ return AccessController.doPrivileged(action);
+ }
+
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/jbosscache/ExoJBossCacheFactory.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/jbosscache/ExoJBossCacheFactory.java 2010-06-15
10:53:03 UTC (rev 2600)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/jbosscache/ExoJBossCacheFactory.java 2010-06-15
12:47:05 UTC (rev 2601)
@@ -31,6 +31,8 @@
import java.io.IOException;
import java.io.InputStream;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import javax.transaction.TransactionManager;
@@ -124,9 +126,18 @@
}
// create cache
- CacheFactory<K, V> factory = new DefaultCacheFactory<K, V>();
- Cache<K, V> cache = factory.createCache(configStream, false);
+ final CacheFactory<K, V> factory = new DefaultCacheFactory<K, V>();
+ final InputStream stream = configStream;
+ PrivilegedAction<Cache<K, V>> action = new
PrivilegedAction<Cache<K, V>>()
+ {
+ public Cache<K, V> run()
+ {
+ return factory.createCache(stream, false);
+ }
+ };
+ Cache<K, V> cache = AccessController.doPrivileged(action);
+
// inject transaction manager if defined
if (transactionManager != null)
{