コード例 #1
0
ファイル: UserNode.java プロジェクト: cismet/abf
  @Override
  public void destroy() throws IOException {
    final Set<UserGroup> ugs;

    try {
      final Backend backend = project.getCidsDataObjectBackend();
      for (final UserGroup ug : user.getUserGroups()) {
        ug.getUsers().remove(user);
        backend.store(ug);
      }
      ugs = new HashSet<UserGroup>(user.getUserGroups());
      user.getUserGroups().clear();

      backend.delete(user);

      deleted = true;
    } catch (final Exception ex) {
      final String message = "could not delete user: " + user; // NOI18N
      LOG.error(message, ex);
      throw new IOException(message, ex);
    }
    project.getLookup().lookup(UserManagement.class).refreshGroups(ugs);
    project.getLookup().lookup(ConfigAttrManagement.class).refresh();
  }
コード例 #2
0
ファイル: UserNode.java プロジェクト: cismet/abf
  /**
   * DOCUMENT ME!
   *
   * @param project backend map DOCUMENT ME!
   * @param sheet DOCUMENT ME!
   * @param group DOCUMENT ME!
   * @param user DOCUMENT ME!
   * @throws IllegalArgumentException DOCUMENT ME!
   * @throws IllegalStateException DOCUMENT ME!
   */
  public static void populateLegacyConfigAttrSet(
      final DomainserverProject project,
      final Sheet sheet,
      final UserGroup group,
      final User user) {
    if ((user == null) && (group == null)) {
      throw new IllegalArgumentException("group and user must not be null"); // NOI18N
    }
    final ReadOnly<String> propCAttr =
        new ReadOnly<String>(
            "configattrs", // NOI18N
            String.class,
            NbBundle.getMessage(
                UserNode.class, "UserNode.createSheet().propCAttr.displayName"), // NOI18N
            null) {

          @Override
          public String getHtmlDisplayName() {
            return "<html><b>" // NOI18N
                + NbBundle.getMessage(
                    UserNode.class, "UserNode.createSheet().propCAttr.displayName")
                + "</b></html>"; // NOI18N
          }

          @Override
          public String getValue() throws IllegalAccessException, InvocationTargetException {
            return ""; // NOI18N
          }
        };

    final ReadOnly<String> propAAttr =
        new ReadOnly<String>(
            "actionattrs", // NOI18N
            String.class,
            NbBundle.getMessage(
                UserNode.class, "UserNode.createSheet().propAAttr.displayName"), // NOI18N
            null) {

          @Override
          public String getHtmlDisplayName() {
            return "<html><b>" // NOI18N
                + NbBundle.getMessage(
                    UserNode.class, "UserNode.createSheet().propAAttr.displayName")
                + "</b></html>"; // NOI18N
          }

          @Override
          public String getValue() throws IllegalAccessException, InvocationTargetException {
            return ""; // NOI18N
          }
        };

    final ReadOnly<String> propXAttr =
        new ReadOnly<String>(
            "xmlattrs", // NOI18N
            String.class,
            NbBundle.getMessage(
                UserNode.class, "UserNode.createSheet().propXAttr.displayName"), // NOI18N
            null) {

          @Override
          public String getHtmlDisplayName() {
            return "<html><b>" // NOI18N
                + NbBundle.getMessage(
                    UserNode.class, "UserNode.createSheet().propXAttr.displayName")
                + "</b></html>"; // NOI18N
          }

          @Override
          public String getValue() throws IllegalAccessException, InvocationTargetException {
            return ""; // NOI18N
          }
        };

    final List<UserGroup> ugs;
    if (user == null) {
      ugs = new ArrayList<UserGroup>(1);
      ugs.add(group);
    } else {
      ugs = new ArrayList<UserGroup>(user.getUserGroups());
      Collections.sort(ugs, new Comparators.UserGroups());
    }

    for (final UserGroup ug : ugs) {
      final List<ConfigAttrEntry> caes =
          project
              .getCidsDataObjectBackend()
              .getEntries(
                  ug.getDomain(),
                  ug,
                  user,
                  project.getRuntimeProps().getProperty("serverName"), // NOI18N
                  true);
      Collections.sort(caes, new Comparators.ConfigAttrEntries());

      if (!caes.isEmpty()) {
        final Sheet.Set ugSet = Sheet.createPropertiesSet();
        ugSet.setName(ug.toString());
        ugSet.setDisplayName(ug.getName() + "@" + ug.getDomain().getName()); // NOI18N

        final Map<ReadOnly<String>, List<ReadOnly<String>>> map =
            new TreeMap<ReadOnly<String>, List<ReadOnly<String>>>(
                new Comparator<ReadOnly<String>>() {

                  @Override
                  public int compare(final ReadOnly<String> o1, final ReadOnly<String> o2) {
                    return o1.getDisplayName().compareTo(o2.getDisplayName());
                  }
                });

        for (final ConfigAttrEntry cae : caes) {
          final PropertySupport.ReadOnly<String> p =
              new PropertySupport.ReadOnly<String>(
                  cae.getKey().getKey() + cae.getId(),
                  String.class,
                  cae.getKey().getKey()
                      + " [" // NOI18N
                      + ((cae.getUser() == null)
                          ? ((cae.getUsergroup() == null)
                              ? NbBundle.getMessage(
                                  UserNode.class,
                                  "UserNode.createSheet().caentryProp.displayName.category.domain") // NOI18N
                              : NbBundle.getMessage(
                                  UserNode.class,
                                  "UserNode.createSheet().caentryProp.displayName.category.ug")) // NOI18N
                          : NbBundle.getMessage(
                              UserNode.class,
                              "UserNode.createSheet().caentryProp.displayName.category.user")) // NOI18N
                      + "]", // NOI18N
                  null) {

                @Override
                public String getHtmlDisplayName() {
                  return "<html>"
                      + cae.getKey().getKey() // NOI18N
                      + " <font color=\"!controlShadow\"> [" // NOI18N
                      + ((cae.getUser() == null)
                          ? ((cae.getUsergroup() == null)
                              ? NbBundle.getMessage(
                                  UserNode.class,
                                  "UserNode.createSheet().caentryProp.displayName.category.domain") // NOI18N
                              : NbBundle.getMessage(
                                  UserNode.class,
                                  "UserNode.createSheet().caentryProp.displayName.category.ug")) // NOI18N
                          : NbBundle.getMessage(
                              UserNode.class,
                              "UserNode.createSheet().caentryProp.displayName.category.user")) // NOI18N
                      + "]</font></html>"; // NOI18N
                }

                @Override
                public String getValue() throws IllegalAccessException, InvocationTargetException {
                  return cae.getValue().getValue();
                }
              };

          List<ReadOnly<String>> attrList;
          switch (cae.getType().getAttrType()) {
            case CONFIG_ATTR:
              {
                attrList = map.get(propCAttr);
                if (attrList == null) {
                  attrList = new ArrayList<ReadOnly<String>>();
                  map.put(propCAttr, attrList);
                }

                break;
              }
            case ACTION_TAG:
              {
                attrList = map.get(propAAttr);
                if (attrList == null) {
                  attrList = new ArrayList<ReadOnly<String>>();
                  map.put(propAAttr, attrList);
                }

                break;
              }
            case XML_ATTR:
              {
                attrList = map.get(propXAttr);
                if (attrList == null) {
                  attrList = new ArrayList<ReadOnly<String>>();
                  map.put(propXAttr, attrList);
                }

                break;
              }
            default:
              {
                throw new IllegalStateException(
                    "unknown type: " + cae.getType().getAttrType()); // NOI18N
              }
          }

          attrList.add(p);
        }

        for (final ReadOnly<String> typeProp : map.keySet()) {
          ugSet.put(typeProp);
          for (final ReadOnly<String> entryProp : map.get(typeProp)) {
            ugSet.put(entryProp);
          }
        }

        sheet.put(ugSet);
      }
    }
  }
