2021-09-21 17:45:18 +02:00
|
|
|
package org.gcube.application.cms.tests;
|
2021-09-20 18:11:51 +02:00
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2022-05-24 14:26:47 +02:00
|
|
|
import org.gcube.application.geoportal.common.utils.Files;
|
|
|
|
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
|
2021-09-20 18:11:51 +02:00
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
|
2022-05-24 14:26:47 +02:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.charset.Charset;
|
2021-09-20 18:11:51 +02:00
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
public class TokenSetter {
|
|
|
|
|
|
|
|
|
|
|
|
private static Properties props=new Properties();
|
|
|
|
|
|
|
|
static{
|
|
|
|
try {
|
|
|
|
props.load(TokenSetter.class.getResourceAsStream("/tokens.properties"));
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new RuntimeException("YOU NEED TO SET TOKEN FILE IN CONFIGURATION");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void set(String scope){
|
|
|
|
try{
|
|
|
|
if(!props.containsKey(scope)) throw new RuntimeException("No token found for scope : "+scope);
|
|
|
|
SecurityTokenProvider.instance.set(props.getProperty(scope));
|
|
|
|
}catch(Throwable e){
|
|
|
|
log.warn("Unable to set token for scope "+scope,e);
|
|
|
|
}
|
|
|
|
ScopeProvider.instance.set(scope);
|
|
|
|
}
|
2022-05-24 14:26:47 +02:00
|
|
|
|
|
|
|
public static void setUma() throws IOException {
|
|
|
|
File umaFile = new File("uma.json");
|
|
|
|
String uma= Files.readFileAsString(umaFile.getAbsolutePath(), Charset.defaultCharset());
|
|
|
|
AccessTokenProvider.instance.set(uma);
|
|
|
|
|
|
|
|
}
|
2021-09-20 18:11:51 +02:00
|
|
|
}
|