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

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Jun 15 04:26:28 EDT 2010


Author: tolusha
Date: 2010-06-15 04:26:28 -0400 (Tue, 15 Jun 2010)
New Revision: 2592

Added:
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/TesterSecurityManager.java
Modified:
   jcr/trunk/exo.jcr.component.core/pom.xml
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/BaseStandaloneTest.java
Log:
EXOJCR-756: add TesterSecurityManager

Modified: jcr/trunk/exo.jcr.component.core/pom.xml
===================================================================
--- jcr/trunk/exo.jcr.component.core/pom.xml	2010-06-15 08:25:16 UTC (rev 2591)
+++ jcr/trunk/exo.jcr.component.core/pom.xml	2010-06-15 08:26:28 UTC (rev 2592)
@@ -374,7 +374,7 @@
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-surefire-plugin</artifactId>
             <configuration>
-               <argLine>${env.MAVEN_OPTS}</argLine>
+               <argLine>${env.MAVEN_OPTS} -Djava.security.manager=org.exoplatform.services.jcr.impl.util.TesterSecurityManager -Djava.security.policy=${project.build.directory}/test-classes/test.policy</argLine>
                <systemProperties>
                   <property>
                      <name>jcr.test.configuration.file</name>

Added: 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	                        (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/TesterSecurityManager.java	2010-06-15 08:26:28 UTC (rev 2592)
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.util;
+
+import java.security.Permission;
+
+/**
+ * @author <a href="anatoliy.bazko at exoplatform.org">Anatoliy Bazko</a>
+ * @version $Id: TesterSecurityManager.java 111 2010-11-11 11:11:11Z tolusha $
+ *
+ */
+public class TesterSecurityManager extends SecurityManager
+{
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public void checkPermission(Permission perm)
+   {
+      try
+      {
+         super.checkPermission(perm);
+      }
+      catch (SecurityException se)
+      {
+         Throwable e = se;
+
+         boolean srcCode = false;
+         boolean testCode = false;
+
+         while (e != null)
+         {
+            StackTraceElement[] traceElements = e.getStackTrace();
+            for (int i = 0; i < traceElements.length; i++)
+            {
+               StackTraceElement el = traceElements[i];
+               String cl = el.getClassName();
+
+               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"))
+                  {
+                     continue;
+                  }
+
+                  // hide Exception
+                  if (cl.equals("BaseStandaloneTest"))
+                  {
+                     return;
+                  }
+
+                  if (cl.startsWith("Test") || cl.endsWith("Test") || cl.endsWith("TestBase"))
+                  {
+                     testCode = true;
+                  }
+                  else
+                  {
+                     srcCode = true;
+                  }
+               }
+            }
+
+            e = e.getCause();
+         }
+
+         // hide Exception if only test code exists
+         if (!srcCode && testCode)
+         {
+            return;
+         }
+
+         throw se;
+      }
+   }
+}

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/BaseStandaloneTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/BaseStandaloneTest.java	2010-06-15 08:25:16 UTC (rev 2591)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/BaseStandaloneTest.java	2010-06-15 08:26:28 UTC (rev 2592)
@@ -19,7 +19,6 @@
 package org.exoplatform.services.jcr;
 
 import junit.framework.TestCase;
-import sun.security.provider.PolicyFile;
 
 import org.exoplatform.container.StandaloneContainer;
 import org.exoplatform.services.jcr.config.WorkspaceEntry;
@@ -43,7 +42,6 @@
 import java.io.InputStream;
 import java.lang.ref.WeakReference;
 import java.net.URL;
-import java.security.Policy;
 import java.util.Random;
 
 import javax.jcr.Node;
@@ -107,8 +105,6 @@
    @Override
    public void setUp() throws Exception
    {
-      System.setSecurityManager(null);
-
       String configPath = System.getProperty("jcr.test.configuration.file");
       if (configPath == null)
       {
@@ -164,17 +160,15 @@
       fileCleaner = wfcleaner.getFileCleaner();
       holder = new ReaderSpoolFileHolder();
 
-      URL url = Thread.currentThread().getContextClassLoader().getResource("./test.policy");
-      Policy.setPolicy(new PolicyFile(url));
-
-      System.setSecurityManager(new SecurityManager());
+      //      URL url = Thread.currentThread().getContextClassLoader().getResource("./test.policy");
+      //      Policy.setPolicy(new PolicyFile(url));
+      //
+      //      System.setSecurityManager(new TesterSecurityManager());
    }
 
    @Override
    protected void tearDown() throws Exception
    {
-      System.setSecurityManager(null);
-
       if (session != null)
       {
          try



More information about the exo-jcr-commits mailing list