Fixing property reading

This commit is contained in:
luca.frosini 2023-06-26 10:43:41 +02:00
parent ce8f089de8
commit c29377bc6d
2 changed files with 24 additions and 3 deletions

View File

@ -1,6 +1,7 @@
package org.gcube.gcat.utils;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;
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.keycloak.KeycloakClientFactory;
import org.gcube.common.keycloak.model.TokenResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class Constants {
private static final Logger logger = LoggerFactory.getLogger(Constants.class);
public static final String CATALOGUE_NAME = "gCat";
private static final String CLIENT_SECRET_FILENAME = "config.properties";
private static final String CLIENT_ID = "gcat";
protected static final String CLIENT_SECRET_FILENAME = "config.properties";
protected static final String CLIENT_ID = "gcat";
protected static String clientSecret;
private static String getClientSecret(String context) {
try {
if(clientSecret==null) {
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);
int index = context.indexOf('/', 1);
String root = context.substring(0, index == -1 ? context.length() : index);

View File

@ -1,5 +1,7 @@
package org.gcube.gcat.utils;
import java.net.URL;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
import org.gcube.common.authorization.utils.secret.Secret;
import org.gcube.common.encryption.encrypter.StringEncrypter;
@ -34,4 +36,16 @@ public class ConstantsTest extends ContextTest {
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);
}
}