diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..4214a97
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..4f26656
--- /dev/null
+++ b/.project
@@ -0,0 +1,23 @@
+
+
+ threadlocal-vars-cleaner
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.m2e.core.maven2Builder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+ org.eclipse.m2e.core.maven2Nature
+
+
diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..f9fe345
--- /dev/null
+++ b/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,4 @@
+eclipse.preferences.version=1
+encoding//src/main/java=UTF-8
+encoding//src/test/java=UTF-8
+encoding/=UTF-8
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..ec4300d
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,5 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.7
diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 0000000..f897a7f
--- /dev/null
+++ b/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/distro/LICENSE b/distro/LICENSE
new file mode 100644
index 0000000..2d9616a
--- /dev/null
+++ b/distro/LICENSE
@@ -0,0 +1 @@
+${gcube.license}
\ No newline at end of file
diff --git a/distro/README b/distro/README
new file mode 100644
index 0000000..35c99c0
--- /dev/null
+++ b/distro/README
@@ -0,0 +1,67 @@
+The gCube System - ${name}
+--------------------------------------------------
+
+${description}
+
+
+${gcube.description}
+
+${gcube.funding}
+
+
+Version
+--------------------------------------------------
+
+${version} (${buildDate})
+
+Please see the file named "changelog.xml" in this directory for the release notes.
+
+
+Authors
+--------------------------------------------------
+
+* Massimiliano Assante (massimiliano.assante-AT-isti.cnr.it), Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" - CNR, Pisa (Italy).
+
+
+
+Maintainers
+-----------
+
+* Massimiliano Assante (massimiliano.assante-AT-isti.cnr.it), Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" - CNR, Pisa (Italy).
+
+
+Download information
+--------------------------------------------------
+
+Source code is available from SVN:
+ ${scm.url}
+
+Binaries can be downloaded from the gCube website:
+ ${gcube.website}
+
+
+Installation
+--------------------------------------------------
+
+Installation documentation is available on-line in the gCube Wiki:
+ ${gcube.wikiRoot}/
+
+
+Documentation
+--------------------------------------------------
+
+Documentation is available on-line in the gCube Wiki:
+ ${gcube.wikiRoot}/
+ ${gcube.wikiRoot}/
+
+Support
+--------------------------------------------------
+
+Bugs and support requests can be reported in the gCube issue tracking tool:
+ ${gcube.issueTracking}
+
+
+Licensing
+--------------------------------------------------
+
+This software is licensed under the terms you may find in the file named "LICENSE" in this directory.
diff --git a/distro/changelog.xml b/distro/changelog.xml
new file mode 100644
index 0000000..1e8a8dc
--- /dev/null
+++ b/distro/changelog.xml
@@ -0,0 +1,5 @@
+
+
+ First Release
+
+
diff --git a/distro/descriptor.xml b/distro/descriptor.xml
new file mode 100644
index 0000000..1edba8b
--- /dev/null
+++ b/distro/descriptor.xml
@@ -0,0 +1,47 @@
+
+ servicearchive
+
+ tar.gz
+
+ /
+
+
+ ${distroDirectory}
+ /
+ true
+
+ README
+ LICENSE
+ changelog.xml
+ profile.xml
+
+ 755
+ true
+
+
+ target/apidocs
+ /${artifactId}/doc/api
+ true
+ 755
+
+
+
+
+
+ ./
+ true
+
+
+
+ /${artifactId}
+
+
+
+ /${artifactId}
+ true
+
+
+
\ No newline at end of file
diff --git a/distro/profile.xml b/distro/profile.xml
new file mode 100644
index 0000000..4dda0b9
--- /dev/null
+++ b/distro/profile.xml
@@ -0,0 +1,25 @@
+
+
+
+ Library
+
+ ${description}
+ Portal
+ ${artifactId}
+ 1.0.0
+
+
+ ${artifactId}
+ ${version}
+
+ ${groupId}
+ ${artifactId}
+ ${version}
+
+
+ ${build.finalName}.war
+
+
+
+
+
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..1635a19
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,152 @@
+
+ 4.0.0
+
+ maven-parent
+ org.gcube.tools
+ 1.0.0
+
+
+
+ org.gcube.portal
+ threadlocal-vars-cleaner
+ 0.0.1-SNAPSHOT
+ jar
+
+ threadlocal-vars-cleaner
+ http://maven.apache.org
+ This component clean the Smartgears ThreadLocal variables each time a new Thread is assigned to a request from tomcat thread pool
+
+ 1.7
+ 6.0.6
+ ${project.basedir}/distro
+ ${project.build.directory}/${project.build.finalName}
+ distro
+
+ UTF-8
+ UTF-8
+
+
+
+
+ http://svn.d4science.research-infrastructures.eu/gcube/trunk/portal/${project.artifactId}
+
+
+
+
+ org.gcube.distribution
+ maven-portal-bom
+ LATEST
+ pom
+ import
+
+
+
+
+
+ org.apache.tomcat
+ catalina
+ 6.0.29
+ provided
+
+
+ org.gcube.common
+ authorization-client
+ provided
+
+
+ org.gcube.common
+ common-authorization
+ provided
+
+
+ org.slf4j
+ slf4j-api
+ provided
+
+
+ junit
+ junit
+ 3.8.1
+ test
+
+
+
+ threadlocal-vars-cleaner-${project.version}
+
+
+ org.apache.maven.plugins
+ maven-war-plugin
+ 2.1.1
+
+
+ compile
+
+ exploded
+
+
+
+
+ ${webappDirectory}
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.3.2
+
+
+ 1.7
+
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+ 2.2
+
+
+ ${distroDirectory}/descriptor.xml
+
+
+
+
+ servicearchive
+ install
+
+ single
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 2.5
+
+
+ copy-profile
+ install
+
+ copy-resources
+
+
+ target
+
+
+ ${distroDirectory}
+ true
+
+ profile.xml
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/java/org/gcube/portal/threadlocalexec/SmartGearsPortalExecutor.java b/src/main/java/org/gcube/portal/threadlocalexec/SmartGearsPortalExecutor.java
new file mode 100644
index 0000000..6d63bf4
--- /dev/null
+++ b/src/main/java/org/gcube/portal/threadlocalexec/SmartGearsPortalExecutor.java
@@ -0,0 +1,54 @@
+package org.gcube.portal.threadlocalexec;
+
+import org.apache.catalina.core.StandardThreadExecutor;
+import org.gcube.common.authorization.library.provider.AuthorizationProvider;
+import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
+import org.gcube.common.scope.api.ScopeProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+/**
+ *
+ * @author Massimiliano Assante, CNR ISTI
+ *
+ */
+public class SmartGearsPortalExecutor extends StandardThreadExecutor {
+ private static final Logger _log = LoggerFactory.getLogger(SmartGearsPortalExecutor.class);
+ public SmartGearsPortalExecutor() {
+ }
+
+// @Override
+// public void execute(Runnable command, long timeout, TimeUnit unit) {
+// super.execute(new WrappedRunnable(command), timeout, unit);
+// }
+
+ @Override
+ public void execute(Runnable command) {
+ super.execute(new WrappedRunnable(command));
+ }
+
+ public static class WrappedRunnable implements Runnable{
+
+ private Runnable runnable;
+
+ protected WrappedRunnable(Runnable runnable){
+ this.runnable = runnable;
+ }
+
+ public void run() {
+ try{
+ this.runnable.run();
+ _log.debug("execution finished on thread "+Thread.currentThread().getName() + " server.RStudioServiceImpl LOGtoRemove");
+ System.out.println("execution finished on thread "+Thread.currentThread().getName()+ " server.RStudioServiceImpl LOGtoRemove");
+ } finally {
+ SecurityTokenProvider.instance.reset();
+ ScopeProvider.instance.reset();
+ AuthorizationProvider.instance.reset();
+ _log.debug("done reset all the thread locals on thread "+Thread.currentThread().getName()+ " server.RStudioServiceImpl LOGtoRemove");
+ System.out.println("done reset all the thread locals on thread "+Thread.currentThread().getName()+ " server.RStudioServiceImpl LOGtoRemove");
+ }
+ }
+
+ }
+
+}
+
diff --git a/src/test/java/org/gcube/portal/threadlocalexec/AppTest.java b/src/test/java/org/gcube/portal/threadlocalexec/AppTest.java
new file mode 100644
index 0000000..dc8c0d9
--- /dev/null
+++ b/src/test/java/org/gcube/portal/threadlocalexec/AppTest.java
@@ -0,0 +1,38 @@
+package org.gcube.portal.threadlocalexec;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest
+ extends TestCase
+{
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public AppTest( String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * @return the suite of tests being tested
+ */
+ public static Test suite()
+ {
+ return new TestSuite( AppTest.class );
+ }
+
+ /**
+ * Rigourous Test :-)
+ */
+ public void testApp()
+ {
+ assertTrue( true );
+ }
+}
diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties
new file mode 100644
index 0000000..b0eeb1b
--- /dev/null
+++ b/target/maven-archiver/pom.properties
@@ -0,0 +1,5 @@
+#Generated by Maven
+#Tue Apr 19 18:02:51 CEST 2016
+version=0.0.1-SNAPSHOT
+groupId=org.gcube.portal
+artifactId=threadlocal-vars-cleaner
diff --git a/target/profile.xml b/target/profile.xml
new file mode 100644
index 0000000..6396089
--- /dev/null
+++ b/target/profile.xml
@@ -0,0 +1,25 @@
+
+
+
+ Library
+
+ This component clean the Smartgears ThreadLocal variables each time a new Thread is assigned to a request from tomcat thread pool
+ Portal
+ threadlocal-vars-cleaner
+ 1.0.0
+
+
+ threadlocal-vars-cleaner
+ 0.0.1-SNAPSHOT
+
+ org.gcube.portal
+ threadlocal-vars-cleaner
+ 0.0.1-SNAPSHOT
+
+
+ threadlocal-vars-cleaner-0.0.1-SNAPSHOT.war
+
+
+
+
+
diff --git a/target/surefire-reports/TEST-org.gcube.portal.threadlocalexec.AppTest.xml b/target/surefire-reports/TEST-org.gcube.portal.threadlocalexec.AppTest.xml
new file mode 100644
index 0000000..c04c785
--- /dev/null
+++ b/target/surefire-reports/TEST-org.gcube.portal.threadlocalexec.AppTest.xml
@@ -0,0 +1,67 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/target/surefire-reports/org.gcube.portal.threadlocalexec.AppTest.txt b/target/surefire-reports/org.gcube.portal.threadlocalexec.AppTest.txt
new file mode 100644
index 0000000..ccb5e1e
--- /dev/null
+++ b/target/surefire-reports/org.gcube.portal.threadlocalexec.AppTest.txt
@@ -0,0 +1,4 @@
+-------------------------------------------------------------------------------
+Test set: org.gcube.portal.threadlocalexec.AppTest
+-------------------------------------------------------------------------------
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.004 sec
diff --git a/target/threadlocal-vars-cleaner-0.0.1-SNAPSHOT.jar b/target/threadlocal-vars-cleaner-0.0.1-SNAPSHOT.jar
new file mode 100644
index 0000000..9fc65bb
Binary files /dev/null and b/target/threadlocal-vars-cleaner-0.0.1-SNAPSHOT.jar differ
diff --git a/target/threadlocal-vars-cleaner-0.0.1-SNAPSHOT/WEB-INF/classes/org/gcube/portal/threadlocalexec/SmartGearsPortalExecutor$WrappedRunnable.class b/target/threadlocal-vars-cleaner-0.0.1-SNAPSHOT/WEB-INF/classes/org/gcube/portal/threadlocalexec/SmartGearsPortalExecutor$WrappedRunnable.class
new file mode 100644
index 0000000..a2a4e5b
Binary files /dev/null and b/target/threadlocal-vars-cleaner-0.0.1-SNAPSHOT/WEB-INF/classes/org/gcube/portal/threadlocalexec/SmartGearsPortalExecutor$WrappedRunnable.class differ
diff --git a/target/threadlocal-vars-cleaner-0.0.1-SNAPSHOT/WEB-INF/classes/org/gcube/portal/threadlocalexec/SmartGearsPortalExecutor.class b/target/threadlocal-vars-cleaner-0.0.1-SNAPSHOT/WEB-INF/classes/org/gcube/portal/threadlocalexec/SmartGearsPortalExecutor.class
new file mode 100644
index 0000000..315490c
Binary files /dev/null and b/target/threadlocal-vars-cleaner-0.0.1-SNAPSHOT/WEB-INF/classes/org/gcube/portal/threadlocalexec/SmartGearsPortalExecutor.class differ