|
|
|
@ -5,18 +5,11 @@ import java.io.InputStream;
|
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
|
|
import org.gcube.common.authorization.client.Constants;
|
|
|
|
|
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
|
|
|
|
import org.gcube.common.authorization.library.AuthorizationEntry;
|
|
|
|
|
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.authorization.library.utils.Caller;
|
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
|
import org.gcube.common.authorization.utils.manager.SecretManager;
|
|
|
|
|
import org.gcube.common.authorization.utils.secret.GCubeSecret;
|
|
|
|
|
import org.gcube.common.authorization.utils.secret.Secret;
|
|
|
|
|
import org.junit.AfterClass;
|
|
|
|
|
import org.junit.BeforeClass;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
|
|
@ -24,8 +17,6 @@ import org.slf4j.LoggerFactory;
|
|
|
|
|
*/
|
|
|
|
|
public class ContextTest {
|
|
|
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ContextTest.class);
|
|
|
|
|
|
|
|
|
|
protected static Properties properties;
|
|
|
|
|
protected static final String PROPERTIES_FILENAME = "token.properties";
|
|
|
|
|
|
|
|
|
@ -76,36 +67,29 @@ public class ContextTest {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String getCurrentContextFullName() {
|
|
|
|
|
String token = SecurityTokenProvider.instance.get();
|
|
|
|
|
AuthorizationEntry authorizationEntry = null;
|
|
|
|
|
try {
|
|
|
|
|
authorizationEntry = Constants.authorizationService().get(token);
|
|
|
|
|
} catch(Exception e) {
|
|
|
|
|
return ScopeProvider.instance.get();
|
|
|
|
|
}
|
|
|
|
|
return authorizationEntry.getContext();
|
|
|
|
|
public static void set(Secret secret) throws Exception {
|
|
|
|
|
SecretManager.instance.get().reset();
|
|
|
|
|
secret.set();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String getContextFullName(String token) throws ObjectNotFound, Exception {
|
|
|
|
|
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
|
|
|
|
return authorizationEntry.getContext();
|
|
|
|
|
public static void setContext(String token) throws Exception {
|
|
|
|
|
Secret secret = getSecret(token);
|
|
|
|
|
set(secret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void setContextByName(String fullContextName) throws Exception {
|
|
|
|
|
Secret secret = getSecretByContextName(fullContextName);
|
|
|
|
|
set(secret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void setContextByName(String fullContextName) throws ObjectNotFound, Exception {
|
|
|
|
|
String token = ContextTest.properties.getProperty(fullContextName);
|
|
|
|
|
setContext(token);
|
|
|
|
|
private static Secret getSecret(String token) throws Exception {
|
|
|
|
|
GCubeSecret secret = new GCubeSecret(token);
|
|
|
|
|
return secret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void setContext(String token) throws ObjectNotFound, Exception {
|
|
|
|
|
SecurityTokenProvider.instance.set(token);
|
|
|
|
|
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
|
|
|
|
ClientInfo clientInfo = authorizationEntry.getClientInfo();
|
|
|
|
|
logger.debug("User : {} - Type : {}", clientInfo.getId(), clientInfo.getType().name());
|
|
|
|
|
String qualifier = authorizationEntry.getQualifier();
|
|
|
|
|
Caller caller = new Caller(clientInfo, qualifier);
|
|
|
|
|
AuthorizationProvider.instance.set(caller);
|
|
|
|
|
ScopeProvider.instance.set(getContextFullName(token));
|
|
|
|
|
private static Secret getSecretByContextName(String fullContextName) throws Exception {
|
|
|
|
|
String token = ContextTest.properties.getProperty(fullContextName);
|
|
|
|
|
return getSecret(token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
@ -115,8 +99,7 @@ public class ContextTest {
|
|
|
|
|
|
|
|
|
|
@AfterClass
|
|
|
|
|
public static void afterClass() throws Exception {
|
|
|
|
|
SecurityTokenProvider.instance.reset();
|
|
|
|
|
ScopeProvider.instance.reset();
|
|
|
|
|
SecretManager.instance.get().reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|