From a5ce8330d674242cb4dae73194871a7b7a608734 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 7 Mar 2022 14:16:51 +0100 Subject: [PATCH] Migrating to new SecretManagerProvider --- .../resourceregistry/contexts/ContextUtility.java | 14 ++------------ .../resourceregistry/utils/HeaderUtility.java | 15 ++------------- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ContextUtility.java b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ContextUtility.java index 8d7b12b..8d00939 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ContextUtility.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ContextUtility.java @@ -5,10 +5,7 @@ import java.util.Map; import java.util.NoSuchElementException; import java.util.UUID; -import org.gcube.common.authorization.client.Constants; -import org.gcube.common.authorization.library.AuthorizationEntry; -import org.gcube.common.authorization.library.provider.SecurityTokenProvider; -import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.common.authorization.utils.manager.SecretManagerProvider; import org.gcube.common.scope.impl.ScopeBean; import org.gcube.informationsystem.base.reference.IdentifiableElement; import org.gcube.informationsystem.contexts.reference.entities.Context; @@ -84,14 +81,7 @@ public class ContextUtility { } public static String getCurrentContextFullName() { - String token = SecurityTokenProvider.instance.get(); - AuthorizationEntry authorizationEntry = null; - try { - authorizationEntry = Constants.authorizationService().get(token); - } catch(Exception e) { - return ScopeProvider.instance.get(); - } - return authorizationEntry.getContext(); + return SecretManagerProvider.instance.get().getContext(); } public static SecurityContext getCurrentSecurityContext() throws ResourceRegistryException { diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/utils/HeaderUtility.java b/src/main/java/org/gcube/informationsystem/resourceregistry/utils/HeaderUtility.java index e57a052..fc79118 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/utils/HeaderUtility.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/utils/HeaderUtility.java @@ -9,9 +9,7 @@ import java.util.UUID; import org.gcube.com.fasterxml.jackson.core.JsonParseException; import org.gcube.com.fasterxml.jackson.databind.JsonMappingException; import org.gcube.com.fasterxml.jackson.databind.JsonNode; -import org.gcube.common.authorization.library.provider.AuthorizationProvider; -import org.gcube.common.authorization.library.provider.ClientInfo; -import org.gcube.common.authorization.library.utils.Caller; +import org.gcube.common.authorization.utils.manager.SecretManagerProvider; import org.gcube.informationsystem.base.reference.IdentifiableElement; import org.gcube.informationsystem.model.reference.properties.Header; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; @@ -33,16 +31,7 @@ public class HeaderUtility { public static String getUser() { String user = Header.UNKNOWN_USER; try { - Caller caller = AuthorizationProvider.instance.get(); - if(caller != null) { - ClientInfo clientInfo = caller.getClient(); - String clientId = clientInfo.getId(); - if(clientId != null && clientId.compareTo("") != 0) { - user = clientId; - } else { - throw new Exception("Username null or empty"); - } - } + user = SecretManagerProvider.instance.get().getUser().getUsername(); } catch(Exception e) { logger.error("Unable to retrieve user. {} will be used", user); }