gcube-cms-suite/geoportal-common/src/main/java/org/gcube/application/geoportal/common/utils/ContextUtils.java

28 lines
925 B
Java
Raw Normal View History

2021-09-20 16:47:35 +02:00
package org.gcube.application.geoportal.common.utils;
2022-09-26 16:17:37 +02:00
import lombok.extern.slf4j.Slf4j;
2021-09-20 16:47:35 +02:00
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
2022-09-26 16:17:37 +02:00
import static org.gcube.common.authorization.client.Constants.authorizationService;
2021-09-20 16:47:35 +02:00
@Slf4j
2023-01-10 15:57:40 +01:00
@Deprecated
2021-09-20 16:47:35 +02:00
public class ContextUtils {
public static String getCurrentCaller(){
try{
String token=SecurityTokenProvider.instance.get();
if(token==null) throw new Exception("Security Token is null");
2023-01-10 15:57:40 +01:00
log.trace("Token is : "+token.substring(0,2)+"..."+token.substring(token.length()-3));
2021-09-20 16:47:35 +02:00
AuthorizationEntry entry = authorizationService().get(token);
return entry.getClientInfo().getId();
}catch(Exception e ){
2023-01-10 15:57:40 +01:00
log.warn("Unable to resolve token using legacy utils, using default ..",e);
return "CMS_default_user";
2021-09-20 16:47:35 +02:00
}
}
}