40 lines
1.3 KiB
Java
40 lines
1.3 KiB
Java
package org.gcube.application.geoportal.service.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);
|
|
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);
|
|
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";
|
|
}
|
|
}
|
|
}
|