Commit ddeb8ffe authored by shake's avatar shake
Browse files

Added context listener for modifying system settings

git-svn-id: https://subversion.umiacs.umd.edu/ace/trunk@159 f1b3a171-7291-4a19-a512-95ad0ad9394a
parent e5429a31
/*
*
* Copyright (c) 2007-2010, University of Maryland
* All rights reserved.
*
......@@ -33,6 +34,7 @@ package edu.umiacs.ace.monitor.users;
import edu.umiacs.ace.monitor.settings.SettingsParameter;
import edu.umiacs.ace.util.PersistUtil;
import edu.umiacs.util.Strings;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;
......@@ -172,35 +174,40 @@ public class DefaultAccountContextListener implements ServletContextListener {
em.persist(updateSysSettings);
et.commit();
persistSystemUser();
}
} catch ( Exception e ) {
LOG.error("Error creating default account", e);
}
checkSystemSettings(em);
}
}
private void persistSystemUser() {
EntityManager em = PersistUtil.getEntityManager();
Users u = new Users();
u.setUsername("system");
u.setPassword("system");
UserRoles log = new UserRoles();
log.setRolename("Log");
log.setUsername("system");
// It's possible to already have an admin account and not have the
// system settings option yet, so check that here
private void checkSystemSettings(EntityManager em) {
boolean settingsMigration = false;
Query roleQuery = em.createNamedQuery("UserRoles.listRolesForUser");
roleQuery.setParameter("user", "admin");
List<UserRoles> adminRoles = roleQuery.getResultList();
for ( UserRoles role: adminRoles ) {
if ( role.getRolename().equals("Modify System Settings") ) {
settingsMigration = true;
}
}
if ( !settingsMigration ) {
System.out.println("Adding modify system settings role");
UserRoles updateSysSettings = new UserRoles();
updateSysSettings.setRolename("Modify System Settings");
updateSysSettings.setUsername("system");
EntityTransaction trans = em.getTransaction();
trans.begin();
em.persist(u);
em.persist(log);
updateSysSettings.setUsername("admin");
EntityTransaction et = em.getTransaction();
et.begin();
em.persist(updateSysSettings);
et.commit();
}
}
@Override
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment