Fixes #22280
parent
0f9a7329c0
commit
b6d719e431
@ -1,38 +0,0 @@
|
||||
package org.gcube.application.geoportal.service.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
|
||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||
|
||||
@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";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package org.gcube.application.geoportal.service.utils;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
|
||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||
import org.gcube.common.authorization.library.provider.ClientInfo;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
|
||||
@Slf4j
|
||||
public class UserUtils {
|
||||
|
||||
public static User getCurrent() throws SecurityException {
|
||||
String context=ScopeProvider.instance.get();
|
||||
if(context==null) throw new SecurityException("Cannot determine context");
|
||||
|
||||
log.debug("Context is {}, checking tokens..",context);
|
||||
|
||||
ClientInfo client = null;
|
||||
try{
|
||||
AuthorizationProvider.instance.get().getClient();
|
||||
}catch(Throwable e) {
|
||||
log.warn("Unable to get client info ",e);
|
||||
}
|
||||
User toReturn = new User(client, AccessTokenProvider.instance.get(),SecurityTokenProvider.instance.get(),context);
|
||||
|
||||
log.info("Current User is {} ",toReturn);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public static class User {
|
||||
private ClientInfo user;
|
||||
private String uma_token;
|
||||
|
||||
private String gcube_token;
|
||||
|
||||
private String context;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("User [user=");
|
||||
builder.append(user);
|
||||
builder.append(", uma_token=");
|
||||
builder.append(uma_token==null?uma_token:"***");
|
||||
|
||||
builder.append(", gcube_token=");
|
||||
builder.append(gcube_token==null?gcube_token:"***");
|
||||
|
||||
builder.append(", context=");
|
||||
builder.append(context);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue