public SystemUser update(
      SystemUserVO systemUserVO,
      String oldPassword,
      String[] roleNames,
      String[] groupNames,
      Database db)
      throws ConstraintException, SystemException, Exception {
    logger.info("systemUserVO:" + systemUserVO.getUserName());
    logger.info("oldPassword:"******"newPassword:"******"roleNames:" + roleNames);
    logger.info("groupNames:" + groupNames);
    if (CmsPropertyHandler.getUsePasswordEncryption()) {
      String password = systemUserVO.getPassword();
      try {
        byte[] encryptedPassRaw = DigestUtils.sha(password);
        String encryptedPass = new String(new Base64().encode(encryptedPassRaw), "ASCII");
        password = encryptedPass;
        systemUserVO.setPassword(password);

        byte[] encryptedOldPasswordRaw = DigestUtils.sha(oldPassword);
        String encryptedOldPassword =
            new String(new Base64().encode(encryptedOldPasswordRaw), "ASCII");
        oldPassword = encryptedOldPassword;
      } catch (Exception e) {
        logger.error("Error generating password:"******"Wrong user or password.");

    systemUserVO.setUserName(systemUser.getUserName());

    if (roleNames != null) {
      systemUser.getRoles().clear();
      for (int i = 0; i < roleNames.length; i++) {
        Role role = RoleController.getController().getRoleWithName(roleNames[i], db);
        systemUser.getRoles().add(role);
        role.getSystemUsers().add(systemUser);
      }
    }

    if (groupNames != null) {
      systemUser.getGroups().clear();
      for (int i = 0; i < groupNames.length; i++) {
        Group group = GroupController.getController().getGroupWithName(groupNames[i], db);
        systemUser.getGroups().add(group);
        group.getSystemUsers().add(systemUser);
      }
    }

    // systemUserVO.setPassword(systemUser.getPassword());
    systemUser.setValueObject(systemUserVO);

    return systemUser;
  }
  /*
   * CREATE
   *
   */
  public SystemUserVO create(SystemUserVO systemUserVO)
      throws ConstraintException, SystemException {
    if (CmsPropertyHandler.getUsePasswordEncryption()) {
      String password = systemUserVO.getPassword();
      try {
        byte[] encryptedPassRaw = DigestUtils.sha(password);
        String encryptedPass = new String(new Base64().encode(encryptedPassRaw), "ASCII");
        password = encryptedPass;
        systemUserVO.setPassword(password);
      } catch (Exception e) {
        System.out.println("Error generating password:" + e.getMessage());
      }
    }

    SystemUser systemUser = new SystemUserImpl();
    systemUser.setValueObject(systemUserVO);
    systemUser = (SystemUser) createEntity(systemUser);
    return systemUser.getValueObject();
  }