58 lines
1.7 KiB
Java
58 lines
1.7 KiB
Java
package org.gcube.usecases.ws.thredds.engine.impl;
|
||
|
||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||
|
||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||
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 Security {
|
||
|
||
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 getContext(String token) {
|
||
try{
|
||
log.debug("Resolving token {} ",token);
|
||
AuthorizationEntry entry = authorizationService().get(token);
|
||
return entry.getContext();
|
||
}catch(Exception e) {
|
||
log.warn("Unable to resolve "+token,e);
|
||
return null;
|
||
}
|
||
}
|
||
|
||
public static String getToken() {
|
||
return SecurityTokenProvider.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";
|
||
}
|
||
}
|
||
}
|