[exo-jcr-commits] exo-jcr SVN: r2551 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl: dataflow/persistent and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Jun 11 05:49:46 EDT 2010


Author: tolusha
Date: 2010-06-11 05:49:45 -0400 (Fri, 11 Jun 2010)
New Revision: 2551

Modified:
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/StreamPersistedValueData.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/GenericCQConnectionFactory.java
Log:
EXOJCR-756: fixed RepositoryImpl, StreamPersistedValueData, GenericCQConnectionFactory

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java	2010-06-11 09:39:49 UTC (rev 2550)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java	2010-06-11 09:49:45 UTC (rev 2551)
@@ -44,6 +44,9 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -520,8 +523,8 @@
    /**
     * {@inheritDoc}
     */
-   public Session login(Credentials credentials, String workspaceName) throws LoginException, NoSuchWorkspaceException,
-      RepositoryException
+   public Session login(final Credentials credentials, String workspaceName) throws LoginException,
+      NoSuchWorkspaceException, RepositoryException
    {
 
       if (getState() == OFFLINE)
@@ -529,13 +532,38 @@
 
       ConversationState state;
 
-      if (credentials != null)
-         state = authenticationPolicy.authenticate(credentials);
-      else
-         state = authenticationPolicy.authenticate();
+      PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+      {
+         public Object run() throws Exception
+         {
+            if (credentials != null)
+               return authenticationPolicy.authenticate(credentials);
+            else
+               return authenticationPolicy.authenticate();
+         }
+      };
+      try
+      {
+         state = (ConversationState)AccessController.doPrivileged(action);
+      }
+      catch (PrivilegedActionException pae)
+      {
+         Throwable cause = pae.getCause();
+         if (cause instanceof LoginException)
+         {
+            throw (LoginException)cause;
+         }
+         else if (cause instanceof RuntimeException)
+         {
+            throw (RuntimeException)cause;
+         }
+         else
+         {
+            throw new RuntimeException(cause);
+         }
+      }
 
       return internalLogin(state, workspaceName);
-
    }
 
    /**

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/StreamPersistedValueData.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/StreamPersistedValueData.java	2010-06-11 09:39:49 UTC (rev 2550)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/StreamPersistedValueData.java	2010-06-11 09:49:45 UTC (rev 2551)
@@ -27,6 +27,8 @@
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 
 import javax.jcr.RepositoryException;
 
@@ -180,36 +182,43 @@
    @Override
    public long getLength()
    {
-      if (file != null)
+      PrivilegedAction<Object> action = new PrivilegedAction<Object>()
       {
-         return file.length();
-      }
-      else if (tempFile != null)
-      {
-         return tempFile.length();
-      }
-      else if (stream instanceof FileInputStream)
-      {
-         try
+         public Object run()
          {
-            return ((FileInputStream)stream).getChannel().size();
+            if (file != null)
+            {
+               return file.length();
+            }
+            else if (tempFile != null)
+            {
+               return tempFile.length();
+            }
+            else if (stream instanceof FileInputStream)
+            {
+               try
+               {
+                  return ((FileInputStream)stream).getChannel().size();
+               }
+               catch (IOException e)
+               {
+                  return -1;
+               }
+            }
+            else
+            {
+               try
+               {
+                  return stream.available();
+               }
+               catch (IOException e)
+               {
+                  return -1;
+               }
+            }
          }
-         catch (IOException e)
-         {
-            return -1;
-         }
-      }
-      else
-      {
-         try
-         {
-            return stream.available();
-         }
-         catch (IOException e)
-         {
-            return -1;
-         }
-      }
+      };
+      return (Long)AccessController.doPrivileged(action);
    }
 
    /**
@@ -224,6 +233,7 @@
    /**
     * {@inheritDoc}
     */
+   @Override
    protected void finalize() throws Throwable
    {
       try

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/GenericCQConnectionFactory.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/GenericCQConnectionFactory.java	2010-06-11 09:39:49 UTC (rev 2550)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/GenericCQConnectionFactory.java	2010-06-11 09:49:45 UTC (rev 2551)
@@ -24,6 +24,9 @@
 import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
 
 import java.io.File;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.SQLException;
@@ -155,6 +158,7 @@
    /**
     * {@inheritDoc}
     */
+   @Override
    public WorkspaceStorageConnection openConnection() throws RepositoryException
    {
       return openConnection(false);
@@ -163,6 +167,7 @@
    /**
     * {@inheritDoc}
     */
+   @Override
    public WorkspaceStorageConnection openConnection(boolean readOnly) throws RepositoryException
    {
       try
@@ -187,21 +192,47 @@
    /**
     * {@inheritDoc}
     */
+   @Override
    public Connection getJdbcConnection(boolean readOnly) throws RepositoryException
    {
       try
       {
-         final Connection conn =
-            dbDataSource != null ? dbDataSource.getConnection() : (dbUserName != null ? DriverManager.getConnection(
-               dbUrl, dbUserName, dbPassword) : DriverManager.getConnection(dbUrl));
+         PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+         {
+            public Object run() throws Exception
+            {
+               return dbDataSource != null ? dbDataSource.getConnection() : (dbUserName != null ? DriverManager
+                  .getConnection(dbUrl, dbUserName, dbPassword) : DriverManager.getConnection(dbUrl));
+            }
+         };
+         try
+         {
+            final Connection conn = (Connection)AccessController.doPrivileged(action);
 
-         if (readOnly)
-         { 
-            // set this feature only if it asked
-            conn.setReadOnly(readOnly);
+            if (readOnly)
+            {
+               // set this feature only if it asked
+               conn.setReadOnly(readOnly);
+            }
+
+            return conn;
          }
-
-         return conn;
+         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);
+            }
+         }
       }
       catch (SQLException e)
       {
@@ -215,6 +246,7 @@
    /**
     * {@inheritDoc}
     */
+   @Override
    public Connection getJdbcConnection() throws RepositoryException
    {
       return getJdbcConnection(false);



More information about the exo-jcr-commits mailing list