diff --git a/src/main/java/org/gcube/spatial/data/geonetwork/utils/ScopeUtils.java b/src/main/java/org/gcube/spatial/data/geonetwork/utils/ScopeUtils.java index 87904f3..b365958 100644 --- a/src/main/java/org/gcube/spatial/data/geonetwork/utils/ScopeUtils.java +++ b/src/main/java/org/gcube/spatial/data/geonetwork/utils/ScopeUtils.java @@ -15,16 +15,35 @@ import lombok.extern.slf4j.Slf4j; public class ScopeUtils { public static String getCurrentScope(){ - try{ - String token=SecurityTokenProvider.instance.get(); - log.debug("Token is : "+token); - if(token==null) throw new Exception("Security Token is null"); - AuthorizationEntry entry = authorizationService().get(token); - return entry.getContext(); - }catch(Exception e ){ - log.debug("Unable to resolve token, checking scope provider..",e); - return ScopeProvider.instance.get(); + // try{ + // String token=SecurityTokenProvider.instance.get(); + // log.debug("Token is : "+token); + // if(token==null) throw new Exception("Security Token is null"); + // AuthorizationEntry entry = authorizationService().get(token); + // return entry.getContext(); + // }catch(Exception e ){ + // log.debug("Unable to resolve token, checking scope provider..",e); + // return ScopeProvider.instance.get(); + // } + + String scope=ScopeProvider.instance.get(); + if(scope!=null) { + log.debug("Found scope provider {}, skipping token",scope); + return scope; + }else{ + try{ + log.debug("Scope provider not set, reverting to token"); + String token=SecurityTokenProvider.instance.get(); + log.debug("Token is : "+token); + if(token==null) throw new Exception("Security Token is null"); + AuthorizationEntry entry = authorizationService().get(token); + return entry.getContext(); + }catch(Exception e){ + throw new RuntimeException("Unable to evaluate scope ",e); + } } + + } public static String getCurrentScopeName(){ diff --git a/src/test/java/org/gcube/spatial/data/geonetwork/test/ScopeTests.java b/src/test/java/org/gcube/spatial/data/geonetwork/test/ScopeTests.java index 65881d4..15fb20d 100644 --- a/src/test/java/org/gcube/spatial/data/geonetwork/test/ScopeTests.java +++ b/src/test/java/org/gcube/spatial/data/geonetwork/test/ScopeTests.java @@ -1,6 +1,5 @@ package org.gcube.spatial.data.geonetwork.test; -import org.gcube.common.scope.api.ScopeProvider; import org.gcube.spatial.data.geonetwork.GeoNetwork; import org.gcube.spatial.data.geonetwork.GeoNetworkAdministration; import org.gcube.spatial.data.geonetwork.GeoNetworkReader;