2016-04-01 13:09:40 +02:00
|
|
|
package org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mapping;
|
|
|
|
|
2016-09-27 15:44:14 +02:00
|
|
|
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
|
|
|
|
|
|
|
import org.gcube.common.authorization.library.AuthorizationEntry;
|
2016-04-01 13:09:40 +02:00
|
|
|
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
2016-09-08 16:42:26 +02:00
|
|
|
import org.gcube.common.authorization.library.provider.ClientInfo;
|
2016-09-27 15:44:14 +02:00
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
2016-04-01 13:09:40 +02:00
|
|
|
import org.gcube.common.authorization.library.provider.UserInfo;
|
|
|
|
|
|
|
|
public class TokenManager {
|
|
|
|
|
|
|
|
String username;
|
|
|
|
String scope;
|
2016-09-27 15:44:14 +02:00
|
|
|
String token;
|
2016-04-01 13:09:40 +02:00
|
|
|
|
|
|
|
public String getScope(){
|
|
|
|
return scope;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getUserName(){
|
|
|
|
return username;
|
|
|
|
}
|
|
|
|
|
2016-09-27 15:44:14 +02:00
|
|
|
public String getToken(){
|
|
|
|
return token;
|
|
|
|
}
|
|
|
|
|
2016-04-01 13:09:40 +02:00
|
|
|
public void getCredentials() {
|
|
|
|
try{
|
|
|
|
System.out.println("Retrieving token credentials");
|
2016-09-27 15:44:14 +02:00
|
|
|
//scope = ScopeProvider.instance.get();
|
2016-04-01 13:09:40 +02:00
|
|
|
System.out.println("Credentials from the GHN: scope: "+scope);
|
|
|
|
//get username from SmartGears
|
2016-09-27 15:44:14 +02:00
|
|
|
ClientInfo tokenInfo = (UserInfo) AuthorizationProvider.instance.get().getClient();
|
|
|
|
username = tokenInfo.getId();
|
|
|
|
token = SecurityTokenProvider.instance.get();
|
|
|
|
AuthorizationEntry entry = authorizationService().get(token);
|
|
|
|
scope = entry.getContext();
|
|
|
|
|
|
|
|
System.out.println("Credentials from the GHN: user: "+username+" , "+scope+" , "+token);
|
2016-04-01 13:09:40 +02:00
|
|
|
}catch(Exception e){
|
|
|
|
e.printStackTrace();
|
|
|
|
System.out.println("Error Retrieving token credentials: "+e.getLocalizedMessage());
|
|
|
|
scope = null;
|
|
|
|
username= null;
|
2016-09-27 15:44:14 +02:00
|
|
|
|
2016-04-01 13:09:40 +02:00
|
|
|
}
|
|
|
|
if ((scope==null || username==null) && ConfigurationManager.isSimulationMode()){
|
|
|
|
scope = ConfigurationManager.defaultScope;
|
|
|
|
username = ConfigurationManager.defaultUsername;
|
|
|
|
}
|
2016-09-27 15:44:14 +02:00
|
|
|
System.out.println("Retrieved scope: "+scope+" Username: "+username +" Token "+token+" SIMULATION MODE: "+ConfigurationManager.isSimulationMode());
|
2016-04-01 13:09:40 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|