Skip to content

Commit

Permalink
[New] Enable getting username and password from config-core.properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew-Kulich committed Feb 15, 2023
1 parent 3d19848 commit ec316b0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class CoreConfigProperies {
private static final String CONFIG_FILE = "config-core.properties";
private static final java.util.Properties prop = new java.util.Properties();
private static final Logger LOG = LoggerFactory.getLogger(CoreConfigProperies.class);
private static final String variableAssignmentPrefix = "variable.assignment";

static {
try {
Expand Down Expand Up @@ -59,4 +60,7 @@ private static String getEnvValue(String name){
return System.getenv(name.toUpperCase().replaceAll("\\.", "_"));
}

public static String getConfigurationVariable(String name) {
return get(variableAssignmentPrefix + "." + name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import cz.cvut.spipes.constants.KBSS_MODULE;
import cz.cvut.spipes.engine.ExecutionContext;
import cz.cvut.spipes.engine.ExecutionContextFactory;
import cz.cvut.spipes.engine.VariablesBinding;
import cz.cvut.spipes.util.CoreConfigProperies;
import org.apache.jena.rdf.model.Property;
import org.apache.jena.rdf.model.RDFNode;
import org.apache.jena.rdf.model.ResourceFactory;
import org.apache.jena.riot.RDFLanguages;
import org.eclipse.rdf4j.model.Resource;
Expand Down Expand Up @@ -58,6 +57,11 @@ private static Property getParameter(final String name) {
static final Property P_RDF4J_CONTEXT_IRI = getParameter("p-rdf4j-context-iri");
private String rdf4jContextIRI;

static final Property P_RDF4J_REPOSITORY_USERNAME = getParameter("p-rdf4j-secured-username-variable");
private String rdf4jSecuredUsernameVariable;

static final Property P_RDF4J_REPOSITORY_PASSWORD = getParameter("p-rdf4j-secured-password-variable");
private String rdf4jSecuredPasswordVariable;
/**
* Whether the context should be replaced (true) or just enriched (false).
*/
Expand Down Expand Up @@ -105,17 +109,8 @@ ExecutionContext executeSelf() {
rdf4jServerURL,
rdf4jRepositoryName);

VariablesBinding variablesBinding = getExecutionContext().getVariablesBinding();

String username = Optional
.ofNullable(variablesBinding.getNode("p-username"))
.map(RDFNode::toString)
.orElse(null);

String password = Optional
.ofNullable(variablesBinding.getNode("p-password"))
.map(RDFNode::toString)
.orElse(null);
String username = CoreConfigProperies.getConfigurationVariable(rdf4jSecuredUsernameVariable);
String password = CoreConfigProperies.getConfigurationVariable(rdf4jSecuredPasswordVariable);

try {
RepositoryManager repositoryManager = RepositoryProvider.getRepositoryManager(rdf4jServerURL);
Expand Down Expand Up @@ -187,6 +182,8 @@ public void loadConfiguration() {
rdf4jContextIRI = getEffectiveValue(P_RDF4J_CONTEXT_IRI).asLiteral().getString();
}
isReplaceContext = this.getPropertyValue(P_IS_REPLACE_CONTEXT_IRI, false);
rdf4jSecuredUsernameVariable = getEffectiveValue(P_RDF4J_REPOSITORY_USERNAME).asLiteral().getString();
rdf4jSecuredPasswordVariable = getEffectiveValue(P_RDF4J_REPOSITORY_PASSWORD).asLiteral().getString();
}

private boolean isRdf4jContextIRIDefined() {
Expand Down

0 comments on commit ec316b0

Please sign in to comment.