コード例 #3
0
ファイル: UserNode.java プロジェクト: cismet/abf
  @Override
  protected Sheet createSheet() {
    sheetInitialised = true;
    final Sheet sheet = Sheet.createDefault();
    final Sheet.Set set = Sheet.createPropertiesSet();
    final Sheet.Set setUG = Sheet.createPropertiesSet();

    try {
      // <editor-fold defaultstate="collapsed" desc=" Create Property: ID ">
      final Property<Integer> idProp =
          new PropertySupport.Reflection<Integer>(user, Integer.class, "getId", null); // NOI18N
      idProp.setName(
          NbBundle.getMessage(UserNode.class, "UserNode.createSheet().idProp.name")); // NOI18N
      // </editor-fold>
      // <editor-fold defaultstate="collapsed" desc=" Create Property: PasswordChange ">
      final Property<Date> pwchangeProp =
          new PropertySupport<Date>(
              "lastPWChange", // NOI18N
              Date.class,
              NbBundle.getMessage(
                  UserNode.class, "UserNode.createSheet().pwchangeProp.lastPWChange"), // NOI18N
              NbBundle.getMessage(
                  UserNode.class,
                  "UserNode.createSheet().pwchangeProp.timestampLastPWChange"), // NOI18N
              true,
              false) {

            @Override
            public Date getValue() throws IllegalAccessException, InvocationTargetException {
              return user.getLastPwdChange();
            }

            @Override
            public void setValue(final Date object)
                throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
              // not needed
            }
          }; // </editor-fold>

      // <editor-fold defaultstate="collapsed" desc=" Create Property: Name ">
      final Property<String> nameProp =
          new PropertySupport<String>(
              "name", // NOI18N
              String.class,
              NbBundle.getMessage(UserNode.class, "UserNode.createSheet().nameProp.name"), // NOI18N
              NbBundle.getMessage(
                  UserNode.class, "UserNode.createSheet().nameProp.userLogin"), // NOI18N
              true,
              true) {

            @Override
            public String getValue() throws IllegalAccessException, InvocationTargetException {
              return user.getLoginname();
            }

            @Override
            public void setValue(final String object)
                throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
              final User old = user;
              try {
                user.setLoginname(object);
                user = project.getCidsDataObjectBackend().store(user);
              } catch (final Exception ex) {
                LOG.error("could not store user", ex); // NOI18N
                user = old;
                ErrorManager.getDefault().notify(ex);
              }
              fireDisplayNameChange(null, object);
            }
          }; // </editor-fold>

      // <editor-fold defaultstate="collapsed" desc=" Create Property: Password ">
      final PasswordPropertyEditor pwEditor = new PasswordPropertyEditor();
      final Property<String> passProp =
          new PropertySupport<String>(
              "password", // NOI18N
              String.class,
              NbBundle.getMessage(
                  UserNode.class, "UserNode.createSheet().passProp.password"), // NOI18N
              NbBundle.getMessage(
                  UserNode.class, "UserNode.createSheet().passProp.passwordOfUser"), // NOI18N
              true,
              true) {

            @Override
            public String getValue() throws IllegalAccessException, InvocationTargetException {
              return "****"; // NOI18N
            }

            @Override
            public PropertyEditor getPropertyEditor() {
              return pwEditor;
            }

            @Override
            public void setValue(final String object)
                throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
              if ((object == null) || object.toString().equals("****")) { // NOI18N
                // ignore
                return;
              }

              final User old = user;
              try {
                user.setPassword(object);
                user.setLastPwdChange(Calendar.getInstance().getTime());
                user = project.getCidsDataObjectBackend().store(user);
              } catch (final Exception ex) {
                LOG.error("could not store user", ex); // NOI18N
                user = old;
                ErrorManager.getDefault().notify(ex);
              }
              firePropertyChange(
                  "lastPWChange", // NOI18N
                  null,
                  user.getLastPwdChange());
            }
          };
      passProp.setValue("canEditAsText", Boolean.FALSE); // NOI18N
      // </editor-fold>

      // <editor-fold defaultstate="collapsed" desc=" Create Property: Administrator ">
      final Property<Boolean> adminProp =
          new PropertySupport<Boolean>(
              "admin", // NOI18N
              Boolean.class,
              NbBundle.getMessage(
                  UserNode.class, "UserNode.createSheet().adminProp.admin"), // NOI18N
              NbBundle.getMessage(
                  UserNode.class, "UserNode.createSheet().adminProp.isUserAdmin"), // NOI18N
              true,
              true) {

            @Override
            public Boolean getValue() throws IllegalAccessException, InvocationTargetException {
              return user.isAdmin();
            }

            @Override
            public void setValue(final Boolean object)
                throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
              final User old = user;
              try {
                user.setAdmin(object);
                user = project.getCidsDataObjectBackend().store(user);
              } catch (final Exception ex) {
                LOG.error("could not store user", ex); // NOI18N
                user = old;
                ErrorManager.getDefault().notify(ex);
              }
              fireIconChange();
            }
          }; // </editor-fold>

      // <editor-fold defaultstate="collapsed" desc=" Create Property: GroupInfo ">
      final List<UserGroup> ugs = new ArrayList<UserGroup>(user.getUserGroups());
      Collections.sort(ugs, new Comparators.UserGroups());
      for (final UserGroup ug : user.getUserGroups()) {
        setUG.put(
            new PropertySupport.ReadOnly<Integer>(
                "ug" // NOI18N
                    + ug.getId(),
                Integer.class,
                ug.getName(),
                ug.getDescription()) {

              @Override
              public Integer getValue() throws IllegalAccessException, InvocationTargetException {
                return ug.getId();
              }
            });
      } // </editor-fold>

      setUG.setName("usergroups"); // NOI18N
      setUG.setDisplayName(
          NbBundle.getMessage(
              UserNode.class, "UserNode.createSheet().setUG.displayName")); // NOI18N

      set.put(nameProp);
      set.put(passProp);
      set.put(pwchangeProp);
      set.put(adminProp);
      set.put(idProp);

      sheet.put(set);
      sheet.put(setUG);

      // <editor-fold defaultstate="collapsed" desc=" Create Property: ConfigAttrs legacy">
      if (Boolean.valueOf(
          project
              .getProperties()
              .getProperty(
                  DomainserverProjectCustomizer.PROP_USER_SHOW_LEGACY_CFGATTR_PROPS,
                  "false"))) { // NOI18N
        populateLegacyConfigAttrSet(project, sheet, null, user);
      }
      // </editor-fold>

      // <editor-fold defaultstate="collapsed" desc=" Create Property: ConfigAttrs">
      if (Boolean.valueOf(
          project
              .getProperties()
              .getProperty(
                  DomainserverProjectCustomizer.PROP_USER_SHOW_CFGATTR_PROPS, "false"))) { // NOI18N
        populateConfigAttrSet(sheet);
      }
      // </editor-fold>
    } catch (final Exception ex) {
      LOG.error("could not create property sheet", ex); // NOI18N
      ErrorManager.getDefault().notify(ex);
    }

    return sheet;
  }