removed unuseful instance from SecurityManageProvider
This commit is contained in:
parent
49af45c140
commit
86bbb19471
13
.classpath
13
.classpath
|
@ -6,11 +6,6 @@
|
|||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</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">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
|
@ -18,13 +13,7 @@
|
|||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<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">
|
||||
<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"/>
|
||||
</attributes>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
|
||||
org.eclipse.jdt.core.compiler.compliance=11
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
||||
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
33
pom.xml
|
@ -2,34 +2,35 @@
|
|||
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">
|
||||
<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>
|
||||
<artifactId>maven-parent</artifactId>
|
||||
<groupId>org.gcube.tools</groupId>
|
||||
<version>1.2.0</version>
|
||||
</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>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-bom</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.0.1-SNAPSHOT</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
|
|
@ -20,20 +20,20 @@ public class AuthorizedTasks {
|
|||
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>() {
|
||||
@Override
|
||||
public V call() throws Exception {
|
||||
|
||||
SecretManagerProvider.instance.set(secret);
|
||||
SecretManagerProvider.set(secret);
|
||||
|
||||
try {
|
||||
logger.info("setting on authorized task context {} ", secret.getContext());
|
||||
return task.call();
|
||||
}
|
||||
finally {
|
||||
SecretManagerProvider.instance.reset();
|
||||
SecretManagerProvider.reset();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -48,20 +48,20 @@ public class AuthorizedTasks {
|
|||
static public <V> Runnable bind(final Runnable task) {
|
||||
|
||||
|
||||
final Secret secret = SecretManagerProvider.instance.get();
|
||||
final Secret secret = SecretManagerProvider.get();
|
||||
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
SecretManagerProvider.instance.set(secret);
|
||||
SecretManagerProvider.set(secret);
|
||||
|
||||
try {
|
||||
logger.info("setting on authorized task context {} ", secret.getContext());
|
||||
task.run();
|
||||
}
|
||||
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
|
||||
*/
|
||||
static public void executeSafely(final Runnable task, final Secret secret){
|
||||
Secret previousSecret = SecretManagerProvider.instance.get();
|
||||
Secret previousSecret = SecretManagerProvider.get();
|
||||
try {
|
||||
SecretManagerProvider.instance.set(secret);
|
||||
SecretManagerProvider.set(secret);
|
||||
task.run();
|
||||
} 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
|
||||
*/
|
||||
static public <T> T executeSafely(final Callable<T> task, final Secret secret) throws Throwable {
|
||||
Secret previousSecret = SecretManagerProvider.instance.get();
|
||||
Secret previousSecret = SecretManagerProvider.get();
|
||||
try {
|
||||
SecretManagerProvider.instance.set(secret);
|
||||
SecretManagerProvider.set(secret);
|
||||
return task.call();
|
||||
} finally {
|
||||
SecretManagerProvider.instance.set(previousSecret);
|
||||
SecretManagerProvider.set(previousSecret);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,6 @@ import org.gcube.common.security.secrets.Secret;
|
|||
*/
|
||||
public class SecretManagerProvider {
|
||||
|
||||
public static SecretManagerProvider instance = new SecretManagerProvider();
|
||||
|
||||
// Thread local variable containing each thread's ID
|
||||
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();
|
||||
return secret;
|
||||
}
|
||||
|
||||
public void set(Secret secret){
|
||||
public static void set(Secret secret){
|
||||
thread.set(secret);
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
public static void reset(){
|
||||
thread.remove();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue