コード例 #1
0
  @Nonnull
  protected IHCNode getTabWithUsers(
      @Nonnull final Locale aDisplayLocale,
      @Nonnull final Collection<? extends IUser> aUsers,
      @Nonnull @Nonempty final String sTableID) {
    final boolean bSeparateLoginName = !useEmailAddressAsLoginName();
    final AccessManager aMgr = AccessManager.getInstance();
    // List existing
    final List<HCCol> aCols = new ArrayList<HCCol>();
    aCols.add(new HCCol(200));
    if (bSeparateLoginName) aCols.add(new HCCol(200));
    aCols.add(HCCol.star());
    aCols.add(new HCCol(150));
    aCols.add(createActionCol(3));
    final IHCTable<?> aTable =
        getStyler().createTable(ArrayHelper.newArray(aCols, HCCol.class)).setID(sTableID);
    final HCRow aHeaderRow = aTable.addHeaderRow();
    aHeaderRow.addCell(EText.HEADER_NAME.getDisplayText(aDisplayLocale));
    if (bSeparateLoginName)
      aHeaderRow.addCell(EText.HEADER_LOGINNAME.getDisplayText(aDisplayLocale));
    aHeaderRow.addCells(
        EText.HEADER_EMAIL.getDisplayText(aDisplayLocale),
        EText.HEADER_USERGROUPS.getDisplayText(aDisplayLocale),
        EWebBasicsText.MSG_ACTIONS.getDisplayText(aDisplayLocale));

    for (final IUser aCurUser : aUsers) {
      final ISimpleURL aViewLink = createViewURL(aCurUser);

      final HCRow aRow = aTable.addBodyRow();
      aRow.addCell(
          new HCA(aViewLink).addChild(SecurityUI.getUserDisplayName(aCurUser, aDisplayLocale)));
      if (bSeparateLoginName) aRow.addCell(new HCA(aViewLink).addChild(aCurUser.getLoginName()));
      aRow.addCell(new HCA(aViewLink).addChild(aCurUser.getEmailAddress()));

      // User groups
      final Collection<IUserGroup> aUserGroups =
          aMgr.getAllUserGroupsWithAssignedUser(aCurUser.getID());
      final StringBuilder aUserGroupsStr = new StringBuilder();
      for (final IUserGroup aUserGroup :
          ContainerHelper.getSorted(
              aUserGroups, new ComparatorHasName<IUserGroup>(aDisplayLocale))) {
        if (aUserGroupsStr.length() > 0) aUserGroupsStr.append(", ");
        aUserGroupsStr.append(aUserGroup.getName());
      }
      aRow.addCell(new HCA(aViewLink).addChild(aUserGroupsStr.toString()));

      final IHCCell<?> aActionCell = aRow.addCell();

      // Edit user
      if (isEditAllowed(aCurUser)) aActionCell.addChild(createEditLink(aCurUser, aDisplayLocale));
      else aActionCell.addChild(createEmptyAction());

      // Copy
      aActionCell.addChild(createCopyLink(aCurUser, aDisplayLocale));

      // Reset password of user
      if (canResetPassword(aCurUser)) {
        aActionCell.addChild(
            new HCA(
                    LinkUtils.getSelfHref()
                        .add(CHCParam.PARAM_ACTION, ACTION_RESET_PASSWORD)
                        .add(CHCParam.PARAM_OBJECT, aCurUser.getID()))
                .setTitle(
                    EText.TITLE_RESET_PASSWORD.getDisplayTextWithArgs(
                        aDisplayLocale, SecurityUI.getUserDisplayName(aCurUser, aDisplayLocale)))
                .addChild(getResetPasswordIcon()));
      } else aActionCell.addChild(createEmptyAction());
    }

    final HCNodeList aNodeList = new HCNodeList();
    aNodeList.addChild(aTable);

    final DataTables aDataTables = getStyler().createDefaultDataTables(aTable, aDisplayLocale);
    aDataTables.getOrCreateColumnOfTarget(3).addClass(CSS_CLASS_ACTION_COL).setSortable(false);
    aDataTables.setInitialSorting(1, ESortOrder.ASCENDING);
    aNodeList.addChild(aDataTables);

    // Required for best layout inside a tab!
    aTable.removeAllColumns();

    return aNodeList;
  }
コード例 #2
0
  @SuppressWarnings("null")
  @Override
  protected void showInputForm(
      @Nonnull final WebPageExecutionContext aWPEC,
      @Nullable final IUser aSelectedObject,
      @Nonnull final HCForm aForm,
      final boolean bEdit,
      final boolean bCopy,
      @Nonnull final FormErrors aFormErrors) {
    if (bEdit && !isEditAllowed(aSelectedObject)) throw new IllegalStateException("Won't work!");

    final boolean bIsAdministrator = aSelectedObject != null && aSelectedObject.isAdministrator();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final AccessManager aMgr = AccessManager.getInstance();
    final IHCTableForm<?> aTable =
        aForm.addAndReturnChild(
            getStyler().createTableForm(new HCCol(170), HCCol.star(), new HCCol(20)));
    aTable.setSpanningHeaderContent(
        bEdit
            ? EText.TITLE_EDIT.getDisplayTextWithArgs(
                aDisplayLocale, SecurityUI.getUserDisplayName(aSelectedObject, aDisplayLocale))
            : EText.TITLE_CREATE.getDisplayText(aDisplayLocale));

    if (!useEmailAddressAsLoginName()) {
      final String sLoginName = EText.LABEL_LOGINNAME.getDisplayText(aDisplayLocale);
      aTable
          .createItemRow()
          .setLabelMandatory(sLoginName)
          .setCtrl(
              new HCEdit(
                      new RequestField(
                          FIELD_LOGINNAME,
                          aSelectedObject == null ? null : aSelectedObject.getLoginName()))
                  .setPlaceholder(sLoginName))
          .setErrorList(aFormErrors.getListOfField(FIELD_LOGINNAME));
    }

    {
      final String sFirstName = EText.LABEL_FIRSTNAME.getDisplayText(aDisplayLocale);
      aTable
          .createItemRow()
          .setLabel(sFirstName)
          .setCtrl(
              new HCEdit(
                      new RequestField(
                          FIELD_FIRSTNAME,
                          aSelectedObject == null ? null : aSelectedObject.getFirstName()))
                  .setPlaceholder(sFirstName))
          .setErrorList(aFormErrors.getListOfField(FIELD_FIRSTNAME));
    }

    {
      final String sLastName = EText.LABEL_LASTNAME.getDisplayText(aDisplayLocale);
      aTable
          .createItemRow()
          .setLabel(sLastName, isLastNameMandatory() ? ELabelType.MANDATORY : ELabelType.OPTIONAL)
          .setCtrl(
              new HCEdit(
                      new RequestField(
                          FIELD_LASTNAME,
                          aSelectedObject == null ? null : aSelectedObject.getLastName()))
                  .setPlaceholder(sLastName))
          .setErrorList(aFormErrors.getListOfField(FIELD_LASTNAME));
    }

    {
      final String sEmail = EText.LABEL_EMAIL.getDisplayText(aDisplayLocale);
      aTable
          .createItemRow()
          .setLabel(sEmail, isEmailMandatory() ? ELabelType.MANDATORY : ELabelType.OPTIONAL)
          .setCtrl(
              new HCEdit(
                      new RequestField(
                          FIELD_EMAILADDRESS,
                          aSelectedObject == null ? null : aSelectedObject.getEmailAddress()))
                  .setPlaceholder(sEmail))
          .setErrorList(aFormErrors.getListOfField(FIELD_EMAILADDRESS));
    }

    if (!bEdit) {
      // Password is only shown on creation of a new user
      final boolean bHasAnyPasswordConstraint =
          GlobalPasswordSettings.getPasswordConstraintList().hasConstraints();

      final String sPassword = EText.LABEL_PASSWORD.getDisplayText(aDisplayLocale);
      aTable
          .createItemRow()
          .setLabel(
              sPassword, bHasAnyPasswordConstraint ? ELabelType.MANDATORY : ELabelType.OPTIONAL)
          .setCtrl(new HCEditPassword(FIELD_PASSWORD).setPlaceholder(sPassword))
          .setNote(SecurityUI.createPasswordConstraintTip(aDisplayLocale))
          .setErrorList(aFormErrors.getListOfField(FIELD_PASSWORD));

      final String sPasswordConfirm = EText.LABEL_PASSWORD_CONFIRM.getDisplayText(aDisplayLocale);
      aTable
          .createItemRow()
          .setLabel(
              sPasswordConfirm,
              bHasAnyPasswordConstraint ? ELabelType.MANDATORY : ELabelType.OPTIONAL)
          .setCtrl(new HCEditPassword(FIELD_PASSWORD_CONFIRM).setPlaceholder(sPasswordConfirm))
          .setNote(SecurityUI.createPasswordConstraintTip(aDisplayLocale))
          .setErrorList(aFormErrors.getListOfField(FIELD_PASSWORD_CONFIRM));
    }

    if (bIsAdministrator) {
      // Cannot edit enabled state of administrator
      aTable
          .createItemRow()
          .setLabel(EText.LABEL_ENABLED.getDisplayText(aDisplayLocale))
          .setCtrl(EWebBasicsText.getYesOrNo(aSelectedObject.isEnabled(), aDisplayLocale));
    } else {
      aTable
          .createItemRow()
          .setLabelMandatory(EText.LABEL_ENABLED.getDisplayText(aDisplayLocale))
          .setCtrl(
              new HCCheckBox(
                  new RequestFieldBoolean(
                      FIELD_ENABLED,
                      aSelectedObject == null ? DEFAULT_ENABLED : aSelectedObject.isEnabled())))
          .setErrorList(aFormErrors.getListOfField(FIELD_ENABLED));
    }

    {
      final Collection<String> aUserGroupIDs =
          aSelectedObject == null
              ? aWPEC.getAttrs(FIELD_USERGROUPS)
              : aMgr.getAllUserGroupIDsWithAssignedUser(aSelectedObject.getID());
      final UserGroupForUserSelect aSelect =
          new UserGroupForUserSelect(
              new RequestField(FIELD_USERGROUPS), aDisplayLocale, aUserGroupIDs);
      aTable
          .createItemRow()
          .setLabelMandatory(EText.LABEL_USERGROUPS_0.getDisplayText(aDisplayLocale))
          .setCtrl(aSelect)
          .setErrorList(aFormErrors.getListOfField(FIELD_USERGROUPS));
      if (bIsAdministrator) {
        // Cannot edit user groups of administrator
        aSelect.setReadonly(true);
      }
      showInputFormModifyUserGroupSelect(aSelect);
    }

    // Custom overridable
    showInputFormEnd(aWPEC, aSelectedObject, aForm, bEdit, bCopy, aFormErrors, aTable);
  }
コード例 #3
0
  @Override
  protected boolean handleCustomActions(
      @Nonnull final WebPageExecutionContext aWPEC, @Nullable final IUser aSelectedObject) {
    if (aWPEC.hasAction(ACTION_RESET_PASSWORD) && aSelectedObject != null) {
      if (!canResetPassword(aSelectedObject)) throw new IllegalStateException("Won't work!");

      final Locale aDisplayLocale = aWPEC.getDisplayLocale();
      final boolean bShowForm = true;
      final FormErrors aFormErrors = new FormErrors();
      if (aWPEC.hasSubAction(ACTION_PERFORM)) {
        final String sPlainTextPassword = aWPEC.getAttr(FIELD_PASSWORD);
        final String sPlainTextPasswordConfirm = aWPEC.getAttr(FIELD_PASSWORD_CONFIRM);

        final List<String> aPasswordErrors =
            GlobalPasswordSettings.getPasswordConstraintList()
                .getInvalidPasswordDescriptions(sPlainTextPassword, aDisplayLocale);
        for (final String sPasswordError : aPasswordErrors)
          aFormErrors.addFieldError(FIELD_PASSWORD, sPasswordError);
        if (!EqualsUtils.equals(sPlainTextPassword, sPlainTextPasswordConfirm))
          aFormErrors.addFieldError(
              FIELD_PASSWORD_CONFIRM,
              EText.ERROR_PASSWORDS_DONT_MATCH.getDisplayText(aDisplayLocale));

        if (aFormErrors.isEmpty()) {
          AccessManager.getInstance().setUserPassword(aSelectedObject.getID(), sPlainTextPassword);
          aWPEC
              .getNodeList()
              .addChild(
                  getStyler()
                      .createSuccessBox(
                          EText.SUCCESS_RESET_PASSWORD.getDisplayTextWithArgs(
                              aDisplayLocale,
                              SecurityUI.getUserDisplayName(aSelectedObject, aDisplayLocale))));
          return true;
        }
      }
      if (bShowForm) {
        // Show input form
        final boolean bHasAnyPasswordConstraint =
            GlobalPasswordSettings.getPasswordConstraintList().hasConstraints();
        final HCForm aForm = aWPEC.getNodeList().addAndReturnChild(createFormSelf());
        final IHCTableForm<?> aTable =
            aForm.addAndReturnChild(
                getStyler().createTableForm(new HCCol(200), HCCol.star(), new HCCol(20)));
        aTable.setSpanningHeaderContent(
            EText.TITLE_RESET_PASSWORD.getDisplayTextWithArgs(
                aDisplayLocale, SecurityUI.getUserDisplayName(aSelectedObject, aDisplayLocale)));

        final String sPassword = EText.LABEL_PASSWORD.getDisplayText(aDisplayLocale);
        aTable
            .createItemRow()
            .setLabel(
                sPassword, bHasAnyPasswordConstraint ? ELabelType.MANDATORY : ELabelType.OPTIONAL)
            .setCtrl(new HCEditPassword(FIELD_PASSWORD).setPlaceholder(sPassword))
            .setNote(SecurityUI.createPasswordConstraintTip(aDisplayLocale))
            .setErrorList(aFormErrors.getListOfField(FIELD_PASSWORD));

        final String sPasswordConfirm = EText.LABEL_PASSWORD_CONFIRM.getDisplayText(aDisplayLocale);
        aTable
            .createItemRow()
            .setLabel(
                sPasswordConfirm,
                bHasAnyPasswordConstraint ? ELabelType.MANDATORY : ELabelType.OPTIONAL)
            .setCtrl(new HCEditPassword(FIELD_PASSWORD_CONFIRM).setPlaceholder(sPasswordConfirm))
            .setNote(SecurityUI.createPasswordConstraintTip(aDisplayLocale))
            .setErrorList(aFormErrors.getListOfField(FIELD_PASSWORD_CONFIRM));

        final IButtonToolbar<?> aToolbar = aForm.addAndReturnChild(getStyler().createToolbar());
        aToolbar.addHiddenField(CHCParam.PARAM_ACTION, ACTION_RESET_PASSWORD);
        aToolbar.addHiddenField(CHCParam.PARAM_OBJECT, aSelectedObject.getID());
        aToolbar.addHiddenField(CHCParam.PARAM_SUBACTION, ACTION_PERFORM);
        aToolbar.addSubmitButtonSave(aDisplayLocale);
        aToolbar.addButtonCancel(aDisplayLocale);
      }
      return false;
    }
    return true;
  }
