/** * If the "user" group is the first element of the list of groups that this * user is a member of, then check if there's a second value which could be * used as the default instead. */ private ExperimenterGroup shouldBeDefault(Experimenter usr, Session s) { List<ExperimenterGroup> grps = usr.linkedExperimenterGroupList(); if (grps.size() >= 2) { // If there are either no groups, or no alternatives so there's // nothing we need to check. final String USER = sec.getSecurityRoles().getUserGroupName(); if (USER.equals(grps.get(0).getName())) { return grps.get(1); } } return null; } }
public void addGroups(final Experimenter user, final ExperimenterGroup... groups) { final Session session = sf.getSession(); final List<String> added = new ArrayList<String>(); Experimenter foundUser = userById(user.getId(), session); for (ExperimenterGroup group : groups) { ExperimenterGroup foundGroup = groupById(group.getId(), session); boolean found = false; for (ExperimenterGroup currentGroup : foundUser .linkedExperimenterGroupList()) { found |= HibernateUtils.idEqual(foundGroup, currentGroup); } if (!found) { linkGroupAndUser(foundGroup, foundUser, false); added.add(foundGroup.getName()); } } fixDefaultGroup(foundUser, session); }
else { final long systemGroupId = sec.getSecurityRoles().getSystemGroupId(); for (final ExperimenterGroup group : e.linkedExperimenterGroupList()) { if (group.getId() == systemGroupId) { throw helper.cancel(new ERR(), null, "password-change-failed",
public void runAsAdmin() { Experimenter e = iQuery.findByString(Experimenter.class, "omeName", name); if (e == null) { throw new AuthenticationException("Unknown user."); } else if (e.getEmail() == null) { throw new AuthenticationException( "User has no email address."); } else if (!e.getEmail().equals(email)) { throw new AuthenticationException( "Email address does not match."); } else if (passwordUtil.getDnById(e.getId())) { throw new AuthenticationException( "User is authenticated by LDAP server you cannot reset this password."); } else { final long systemGroupId = getSecurityRoles().getSystemGroupId(); for (final ExperimenterGroup group : e.linkedExperimenterGroupList()) { if (group.getId() == systemGroupId) { throw new ApiUsageException( "Cannot reset password of administrators. Have another administrator set the new password."); } } String passwd = passwordUtil.generateRandomPasswd(); sendEmail(e, passwd); // changeUserPassword checks adminOrPiOfUser // Skipping that. See #7327 _changePassword(e.getOmeName(), passwd); } } });