NIHVIVO-119 If there are no users in the model, and none from files in ontologies/auth, create one from deploy.properties "initialAdminUser".
This commit is contained in:
parent
1367b10da3
commit
bdb154935c
3 changed files with 60 additions and 16 deletions
|
@ -81,6 +81,9 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java
|
||||||
}
|
}
|
||||||
if (userAccountsModel.size() == 0) {
|
if (userAccountsModel.size() == 0) {
|
||||||
readOntologyFilesInPathSet(AUTHPATH, sce.getServletContext(), userAccountsModel);
|
readOntologyFilesInPathSet(AUTHPATH, sce.getServletContext(), userAccountsModel);
|
||||||
|
if (userAccountsModel.size() == 0) {
|
||||||
|
createInitialAdminUser(userAccountsModel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ensureEssentialInterfaceData(memModel, sce, wadf);
|
ensureEssentialInterfaceData(memModel, sce, wadf);
|
||||||
|
|
|
@ -15,8 +15,10 @@ import com.hp.hpl.jena.graph.Graph;
|
||||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDBGraphGenerator;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDBGraphGenerator;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RegeneratingGraph;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.RegeneratingGraph;
|
||||||
|
|
||||||
|
@ -126,8 +128,10 @@ public class JenaDataSourceSetupBase {
|
||||||
return dbModel;
|
return dbModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void readOntologyFilesInPathSet(String path, ServletContext ctx, Model model) {
|
public static void readOntologyFilesInPathSet(String path,
|
||||||
|
ServletContext ctx, Model model) {
|
||||||
Set<String> paths = ctx.getResourcePaths(path);
|
Set<String> paths = ctx.getResourcePaths(path);
|
||||||
|
if (paths != null) {
|
||||||
for (String p : paths) {
|
for (String p : paths) {
|
||||||
log.debug("Loading ontology file at " + p);
|
log.debug("Loading ontology file at " + p);
|
||||||
InputStream ontologyInputStream = ctx.getResourceAsStream(p);
|
InputStream ontologyInputStream = ctx.getResourceAsStream(p);
|
||||||
|
@ -139,5 +143,38 @@ public class JenaDataSourceSetupBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the {@link ConfigurationProperties} has a name for the initial admin
|
||||||
|
* user, create the user and add it to the model.
|
||||||
|
*/
|
||||||
|
protected void createInitialAdminUser(Model model) {
|
||||||
|
String initialAdminUsername = ConfigurationProperties
|
||||||
|
.getProperty("initialAdminUser");
|
||||||
|
if (initialAdminUsername == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A hard-coded MD5 encryption of "defaultAdmin"
|
||||||
|
String initialAdminPassword = "22BA075EC8951A70960A0A95C0BC2294";
|
||||||
|
|
||||||
|
String vitroDefaultNs = "http://vitro.mannlib.cornell.edu/ns/vitro/default#";
|
||||||
|
|
||||||
|
Resource user = model.createResource(vitroDefaultNs
|
||||||
|
+ "defaultAdminUser");
|
||||||
|
model.add(model.createStatement(user, model
|
||||||
|
.createProperty(VitroVocabulary.RDF_TYPE), model
|
||||||
|
.createLiteral(VitroVocabulary.USER)));
|
||||||
|
model.add(model.createStatement(user, model
|
||||||
|
.createProperty(VitroVocabulary.USER_USERNAME), model
|
||||||
|
.createTypedLiteral(initialAdminUsername)));
|
||||||
|
model.add(model.createStatement(user, model
|
||||||
|
.createProperty(VitroVocabulary.USER_MD5PASSWORD), model
|
||||||
|
.createTypedLiteral(initialAdminPassword)));
|
||||||
|
model.add(model.createStatement(user, model
|
||||||
|
.createProperty(VitroVocabulary.USER_ROLE), model
|
||||||
|
.createTypedLiteral("role:/50")));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,8 +89,12 @@ public class JenaPersistentDataSourceSetup extends JenaDataSourceSetupBase imple
|
||||||
// user accounts Model
|
// user accounts Model
|
||||||
try {
|
try {
|
||||||
Model userAccountsDbModel = makeDBModelFromConfigurationProperties(JENA_USER_ACCOUNTS_MODEL, DB_ONT_MODEL_SPEC);
|
Model userAccountsDbModel = makeDBModelFromConfigurationProperties(JENA_USER_ACCOUNTS_MODEL, DB_ONT_MODEL_SPEC);
|
||||||
if (firstStartup) {
|
if (userAccountsDbModel.size() == 0) {
|
||||||
readOntologyFilesInPathSet(AUTHPATH, sce.getServletContext(), userAccountsDbModel);
|
readOntologyFilesInPathSet(AUTHPATH, sce.getServletContext(),
|
||||||
|
userAccountsDbModel);
|
||||||
|
if (userAccountsDbModel.size() == 0) {
|
||||||
|
createInitialAdminUser(userAccountsDbModel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
OntModel userAccountsModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
OntModel userAccountsModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
||||||
userAccountsModel.add(userAccountsDbModel);
|
userAccountsModel.add(userAccountsDbModel);
|
||||||
|
|
Loading…
Add table
Reference in a new issue