You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gcube-cms-suite/geoportal-common/src/main/java/org/gcube/application/geoportal/common/utils/ContextUtils.java

42 lines
1.4 KiB
Java

package org.gcube.application.geoportal.common.utils;
import static org.gcube.common.authorization.client.Constants.authorizationService;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class ContextUtils {
public static String getCurrentScope(){
try{
String token=SecurityTokenProvider.instance.get();
log.debug("Token is : "+token.substring(0,2)+"..."+token.substring(token.length()-3));
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();
}
}
public static String getCurrentCaller(){
try{
String token=SecurityTokenProvider.instance.get();
log.debug("Token is : "+token.substring(0,2)+"..."+token.substring(token.length()-3));
if(token==null) throw new Exception("Security Token is null");
AuthorizationEntry entry = authorizationService().get(token);
return entry.getClientInfo().getId();
}catch(Exception e ){
log.debug("Unable to resolve token, checking scope provider..",e);
return "Unidentified data-transfer user";
}
}
}