예제 #1
0
  private Uid doUpdate() throws IOException, JSchException {

    if (uid == null || StringUtil.isBlank(uid.getUidValue())) {
      throw new IllegalArgumentException("No Uid attribute provided in the attributes");
    }

    LOG.info("Update user: "******"Wrong object class");
    }

    if (objectClass.equals(ObjectClass.ACCOUNT)) {
      if (!EvaluateCommandsResultOutput.evaluateUserOrGroupExists(
          unixConnection.execute(
              UnixConnector.getCommandGenerator().userExists(uid.getUidValue())))) {
        throw new ConnectorException("User " + uid + " do not exists");
      }
      for (Attribute attr : attrs) {
        if (attr.is(Name.NAME) || attr.is(Uid.NAME)) {
          newUserName = (String) attr.getValue().get(0);
        } else if (attr.is(OperationalAttributes.PASSWORD_NAME)) {
          password = Utilities.getPlainPassword((GuardedString) attr.getValue().get(0));
        } else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
          status = Boolean.parseBoolean(attr.getValue().get(0).toString());
        } else if (attr.is(configuration.getCommentAttribute())) {
          comment = attr.getValue().get(0).toString();
        } else if (attr.is(configuration.getShellAttribute())) {
          shell = (String) attr.getValue().get(0).toString();
        } else if (attr.is(configuration.getHomeDirectoryAttribute())) {
          homeDirectory = (String) attr.getValue().get(0).toString();
        }
      }
      unixConnection.execute(
          UnixConnector.getCommandGenerator()
              .updateUser(
                  uid.getUidValue(), newUserName, password, status, comment, shell, homeDirectory));
      //            unixConnection.execute("mv /home/" + uid.getUidValue() + " /home/" +
      // newUserName);
      unixConnection.execute(
          UnixConnector.getCommandGenerator().moveHomeDirectory(uid.getUidValue(), newUserName));
      if (!status) {
        unixConnection.execute(UnixConnector.getCommandGenerator().lockUser(uid.getUidValue()));
      } else {
        unixConnection.execute(UnixConnector.getCommandGenerator().unlockUser(uid.getUidValue()));
      }
      if (StringUtil.isNotBlank(newUserName) && StringUtil.isNotEmpty(newUserName)) {
        unixConnection.execute(
            UnixConnector.getCommandGenerator().updateGroup(uid.getUidValue(), newUserName));
      }
    } else if (objectClass.equals(ObjectClass.GROUP)) {
      if (!EvaluateCommandsResultOutput.evaluateUserOrGroupExists(
          unixConnection.execute(UnixConnector.getCommandGenerator().groupExists(newUserName)))) {
        throw new ConnectorException("Group do not exists");
      }
      unixConnection.execute(
          UnixConnector.getCommandGenerator().updateGroup(uid.getUidValue(), newUserName));
    }
    return uid;
  }
예제 #2
0
  private Uid doUpdate() throws IOException {

    if (!objectClass.equals(ObjectClass.ACCOUNT) && (!objectClass.equals(ObjectClass.GROUP))) {
      throw new IllegalStateException("Wrong object class");
    }

    if (!userExists(
        uid.getUidValue(), configuration.getOpenamRealm(), adminToken.getToken(), connection)) {
      LOG.error("User " + uid.getUidValue() + " do not exists");
      throw new ConnectorException("User " + uid.getUidValue() + " do not exists");
    }

    try {
      connection.update(createUpdateQueryString(uid, attrs, adminToken).toString());
      LOG.ok("User " + uid.getUidValue() + " updated");
    } catch (HttpClientErrorException hcee) {
      throw hcee;
    }
    return uid;
  }