data-transfer-library/src/main/java/org/gcube/data/transfer/library/utils/ScopeUtils.java

37 lines
994 B
Java
Raw Normal View History

package org.gcube.data.transfer.library.utils;
2021-05-10 15:18:14 +02:00
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
2021-05-11 16:48:24 +02:00
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
2021-05-11 16:48:24 +02:00
import static org.gcube.common.authorization.client.Constants.authorizationService;
2021-05-11 16:48:24 +02:00
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class ScopeUtils {
public static String getCurrentScope(){
2021-05-10 15:18:14 +02:00
return ScopeProvider.instance.get();
}
public static String getCurrentCaller(){
2021-05-11 16:48:24 +02:00
try{
return AuthorizationProvider.instance.get().getClient().getId();
}catch(Throwable e ){
try {
log.warn("Unable to get Client ID from UMA , checking gcube-token.. ",e);
String token=SecurityTokenProvider.instance.get();
return authorizationService().get(token).getClientInfo().getId();
}catch(Throwable e1 ){
log.warn("Unable to resolve gcube-token ",e1);
return "Unidentified data-transfer user";
}
}
}
}