public EditUser(User user) {
      name = user.getName();
      String email = user.getUserAttribute(User.USER_ATTRIBUTE_EMAIL);
      String language = user.getUserAttribute(User.USER_ATTRIBUTE_LANGUAGE);
      if (email != null) {
        attributes.put(User.USER_ATTRIBUTE_EMAIL, email);
      }
      if (language != null) {
        attributes.put(User.USER_ATTRIBUTE_LANGUAGE, language);
      }
      attributes.resetMonitor();

      // copy resource authorizations
      ResourceTypeAuthorizationStore store =
          CloudManagerApp.getInstance().getResourceTypeAuthorizationStore();
      for (ResourceModule module : CloudManagerApp.getInstance().getAllResourceModules()) {
        try {
          ResourceTypeAuthorizationConfig config =
              store.loadResourceTypeAuthorizations(module.getResourceType());
          if (config != null) {
            ResourceTypeAuthorization auth = config.getResourceTypeAuthorizationForUser(user);
            if (auth != null) {
              resourceAuthorizations.add(
                  new ResourceAuthorizationEntry(module.getResourceType().getName(), auth));
            }
          }
        } catch (StoreException e) {
          LOG.error("Could not load resource type authorizations", e);
        }
      }
    }
  public List<SelectItem> getResourceTypeItems() {
    List<SelectItem> result = new ArrayList<SelectItem>();

    for (ResourceModule module : CloudManagerApp.getInstance().getAllResourceModules()) {
      result.add(new SelectItem(module.getResourceType().getName(), module.getDisplayName()));
    }

    return result;
  }
  public void save(EditUser user) {
    UserDatabase db = CloudManagerApp.getInstance().getSelectedUserDatabase();
    if (user == null || db.isReadOnly()) {
      return;
    }

    // validate resource authorizations here
    Set<String> resourceTypes = new HashSet<String>();
    for (ResourceAuthorizationEntry entry : user.getResourceAuthorizations()) {
      if (resourceTypes.contains(entry.getResourceType())) {
        FacesContext.getCurrentInstance()
            .addMessage(
                null,
                JSFUtil.createErrorMessage(
                    "The resource type "
                        + entry.getResourceType()
                        + " must only be assigned once."));
        return;
      }
      resourceTypes.add(entry.getResourceType());
    }

    try {
      User dbUser;
      boolean includePwd = false;

      // create user first, if new user
      if (user == newUser) {
        try {
          dbUser = db.create(user.getName());
        } catch (IllegalArgumentException iae) {
          // name already existing
          FacesContext.getCurrentInstance()
              .addMessage(null, JSFUtil.createErrorMessage("The user name does already exist."));
          return;
        }
        newUser = createEmptyUser();
        includePwd = true;
      } else {
        dbUser = db.findUser(user.getName());
      }

      if (user.newPassword != null) {
        db.changePassword(dbUser, user.newPassword);
        FacesContext.getCurrentInstance()
            .addMessage(
                null,
                JSFUtil.createInfoMessage(
                    "The user password has been changed"
                        + (includePwd ? " to " + user.newPassword : "******")));
      }
      // attribute update
      for (String key : user.attributes.getRemovedKeys()) {
        db.modifyUserAttribute(dbUser, key, null);
      }
      for (String key : user.attributes.getAddedKeys()) {
        db.modifyUserAttribute(dbUser, key, user.attributes.get(key));
      }
      for (String key : user.attributes.getChangedKeys()) {
        db.modifyUserAttribute(dbUser, key, user.attributes.get(key));
      }

      // authorization update
      ResourceTypeAuthorizationStore store =
          CloudManagerApp.getInstance().getResourceTypeAuthorizationStore();

      for (ResourceModule module : CloudManagerApp.getInstance().getAllResourceModules()) {
        try {
          ResourceTypeAuthorizationConfig config =
              store.loadResourceTypeAuthorizations(module.getResourceType());
          if (config == null) {
            config = new SimpleResourceTypeAuthorizationConfig();
          }
          SimpleResourceTypeAuthorizationConfig mutableConfig =
              new SimpleResourceTypeAuthorizationConfig(config);

          ResourceAuthorizationEntry entry =
              user.getResourceAuthorization(module.getResourceType());
          boolean update = false;

          // if user does not contain authorization for type, but is configured, remove
          if (entry == null && mutableConfig.getConfiguredUsers().contains(dbUser)) {
            mutableConfig.removeUser(dbUser);
            update = true;
          } else if (entry != null) {
            if (!mutableConfig.getConfiguredUsers().contains(dbUser)) {
              mutableConfig.addUser(dbUser, entry.toResourceTypeAuthorization());
            } else {
              mutableConfig.editUserAuthorization(dbUser, entry.toResourceTypeAuthorization());
            }
            update = true;
          }
          if (update) {
            store.saveResourceTypeAuthorizations(module.getResourceType(), mutableConfig);
          }
        } catch (StoreException e) {
          LOG.error("Could not update resource type authorizations", e);
        }
      }

      FacesContext.getCurrentInstance()
          .addMessage(
              null, JSFUtil.createInfoMessage("The user details have been updated successfully."));

      // reload users from database
      users = null;
    } catch (StoreException se) {
      LOG.error("Exception when saving user details", se);
      FacesContext.getCurrentInstance()
          .addMessage(
              null,
              JSFUtil.createErrorMessage("Exception when saving user details: " + se.getMessage()));
    }
  }