2016-11-04 16:52:41 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.informationsystem.resourceregistry.client.proxy;
|
|
|
|
|
2016-11-09 16:30:15 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.util.Properties;
|
|
|
|
|
2016-11-04 16:52:41 +01:00
|
|
|
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.SecurityTokenProvider;
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
import org.junit.AfterClass;
|
|
|
|
import org.junit.BeforeClass;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class ScopedTest {
|
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ScopedTest.class);
|
|
|
|
|
2016-11-09 16:30:15 +01:00
|
|
|
protected static final String PROPERTIES_FILENAME = "config.properties";
|
|
|
|
|
|
|
|
private static final String TOKEN_VARNAME = "TOKEN";
|
|
|
|
private static final String TOKEN;
|
|
|
|
|
|
|
|
static {
|
|
|
|
Properties properties = new Properties();
|
|
|
|
InputStream input = ScopedTest.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME);
|
|
|
|
|
|
|
|
try {
|
|
|
|
// load the properties file
|
|
|
|
properties.load(input);
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
TOKEN = properties.getProperty(TOKEN_VARNAME);
|
|
|
|
}
|
2016-11-04 16:52:41 +01:00
|
|
|
|
|
|
|
private static String getCurrentScope() throws ObjectNotFound, Exception{
|
|
|
|
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(TOKEN);
|
|
|
|
String context = authorizationEntry.getContext();
|
|
|
|
logger.info("Context of token {} is {}", TOKEN, context);
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
public static void beforeClass() throws Exception{
|
|
|
|
SecurityTokenProvider.instance.set(TOKEN);
|
|
|
|
ScopeProvider.instance.set(getCurrentScope());
|
|
|
|
}
|
|
|
|
|
|
|
|
@AfterClass
|
|
|
|
public static void afterClass() throws Exception{
|
|
|
|
SecurityTokenProvider.instance.reset();
|
|
|
|
ScopeProvider.instance.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|