Write a warning to the log if a root user already exists with an email address that is different from the one in the deploy.properties

This commit is contained in:
j2blake 2011-06-14 20:12:57 +00:00
parent edfd1798ef
commit ef3affb349

View file

@ -75,6 +75,8 @@ public class RootUserPolicy implements PolicyIface {
UserAccountsDao uaDao = getUserAccountsDao(ctx); UserAccountsDao uaDao = getUserAccountsDao(ctx);
OntModel userAccountsModel = getUserAccountsModel(ctx); OntModel userAccountsModel = getUserAccountsModel(ctx);
checkForWrongRootUser(ctx, uaDao);
if (!rootUserExists(uaDao)) { if (!rootUserExists(uaDao)) {
createRootUser(ctx, uaDao, userAccountsModel); createRootUser(ctx, uaDao, userAccountsModel);
} }
@ -103,13 +105,34 @@ public class RootUserPolicy implements PolicyIface {
.getUserAccountsModel(); .getUserAccountsModel();
} }
private void checkForWrongRootUser(ServletContext ctx,
UserAccountsDao uaDao) {
UserAccount root = getRootUser(uaDao);
if (root == null) {
return;
}
String actualRootEmail = root.getEmailAddress();
String configRootEmail = ConfigurationProperties.getBean(ctx)
.getProperty(PROPERTY_ROOT_USER_EMAIL);
if (actualRootEmail.equals(configRootEmail)) {
return;
}
log.warn("Root user '" + actualRootEmail + "' already exists.");
}
private boolean rootUserExists(UserAccountsDao uaDao) { private boolean rootUserExists(UserAccountsDao uaDao) {
return (getRootUser(uaDao) != null);
}
private UserAccount getRootUser(UserAccountsDao uaDao) {
for (UserAccount ua : uaDao.getAllUserAccounts()) { for (UserAccount ua : uaDao.getAllUserAccounts()) {
if (uaDao.isRootUser(ua)) { if (uaDao.isRootUser(ua)) {
return true; return ua;
} }
} }
return false; return null;
} }
/** /**