removed unuseful instance from SecurityManageProvider

This commit is contained in:
lucio 2024-02-21 20:24:06 +01:00
parent 49af45c140
commit 86bbb19471
5 changed files with 36 additions and 50 deletions

View File

@ -6,11 +6,6 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> <classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
@ -18,13 +13,7 @@
<attribute name="test" value="true"/> <attribute name="test" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>

View File

@ -1,8 +1,8 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8 org.eclipse.jdt.core.compiler.source=11

33
pom.xml
View File

@ -2,34 +2,35 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.common</groupId>
<artifactId>common-security</artifactId>
<version>1.0.0</version>
<name>gcube security</name>
<scm>
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/common-security</connection>
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/common-security</developerConnection>
<url>https://code-repo.d4science.org/gCubeSystem/common-security</url>
</scm>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<parent> <parent>
<artifactId>maven-parent</artifactId> <artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId> <groupId>org.gcube.tools</groupId>
<version>1.2.0</version> <version>1.2.0</version>
</parent> </parent>
<groupId>org.gcube.common</groupId>
<artifactId>common-security</artifactId>
<version>1.0.0</version>
<name>gcube security</name>
<scm>
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/common-security</connection>
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/common-security</developerConnection>
<url>https://code-repo.d4science.org/gCubeSystem/common-security</url>
</scm>
<properties>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
</properties>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.gcube.distribution</groupId> <groupId>org.gcube.distribution</groupId>
<artifactId>gcube-bom</artifactId> <artifactId>gcube-bom</artifactId>
<version>3.0.0</version> <version>3.0.1-SNAPSHOT</version>
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>

View File

@ -20,20 +20,20 @@ public class AuthorizedTasks {
static public <V> Callable<V> bind(final Callable<V> task) { static public <V> Callable<V> bind(final Callable<V> task) {
final Secret secret = SecretManagerProvider.instance.get(); final Secret secret = SecretManagerProvider.get();
return new Callable<V>() { return new Callable<V>() {
@Override @Override
public V call() throws Exception { public V call() throws Exception {
SecretManagerProvider.instance.set(secret); SecretManagerProvider.set(secret);
try { try {
logger.info("setting on authorized task context {} ", secret.getContext()); logger.info("setting on authorized task context {} ", secret.getContext());
return task.call(); return task.call();
} }
finally { finally {
SecretManagerProvider.instance.reset(); SecretManagerProvider.reset();
} }
} }
@ -48,20 +48,20 @@ public class AuthorizedTasks {
static public <V> Runnable bind(final Runnable task) { static public <V> Runnable bind(final Runnable task) {
final Secret secret = SecretManagerProvider.instance.get(); final Secret secret = SecretManagerProvider.get();
return new Runnable() { return new Runnable() {
@Override @Override
public void run() { public void run() {
SecretManagerProvider.instance.set(secret); SecretManagerProvider.set(secret);
try { try {
logger.info("setting on authorized task context {} ", secret.getContext()); logger.info("setting on authorized task context {} ", secret.getContext());
task.run(); task.run();
} }
finally { finally {
SecretManagerProvider.instance.reset(); SecretManagerProvider.reset();
} }
} }
@ -75,12 +75,12 @@ public class AuthorizedTasks {
* @return an equivalent {@link Runnable} task bound to the current scope and user * @return an equivalent {@link Runnable} task bound to the current scope and user
*/ */
static public void executeSafely(final Runnable task, final Secret secret){ static public void executeSafely(final Runnable task, final Secret secret){
Secret previousSecret = SecretManagerProvider.instance.get(); Secret previousSecret = SecretManagerProvider.get();
try { try {
SecretManagerProvider.instance.set(secret); SecretManagerProvider.set(secret);
task.run(); task.run();
} finally { } finally {
SecretManagerProvider.instance.set(previousSecret); SecretManagerProvider.set(previousSecret);
} }
} }
@ -92,12 +92,12 @@ public class AuthorizedTasks {
* @return an equivalent {@link Runnable} task bound to the current scope and user * @return an equivalent {@link Runnable} task bound to the current scope and user
*/ */
static public <T> T executeSafely(final Callable<T> task, final Secret secret) throws Throwable { static public <T> T executeSafely(final Callable<T> task, final Secret secret) throws Throwable {
Secret previousSecret = SecretManagerProvider.instance.get(); Secret previousSecret = SecretManagerProvider.get();
try { try {
SecretManagerProvider.instance.set(secret); SecretManagerProvider.set(secret);
return task.call(); return task.call();
} finally { } finally {
SecretManagerProvider.instance.set(previousSecret); SecretManagerProvider.set(previousSecret);
} }
} }

View File

@ -7,8 +7,6 @@ import org.gcube.common.security.secrets.Secret;
*/ */
public class SecretManagerProvider { public class SecretManagerProvider {
public static SecretManagerProvider instance = new SecretManagerProvider();
// Thread local variable containing each thread's ID // Thread local variable containing each thread's ID
private static final InheritableThreadLocal<Secret> thread = new InheritableThreadLocal<Secret>() { private static final InheritableThreadLocal<Secret> thread = new InheritableThreadLocal<Secret>() {
@ -18,19 +16,17 @@ public class SecretManagerProvider {
} }
}; };
private SecretManagerProvider(){}
public Secret get(){ public static Secret get(){
Secret secret = thread.get(); Secret secret = thread.get();
return secret; return secret;
} }
public void set(Secret secret){ public static void set(Secret secret){
thread.set(secret); thread.set(secret);
} }
public void reset(){ public static void reset(){
thread.remove(); thread.remove();
} }