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 * Copyright (c) 2007-2010, University of Maryland
* All rights reserved. * All rights reserved.
* *
...@@ -33,6 +34,7 @@ package edu.umiacs.ace.monitor.users; ...@@ -33,6 +34,7 @@ package edu.umiacs.ace.monitor.users;
import edu.umiacs.ace.monitor.settings.SettingsParameter; import edu.umiacs.ace.monitor.settings.SettingsParameter;
import edu.umiacs.ace.util.PersistUtil; import edu.umiacs.ace.util.PersistUtil;
import edu.umiacs.util.Strings; import edu.umiacs.util.Strings;
import java.util.List;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction; import javax.persistence.EntityTransaction;
import javax.persistence.Query; import javax.persistence.Query;
...@@ -172,35 +174,40 @@ public class DefaultAccountContextListener implements ServletContextListener { ...@@ -172,35 +174,40 @@ public class DefaultAccountContextListener implements ServletContextListener {
em.persist(updateSysSettings); em.persist(updateSysSettings);
et.commit(); et.commit();
persistSystemUser();
} }
} catch ( Exception e ) { } catch ( Exception e ) {
LOG.error("Error creating default account", e); LOG.error("Error creating default account", e);
} }
checkSystemSettings(em);
} }
} }
private void persistSystemUser() { // It's possible to already have an admin account and not have the
EntityManager em = PersistUtil.getEntityManager(); // system settings option yet, so check that here
private void checkSystemSettings(EntityManager em) {
Users u = new Users(); boolean settingsMigration = false;
u.setUsername("system"); Query roleQuery = em.createNamedQuery("UserRoles.listRolesForUser");
u.setPassword("system"); roleQuery.setParameter("user", "admin");
UserRoles log = new UserRoles(); List<UserRoles> adminRoles = roleQuery.getResultList();
log.setRolename("Log"); for ( UserRoles role: adminRoles ) {
log.setUsername("system"); if ( role.getRolename().equals("Modify System Settings") ) {
settingsMigration = true;
UserRoles updateSysSettings = new UserRoles(); }
updateSysSettings.setRolename("Modify System Settings"); }
updateSysSettings.setUsername("system");
EntityTransaction trans = em.getTransaction(); if ( !settingsMigration ) {
trans.begin(); System.out.println("Adding modify system settings role");
em.persist(u); UserRoles updateSysSettings = new UserRoles();
em.persist(log); updateSysSettings.setRolename("Modify System Settings");
em.persist(updateSysSettings); updateSysSettings.setUsername("admin");
EntityTransaction et = em.getTransaction();
et.begin();
em.persist(updateSysSettings);
et.commit();
}
} }
@Override @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