added possibility to get Configuration folder outside tomcat
This commit is contained in:
parent
82c155e3a4
commit
1fbd524fc4
2
pom.xml
2
pom.xml
|
@ -37,13 +37,13 @@
|
||||||
<url>https://code-repo.d4science.org/gCubeSystem/common-smartgears</url>
|
<url>https://code-repo.d4science.org/gCubeSystem/common-smartgears</url>
|
||||||
</scm>
|
</scm>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
|
|
||||||
<!--
|
<!--
|
||||||
https://mvnrepository.com/artifact/jakarta.servlet/jakarta.servlet-api -->
|
https://mvnrepository.com/artifact/jakarta.servlet/jakarta.servlet-api -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>jakarta.servlet</groupId>
|
<groupId>jakarta.servlet</groupId>
|
||||||
<artifactId>jakarta.servlet-api</artifactId>
|
<artifactId>jakarta.servlet-api</artifactId>
|
||||||
<version>6.0.0</version>
|
<version>6.0.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.reflections</groupId>
|
<groupId>org.reflections</groupId>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.gcube.smartgears.context.application;
|
package org.gcube.smartgears.context.application;
|
||||||
|
|
||||||
import jakarta.servlet.ServletContext;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
import org.gcube.common.events.Hub;
|
import org.gcube.common.events.Hub;
|
||||||
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
|
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
|
||||||
|
@ -10,6 +10,8 @@ import org.gcube.smartgears.lifecycle.application.ApplicationLifecycle;
|
||||||
import org.gcube.smartgears.persistence.PersistenceWriter;
|
import org.gcube.smartgears.persistence.PersistenceWriter;
|
||||||
import org.gcube.smartgears.security.AuthorizationProvider;
|
import org.gcube.smartgears.security.AuthorizationProvider;
|
||||||
|
|
||||||
|
import jakarta.servlet.ServletContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The management context of an application.
|
* The management context of an application.
|
||||||
*
|
*
|
||||||
|
@ -83,4 +85,11 @@ public interface ApplicationContext {
|
||||||
**/
|
**/
|
||||||
AuthorizationProvider authorizationProvider();
|
AuthorizationProvider authorizationProvider();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the Path to the configuration Folder for the current app
|
||||||
|
*
|
||||||
|
* @return the Path to the folder , null if the Path is not present
|
||||||
|
*/
|
||||||
|
Path appSpecificConfigurationFolder();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,10 @@ import static org.gcube.smartgears.Constants.profile_file_path;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import jakarta.servlet.ServletContext;
|
|
||||||
|
|
||||||
import org.gcube.common.events.Hub;
|
import org.gcube.common.events.Hub;
|
||||||
import org.gcube.smartgears.configuration.PersistenceConfiguration;
|
import org.gcube.smartgears.configuration.PersistenceConfiguration;
|
||||||
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
|
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
|
||||||
|
@ -17,9 +17,12 @@ import org.gcube.smartgears.context.container.ContainerContext;
|
||||||
import org.gcube.smartgears.lifecycle.application.ApplicationLifecycle;
|
import org.gcube.smartgears.lifecycle.application.ApplicationLifecycle;
|
||||||
import org.gcube.smartgears.persistence.PersistenceWriter;
|
import org.gcube.smartgears.persistence.PersistenceWriter;
|
||||||
import org.gcube.smartgears.security.AuthorizationProvider;
|
import org.gcube.smartgears.security.AuthorizationProvider;
|
||||||
|
import org.gcube.smartgears.utils.Utils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import jakarta.servlet.ServletContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default {@link ApplicationContext} implementation.
|
* Default {@link ApplicationContext} implementation.
|
||||||
*
|
*
|
||||||
|
@ -38,6 +41,9 @@ public class DefaultApplicationContext implements ApplicationContext {
|
||||||
private final Hub hub;
|
private final Hub hub;
|
||||||
private final PersistenceWriter persistenceWriter;
|
private final PersistenceWriter persistenceWriter;
|
||||||
private final String id;
|
private final String id;
|
||||||
|
private Path appSpecificConfigurationFolder;
|
||||||
|
|
||||||
|
private final static String APPS_CONFIG__DIR = "config/apps";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Crates an intance with mandatory parameters
|
* Crates an intance with mandatory parameters
|
||||||
|
@ -78,6 +84,7 @@ public class DefaultApplicationContext implements ApplicationContext {
|
||||||
this.configuration=configuration;
|
this.configuration=configuration;
|
||||||
this.hub=hub;
|
this.hub=hub;
|
||||||
this.lifecycle = lifecycle;
|
this.lifecycle = lifecycle;
|
||||||
|
this.appSpecificConfigurationFolder = getApplicationSpecificConfig();
|
||||||
this.properties=properties;
|
this.properties=properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,4 +161,34 @@ public class DefaultApplicationContext implements ApplicationContext {
|
||||||
return container().authorizationProvider();
|
return container().authorizationProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Path appSpecificConfigurationFolder() {
|
||||||
|
return this.appSpecificConfigurationFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Path getApplicationSpecificConfig(){
|
||||||
|
String home = Utils.home();
|
||||||
|
|
||||||
|
|
||||||
|
File homeDir = new File(home);
|
||||||
|
|
||||||
|
if (!(homeDir.exists() && homeDir.isDirectory() && homeDir.canRead()))
|
||||||
|
throw new IllegalStateException("invalid node configuration: home " + home
|
||||||
|
+ " does not exist or is not a directory or cannot be accessed in read mode");
|
||||||
|
|
||||||
|
String appName = this.configuration.name();
|
||||||
|
|
||||||
|
Path appSpecificConfigurationPath = Paths.get(home, APPS_CONFIG__DIR, appName);
|
||||||
|
|
||||||
|
File appSpecificConfiguration = appSpecificConfigurationPath.toFile();
|
||||||
|
|
||||||
|
if (!(appSpecificConfiguration.exists() && appSpecificConfiguration.isDirectory() && appSpecificConfiguration.canRead())) {
|
||||||
|
log.warn("specific configuration folder for {} not found", appName);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("reading specific app configuration folder @ {} ", appSpecificConfiguration.getAbsolutePath());
|
||||||
|
|
||||||
|
return appSpecificConfigurationPath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,7 +150,11 @@ public class RequestValidator extends RequestHandler {
|
||||||
RequestError.internal_server_error.fire("error contacting keycloak client", e);
|
RequestError.internal_server_error.fire("error contacting keycloak client", e);
|
||||||
}
|
}
|
||||||
} else if (token!=null && !token.isEmpty())
|
} else if (token!=null && !token.isEmpty())
|
||||||
|
try {
|
||||||
secret = new GCubeSecret(token);
|
secret = new GCubeSecret(token);
|
||||||
|
}catch(Throwable t) {
|
||||||
|
RequestError.request_not_authorized_error.fire("gcube token verification error ("+t.getMessage()+")");
|
||||||
|
}
|
||||||
return secret;
|
return secret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,8 @@ public class ApplicationManager {
|
||||||
|
|
||||||
//adding the context name to the configuration
|
//adding the context name to the configuration
|
||||||
context.configuration().context(application.getContextPath());
|
context.configuration().context(application.getContextPath());
|
||||||
|
|
||||||
|
|
||||||
// we're in business
|
// we're in business
|
||||||
context.lifecycle().moveTo(active);
|
context.lifecycle().moveTo(active);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue