*/
@Override
public boolean setupAdminUser() {
boolean exist = false;
// let's check if there are users in the database
UserDAO userDAO = (UserDAO) getDao();
if (userDAO.countAll() > 0)
exist = true;
else {
// if none, let's create admin user
BaseUser user = new BaseUser();
UserCredential cred = new UserCredential();
cred.setUsername("admin");
cred.setPassword("ideyatech");
cred.setEnabled(true);
cred.setUser(user);
user.setCredential(cred);
user.setEmailAddress("admin@ideyatech.com");
user.setFirstName("SuperAdmin");
user.setLastName("User");
// create usergroup for user
UserGroup userGroup = new UserGroup();
userGroup.setName("Super User");
userGroup.setDescription("With all roles");
// Let's super user role
List<String> roleNames = new ArrayList<String>();
roleNames.add("SUPER_USER");
roleNames.add("ACCESS_ALL");
userGroup.setRoleNames(roleNames);
userGroupDAO.saveEntityModel(userGroup);
user.addGroup(userGroup);
userDAO.saveEntityModel(user);
_log.info("New installation detected, inserted admin/ideyatech user to database.");
}
return !exist;
}