ApplicationContext ac = DirectoryUtil.getApplicationContext();
if (ac != null) {
WorkflowUserManager workflowUserManager = (WorkflowUserManager) DirectoryUtil.getApplicationContext().getBean("workflowUserManager");
if (workflowUserManager != null && !(workflowUserManager.isCurrentUserInRole(WorkflowUserManager.ROLE_ADMIN) || workflowUserManager.isSystemUser())){
Role adminRole = roleDao.getRole(WorkflowUserManager.ROLE_ADMIN);
if (user.getRoles() != null && user.getRoles().contains(adminRole)) {
user.getRoles().remove(adminRole);
Role userRole = roleDao.getRole("ROLE_USER");
if (userRole != null && !user.getRoles().contains(userRole)) {
user.getRoles().add(userRole);
}
}
}