exo-jcr SVN: r2666 - ws/trunk/exo.ws.rest.ext/src/test/resources.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-06-21 06:20:31 -0400 (Mon, 21 Jun 2010)
New Revision: 2666
Added:
ws/trunk/exo.ws.rest.ext/src/test/resources/test.policy
Log:
EXOJCR-793 :
Added: ws/trunk/exo.ws.rest.ext/src/test/resources/test.policy
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/test/resources/test.policy (rev 0)
+++ ws/trunk/exo.ws.rest.ext/src/test/resources/test.policy 2010-06-21 10:20:31 UTC (rev 2666)
@@ -0,0 +1,16 @@
+grant codeBase "@MAVEN_REPO@-" {
+ permission java.security.AllPermission;
+};
+
+grant codeBase "@MAIN_CLASSES@-" {
+ permission java.security.AllPermission;
+};
+
+grant codeBase "@TEST_CLASSES@-" {
+ permission java.security.AllPermission;
+};
+
+grant codeBase "file:/groovy/script" {
+// be sure only /groovy/script/jaxrs is restricted
+ permission java.security.AllPermission;
+};
13 years, 11 months
exo-jcr SVN: r2665 - in ws/trunk/exo.ws.rest.ext: src/test/java/org/exoplatform/services/rest/ext/groovy and 2 other directories.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-06-21 06:19:10 -0400 (Mon, 21 Jun 2010)
New Revision: 2665
Added:
ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovySecureRestrictionTest.java
ws/trunk/exo.ws.rest.ext/src/test/resources/groovy3.groovy
Modified:
ws/trunk/exo.ws.rest.ext/pom.xml
ws/trunk/exo.ws.rest.ext/src/test/resources/conf/standalone/test-configuration.xml
Log:
EXOJCR-793 : test for security restriction
Modified: ws/trunk/exo.ws.rest.ext/pom.xml
===================================================================
--- ws/trunk/exo.ws.rest.ext/pom.xml 2010-06-18 13:57:10 UTC (rev 2664)
+++ ws/trunk/exo.ws.rest.ext/pom.xml 2010-06-21 10:19:10 UTC (rev 2665)
@@ -1,99 +1,129 @@
-<!--
- Copyright (C) 2009 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.
-
--->
+ Copyright (C) 2009 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.
+ -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
+ <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.exoplatform.ws</groupId>
- <artifactId>ws-parent</artifactId>
- <version>2.2.0-Beta01-SNAPSHOT</version>
- </parent>
+ <parent>
+ <groupId>org.exoplatform.ws</groupId>
+ <artifactId>ws-parent</artifactId>
+ <version>2.2.0-Beta01-SNAPSHOT</version>
+ </parent>
- <artifactId>exo.ws.rest.ext</artifactId>
+ <artifactId>exo.ws.rest.ext</artifactId>
- <name>eXo WS :: REST :: Extentions</name>
+ <name>eXo WS :: REST :: Extentions</name>
- <dependencies>
- <dependency>
- <groupId>org.exoplatform.kernel</groupId>
- <artifactId>exo.kernel.container</artifactId>
- </dependency>
- <dependency>
- <groupId>org.exoplatform.kernel</groupId>
- <artifactId>exo.kernel.commons</artifactId>
- </dependency>
- <dependency>
- <groupId>org.exoplatform.core</groupId>
- <artifactId>exo.core.component.xml-processing</artifactId>
- </dependency>
- <dependency>
- <groupId>org.exoplatform.core</groupId>
- <artifactId>exo.core.component.script.groovy</artifactId>
- </dependency>
- <dependency>
- <groupId>org.exoplatform.ws</groupId>
- <artifactId>exo.ws.commons</artifactId>
- </dependency>
- <dependency>
- <groupId>org.exoplatform.ws</groupId>
- <artifactId>exo.ws.rest.core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.exoplatform.ws</groupId>
- <artifactId>exo.ws.testframework</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>javax.annotation</groupId>
- <artifactId>jsr250-api</artifactId>
- </dependency>
- <dependency>
- <groupId>jtidy</groupId>
- <artifactId>jtidy</artifactId>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
- <dependency>
- <groupId>javax.ws.rs</groupId>
- <artifactId>jsr311-api</artifactId>
- </dependency>
- <dependency>
- <groupId>javax.xml.stream</groupId>
- <artifactId>stax-api</artifactId>
- <version>1.0</version>
- </dependency>
- <dependency>
- <groupId>xpp3</groupId>
- <artifactId>xpp3</artifactId>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.codehaus.groovy</groupId>
- <artifactId>groovy-all</artifactId>
- </dependency>
- </dependencies>
+ <dependencies>
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.container</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.commons</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.core</groupId>
+ <artifactId>exo.core.component.xml-processing</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.core</groupId>
+ <artifactId>exo.core.component.script.groovy</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.ws</groupId>
+ <artifactId>exo.ws.commons</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.ws</groupId>
+ <artifactId>exo.ws.rest.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.ws</groupId>
+ <artifactId>exo.ws.testframework</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>jsr250-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>jtidy</groupId>
+ <artifactId>jtidy</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>jsr311-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.xml.stream</groupId>
+ <artifactId>stax-api</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>xpp3</groupId>
+ <artifactId>xpp3</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy-all</artifactId>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <argLine>-Djava.security.manager=default -Djava.security.policy=${project.build.directory}/test-classes/test.policy</argLine>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>prepare-test-policy</id>
+ <phase>process-test-resources</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <tasks>
+ <echo>***** Creating Access Policy for tests *****</echo>
+ <makeurl file="${settings.localRepository}" property="localRepositoryURL" />
+ <makeurl file="${project.build.outputDirectory}" property="outputDirectoryURL" />
+ <makeurl file="${project.build.testOutputDirectory}" property="testOutputDirectoryURL" />
+ <copy todir="${project.build.testOutputDirectory}" overwrite="true">
+ <fileset dir="${project.basedir}/src/test/resources/">
+ <include name="test.policy" />
+ </fileset>
+ <filterset>
+ <filter token="MAVEN_REPO" value="${localRepositoryURL}" />
+ <filter token="MAIN_CLASSES" value="${outputDirectoryURL}" />
+ <filter token="TEST_CLASSES" value="${testOutputDirectoryURL}" />
+ </filterset>
+ </copy>
+ </tasks>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
Added: ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovySecureRestrictionTest.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovySecureRestrictionTest.java (rev 0)
+++ ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovySecureRestrictionTest.java 2010-06-21 10:19:10 UTC (rev 2665)
@@ -0,0 +1,55 @@
+/**
+ * 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.rest.ext.groovy;
+
+import org.exoplatform.services.rest.ext.BaseTest;
+import org.exoplatform.services.rest.impl.ContainerResponse;
+import org.exoplatform.services.rest.tools.ByteArrayContainerResponseWriter;
+
+import java.io.InputStream;
+
+/**
+ * @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
+ * @version $Id$
+ */
+public class GroovySecureRestrictionTest extends BaseTest
+{
+
+ private InputStream script;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ assertNotNull("SecurityManager not installed", System.getSecurityManager());
+ script = Thread.currentThread().getContextClassLoader().getResourceAsStream("groovy3.groovy");
+ assertNotNull(script);
+ }
+
+ public void testReadSystemPropertyFail() throws Exception
+ {
+ groovyPublisher.publishPerRequest(script, new BaseResourceId("g1"));
+ ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
+ ContainerResponse resp = service("GET", "/a/b", "", null, null, writer);
+ assertEquals(500, resp.getStatus());
+ assertTrue(new String(writer.getBody()).startsWith("access denied"));
+ }
+
+}
Property changes on: ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovySecureRestrictionTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: ws/trunk/exo.ws.rest.ext/src/test/resources/conf/standalone/test-configuration.xml
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/test/resources/conf/standalone/test-configuration.xml 2010-06-18 13:57:10 UTC (rev 2664)
+++ ws/trunk/exo.ws.rest.ext/src/test/resources/conf/standalone/test-configuration.xml 2010-06-21 10:19:10 UTC (rev 2665)
@@ -32,7 +32,7 @@
<property name="log4j.appender.file.File" value="target/container.log" />
<property name="log4j.appender.file.layout" value="org.apache.log4j.PatternLayout" />
<property name="log4j.appender.file.layout.ConversionPattern" value="%d{dd.MM.yyyy HH:mm:ss} *%-5p* [%t] %c{1}: %m (%F, line %L) %n" />
-
+ <!-- <property name="log4j.category.exo.ws.rest.core" value="DEBUG" />-->
</properties-param>
</init-params>
</component>
Added: ws/trunk/exo.ws.rest.ext/src/test/resources/groovy3.groovy
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/test/resources/groovy3.groovy (rev 0)
+++ ws/trunk/exo.ws.rest.ext/src/test/resources/groovy3.groovy 2010-06-21 10:19:10 UTC (rev 2665)
@@ -0,0 +1,19 @@
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+@Path("a")
+class CroovyResource3
+{
+
+ CroovyResource3()
+ {
+ }
+
+ @GET
+ @Path("b")
+ def m0()
+ {
+ return System.getProperty("java.home");
+ }
+
+}
\ No newline at end of file
13 years, 11 months
exo-jcr SVN: r2664 - in jcr/trunk/exo.jcr.component.ext/src: test/java/org/exoplatform/services/jcr/ext/script/groovy and 1 other directory.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-06-18 09:57:10 -0400 (Fri, 18 Jun 2010)
New Revision: 2664
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoader.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestUpdateListener.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/NodeScriptKey.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/ScriptKey.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/SimpleScriptKey.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/URLScriptKey.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderTest.java
Log:
EXOJCR-793 :
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoader.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoader.java 2010-06-18 13:50:27 UTC (rev 2663)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoader.java 2010-06-18 13:57:10 UTC (rev 2664)
@@ -18,6 +18,8 @@
*/
package org.exoplatform.services.jcr.ext.script.groovy;
+import groovy.lang.GroovyClassLoader;
+
import org.apache.commons.fileupload.FileItem;
import org.exoplatform.container.component.ComponentPlugin;
import org.exoplatform.container.configuration.ConfigurationManager;
@@ -32,6 +34,8 @@
import org.exoplatform.services.jcr.ext.registry.RegistryService;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
+import org.exoplatform.services.rest.ext.groovy.GroovyJaxrsPublisher;
+import org.exoplatform.services.rest.ext.groovy.ResourceId;
import org.exoplatform.services.rest.impl.ResourceBinder;
import org.exoplatform.services.rest.resource.ResourceContainer;
import org.exoplatform.services.script.groovy.GroovyScriptInstantiator;
@@ -40,6 +44,7 @@
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
+import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
@@ -47,10 +52,8 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import java.util.StringTokenizer;
import java.util.regex.Pattern;
@@ -78,7 +81,8 @@
/**
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
- * @version $Id: GroovyScript2RestLoader.java 34445 2009-07-24 07:51:18Z dkatayev $
+ * @version $Id: GroovyScript2RestLoader.java 34445 2009-07-24 07:51:18Z
+ * dkatayev $
*/
@Path("script/groovy")
public class GroovyScript2RestLoader implements Startable
@@ -93,15 +97,11 @@
/** Service name. */
private static final String SERVICE_NAME = "GroovyScript2RestLoader";
+ //
+
/** See {@link InitParams}. */
protected InitParams initParams;
- /** See {@link ResourceBinder}. */
- protected ResourceBinder binder;
-
- /** See {@link GroovyScriptInstantiator}. */
- protected GroovyScriptInstantiator groovyScriptInstantiator;
-
/** See {@link RepositoryService}. */
protected RepositoryService repositoryService;
@@ -111,21 +111,20 @@
/** See {@link RegistryService}. */
protected RegistryService registryService;
- /**
- * See {@link SessionProviderService},
- * {@link ThreadLocalSessionProviderService}.
- */
+ /** See {@link SessionProviderService} */
protected ThreadLocalSessionProviderService sessionProviderService;
/** Keeps configuration for observation listener. */
- protected ObservationListenerConfiguration observationListenerConfiguration;
+ private ObservationListenerConfiguration observationListenerConfiguration;
- /** Node type for Groovy scripts. */
- protected String nodeType;
+ protected GroovyJaxrsPublisher groovyPublisher;
- /** Mapping scripts URL (or other key) to classes. */
- protected Map<ScriptKey, Class<?>> scriptsURL2ClassMap = new HashMap<ScriptKey, Class<?>>();
+ /** See {@link ResourceBinder}. */
+ private ResourceBinder binder;
+ /** Node type for Groovy scripts. */
+ private String nodeType;
+
/**
* @param binder binder for RESTful services
* @param groovyScriptInstantiator instantiate groovy scripts
@@ -139,7 +138,7 @@
ConfigurationManager configurationManager, InitParams params)
{
this(binder, groovyScriptInstantiator, repositoryService, sessionProviderService, configurationManager, null,
- params);
+ new GroovyJaxrsPublisher(binder, groovyScriptInstantiator), params);
}
/**
@@ -155,21 +154,29 @@
RepositoryService repositoryService, ThreadLocalSessionProviderService sessionProviderService,
ConfigurationManager configurationManager, RegistryService registryService, InitParams params)
{
+ this(binder, groovyScriptInstantiator, repositoryService, sessionProviderService, configurationManager,
+ registryService, new GroovyJaxrsPublisher(binder, groovyScriptInstantiator), params);
+ }
+ public GroovyScript2RestLoader(ResourceBinder binder, GroovyScriptInstantiator groovyScriptInstantiator,
+ RepositoryService repositoryService, ThreadLocalSessionProviderService sessionProviderService,
+ ConfigurationManager configurationManager, RegistryService registryService, GroovyJaxrsPublisher groovyPublisher,
+ InitParams params)
+ {
this.binder = binder;
- this.groovyScriptInstantiator = groovyScriptInstantiator;
this.repositoryService = repositoryService;
this.configurationManager = configurationManager;
this.registryService = registryService;
this.sessionProviderService = sessionProviderService;
+ this.groovyPublisher = groovyPublisher;
this.initParams = params;
}
/**
* Remove script with specified URL from ResourceBinder.
*
- * @param url the URL. The <code>url.toString()</code> must be corresponded to
- * script class.
+ * @param url the URL. The <code>url.toString()</code> must be corresponded
+ * to script class.
* @see GroovyScriptRestLoader#loadScript(URL).
*/
public void unloadScript(URL url)
@@ -192,23 +199,7 @@
public boolean unloadScript(ScriptKey key)
{
- if (scriptsURL2ClassMap.containsKey(key))
- {
- if (binder.unbind(scriptsURL2ClassMap.get(key)))
- {
- scriptsURL2ClassMap.remove(key);
- return true;
- }
- else
- {
- LOG.warn("Can't remove groovy script, key " + key);
- }
- }
- else
- {
- LOG.warn("Specified key '" + key + "' does not corresponds to any class name.");
- }
- return false;
+ return groovyPublisher.unpublishResource(key);
}
/**
@@ -236,12 +227,12 @@
*/
public boolean isLoaded(ScriptKey key)
{
- return scriptsURL2ClassMap.containsKey(key);
+ return groovyPublisher.isPublished(key);
}
/**
- * Get node type for store scripts, may throw {@link IllegalStateException} if
- * <tt>nodeType</tt> not initialized yet.
+ * Get node type for store scripts, may throw {@link IllegalStateException}
+ * if <tt>nodeType</tt> not initialized yet.
*
* @return return node type
*/
@@ -260,18 +251,8 @@
*/
public boolean loadScript(URL url) throws IOException
{
- Object resource = groovyScriptInstantiator.instantiateScript(url);
- if (binder.bind(resource))
- {
- // add mapping script URL to name of class.
- scriptsURL2ClassMap.put(new URLScriptKey(url), resource.getClass());
- return true;
- }
- else
- {
- LOG.warn("Groovy script was not binded, URL: " + url);
- return false;
- }
+ ResourceId key = new URLScriptKey(url);
+ return groovyPublisher.publishPerRequest(new BufferedInputStream(url.openStream()), key);
}
/**
@@ -294,7 +275,7 @@
*
* @param key the key which must be corresponded to object class name.
* @param name this name will be passed to compiler to get understandable if
- * compilation failed
+ * compilation failed
* @param stream the stream which represents groovy script.
* @return if script loaded false otherwise
* @throws IOException if script can't be loaded or parsed.
@@ -308,30 +289,31 @@
/**
* @param key the key which must be corresponded to object class name
- * @param name this name will be passed to compiler to get understandable if
- * compilation failed. This parameter may be set as null then groovy
- * compiler will user automatically generated name for script.
- * (script000001.groovy)
+ * @param name script name
* @param stream the stream which represents groovy script.
* @return if script loaded false otherwise
* @throws IOException if script can't be loaded or parsed
+ * @deprecated use {@link #loadScript(ResourceId, InputStream)} instead.
+ * Parameter <code>name</code> is not in used,
+ * {@link ResourceId#getId()} will be used as script name
*/
public boolean loadScript(ScriptKey key, String name, InputStream stream) throws IOException
{
- Object resource = groovyScriptInstantiator.instantiateScript(stream, name);
- if (binder.bind(resource))
- {
- scriptsURL2ClassMap.put(key, resource.getClass());
- return true;
- }
- else
- {
- LOG.warn("Groovy script was not binded, key: " + key);
- return false;
- }
+ return loadScript(key, stream);
}
/**
+ * @param key the key which must be corresponded to object class name
+ * @param stream the stream which represents groovy script.
+ * @return if script loaded false otherwise
+ * @throws IOException if script can't be loaded or parsed
+ */
+ public boolean loadScript(ResourceId resourceId, InputStream stream)
+ {
+ return groovyPublisher.publishPerRequest(stream, resourceId);
+ }
+
+ /**
* {@inheritDoc}
*/
public void start()
@@ -368,47 +350,49 @@
// Add script from configuration files to JCR.
addScripts();
- try
+ if (observationListenerConfiguration != null)
{
-
- // Deploy auto-load scripts and start Observation Listeners.
- String repositoryName = observationListenerConfiguration.getRepository();
- List<String> workspaceNames = observationListenerConfiguration.getWorkspaces();
-
- ManageableRepository repository = repositoryService.getRepository(repositoryName);
-
- for (String workspaceName : workspaceNames)
+ try
{
- Session session = repository.getSystemSession(workspaceName);
+ // Deploy auto-load scripts and start Observation Listeners.
+ String repositoryName = observationListenerConfiguration.getRepository();
+ List<String> workspaceNames = observationListenerConfiguration.getWorkspaces();
- String xpath = "//element(*, " + getNodeType() + ")[@exo:autoload='true']";
- Query query = session.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
+ ManageableRepository repository = repositoryService.getRepository(repositoryName);
- QueryResult result = query.execute();
- NodeIterator nodeIterator = result.getNodes();
- while (nodeIterator.hasNext())
+ for (String workspaceName : workspaceNames)
{
- Node node = nodeIterator.nextNode();
+ Session session = repository.getSystemSession(workspaceName);
- if (node.getPath().startsWith("/jcr:system"))
+ String xpath = "//element(*, " + getNodeType() + ")[@exo:autoload='true']";
+ Query query = session.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
+
+ QueryResult result = query.execute();
+ NodeIterator nodeIterator = result.getNodes();
+ while (nodeIterator.hasNext())
{
- continue;
+ Node node = nodeIterator.nextNode();
+
+ if (node.getPath().startsWith("/jcr:system"))
+ {
+ continue;
+ }
+
+ loadScript(new NodeScriptKey(repositoryName, workspaceName, node), node.getProperty("jcr:data")
+ .getStream());
}
- loadScript(new NodeScriptKey(repositoryName, workspaceName, node), node.getPath(), node.getProperty(
- "jcr:data").getStream());
+ session.getWorkspace().getObservationManager().addEventListener(
+ new GroovyScript2RestUpdateListener(repositoryName, workspaceName, this, session),
+ Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED, "/", true, null,
+ new String[]{getNodeType()}, false);
}
-
- session.getWorkspace().getObservationManager().addEventListener(
- new GroovyScript2RestUpdateListener(repositoryName, workspaceName, this, session),
- Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED, "/", true, null,
- new String[]{getNodeType()}, false);
}
+ catch (Exception e)
+ {
+ LOG.error("Error occurs ", e);
+ }
}
- catch (Exception e)
- {
- LOG.error("Error occurs ", e);
- }
// Finally bind this object as RESTful service.
// NOTE this service does not implement ResourceContainer, as usually
// done for this type of services. It can't be binded in common way cause
@@ -681,10 +665,17 @@
ObjectParameter param = initParams.getObjectParam("observation.config");
observationListenerConfiguration = (ObservationListenerConfiguration)param.getObject();
}
+ else
+ {
+ nodeType = DEFAULT_NODETYPE;
+ }
LOG.info("NodeType from configuration file: " + getNodeType());
- LOG.info("Repository from configuration file: " + observationListenerConfiguration.getRepository());
- LOG.info("Workspaces node from configuration file: " + observationListenerConfiguration.getWorkspaces());
+ if (observationListenerConfiguration != null)
+ {
+ LOG.info("Repository from configuration file: " + observationListenerConfiguration.getRepository());
+ LOG.info("Workspaces node from configuration file: " + observationListenerConfiguration.getWorkspaces());
+ }
}
/**
@@ -747,20 +738,19 @@
public Response validateScript(@PathParam("name") String name, InputStream script)
{
+ GroovyClassLoader groovyClassLoader = groovyPublisher.getGroovyClassLoader();
+ if (name == null || name.length() == 0)
+ {
+ name = groovyClassLoader.generateScriptName();
+ }
+ else if (name.startsWith("/"))
+ {
+ name = name.substring(1);
+ }
+
try
{
- if (name != null && name.startsWith("/"))
- {
- name = name.substring(1);
- }
- if (name == null || name.length() == 0)
- {
- groovyScriptInstantiator.instantiateScript(script);
- }
- else
- {
- groovyScriptInstantiator.instantiateScript(script, name);
- }
+ groovyClassLoader.parseClass(script, name);
return Response.status(Response.Status.OK).build();
}
catch (Exception e)
@@ -825,10 +815,11 @@
/**
* This method is useful for clients that send scripts as file in
- * 'multipart/*' request body. <br/> NOTE even we use iterator item should be
- * only one, rule one address - one script. This method is created just for
- * comfort loading script from HTML form. NOT use this script for uploading
- * few files in body of 'multipart/form-data' or other type of multipart.
+ * 'multipart/*' request body. <br/>
+ * NOTE even we use iterator item should be only one, rule one address - one
+ * script. This method is created just for comfort loading script from HTML
+ * form. NOT use this script for uploading few files in body of
+ * 'multipart/form-data' or other type of multipart.
*
* @param items iterator {@link FileItem}
* @param uriInfo see {@link UriInfo}
@@ -894,10 +885,11 @@
/**
* This method is useful for clients that send scripts as file in
- * 'multipart/*' request body. <br/> NOTE even we use iterator item should be
- * only one, rule one address - one script. This method is created just for
- * comfort loading script from HTML form. NOT use this script for uploading
- * few files in body of 'multipart/form-data' or other type of multipart.
+ * 'multipart/*' request body. <br/>
+ * NOTE even we use iterator item should be only one, rule one address - one
+ * script. This method is created just for comfort loading script from HTML
+ * form. NOT use this script for uploading few files in body of
+ * 'multipart/form-data' or other type of multipart.
*
* @param items iterator {@link FileItem}
* @param uriInfo see {@link UriInfo}
@@ -1095,9 +1087,9 @@
* @param workspace workspace name
* @param path JCR path to node that contains script
* @param state value for property exo:autoload, if it is not specified then
- * 'true' will be used as default. <br /> Example:
- * .../scripts/groovy/test1.groovy/load is the same to
- * .../scripts/groovy/test1.groovy/load?state=true
+ * 'true' will be used as default. <br />
+ * Example: .../scripts/groovy/test1.groovy/load is the same to
+ * .../scripts/groovy/test1.groovy/load?state=true
*/
@POST
@Path("autoload/{repository}/{workspace}/{path:.*}")
@@ -1143,7 +1135,8 @@
*
* @param repository repository name
* @param workspace workspace name
- * @param path the path to JCR node that contains groovy script to be deployed
+ * @param path the path to JCR node that contains groovy script to be
+ * deployed
*/
@POST
@Path("load/{repository}/{workspace}/{path:.*}")
@@ -1164,7 +1157,7 @@
{
unloadScript(key);
}
- if (!loadScript(key, path, script.getProperty("jcr:data").getStream()))
+ if (!loadScript(key, script.getProperty("jcr:data").getStream()))
{
String message =
"Can't bind script " + path
@@ -1210,8 +1203,8 @@
* @param repository Repository name.
* @param workspace Workspace name.
* @param name Additional search parameter. If not emtpy method returns the
- * list of script names matching wildcard else returns all the
- * scripts found in workspace.
+ * list of script names matching wildcard else returns all the scripts
+ * found in workspace.
* @return
*/
@POST
@@ -1237,7 +1230,7 @@
ArrayList<String> scriptList = new ArrayList<String>();
- if (name == null || "".equals(name))
+ if (name == null || name.length() == 0)
{
while (nodeIterator.hasNext())
{
@@ -1247,7 +1240,7 @@
}
else
{
- StringBuffer p = new StringBuffer();
+ StringBuilder p = new StringBuilder();
// add '.*' pattern at the start
p.append(".*");
for (int i = 0; i < name.length(); i++)
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestUpdateListener.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestUpdateListener.java 2010-06-18 13:50:27 UTC (rev 2663)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestUpdateListener.java 2010-06-18 13:57:10 UTC (rev 2664)
@@ -112,7 +112,7 @@
/**
* Load script form supplied node.
- *
+ *
* @param node JCR node
* @throws Exception if any error occurs
*/
@@ -121,12 +121,12 @@
ScriptKey key = new NodeScriptKey(repository, workspace, node);
if (groovyScript2RestLoader.isLoaded(key))
groovyScript2RestLoader.unloadScript(key);
- groovyScript2RestLoader.loadScript(key, node.getPath(), node.getProperty("jcr:data").getStream());
+ groovyScript2RestLoader.loadScript(key, node.getProperty("jcr:data").getStream());
}
/**
* Unload script.
- *
+ *
* @param path unified JCR node path
* @throws Exception if any error occurs
*/
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/NodeScriptKey.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/NodeScriptKey.java 2010-06-18 13:50:27 UTC (rev 2663)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/NodeScriptKey.java 2010-06-18 13:57:10 UTC (rev 2664)
@@ -18,6 +18,8 @@
*/
package org.exoplatform.services.jcr.ext.script.groovy;
+import org.exoplatform.services.rest.ext.groovy.BaseResourceId;
+
import javax.jcr.Node;
import javax.jcr.RepositoryException;
@@ -25,17 +27,41 @@
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id: NodeScriptKey.java 34445 2009-07-24 07:51:18Z dkatayev $
*/
-public class NodeScriptKey extends SimpleScriptKey implements ScriptKey
+public class NodeScriptKey extends BaseResourceId implements ScriptKey
{
- public NodeScriptKey(String repoName, String wsName, Node node) throws RepositoryException
+ private final String repositoryName;
+
+ private final String workspaceName;
+
+ private final String path;
+
+ public NodeScriptKey(String repositoryName, String workspaceName, Node node) throws RepositoryException
{
- this(repoName, wsName, node.getPath());
+ this(repositoryName, workspaceName, node.getPath());
}
- public NodeScriptKey(String repoName, String wsName, String path)
+ public NodeScriptKey(String repositoryName, String workspaceName, String path)
{
- super(repoName + wsName + path);
+ super(repositoryName + '@' + workspaceName + ':' + path);
+ this.repositoryName = repositoryName;
+ this.workspaceName = workspaceName;
+ this.path = path;
}
+ public String getRepositoryName()
+ {
+ return repositoryName;
+ }
+
+ public String getWorkspaceName()
+ {
+ return workspaceName;
+ }
+
+ public String getPath()
+ {
+ return path;
+ }
+
}
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/ScriptKey.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/ScriptKey.java 2010-06-18 13:50:27 UTC (rev 2663)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/ScriptKey.java 2010-06-18 13:57:10 UTC (rev 2664)
@@ -18,11 +18,14 @@
*/
package org.exoplatform.services.jcr.ext.script.groovy;
+import org.exoplatform.services.rest.ext.groovy.ResourceId;
+
/**
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id: ScriptKey.java 34445 2009-07-24 07:51:18Z dkatayev $
+ * @deprecated use {@link ResourceId} instead
*/
-public interface ScriptKey
+public interface ScriptKey extends ResourceId
{
}
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/SimpleScriptKey.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/SimpleScriptKey.java 2010-06-18 13:50:27 UTC (rev 2663)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/SimpleScriptKey.java 2010-06-18 13:57:10 UTC (rev 2664)
@@ -18,50 +18,19 @@
*/
package org.exoplatform.services.jcr.ext.script.groovy;
+import org.exoplatform.services.rest.ext.groovy.BaseResourceId;
+
/**
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id: SimpleScriptKey.java 34445 2009-07-24 07:51:18Z dkatayev $
+ * @deprecated use {@link BaseResourceId} instead
*/
-// Need this for back compatibility, see @deprecated methods in
-// GroovyScript2RestLoader.
-public class SimpleScriptKey implements ScriptKey
+public class SimpleScriptKey extends BaseResourceId implements ScriptKey
{
- protected final String key;
-
public SimpleScriptKey(String key)
{
- this.key = key;
+ super(key);
}
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj)
- {
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- return key.equals(((SimpleScriptKey)obj).key);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode()
- {
- return key.hashCode();
- }
-
- /**
- * {@inheritDoc}
- */
- public String toString()
- {
- return key;
- }
-
}
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/URLScriptKey.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/URLScriptKey.java 2010-06-18 13:50:27 UTC (rev 2663)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/URLScriptKey.java 2010-06-18 13:57:10 UTC (rev 2664)
@@ -18,13 +18,15 @@
*/
package org.exoplatform.services.jcr.ext.script.groovy;
+import org.exoplatform.services.rest.ext.groovy.BaseResourceId;
+
import java.net.URL;
/**
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id: URLScriptKey.java 34445 2009-07-24 07:51:18Z dkatayev $
*/
-public class URLScriptKey extends SimpleScriptKey implements ScriptKey
+public class URLScriptKey extends BaseResourceId implements ScriptKey
{
public URLScriptKey(URL url)
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderTest.java 2010-06-18 13:50:27 UTC (rev 2663)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderTest.java 2010-06-18 13:57:10 UTC (rev 2664)
@@ -76,7 +76,7 @@
.getComponentInstanceOfType(ThreadLocalSessionProviderService.class);
sesProv.setSessionProvider(null, new SessionProvider(new ConversationState(new Identity("root"))));
binder = (ResourceBinder)container.getComponentInstanceOfType(ResourceBinder.class);
- resourceNumber = binder.getRootResources().size();
+ resourceNumber = binder.getSize();
handler = (RequestHandler)container.getComponentInstanceOfType(RequestHandler.class);
testRoot = root.addNode("testRoot", "nt:unstructured");
@@ -105,10 +105,10 @@
public void testBindScripts() throws Exception
{
- assertEquals(resourceNumber + 1, binder.getRootResources().size());
+ assertEquals(resourceNumber + 1, binder.getSize());
script.getParent().remove();
session.save();
- assertEquals(resourceNumber, binder.getRootResources().size());
+ assertEquals(resourceNumber, binder.getSize());
}
public void testRemoteAccessGetMetatData() throws Exception
@@ -158,7 +158,7 @@
handler.handleRequest(creq, cres);
assertEquals(204, cres.getStatus());
- assertEquals(resourceNumber, binder.getRootResources().size());
+ assertEquals(resourceNumber, binder.getSize());
creq =
new ContainerRequest("POST", new URI("/script/groovy/load/db1/ws/testRoot/script"), new URI(""), null,
new InputHeadersMap(headers));
@@ -166,7 +166,7 @@
handler.handleRequest(creq, cres);
assertEquals(204, cres.getStatus());
- assertEquals(resourceNumber + 1, binder.getRootResources().size());
+ assertEquals(resourceNumber + 1, binder.getSize());
}
public void testRemoteAccessDelete() throws Exception
@@ -179,7 +179,7 @@
handler.handleRequest(creq, cres);
assertEquals(204, cres.getStatus());
- assertEquals(resourceNumber, binder.getRootResources().size());
+ assertEquals(resourceNumber, binder.getSize());
}
public void testRemoteAccessGetScript() throws Exception
@@ -232,7 +232,7 @@
session.save();
// must be rebounded , not created other one
- assertEquals(resourceNumber + 1, binder.getRootResources().size());
+ assertEquals(resourceNumber + 1, binder.getSize());
creq =
new ContainerRequest("GET", new URI("/groovy-test/groovy2/test"), new URI(""), null, new InputHeadersMap(
new MultivaluedMapImpl()));
13 years, 11 months
exo-jcr SVN: r2663 - in ws/trunk/exo.ws.rest.ext/src: test/java/org/exoplatform/services/rest/ext/groovy and 1 other directory.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-06-18 09:50:27 -0400 (Fri, 18 Jun 2010)
New Revision: 2663
Added:
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/BaseResourceId.java
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ResourceId.java
Modified:
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyJaxrsPublisher.java
ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyContextParamTest.java
ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyExoComponentTest.java
ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovySimpleTest.java
Log:
EXOJCR-793 :
Added: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/BaseResourceId.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/BaseResourceId.java (rev 0)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/BaseResourceId.java 2010-06-18 13:50:27 UTC (rev 2663)
@@ -0,0 +1,75 @@
+/**
+ * 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.rest.ext.groovy;
+
+/**
+ * Base implementation of ResourceId.
+ *
+ * @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
+ * @version $Id$
+ */
+public class BaseResourceId implements ResourceId
+{
+
+ protected final String id;
+
+ public BaseResourceId(String id)
+ {
+ this.id = id;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getId()
+ {
+ return id;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ return id.equals(((BaseResourceId)obj).id);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode()
+ {
+ return id.hashCode();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String toString()
+ {
+ return getClass().getSimpleName() + '(' + id + ')';
+ }
+}
Property changes on: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/BaseResourceId.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyJaxrsPublisher.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyJaxrsPublisher.java 2010-06-18 13:22:59 UTC (rev 2662)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/GroovyJaxrsPublisher.java 2010-06-18 13:50:27 UTC (rev 2663)
@@ -29,8 +29,14 @@
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.Charset;
+import java.nio.charset.UnsupportedCharsetException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
/**
+ * Manage via {@link ResourceBinder} Groovy based RESTful services.
+ *
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id$
*/
@@ -38,10 +44,10 @@
{
/** Default character set name. */
- static final String DEFAULT_CHARSET_NAME = "UTF-8";
+ protected static final String DEFAULT_CHARSET_NAME = "UTF-8";
/** Default character set. */
- static final Charset DEFAULT_CHARSET = Charset.forName(DEFAULT_CHARSET_NAME);
+ protected static final Charset DEFAULT_CHARSET = Charset.forName(DEFAULT_CHARSET_NAME);
protected final ResourceBinder binder;
@@ -49,6 +55,9 @@
protected GroovyClassLoader gcl;
+ protected final Map<ResourceId, Class<?>> resources =
+ Collections.synchronizedMap(new HashMap<ResourceId, Class<?>>());
+
/**
* Create GroovyJaxrsPublisher which is able publish per-request and
* singleton resources. Any required dependencies for per-request resource
@@ -67,32 +76,43 @@
}
/**
- * Create GroovyJaxrsPublisher which is able public per-request resources
- * only. This is default behavior for RESTful services. Any required
- * dependencies for resource injected by {@link PerRequestObjectFactory} in
- * runtime.
+ * @return get underling groovy class loader
+ */
+ public GroovyClassLoader getGroovyClassLoader()
+ {
+ return gcl;
+ }
+
+ /**
+ * Check is groovy resource with specified id is published or not
*
- * @param binder resource binder
+ * @param resourceId id of resource to be checked
+ * @return <code>true</code> if resource is published and <code>false</code>
+ * otherwise
*/
- public GroovyJaxrsPublisher(ResourceBinder binder)
+ public boolean isPublished(ResourceId resourceId)
{
- ClassLoader cl = getClass().getClassLoader();
- this.gcl = new GroovyClassLoader(cl);
- this.binder = binder;
- this.instantiator = null;
+ return resources.containsKey(resourceId);
}
/**
* Parse given stream and publish result as per-request RESTful service.
*
* @param in stream which contains groovy source code of RESTful service
- * @param name name of resource
+ * @param resourceId id to be assigned to resource
* @return <code>true</code> if resource was published and <code>false</code>
* otherwise
+ * @throws NullPointerException if <code>resourceId == null</code>
*/
- public boolean publishPerRequest(InputStream in, String name)
+ public boolean publishPerRequest(InputStream in, ResourceId resourceId)
{
- return publishPerRequest(createCodeSource(in, name));
+ Class<?> rc = gcl.parseClass(createCodeSource(in, resourceId.getId()));
+ boolean answ = binder.bind(rc);
+ if (answ)
+ {
+ resources.put(resourceId, rc);
+ }
+ return answ;
}
/**
@@ -100,48 +120,52 @@
* service.
*
* @param source groovy source code of RESTful service
- * @param name name of resource
+ * @param resourceId id to be assigned to resource
* @return <code>true</code> if resource was published and <code>false</code>
* otherwise
+ * @throws NullPointerException if <code>resourceId == null</code>
*/
- public boolean publishPerRequest(String source, String name)
+ public final boolean publishPerRequest(String source, ResourceId resourceId)
{
- byte[] bytes = source.getBytes(DEFAULT_CHARSET);
- return publishPerRequest(new ByteArrayInputStream(bytes), name);
+ return publishPerRequest(source, DEFAULT_CHARSET, resourceId);
}
/**
- * Parse given {@link GroovyCodeSource} and publish result as per-request
- * RESTful service.
+ * Parse given <code>source</code> and publish result as per-request RESTful
+ * service.
*
- * @param gcs groovy code source which contains source code of RESTful
- * service
+ * @param source groovy source code of RESTful service
+ * @param charset source string charset. May be <code>null</code> than
+ * default charset will be in use
+ * @param resourceId id to be assigned to resource
* @return <code>true</code> if resource was published and <code>false</code>
* otherwise
+ * @throws UnsupportedCharsetException if <code>charset</code> is unsupported
+ * @throws NullPointerException if <code>resourceId == null</code>
*/
- public boolean publishPerRequest(GroovyCodeSource gcs)
+ public final boolean publishPerRequest(String source, String charset, ResourceId resourceId)
{
- Class<?> rc = gcl.parseClass(gcs);
- return binder.bind(rc);
+ return publishPerRequest(source, charset == null ? DEFAULT_CHARSET : Charset.forName(charset), resourceId);
}
/**
* Parse given stream and publish result as singleton RESTful service.
*
* @param in stream which contains groovy source code of RESTful service
- * @param name name of resource
+ * @param resourceId id to be assigned to resource
* @return <code>true</code> if resource was published and <code>false</code>
* otherwise
- * @throws UnsupportedOperationException if publisher was created without
- * support of singleton resource, see
- * {@link #GroovyJaxrsPublisher(ResourceBinder)}
+ * @throws NullPointerException if <code>resourceId == null</code>
*/
- public boolean publishSingleton(InputStream in, String name)
+ public boolean publishSingleton(InputStream in, ResourceId resourceId)
{
- if (instantiator == null)
- throw new UnsupportedOperationException(
- "Can't instantiate groovy script. GroovyScriptInstantiator is not set.");
- return publishSingleton(createCodeSource(in, name));
+ Object r = instantiator.instantiateScript(createCodeSource(in, resourceId.getId()), gcl);
+ boolean answ = binder.bind(r);
+ if (answ)
+ {
+ resources.put(resourceId, r.getClass());
+ }
+ return answ;
}
/**
@@ -149,41 +173,32 @@
* service.
*
* @param source groovy source code of RESTful service
- * @param name name of resource
+ * @param resourceId name of resource
* @return <code>true</code> if resource was published and <code>false</code>
* otherwise
- * @throws UnsupportedOperationException if publisher was created without
- * support of singleton resource, see
- * {@link #GroovyJaxrsPublisher(ResourceBinder)}
+ * @throws NullPointerException if <code>resourceId == null</code>
*/
- public boolean publishSingleton(String source, String name)
+ public final boolean publishSingleton(String source, ResourceId resourceId)
{
- if (instantiator == null)
- throw new UnsupportedOperationException(
- "Can't instantiate groovy script. GroovyScriptInstantiator is not set.");
- byte[] bytes = source.getBytes(DEFAULT_CHARSET);
- return publishSingleton(new ByteArrayInputStream(bytes), name);
+ return publishSingleton(source, DEFAULT_CHARSET, resourceId);
}
/**
- * Parse given {@link GroovyCodeSource} and publish result as singleton
- * RESTful service.
+ * Parse given <code>source</code> and publish result as singleton RESTful
+ * service.
*
- * @param gcs groovy code source which contains source code of RESTful
- * service
+ * @param source groovy source code of RESTful service
+ * @param charset source string charset. May be <code>null</code> than
+ * default charset will be in use
+ * @param resourceId name of resource
* @return <code>true</code> if resource was published and <code>false</code>
* otherwise
- * @throws UnsupportedOperationException if publisher was created without
- * support of singleton resource, see
- * {@link #GroovyJaxrsPublisher(ResourceBinder)}
+ * @throws UnsupportedCharsetException if <code>charset</code> is unsupported
+ * @throws NullPointerException if <code>resourceId == null</code>
*/
- public boolean publishSingleton(GroovyCodeSource gcs)
+ public final boolean publishSingleton(String source, String charset, ResourceId resourceId)
{
- if (instantiator == null)
- throw new UnsupportedOperationException(
- "Can't instantiate groovy script. GroovyScriptInstantiator is not set.");
- Object r = instantiator.instantiateScript(gcs, gcl);
- return binder.bind(r);
+ return publishSingleton(source, charset == null ? DEFAULT_CHARSET : Charset.forName(charset), resourceId);
}
/**
@@ -200,6 +215,41 @@
}
/**
+ * Unpublish resource with specified id.
+ *
+ * @param resourceId id of resource to be unpublished
+ * @return <code>true</code> if resource was published and <code>false</code>
+ * otherwise, e.g. because there is not resource corresponded to
+ * supplied <code>resourceId</code>
+ */
+ public boolean unpublishResource(ResourceId resourceId)
+ {
+ Class<?> clazz = resources.get(resourceId);
+ boolean answ = false;
+ if (clazz != null)
+ {
+ answ = binder.unbind(clazz);
+ }
+ if (answ)
+ {
+ resources.remove(resourceId);
+ }
+ return answ;
+ }
+
+ private boolean publishPerRequest(String source, Charset charset, ResourceId resourceId)
+ {
+ byte[] bytes = source.getBytes(charset);
+ return publishPerRequest(new ByteArrayInputStream(bytes), resourceId);
+ }
+
+ private boolean publishSingleton(String source, Charset charset, ResourceId resourceId)
+ {
+ byte[] bytes = source.getBytes(charset);
+ return publishSingleton(new ByteArrayInputStream(bytes), resourceId);
+ }
+
+ /**
* Create {@link GroovyCodeSource} from given stream and name. Code base
* 'file:/groovy/script/jaxrs' will be used.
*
@@ -209,8 +259,7 @@
*/
protected GroovyCodeSource createCodeSource(InputStream in, String name)
{
- GroovyCodeSource gcs =
- new GroovyCodeSource(in, name == null ? gcl.generateScriptName() : name, "/groovy/script/jaxrs");
+ GroovyCodeSource gcs = new GroovyCodeSource(in, name, "/groovy/script/jaxrs");
gcs.setCachable(false);
return gcs;
}
Added: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ResourceId.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ResourceId.java (rev 0)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ResourceId.java 2010-06-18 13:50:27 UTC (rev 2663)
@@ -0,0 +1,36 @@
+/**
+ * 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.rest.ext.groovy;
+
+/**
+ * @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
+ * @version $Id$
+ */
+public interface ResourceId
+{
+
+ /**
+ * Gets the id of resource as string
+ *
+ * @return the resource id
+ */
+ String getId();
+
+}
Property changes on: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/ResourceId.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyContextParamTest.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyContextParamTest.java 2010-06-18 13:22:59 UTC (rev 2662)
+++ ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyContextParamTest.java 2010-06-18 13:50:27 UTC (rev 2663)
@@ -27,7 +27,8 @@
/**
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
- * @version $Id$
+ * @version $Id: GroovyContextParamTest.java 2647 2010-06-17 08:39:29Z aparfonov
+ * $
*/
public class GroovyContextParamTest extends BaseTest
{
@@ -41,11 +42,23 @@
assertNotNull(script);
}
+ @Override
+ public void tearDown() throws Exception
+ {
+ groovyPublisher.resources.clear();
+ super.tearDown();
+ }
+
public void testPerRequest() throws Exception
{
assertEquals(0, binder.getSize());
- groovyPublisher.publishPerRequest(script, "g1");
+ assertEquals(0, groovyPublisher.resources.size());
+
+ groovyPublisher.publishPerRequest(script, new BaseResourceId("g1"));
+
assertEquals(1, binder.getSize());
+ assertEquals(1, groovyPublisher.resources.size());
+
ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
ContainerResponse resp =
service("GET", "http://localhost:8080/context/a/b", "http://localhost:8080/context", null, null, writer);
Modified: ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyExoComponentTest.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyExoComponentTest.java 2010-06-18 13:22:59 UTC (rev 2662)
+++ ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyExoComponentTest.java 2010-06-18 13:50:27 UTC (rev 2663)
@@ -47,27 +47,33 @@
public void tearDown() throws Exception
{
container.unregisterComponent(Component1.class.getName());
+ groovyPublisher.resources.clear();
super.tearDown();
}
public void testExoComponentPerRequest() throws Exception
{
- containerComponentTest(false, "g1");
+ containerComponentTest(false, new BaseResourceId("g1"));
}
public void testExoComponentSingleton() throws Exception
{
- containerComponentTest(true, "g1");
+ containerComponentTest(true, new BaseResourceId("g2"));
}
- private void containerComponentTest(boolean singleton, String name) throws Exception
+ private void containerComponentTest(boolean singleton, ResourceId resourceId) throws Exception
{
assertEquals(0, binder.getSize());
+ assertEquals(0, groovyPublisher.resources.size());
+
if (singleton)
- groovyPublisher.publishSingleton(script, name);
+ groovyPublisher.publishSingleton(script, resourceId);
else
- groovyPublisher.publishPerRequest(script, name);
+ groovyPublisher.publishPerRequest(script, resourceId);
+
assertEquals(1, binder.getSize());
+ assertEquals(1, groovyPublisher.resources.size());
+
ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
ContainerResponse resp = service("GET", "/a/b", "", null, null, writer);
assertEquals(200, resp.getStatus());
Modified: ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovySimpleTest.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovySimpleTest.java 2010-06-18 13:22:59 UTC (rev 2662)
+++ ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovySimpleTest.java 2010-06-18 13:50:27 UTC (rev 2663)
@@ -23,8 +23,6 @@
import org.exoplatform.services.rest.impl.ContainerResponse;
import org.exoplatform.services.rest.tools.ByteArrayContainerResponseWriter;
-import java.io.ByteArrayInputStream;
-
/**
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id$
@@ -32,17 +30,24 @@
public class GroovySimpleTest extends BaseTest
{
+ @Override
+ public void tearDown() throws Exception
+ {
+ groovyPublisher.resources.clear();
+ super.tearDown();
+ }
+
public void testPerRequest() throws Exception
{
- publicationTest(false, "g1");
+ publicationTest(false, new BaseResourceId("g1"));
}
public void testSingleton() throws Exception
{
- publicationTest(true, "g2");
+ publicationTest(true, new BaseResourceId("g2"));
}
- private void publicationTest(boolean singleton, String name) throws Exception
+ private void publicationTest(boolean singleton, ResourceId resourceId) throws Exception
{
String script = //
"@javax.ws.rs.Path(\"a\")" //
@@ -52,13 +57,15 @@
+ "}";
assertEquals(0, binder.getSize());
+ assertEquals(0, groovyPublisher.resources.size());
if (singleton)
- groovyPublisher.publishSingleton(new ByteArrayInputStream(script.getBytes()), name);
+ groovyPublisher.publishSingleton(script, resourceId);
else
- groovyPublisher.publishPerRequest(new ByteArrayInputStream(script.getBytes()), name);
+ groovyPublisher.publishPerRequest(script, resourceId);
assertEquals(1, binder.getSize());
+ assertEquals(1, groovyPublisher.resources.size());
String cs =
binder.getResources().get(0).getObjectModel().getObjectClass().getProtectionDomain().getCodeSource()
@@ -69,6 +76,11 @@
ContainerResponse resp = service("GET", "/a/groovy", "", null, null, writer);
assertEquals(200, resp.getStatus());
assertEquals("hello groovy", new String(writer.getBody()));
+
+ groovyPublisher.unpublishResource(resourceId);
+
+ assertEquals(0, binder.getSize());
+ assertEquals(0, groovyPublisher.resources.size());
}
}
13 years, 11 months
exo-jcr SVN: r2662 - jcr/branches.
by do-not-reply@jboss.org
Author: dkatayev
Date: 2010-06-18 09:22:59 -0400 (Fri, 18 Jun 2010)
New Revision: 2662
Removed:
jcr/branches/1.14.x/
Log:
EXOJCR-751 1.14.x branch removed
13 years, 11 months
exo-jcr SVN: r2661 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-06-18 09:09:06 -0400 (Fri, 18 Jun 2010)
New Revision: 2661
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileOperation.java
Log:
EXOJCR-756: fix
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileOperation.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileOperation.java 2010-06-18 11:04:39 UTC (rev 2660)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileOperation.java 2010-06-18 13:09:06 UTC (rev 2661)
@@ -31,6 +31,9 @@
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
/**
* Created by The eXo Platform SAS.
@@ -243,7 +246,35 @@
try
{
// get the inet address
- InetAddress local = InetAddress.getLocalHost();
+ InetAddress local = null;
+ PrivilegedExceptionAction<InetAddress> action = new PrivilegedExceptionAction<InetAddress>()
+ {
+ public InetAddress run() throws Exception
+ {
+ return InetAddress.getLocalHost();
+ }
+ };
+ try
+ {
+ local = AccessController.doPrivileged(action);
+ }
+ catch (PrivilegedActionException pae)
+ {
+ Throwable cause = pae.getCause();
+ if (cause instanceof UnknownHostException)
+ {
+ throw (UnknownHostException)cause;
+ }
+ else if (cause instanceof RuntimeException)
+ {
+ throw (RuntimeException)cause;
+ }
+ else
+ {
+ throw new RuntimeException(cause);
+ }
+ }
+
localAddr = local.getHostAddress() + " (" + local.getHostName() + ")";
}
catch (UnknownHostException e)
13 years, 11 months
exo-jcr SVN: r2660 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc: optimisation/db and 1 other directory.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2010-06-18 07:04:39 -0400 (Fri, 18 Jun 2010)
New Revision: 2660
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/HSQLDBMultiDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBMultiDbJDBCConnection.java
Log:
EXOJCR-758: HSSQL JDBC connection updated
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/HSQLDBMultiDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/HSQLDBMultiDbJDBCConnection.java 2010-06-18 09:26:59 UTC (rev 2659)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/HSQLDBMultiDbJDBCConnection.java 2010-06-18 11:04:39 UTC (rev 2660)
@@ -16,11 +16,19 @@
*/
package org.exoplatform.services.jcr.impl.storage.jdbc.db;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.PropertyData;
+import org.exoplatform.services.jcr.impl.util.SecurityHelper;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedExceptionAction;
import java.sql.Connection;
+import java.sql.ResultSet;
import java.sql.SQLException;
/**
@@ -34,6 +42,253 @@
public class HSQLDBMultiDbJDBCConnection extends MultiDbJDBCConnection
{
+ @Override
+ protected int addNodeRecord(final NodeData data) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.addNodeRecord(data);
+ }
+ });
+ }
+
+ @Override
+ protected int addPropertyRecord(final PropertyData data) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.addPropertyRecord(data);
+ }
+ });
+ }
+
+ @Override
+ protected int addReference(final PropertyData data) throws SQLException, IOException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.addReference(data);
+ }
+ });
+ }
+
+ @Override
+ protected int addValueData(final String cid, final int orderNumber, final InputStream stream,
+ final int streamLength, final String storageDesc) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.addValueData(cid, orderNumber, stream, streamLength, storageDesc);
+
+ }
+ });
+ }
+
+ @Override
+ protected int deleteItemByIdentifier(final String identifier) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.deleteItemByIdentifier(identifier);
+ }
+ });
+ }
+
+ @Override
+ protected int deleteReference(final String propertyIdentifier) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.deleteReference(propertyIdentifier);
+
+ }
+ });
+ }
+
+ @Override
+ protected int deleteValueData(final String cid) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.deleteValueData(cid);
+ }
+ });
+ }
+
+ @Override
+ protected ResultSet findChildNodesByParentIdentifier(final String parentIdentifier) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.findChildNodesByParentIdentifier(parentIdentifier);
+ }
+ });
+ }
+
+ @Override
+ protected ResultSet findChildNodesCountByParentIdentifier(final String parentIdentifier) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.findChildNodesCountByParentIdentifier(parentIdentifier);
+ }
+ });
+ }
+
+ @Override
+ protected ResultSet findChildPropertiesByParentIdentifier(final String parentIdentifier) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.findChildPropertiesByParentIdentifier(parentIdentifier);
+ }
+ });
+ }
+
+ @Override
+ protected ResultSet findItemByIdentifier(final String identifier) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.findItemByIdentifier(identifier);
+ }
+ });
+ }
+
+ @Override
+ protected ResultSet findItemByName(final String parentId, final String name, final int index) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.findItemByName(parentId, name, index);
+ }
+ });
+ }
+
+ @Override
+ protected ResultSet findPropertyByName(final String parentId, final String name) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.findPropertyByName(parentId, name);
+ }
+ });
+ }
+
+ @Override
+ protected ResultSet findReferences(final String nodeIdentifier) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.findReferences(nodeIdentifier);
+ }
+ });
+ }
+
+ @Override
+ protected ResultSet findValueByPropertyIdOrderNumber(final String cid, final int orderNumb) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.findValueByPropertyIdOrderNumber(cid, orderNumb);
+ }
+ });
+ }
+
+ @Override
+ protected ResultSet findValuesByPropertyId(final String cid) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.findValuesByPropertyId(cid);
+ }
+ });
+ }
+
+ @Override
+ protected ResultSet findValuesStorageDescriptorsByPropertyId(final String cid) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.findValuesStorageDescriptorsByPropertyId(cid);
+
+ }
+ });
+ }
+
+ @Override
+ protected int renameNode(final NodeData data) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.renameNode(data);
+
+ }
+ });
+ }
+
+ @Override
+ protected int updateNodeByIdentifier(final int version, final int index, final int orderNumb, final String identifier)
+ throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.updateNodeByIdentifier(version, index, orderNumb, identifier);
+ }
+ });
+ }
+
+ @Override
+ protected int updatePropertyByIdentifier(final int version, final int type, final String identifier)
+ throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.updatePropertyByIdentifier(version, type, identifier);
+ }
+ });
+ }
+
/**
* HSQLDB Multidatabase JDBC Connection constructor.
*
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBMultiDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBMultiDbJDBCConnection.java 2010-06-18 09:26:59 UTC (rev 2659)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBMultiDbJDBCConnection.java 2010-06-18 11:04:39 UTC (rev 2660)
@@ -17,12 +17,19 @@
package org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.db;
import org.exoplatform.services.jcr.datamodel.IllegalNameException;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.PropertyData;
import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.impl.util.SecurityHelper;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.PrivilegedExceptionAction;
import java.sql.Connection;
+import java.sql.ResultSet;
import java.sql.SQLException;
import javax.jcr.InvalidItemStateException;
@@ -38,6 +45,297 @@
public class HSQLDBMultiDbJDBCConnection extends MultiDbJDBCConnection
{
+ @Override
+ protected int addNodeRecord(final NodeData data) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.addNodeRecord(data);
+ }
+ });
+ }
+
+ @Override
+ protected int addPropertyRecord(final PropertyData data) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.addPropertyRecord(data);
+ }
+ });
+ }
+
+ @Override
+ protected int addReference(final PropertyData data) throws SQLException, IOException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.addReference(data);
+ }
+ });
+ }
+
+ @Override
+ protected int addValueData(final String cid, final int orderNumber, final InputStream stream,
+ final int streamLength, final String storageDesc) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.addValueData(cid, orderNumber, stream, streamLength, storageDesc);
+ }
+ });
+ }
+
+ @Override
+ protected int deleteItemByIdentifier(final String identifier) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.deleteItemByIdentifier(identifier);
+ }
+ });
+ }
+
+ @Override
+ protected int deleteReference(final String propertyIdentifier) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.deleteReference(propertyIdentifier);
+ }
+ });
+ }
+
+ @Override
+ protected int deleteValueData(final String cid) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.deleteValueData(cid);
+ }
+ });
+ }
+
+ @Override
+ protected ResultSet findChildNodesByParentIdentifier(final String parentIdentifier) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.findChildNodesByParentIdentifier(parentIdentifier);
+ }
+ });
+ }
+
+ @Override
+ protected ResultSet findChildNodesByParentIdentifierCQ(final String parentIdentifier) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.findChildNodesByParentIdentifierCQ(parentIdentifier);
+ }
+ });
+ }
+
+ @Override
+ protected ResultSet findChildNodesCountByParentIdentifier(final String parentIdentifier) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.findChildNodesCountByParentIdentifier(parentIdentifier);
+ }
+ });
+ }
+
+ @Override
+ protected ResultSet findChildPropertiesByParentIdentifier(final String parentIdentifier) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.findChildPropertiesByParentIdentifier(parentIdentifier);
+ }
+ });
+ }
+
+ @Override
+ protected ResultSet findChildPropertiesByParentIdentifierCQ(final String parentIdentifier) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.findChildPropertiesByParentIdentifierCQ(parentIdentifier);
+ }
+ });
+ }
+
+ @Override
+ protected ResultSet findItemByIdentifier(final String identifier) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.findItemByIdentifier(identifier);
+ }
+ });
+ }
+
+ @Override
+ protected ResultSet findItemByName(final String parentId, final String name, final int index) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.findItemByName(parentId, name, index);
+ }
+ });
+ }
+
+ @Override
+ protected ResultSet findItemQPathByIdentifierCQ(final String identifier) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.findItemQPathByIdentifierCQ(identifier);
+ }
+ });
+ }
+
+ @Override
+ protected ResultSet findNodeMainPropertiesByParentIdentifierCQ(final String parentIdentifier) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.findNodeMainPropertiesByParentIdentifierCQ(parentIdentifier);
+ }
+ });
+ }
+
+ @Override
+ protected ResultSet findPropertyByName(final String parentId, final String name) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.findPropertyByName(parentId, name);
+ }
+ });
+ }
+
+ @Override
+ protected ResultSet findReferences(final String nodeIdentifier) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.findReferences(nodeIdentifier);
+ }
+ });
+ }
+
+ @Override
+ protected ResultSet findValueByPropertyIdOrderNumber(final String cid, final int orderNumb) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.findValueByPropertyIdOrderNumber(cid, orderNumb);
+ }
+ });
+ }
+
+ @Override
+ protected ResultSet findValuesByPropertyId(final String cid) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.findValuesByPropertyId(cid);
+ }
+ });
+ }
+
+ @Override
+ protected ResultSet findValuesStorageDescriptorsByPropertyId(final String cid) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.findValuesStorageDescriptorsByPropertyId(cid);
+ }
+ });
+ }
+
+ @Override
+ protected int renameNode(final NodeData data) throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.renameNode(data);
+ }
+ });
+ }
+
+ @Override
+ protected int updateNodeByIdentifier(final int version, final int index, final int orderNumb, final String identifier)
+ throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.updateNodeByIdentifier(version, index, orderNumb, identifier);
+ }
+ });
+ }
+
+ @Override
+ protected int updatePropertyByIdentifier(final int version, final int type, final String identifier)
+ throws SQLException
+ {
+ return SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.updatePropertyByIdentifier(version, type, identifier);
+ }
+ });
+ }
+
/**
* HSQLDB Multidatabase JDBC Connection constructor.
*
@@ -88,7 +386,7 @@
FIND_PROPERTIES_BY_PARENTID_CQ =
"select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_CLASS, I.I_INDEX, I.N_ORDER_NUM, I.P_TYPE, I.P_MULTIVALUED,"
+ " V.ORDER_NUM, V.DATA, V.STORAGE_DESC from JCR_MITEM I LEFT OUTER JOIN JCR_MVALUE V ON (V.PROPERTY_ID=I.ID)"
- + " where I.PARENT_ID=? and I.I_CLASS=2 order by I.NAME";
+ + " where I.PARENT_ID=? and I.I_CLASS=2 order by I.NAME";
}
/**
@@ -98,5 +396,5 @@
protected QPath traverseQPath(String cpid) throws SQLException, InvalidItemStateException, IllegalNameException
{
return traverseQPathSQ(cpid);
- }
+ }
}
13 years, 11 months
exo-jcr SVN: r2659 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc: db and 1 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-06-18 05:26:59 -0400 (Fri, 18 Jun 2010)
New Revision: 2659
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/HSQLDBSingleDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBSingleDbJDBCConnection.java
Log:
EXOJCR-756: replace operations on privileged operations for HSQLDB
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java 2010-06-18 09:04:49 UTC (rev 2658)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java 2010-06-18 09:26:59 UTC (rev 2659)
@@ -122,7 +122,7 @@
protected final WriteValueHelper writeValueHelper = new WriteValueHelper();
- // All statements should be closed in cloaseStatements() method.
+ // All statements should be closed in closeStatements() method.
protected PreparedStatement findItemById;
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/HSQLDBSingleDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/HSQLDBSingleDbJDBCConnection.java 2010-06-18 09:04:49 UTC (rev 2658)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/HSQLDBSingleDbJDBCConnection.java 2010-06-18 09:26:59 UTC (rev 2659)
@@ -16,10 +16,16 @@
*/
package org.exoplatform.services.jcr.impl.storage.jdbc.db;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.PropertyData;
+import org.exoplatform.services.jcr.impl.util.SecurityHelper;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.PrivilegedExceptionAction;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -102,7 +108,15 @@
findItemByName.setString(2, containerName);
findItemByName.setString(3, name);
findItemByName.setInt(4, index);
- return findItemByName.executeQuery();
+
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return findItemByName.executeQuery();
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
}
/**
@@ -119,7 +133,15 @@
findPropertyByName.setString(1, parentCid);
findPropertyByName.setString(2, containerName);
findPropertyByName.setString(3, name);
- return findPropertyByName.executeQuery();
+
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return findPropertyByName.executeQuery();
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
}
/**
@@ -135,9 +157,17 @@
findNodesByParentId.setString(1, parentCid);
findNodesByParentId.setString(2, containerName);
- return findNodesByParentId.executeQuery();
+
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return findNodesByParentId.executeQuery();
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
}
-
+
/**
* {@inheritDoc}
*/
@@ -151,7 +181,15 @@
findNodesCountByParentId.setString(1, parentCid);
findNodesCountByParentId.setString(2, containerName);
- return findNodesCountByParentId.executeQuery();
+
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return findNodesCountByParentId.executeQuery();
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
}
/**
@@ -167,6 +205,258 @@
findPropertiesByParentId.setString(1, parentCid);
findPropertiesByParentId.setString(2, containerName);
- return findPropertiesByParentId.executeQuery();
+
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return findPropertiesByParentId.executeQuery();
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected int addNodeRecord(final NodeData data) throws SQLException
+ {
+ PrivilegedExceptionAction<Integer> action = new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.addNodeRecord(data);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected int addPropertyRecord(final PropertyData prop) throws SQLException
+ {
+ PrivilegedExceptionAction<Integer> action = new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.addPropertyRecord(prop);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ResultSet findItemByIdentifier(final String identifier) throws SQLException
+ {
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.findItemByIdentifier(identifier);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected int addReference(final PropertyData data) throws SQLException, IOException
+ {
+ PrivilegedExceptionAction<Integer> action = new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.addReference(data);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected int renameNode(final NodeData data) throws SQLException
+ {
+ PrivilegedExceptionAction<Integer> action = new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.renameNode(data);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected int deleteReference(final String propertyIdentifier) throws SQLException
+ {
+ PrivilegedExceptionAction<Integer> action = new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.deleteReference(propertyIdentifier);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ResultSet findReferences(final String nodeIdentifier) throws SQLException
+ {
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.findReferences(nodeIdentifier);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected int deleteItemByIdentifier(final String identifier) throws SQLException
+ {
+ PrivilegedExceptionAction<Integer> action = new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.deleteItemByIdentifier(identifier);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected int updateNodeByIdentifier(final int version, final int index, final int orderNumb, final String identifier)
+ throws SQLException
+ {
+ PrivilegedExceptionAction<Integer> action = new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.updateNodeByIdentifier(version, index, orderNumb, identifier);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected int updatePropertyByIdentifier(final int version, final int type, final String identifier)
+ throws SQLException
+ {
+ PrivilegedExceptionAction<Integer> action = new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.updatePropertyByIdentifier(version, type, identifier);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ // -------- values processing ------------
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected int addValueData(final String cid, final int orderNumber, final InputStream stream,
+ final int streamLength, final String storageId) throws SQLException
+ {
+ PrivilegedExceptionAction<Integer> action = new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.addValueData(cid, orderNumber, stream, streamLength, storageId);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected int deleteValueData(final String cid) throws SQLException
+ {
+ PrivilegedExceptionAction<Integer> action = new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.deleteValueData(cid);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ResultSet findValuesByPropertyId(final String cid) throws SQLException
+ {
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.findValuesByPropertyId(cid);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ResultSet findValuesStorageDescriptorsByPropertyId(final String cid) throws SQLException
+ {
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.findValuesStorageDescriptorsByPropertyId(cid);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ResultSet findValueByPropertyIdOrderNumber(final String cid, final int orderNumb) throws SQLException
+ {
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.findValueByPropertyIdOrderNumber(cid, orderNumb);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBSingleDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBSingleDbJDBCConnection.java 2010-06-18 09:04:49 UTC (rev 2658)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBSingleDbJDBCConnection.java 2010-06-18 09:26:59 UTC (rev 2659)
@@ -17,11 +17,17 @@
package org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.db;
import org.exoplatform.services.jcr.datamodel.IllegalNameException;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.PropertyData;
import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.impl.util.SecurityHelper;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.PrivilegedExceptionAction;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -98,7 +104,7 @@
FIND_PROPERTIES_BY_PARENTID_CQ =
"select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_CLASS, I.I_INDEX, I.N_ORDER_NUM, I.P_TYPE, I.P_MULTIVALUED, V.ORDER_NUM,"
+ " V.DATA, V.STORAGE_DESC from JCR_SITEM I LEFT OUTER JOIN JCR_SVALUE V ON (V.PROPERTY_ID=I.ID)"
- + " where I.PARENT_ID=? and I.I_CLASS=2 and I.CONTAINER_NAME=? order by I.NAME";
+ + " where I.PARENT_ID=? and I.I_CLASS=2 and I.CONTAINER_NAME=? order by I.NAME";
}
/**
@@ -108,8 +114,8 @@
protected QPath traverseQPath(String cpid) throws SQLException, InvalidItemStateException, IllegalNameException
{
return traverseQPathSQ(cpid);
- }
-
+ }
+
/**
* {@inheritDoc}
*/
@@ -125,7 +131,15 @@
findItemByName.setString(2, containerName);
findItemByName.setString(3, name);
findItemByName.setInt(4, index);
- return findItemByName.executeQuery();
+
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return findItemByName.executeQuery();
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
}
/**
@@ -142,7 +156,15 @@
findPropertyByName.setString(1, parentCid);
findPropertyByName.setString(2, containerName);
findPropertyByName.setString(3, name);
- return findPropertyByName.executeQuery();
+
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return findPropertyByName.executeQuery();
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
}
/**
@@ -158,9 +180,17 @@
findNodesByParentId.setString(1, parentCid);
findNodesByParentId.setString(2, containerName);
- return findNodesByParentId.executeQuery();
+
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return findNodesByParentId.executeQuery();
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
}
-
+
/**
* {@inheritDoc}
*/
@@ -174,7 +204,15 @@
findNodesCountByParentId.setString(1, parentCid);
findNodesCountByParentId.setString(2, containerName);
- return findNodesCountByParentId.executeQuery();
+
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return findNodesCountByParentId.executeQuery();
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
}
/**
@@ -190,9 +228,16 @@
findPropertiesByParentId.setString(1, parentCid);
findPropertiesByParentId.setString(2, containerName);
- return findPropertiesByParentId.executeQuery();
+
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return findPropertiesByParentId.executeQuery();
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
}
-
/**
* {@inheritDoc}
@@ -208,9 +253,17 @@
findNodesByParentIdCQ.setString(1, parentIdentifier);
findNodesByParentIdCQ.setString(2, containerName);
findNodesByParentIdCQ.setString(3, containerName);
- return findNodesByParentIdCQ.executeQuery();
- }
-
+
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return findNodesByParentIdCQ.executeQuery();
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
/**
* {@inheritDoc}
*/
@@ -224,7 +277,290 @@
findPropertiesByParentIdCQ.setString(1, parentIdentifier);
findPropertiesByParentIdCQ.setString(2, containerName);
- return findPropertiesByParentIdCQ.executeQuery();
- }
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return findPropertiesByParentIdCQ.executeQuery();
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected int addNodeRecord(final NodeData data) throws SQLException
+ {
+ PrivilegedExceptionAction<Integer> action = new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.addNodeRecord(data);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected int addPropertyRecord(final PropertyData prop) throws SQLException
+ {
+ PrivilegedExceptionAction<Integer> action = new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.addPropertyRecord(prop);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ResultSet findItemByIdentifier(final String identifier) throws SQLException
+ {
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.findItemByIdentifier(identifier);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected int addReference(final PropertyData data) throws SQLException, IOException
+ {
+ PrivilegedExceptionAction<Integer> action = new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.addReference(data);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected int renameNode(final NodeData data) throws SQLException
+ {
+ PrivilegedExceptionAction<Integer> action = new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.renameNode(data);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected int deleteReference(final String propertyIdentifier) throws SQLException
+ {
+ PrivilegedExceptionAction<Integer> action = new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.deleteReference(propertyIdentifier);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ResultSet findReferences(final String nodeIdentifier) throws SQLException
+ {
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.findReferences(nodeIdentifier);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected int deleteItemByIdentifier(final String identifier) throws SQLException
+ {
+ PrivilegedExceptionAction<Integer> action = new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.deleteItemByIdentifier(identifier);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected int updateNodeByIdentifier(final int version, final int index, final int orderNumb, final String identifier)
+ throws SQLException
+ {
+ PrivilegedExceptionAction<Integer> action = new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.updateNodeByIdentifier(version, index, orderNumb, identifier);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected int updatePropertyByIdentifier(final int version, final int type, final String identifier)
+ throws SQLException
+ {
+ PrivilegedExceptionAction<Integer> action = new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.updatePropertyByIdentifier(version, type, identifier);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ // -------- values processing ------------
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected int addValueData(final String cid, final int orderNumber, final InputStream stream,
+ final int streamLength, final String storageId) throws SQLException
+ {
+ PrivilegedExceptionAction<Integer> action = new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.addValueData(cid, orderNumber, stream, streamLength, storageId);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected int deleteValueData(final String cid) throws SQLException
+ {
+ PrivilegedExceptionAction<Integer> action = new PrivilegedExceptionAction<Integer>()
+ {
+ public Integer run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.deleteValueData(cid);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ResultSet findValuesByPropertyId(final String cid) throws SQLException
+ {
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.findValuesByPropertyId(cid);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ResultSet findValuesStorageDescriptorsByPropertyId(final String cid) throws SQLException
+ {
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.findValuesStorageDescriptorsByPropertyId(cid);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ResultSet findValueByPropertyIdOrderNumber(final String cid, final int orderNumb) throws SQLException
+ {
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.findValueByPropertyIdOrderNumber(cid, orderNumb);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ResultSet findItemQPathByIdentifierCQ(final String identifier) throws SQLException
+ {
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.findItemQPathByIdentifierCQ(identifier);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ResultSet findNodeMainPropertiesByParentIdentifierCQ(final String parentIdentifier) throws SQLException
+ {
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.findNodeMainPropertiesByParentIdentifierCQ(parentIdentifier);
+ }
+ };
+ return SecurityHelper.doPriviledgedSQLExceptionAction(action);
+ }
}
13 years, 11 months
exo-jcr SVN: r2658 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-06-18 05:04:49 -0400 (Fri, 18 Jun 2010)
New Revision: 2658
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/SecurityHelper.java
Log:
EXOJCR-756: add new privileged method
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/SecurityHelper.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/SecurityHelper.java 2010-06-18 06:39:37 UTC (rev 2657)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/SecurityHelper.java 2010-06-18 09:04:49 UTC (rev 2658)
@@ -23,6 +23,7 @@
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
+import java.sql.SQLException;
import javax.jcr.RepositoryException;
@@ -69,6 +70,38 @@
}
/**
+ * Launches action in privileged mode. Can throw only IO exception.
+ *
+ * @param <E>
+ * @param action
+ * @return
+ * @throws IOException
+ */
+ public static <E> E doPriviledgedSQLExceptionAction(PrivilegedExceptionAction<E> action) throws SQLException
+ {
+ try
+ {
+ return 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);
+ }
+ }
+ }
+
+ /**
* Launches action in privileged mode. Can throw only repository exception.
*
* @param <E>
@@ -101,7 +134,6 @@
}
}
-
/**
* Launches action in privileged mode. Can throw only runtime exceptions.
*
13 years, 11 months
exo-jcr SVN: r2657 - kernel/trunk/exo.kernel.commons.test/src/main/java/org/exoplatform/commons/test.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-06-18 02:39:37 -0400 (Fri, 18 Jun 2010)
New Revision: 2657
Modified:
kernel/trunk/exo.kernel.commons.test/src/main/java/org/exoplatform/commons/test/TestSecurityManager.java
Log:
EXOJCR-756: add log.error()
Modified: kernel/trunk/exo.kernel.commons.test/src/main/java/org/exoplatform/commons/test/TestSecurityManager.java
===================================================================
--- kernel/trunk/exo.kernel.commons.test/src/main/java/org/exoplatform/commons/test/TestSecurityManager.java 2010-06-17 15:10:15 UTC (rev 2656)
+++ kernel/trunk/exo.kernel.commons.test/src/main/java/org/exoplatform/commons/test/TestSecurityManager.java 2010-06-18 06:39:37 UTC (rev 2657)
@@ -115,7 +115,7 @@
return;
}
- LOG.error(se);
+ LOG.error("Check permission failed", se);
throw se;
}
}
13 years, 11 months