Removed code not needed if the library is integrated in Smartgears

This commit is contained in:
Luca Frosini 2022-02-25 11:37:19 +01:00
parent 6731b8f6a6
commit a66c1da525
3 changed files with 15 additions and 38 deletions

View File

@ -2,7 +2,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
# Changelog for Authorization utils # Changelog for Authorization utils
## [v1.0.1-SNAPSHOT] ## [v2.0.0-SNAPSHOT]
- Fixed getRoles for JWTSecret [#22754] - Fixed getRoles for JWTSecret [#22754]
- -

View File

@ -10,7 +10,7 @@
<groupId>org.gcube.common</groupId> <groupId>org.gcube.common</groupId>
<artifactId>authorization-utils</artifactId> <artifactId>authorization-utils</artifactId>
<version>1.0.1-SNAPSHOT</version> <version>2.0.0-SNAPSHOT</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -1,12 +1,7 @@
package org.gcube.common.authorization.utils.manager; package org.gcube.common.authorization.utils.manager;
import java.util.ArrayList;
import java.util.List;
import java.util.SortedSet; import java.util.SortedSet;
import org.gcube.common.authorization.utils.provider.GCubeSecretProvider;
import org.gcube.common.authorization.utils.provider.JWTSecretProvider;
import org.gcube.common.authorization.utils.provider.SecretProvider;
import org.gcube.common.authorization.utils.secret.Secret; import org.gcube.common.authorization.utils.secret.Secret;
import org.gcube.common.authorization.utils.user.User; import org.gcube.common.authorization.utils.user.User;
@ -23,43 +18,19 @@ public class SecretManager {
} }
}; };
private List<SecretProvider> secretProviders;
private SecretHolder initialSecretHolder; private SecretHolder initialSecretHolder;
private SecretHolder currentSecretHolder; private SecretHolder currentSecretHolder;
private SecretManager(){ private SecretManager(){
initialSecretHolder = new SecretHolder(); initialSecretHolder = new SecretHolder();
currentSecretHolder = initialSecretHolder; currentSecretHolder = initialSecretHolder;
initSecretProviders();
} }
protected void initSecretProviders() { public synchronized void addSecret(Secret secret) throws Exception {
secretProviders = new ArrayList<>(); if(currentSecretHolder!=initialSecretHolder) {
throw new Exception("You can't add a Secret in a session. You must terminate the session first.");
@SuppressWarnings("unchecked")
Class<SecretProvider>[] classes = new Class[]{
JWTSecretProvider.class, GCubeSecretProvider.class
};
for(Class<SecretProvider> clz : classes) {
try {
SecretProvider authorizationSecretProvider = clz.newInstance();
addSecretProvider(authorizationSecretProvider);
} catch (Exception e) {
}
} }
}
public List<SecretProvider> getSecretProviders(){
return secretProviders;
}
public void addSecretProvider(SecretProvider secretProvider) {
secretProviders.add(secretProvider);
Secret secret = secretProvider.getSecret();
initialSecretHolder.addSecret(secret); initialSecretHolder.addSecret(secret);
} }
@ -67,23 +38,29 @@ public class SecretManager {
if(currentSecretHolder!=initialSecretHolder) { if(currentSecretHolder!=initialSecretHolder) {
throw new Exception("You are already in a session. You must terminate the session first."); throw new Exception("You are already in a session. You must terminate the session first.");
} }
initialSecretHolder.reset();
currentSecretHolder = new SecretHolder(secret); currentSecretHolder = new SecretHolder(secret);
currentSecretHolder.set(); currentSecretHolder.set();
} }
public synchronized void startSession(SortedSet<Secret> secrets) throws Exception { public synchronized void startSession(SortedSet<Secret> secrets) throws Exception {
if(currentSecretHolder!=initialSecretHolder) {
throw new Exception("You are already in a session. You must terminate the session first.");
}
initialSecretHolder.reset();
currentSecretHolder = new SecretHolder(secrets); currentSecretHolder = new SecretHolder(secrets);
currentSecretHolder.set(); currentSecretHolder.set();
} }
public synchronized void endSession() throws Exception { public synchronized void endSession() throws Exception {
if(currentSecretHolder!=initialSecretHolder) { if(currentSecretHolder!=initialSecretHolder) {
currentSecretHolder.reset();
initialSecretHolder.set(); initialSecretHolder.set();
currentSecretHolder = initialSecretHolder; currentSecretHolder = initialSecretHolder;
} }
} }
public void reset() { public synchronized void reset() {
initialSecretHolder.reset(); initialSecretHolder.reset();
if(initialSecretHolder!=currentSecretHolder) { if(initialSecretHolder!=currentSecretHolder) {
currentSecretHolder.reset(); currentSecretHolder.reset();
@ -91,11 +68,11 @@ public class SecretManager {
instance.remove(); instance.remove();
} }
public String getContext() { public synchronized String getContext() {
return currentSecretHolder.getContext(); return currentSecretHolder.getContext();
} }
public User getUser() { public synchronized User getUser() {
return currentSecretHolder.getUser(); return currentSecretHolder.getUser();
} }