コード例 #4
0
  @Override
  @SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
  protected void showSelectedObject(
      @Nonnull final WebPageExecutionContext aWPEC, @Nonnull final IUser aSelectedObject) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final AccessManager aMgr = AccessManager.getInstance();
    final IHCTableFormView<?> aTable =
        aNodeList.addAndReturnChild(getStyler().createTableFormView(new HCCol(170), HCCol.star()));
    aTable.setSpanningHeaderContent(
        EText.HEADER_DETAILS.getDisplayTextWithArgs(
            aDisplayLocale, SecurityUI.getUserDisplayName(aSelectedObject, aDisplayLocale)));
    onShowSelectedObjectTableStart(aTable, aSelectedObject, aDisplayLocale);
    if (!useEmailAddressAsLoginName()) {
      aTable
          .createItemRow()
          .setLabel(EText.LABEL_LOGINNAME.getDisplayText(aDisplayLocale))
          .setCtrl(aSelectedObject.getLoginName());
    }
    aTable
        .createItemRow()
        .setLabel(EText.LABEL_FIRSTNAME.getDisplayText(aDisplayLocale))
        .setCtrl(aSelectedObject.getFirstName());
    aTable
        .createItemRow()
        .setLabel(EText.LABEL_LASTNAME.getDisplayText(aDisplayLocale))
        .setCtrl(aSelectedObject.getLastName());
    aTable
        .createItemRow()
        .setLabel(EText.LABEL_EMAIL.getDisplayText(aDisplayLocale))
        .setCtrl(getStyler().createEmailLink(aSelectedObject.getEmailAddress()));
    aTable
        .createItemRow()
        .setLabel(EText.LABEL_ENABLED.getDisplayText(aDisplayLocale))
        .setCtrl(EWebBasicsText.getYesOrNo(aSelectedObject.isEnabled(), aDisplayLocale));
    aTable
        .createItemRow()
        .setLabel(EText.LABEL_DELETED.getDisplayText(aDisplayLocale))
        .setCtrl(EWebBasicsText.getYesOrNo(aSelectedObject.isDeleted(), aDisplayLocale));
    aTable
        .createItemRow()
        .setLabel(EText.LABEL_LAST_LOGIN.getDisplayText(aDisplayLocale))
        .setCtrl(
            aSelectedObject.getLastLoginDateTime() != null
                ? new HCTextNode(
                    PDTToString.getAsString(aSelectedObject.getLastLoginDateTime(), aDisplayLocale))
                : HCEM.create(EText.LABEL_LAST_LOGIN_NEVER.getDisplayText(aDisplayLocale)));
    aTable
        .createItemRow()
        .setLabel(EText.LABEL_LOGIN_COUNT.getDisplayText(aDisplayLocale))
        .setCtrl(Integer.toString(aSelectedObject.getLoginCount()));
    aTable
        .createItemRow()
        .setLabel(EText.LABEL_CONSECUTIVE_FAILED_LOGIN_COUNT.getDisplayText(aDisplayLocale))
        .setCtrl(Integer.toString(aSelectedObject.getConsecutiveFailedLoginCount()));

    // user groups
    final Collection<IUserGroup> aUserGroups =
        aMgr.getAllUserGroupsWithAssignedUser(aSelectedObject.getID());
    if (aUserGroups.isEmpty()) {
      aTable
          .createItemRow()
          .setLabel(EText.LABEL_USERGROUPS_0.getDisplayText(aDisplayLocale))
          .setCtrl(HCEM.create(EText.NONE_DEFINED.getDisplayText(aDisplayLocale)));
    } else {
      final HCNodeList aUserGroupUI = new HCNodeList();
      for (final IUserGroup aUserGroup :
          ContainerHelper.getSorted(aUserGroups, new ComparatorHasName<IUserGroup>(aDisplayLocale)))
        aUserGroupUI.addChild(HCDiv.create(aUserGroup.getName()));
      aTable
          .createItemRow()
          .setLabel(
              EText.LABEL_USERGROUPS_N.getDisplayTextWithArgs(
                  aDisplayLocale, Integer.toString(aUserGroups.size())))
          .setCtrl(aUserGroupUI);
    }

    // roles
    final Set<IRole> aUserRoles = aMgr.getAllUserRoles(aSelectedObject.getID());
    if (aUserRoles.isEmpty()) {
      aTable
          .createItemRow()
          .setLabel(EText.LABEL_ROLES_0.getDisplayText(aDisplayLocale))
          .setCtrl(HCEM.create(EText.NONE_DEFINED.getDisplayText(aDisplayLocale)));
    } else {
      final HCNodeList aRoleUI = new HCNodeList();
      for (final IRole aRole :
          ContainerHelper.getSorted(aUserRoles, new ComparatorHasName<IRole>(aDisplayLocale)))
        aRoleUI.addChild(HCDiv.create(aRole.getName()));
      aTable
          .createItemRow()
          .setLabel(
              EText.LABEL_ROLES_N.getDisplayTextWithArgs(
                  aDisplayLocale, Integer.toString(aUserRoles.size())))
          .setCtrl(aRoleUI);
    }

    // custom attributes
    final Map<String, Object> aCustomAttrs = aSelectedObject.getAllAttributes();

    // Callback
    final Set<String> aHandledAttrs =
        showCustomAttrsOfSelectedObject(aSelectedObject, aCustomAttrs, aTable, aDisplayLocale);

    if (!aCustomAttrs.isEmpty()) {
      final IHCTable<?> aAttrTable = getStyler().createTable(new HCCol(170), HCCol.star());
      aAttrTable
          .addHeaderRow()
          .addCells(
              EText.HEADER_NAME.getDisplayText(aDisplayLocale),
              EText.HEADER_VALUE.getDisplayText(aDisplayLocale));
      for (final Map.Entry<String, Object> aEntry : aCustomAttrs.entrySet()) {
        final String sName = aEntry.getKey();
        if (aHandledAttrs == null || !aHandledAttrs.contains(sName)) {
          final String sValue = String.valueOf(aEntry.getValue());
          aAttrTable.addBodyRow().addCells(sName, sValue);
        }
      }

      // Maybe all custom attributes where handled in
      // showCustomAttrsOfSelectedObject
      if (aAttrTable.hasBodyRows())
        aTable
            .createItemRow()
            .setLabel(EText.LABEL_ATTRIBUTES.getDisplayText(aDisplayLocale))
            .setCtrl(aAttrTable);
    }

    // Callback
    onShowSelectedObjectTableEnd(aTable, aSelectedObject, aDisplayLocale);
  }