Fixing property reading
This commit is contained in:
parent
ce8f089de8
commit
c29377bc6d
|
@ -1,6 +1,7 @@
|
||||||
package org.gcube.gcat.utils;
|
package org.gcube.gcat.utils;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import javax.ws.rs.InternalServerErrorException;
|
import javax.ws.rs.InternalServerErrorException;
|
||||||
|
@ -10,23 +11,29 @@ import org.gcube.common.authorization.utils.secret.JWTSecret;
|
||||||
import org.gcube.common.authorization.utils.secret.Secret;
|
import org.gcube.common.authorization.utils.secret.Secret;
|
||||||
import org.gcube.common.keycloak.KeycloakClientFactory;
|
import org.gcube.common.keycloak.KeycloakClientFactory;
|
||||||
import org.gcube.common.keycloak.model.TokenResponse;
|
import org.gcube.common.keycloak.model.TokenResponse;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
public class Constants {
|
public class Constants {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(Constants.class);
|
||||||
|
|
||||||
public static final String CATALOGUE_NAME = "gCat";
|
public static final String CATALOGUE_NAME = "gCat";
|
||||||
|
|
||||||
private static final String CLIENT_SECRET_FILENAME = "config.properties";
|
protected static final String CLIENT_SECRET_FILENAME = "config.properties";
|
||||||
private static final String CLIENT_ID = "gcat";
|
protected static final String CLIENT_ID = "gcat";
|
||||||
protected static String clientSecret;
|
protected static String clientSecret;
|
||||||
|
|
||||||
private static String getClientSecret(String context) {
|
private static String getClientSecret(String context) {
|
||||||
try {
|
try {
|
||||||
if(clientSecret==null) {
|
if(clientSecret==null) {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
InputStream input = Constants.class.getClassLoader().getResourceAsStream(CLIENT_SECRET_FILENAME);
|
URL url = ClassLoader.getSystemClassLoader().getResource(CLIENT_SECRET_FILENAME);
|
||||||
|
logger.trace("Going to read {} at {}", CLIENT_SECRET_FILENAME, url.toString());
|
||||||
|
InputStream input = ClassLoader.getSystemClassLoader().getResourceAsStream(CLIENT_SECRET_FILENAME);
|
||||||
properties.load(input);
|
properties.load(input);
|
||||||
int index = context.indexOf('/', 1);
|
int index = context.indexOf('/', 1);
|
||||||
String root = context.substring(0, index == -1 ? context.length() : index);
|
String root = context.substring(0, index == -1 ? context.length() : index);
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.gcube.gcat.utils;
|
package org.gcube.gcat.utils;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
||||||
import org.gcube.common.authorization.utils.secret.Secret;
|
import org.gcube.common.authorization.utils.secret.Secret;
|
||||||
import org.gcube.common.encryption.encrypter.StringEncrypter;
|
import org.gcube.common.encryption.encrypter.StringEncrypter;
|
||||||
|
@ -34,4 +36,16 @@ public class ConstantsTest extends ContextTest {
|
||||||
logger.debug(secret.getToken());
|
logger.debug(secret.getToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getResourceTest() {
|
||||||
|
URL url1 = ConstantsTest.class.getResource(Constants.CLIENT_SECRET_FILENAME);
|
||||||
|
logger.debug("{}", url1);
|
||||||
|
URL url2 = ConstantsTest.class.getClassLoader().getResource(Constants.CLIENT_SECRET_FILENAME);
|
||||||
|
logger.debug("{}", url2);
|
||||||
|
URL url3 = ClassLoader.getSystemClassLoader().getResource(Constants.CLIENT_SECRET_FILENAME);
|
||||||
|
logger.debug("{}", url3);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue