コード例 #1
0
 /**
  * Overrides default implementation to view the 'add NCIP user' page.
  *
  * @return {@link #SUCCESS}
  */
 @Override
 public String execute() {
   try {
     User user = getUserService().getUserById(userId);
     setTemporaryUser(user);
     setGroupList(getGroupService().getAllGroups());
     return SUCCESS;
   } catch (DatabaseConfigException dce) {
     log.error(dce.getMessage(), dce);
     this.addFieldError(
         "editLDAPUserError",
         "Unable to connect to the database. Database Configuration may be incorrect");
     errorType = "error";
     return SUCCESS;
   }
 }
コード例 #2
0
  /**
   * Method that edits the details of the LDAP user
   *
   * @return {@link #SUCCESS}
   */
  public String editLDAPUser() {
    try {
      User user = getUserService().getUserById(userId);
      if (user == null) {
        this.addFieldError(
            "editLDAPUserError",
            "Error in editing LDAP user. An email has been sent to the administrator");
        getUserService().sendEmailErrorReport();
        errorType = "error";
        return ERROR;
      }
      user.setEmail(email);
      user.setFirstName(firstName);
      user.setLastName(lastName);
      user.setPassword(null);
      user.setAccountCreated(new Date());
      user.setFailedLoginAttempts(0);

      List<Server> serverList = getServerService().getAll();
      boolean serverExists = false;
      Server tempServer = null;
      Iterator<Server> iter = serverList.iterator();
      while (iter.hasNext()) {
        tempServer = (Server) iter.next();
        if (tempServer.getType() != Server.ServerType.LOCAL) {
          serverExists = true;
          break;
        }
      }

      if (serverExists == false) {
        this.addFieldError("addLDAPUserError", "NO LDAP Server has been configured");
        errorType = "error";
        return ERROR;
      }
      user.setServer(tempServer);
      user.setLastLogin(new Date());

      // Check if user has permissions
      boolean hasPermission = false;
      if (user.getGroups() != null && user.getGroups().size() > 0) {
        hasPermission = true;
      }

      user.removeAllGroups();
      for (int i = 0; i < groupsSelected.length; i++) {
        Group group = getGroupService().getGroupById(Integer.parseInt(groupsSelected[i]));
        user.addGroup(group);
      }

      User similarEmail = getUserService().getUserByEmail(email, tempServer);
      if (similarEmail != null) {
        if (similarEmail.getId() != userId) {
          if (!similarEmail.getServer().getName().equalsIgnoreCase("Local")) {
            this.addFieldError("editLDAPUserError", "Email ID already exists");
            errorType = "error";
            setGroupList(getGroupService().getAllGroups());
            setTemporaryUser(user);
            setSelectedGroups(groupsSelected);
            return INPUT;
          }
        }
      }
      getUserService().updateUser(user);

      // Email user that permissions has been added.
      if (!hasPermission) {
        getUserService().sendEmailToUserWithPermissions(user);
      }

      return SUCCESS;
    } catch (DatabaseConfigException dce) {
      log.error(dce.getMessage(), dce);
      this.addFieldError(
          "editLDAPUserError",
          "Unable to connect to the database. Database Configuration may be incorrect");
      errorType = "error";
      return ERROR;
    } catch (DataException de) {
      log.error(de.getMessage(), de);
      this.addFieldError(
          "editLDAPUserError",
          "Error in editing LDAP user. An email has been sent to the administrator");
      getUserService().sendEmailErrorReport();
      errorType = "error";
      return ERROR;
    }
  }