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-27 15:44:14 +02:00
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
2017-05-05 10:08:44 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2016-04-01 13:09:40 +02:00
|
|
|
|
|
|
|
public class TokenManager {
|
|
|
|
|
2017-05-05 10:08:44 +02:00
|
|
|
private static final Logger LOGGER= LoggerFactory.getLogger(TokenManager.class);
|
|
|
|
|
2016-04-01 13:09:40 +02:00
|
|
|
String username;
|
|
|
|
String scope;
|
2016-09-27 15:44:14 +02:00
|
|
|
String token;
|
2017-05-05 10:08:44 +02:00
|
|
|
|
2016-04-01 13:09:40 +02:00
|
|
|
public String getScope(){
|
|
|
|
return scope;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getUserName(){
|
|
|
|
return username;
|
|
|
|
}
|
2017-05-05 10:08:44 +02:00
|
|
|
|
2016-09-27 15:44:14 +02:00
|
|
|
public String getToken(){
|
|
|
|
return token;
|
|
|
|
}
|
2017-05-05 10:08:44 +02:00
|
|
|
|
2016-04-01 13:09:40 +02:00
|
|
|
public void getCredentials() {
|
|
|
|
try{
|
2017-05-05 10:08:44 +02:00
|
|
|
LOGGER.debug("Retrieving token credentials");
|
2016-04-01 13:09:40 +02:00
|
|
|
//get username from SmartGears
|
2017-05-05 10:08:44 +02:00
|
|
|
username = AuthorizationProvider.instance.get().getClient().getId();
|
2016-09-27 15:44:14 +02:00
|
|
|
token = SecurityTokenProvider.instance.get();
|
|
|
|
AuthorizationEntry entry = authorizationService().get(token);
|
|
|
|
scope = entry.getContext();
|
2017-05-05 10:08:44 +02:00
|
|
|
|
|
|
|
}catch(Exception e){
|
|
|
|
LOGGER.error("Error Retrieving token credentials ",e);
|
|
|
|
scope = null;
|
|
|
|
username= null;
|
|
|
|
|
|
|
|
}
|
|
|
|
if ((scope==null || username==null) && ConfigurationManager.isSimulationMode()){
|
|
|
|
scope = ConfigurationManager.defaultScope;
|
|
|
|
username = ConfigurationManager.defaultUsername;
|
|
|
|
}
|
|
|
|
LOGGER.debug("Retrieved scope: {} Username: {} Token {} SIMULATION MODE: {} ",scope, username, token, ConfigurationManager.isSimulationMode());
|
2016-04-01 13:09:40 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|