Beispiel #1
0
 protected boolean validateUserContext() {
   UserContext userContext = UserContext.getInstanceFromPageContext(pageContext);
   if (userContext.isImpersonating()) {
     userContext.restoreSession();
   }
   return userContext.hasRequiredRole(IUserManager.ROLE_EPAVIEWER);
 }
  protected ActionForward executeInContext(
      UserContext uc,
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response) {
    if (isCancelled(request)) {
      return mapping.findForward(SUCCESS);
    }
    ReplicationPassPhraseForm form = (ReplicationPassPhraseForm) actionForm;

    IReplicationSecurityManager rsm =
        ManagementContainer.getInstance().getReplicationSecurityManager();
    boolean isOk;
    String operation;
    if (form.isChange()) {
      operation = "change";
      isOk =
          rsm.changePassPhrase(
              uc.getCurrentCustomer().getCustID(), form.getOriginal(), form.getNewPassPhrase());
    } else {
      operation = "set";
      isOk = rsm.createKeyPair(uc.getCurrentCustomer().getCustID(), true, form.getNewPassPhrase());
    }

    if (!isOk) {
      reportSingleError(
          request, ActionMessages.GLOBAL_MESSAGE, "error.sr.passphrase.change.failed", operation);
      return mapping.findForward(FAILURE);
    }

    return mapping.findForward(SUCCESS);
  }
Beispiel #3
0
  protected boolean renderHeader() throws ServletException, IOException {
    if (!isLoggedOn()) {
      pageContext.setAttribute(
          "ems.header.logo",
          BrandManager.DEFAULT_HEADER_LOGO + ".gif",
          //
          // BrandingSettings.getInstance().getHeaderLogo() + ".gif",
          PageContext.REQUEST_SCOPE);
      pageContext.include("/WEB-INF/jspf/common/templates/page/CappEmptyHeader.jspf");
      return true;
    }

    pageContext.getResponse().setCharacterEncoding("UTF-8");

    UserContext userContext = UserContext.getInstanceFromPageContext(pageContext);
    Customer customer = userContext.getCurrentCustomer();
    pageContext.setAttribute("user", userContext.getCurrentUser());
    pageContext.setAttribute("customer", customer);

    // figure out which header to user
    pageContext.setAttribute("user", userContext.getCurrentUser());
    pageContext.setAttribute("ems.header.logoff", "epalogoff.do", PageContext.REQUEST_SCOPE);
    pageContext.setAttribute("ems.header.home", "customerSearch.do", PageContext.REQUEST_SCOPE);
    pageContext.setAttribute(
        "ems.header.logo",
        BrandManager.DEFAULT_HEADER_LOGO + "_epa.gif",
        // BrandingSettings.getInstance().getHeaderLogo() + "_epa.gif",
        PageContext.REQUEST_SCOPE);
    pageContext.include("/WEB-INF/jspf/common/templates/page/CappHeader.jspf");
    return true;
  }
Beispiel #4
0
  @Test
  public void testDescribeUserSetChanges() throws Exception {
    String changes = null;

    HttpSession httpSession = getSession();
    UserContext.newContext(getRequest(), m_user, m_customer);

    changes = DiffUtils.describeUserSetChanges(null, null, null);
    assertNull("DiffUtils.describeUserSetChanges(null, null, null) should return null", changes);

    SavedUserSet susOld = new SavedUserSet(m_customer.getCustID());
    SavedUserSet susNew = new SavedUserSet(m_customer.getCustID());

    changes = DiffUtils.describeUserSetChanges(getRequest(), susOld, susNew);
    assertNull("Expected no diffs for 2 identical user sets", changes);

    List<SearchConstraint> constraints;
    constraints = new ArrayList<SearchConstraint>();
    constraints.add(
        new SearchConstraint(
            IUserManager.PROP_USERID,
            SearchConstraintOperator.CONSTRAINT_EQUALS,
            m_user.getUserID()));

    susNew.addUsers(constraints);

    changes = DiffUtils.describeUserSetChanges(getRequest(), susOld, susNew);
    assertNotNull("Expected diffs on 2 different user sets", changes);
  }
  @Override
  protected ActionForward executeInContext(
      final UserContext userContext,
      final ActionMapping mapping,
      final LookaheadDeleteDataForm form,
      final HttpServletRequest request,
      final HttpServletResponse response)
      throws IOException {
    int userId = userContext.getActualUserID();

    LOGGER.debug(
        "Performing lookahead delete for userid="
            + userId
            + ", field='"
            + form.getField()
            + "', toDelete='"
            + form.getToDelete());
    try {
      int count =
          getLookaheadManager().deleteSpecificValue(userId, form.getField(), form.getToDelete());
      LOGGER.debug(count + " items deleted.");
    } catch (Exception ex) {
      LOGGER.error(
          "Failed lookahead delete for userid="
              + userId
              + ", field='"
              + form.getField()
              + "', toDelete='"
              + form.getToDelete(),
          ex);
      throw new IllegalStateException(ex);
    }
    return null;
  }
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws IOException {
    ManagementContainer container = ManagementContainer.getInstance();
    IAuthenticationManager am = container.getAuthenticationManager();
    HttpSession session = request.getSession();
    Integer userIdObj = (Integer) session.getAttribute(REQUEST_ID);
    if (userIdObj == null) {
      reportSingleError(request, "login", "errors.login.invalid");
      return mapping.findForward(FAILURE);
    }

    int userID = userIdObj.intValue();
    UserLoginResult result = am.checkLoginStatus(userID);
    if (result.getStatus() == LoginStatus.AUTH_PENDING) {
      return mapping.findForward("logon.wait");
    }
    session.removeAttribute(REQUEST_ID);
    if (result.getStatus() == LoginStatus.AUTH_FAILED) {
      reportSingleError(request, "login", "errors.login.invalid");
      return mapping.findForward(FAILURE);
    }

    UserContext.newContext(request, result.getUser(), result.getCustomer());

    if (result.getStatus() == LoginStatus.AUTH_OK) {
      LogonUtils.configureBranding(request, response, result.getCustomer());
    }

    return successfulLoginForward(request, response, mapping, actionForm, result);
  }
Beispiel #7
0
  public ActionForward executeInContext(
      UserContext uc,
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response) {
    int uid = Integer.parseInt(request.getParameter(Constants.USER_ID_FULL));
    int custID = Integer.parseInt(request.getParameter(Constants.CUSTOMER_ID));
    IUserManager um = ManagementContainer.getInstance().getUserManager();

    UserAccount user = um.getUserAccount(custID, uid);

    if (user == null) {
      return mapping.findForward(FAILURE);
    }

    try {
      um.deleteEpaUser(user.getPrimaryEmail());
    } catch (Exception ex) {
      reportSingleError(
          request, ActionMessages.GLOBAL_MESSAGE, "error.epa.user.delete.error", ex.getMessage());
      return mapping.findForward(FAILURE);
    }

    IAuditManager auditManager = ManagementContainer.getInstance().getAuditManager();
    auditManager.saveAudit(
        IAuditManager.AuditCategory.EPA_MGMT,
        "Removed EPA user " + user.getDisplayName() + " ( " + user.getPrimaryEmail() + " )",
        "Remove EPA User Audit",
        null,
        uc.getCurrentUser().getPrimaryEmail());
    return mapping.findForward(SUCCESS);
  }
Beispiel #8
0
  private List<Task> getTasksToDisplay() {
    final List<Task> tasksToDisplay = new LinkedList<Task>();

    final UserContext userContext = UserContext.getInstanceFromPageContext(pageContext);
    final boolean isAdmin = userContext.hasRequiredRole(IUserManager.ROLE_ADMIN);

    final ITaskManager taskManager = ManagementContainer.getInstance().getTaskManager();
    final Calendar whenCompleted = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    whenCompleted.setTime((Date) pageContext.getSession().getAttribute("ems.session.start.time"));
    whenCompleted.add(Calendar.DAY_OF_YEAR, -1);
    final Date searchDate = whenCompleted.getTime();
    final List<Task> tasks =
        taskManager.getDisplayedTasks(userContext.getCurrentCustomer().getCustID(), searchDate);

    final IReviewerGroupManager rgm = ManagementContainer.getInstance().getReviewerGroupManager();
    final Collection<ReviewerGroup> reviewerGroups =
        rgm.getReviewerGroups(
            userContext.getCurrentCustomer().getCustID(), userContext.getActualUser().getUserID());

    final List<Integer> reviewerGroupIdList =
        CollectionBuilder.buildList(reviewerGroups, ReviewerGroup.getReviewerGroupIdFunction());

    for (final Task task : tasks) {
      if (isAdmin
          || userContext.getActualUser().getUserID() == task.getUserID()
          || reviewerGroupIdList.contains(task.getInternalData())) {
        if (getType() == null || getType().equals(task.getType())) {
          tasksToDisplay.add(task);
        }
      }
    }

    return tasksToDisplay;
  }
  protected ActionForward executeInContext(
      UserContext uc,
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response) {
    UserEmergencyContactsForm form = (UserEmergencyContactsForm) actionForm;
    IUserManager userManager = ManagementContainer.getInstance().getUserManager();
    EmergencyContactSet contactSets =
        userManager.getEmergencyContacts(uc.getCurrentUser().getUserID());
    if (contactSets != null) {
      form.populateForm(contactSets);
    }

    return mapping.findForward(SUCCESS);
  }
Beispiel #10
0
  @Test
  public void testDescribeReviewerGroupReviewerChanges() throws Exception {
    String changes = null;

    UserContext.newContext(getRequest(), m_user, m_customer);

    changes = DiffUtils.describeReviewerGroupReviewerChanges(null, null, null);
    assertNull(
        "DiffUtils.describeReviewerGroupReviewerChanges(null, null, null) should return null",
        changes);

    List<SearchConstraint> constraints;
    constraints = new ArrayList<SearchConstraint>();
    constraints.add(
        new SearchConstraint(
            IUserManager.PROP_USERID,
            SearchConstraintOperator.CONSTRAINT_EQUALS,
            m_user.getUserID()));

    SavedUserSet reviewers = new SavedUserSet(m_customer.getCustID());
    reviewers.addUsers(constraints);

    ReviewerGroup oldRG =
        new ReviewerGroup(m_customer.getCustID(), 1, "name", reviewers, null, "extra");
    ReviewerGroup newRG =
        new ReviewerGroup(m_customer.getCustID(), 1, "name", reviewers, null, "extra");

    changes = DiffUtils.describeReviewerGroupReviewerChanges(getRequest(), oldRG, newRG);
    assertNull("Expected no diffs for 2 identical user sets", changes);

    reviewers = new SavedUserSet(m_customer.getCustID());
    newRG.setReviewers(reviewers);

    changes = DiffUtils.describeReviewerGroupReviewerChanges(getRequest(), oldRG, newRG);
    assertNotNull("Expected diffs on 2 different reviewer groups", changes);

    SavedUserSet reviewers1 = new SavedUserSet(m_customer.getCustID());
    reviewers1.addConstraintSets(InternalUserSets.getAllUsersSet(m_customer.getCustID()));
    oldRG.setReviewers(reviewers1);

    SavedUserSet reviewers2 = new SavedUserSet(m_customer.getCustID());
    newRG.setReviewers(reviewers2);

    changes = DiffUtils.describeReviewerGroupReviewerChanges(getRequest(), oldRG, newRG);
    assertNotNull("Expected diffs on 2 different reviewer groups", changes);
  }
Beispiel #11
0
  /**
   * override for testing
   *
   * @return utils object
   */
  protected ActionForward executeInContext(
      UserContext uc,
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {

    int customerId = uc.getCurrentCustomer().getCustID();

    String statistic = request.getParameter(STATISTICS);
    String interval = request.getParameter(INTERVAL);

    try {
      List<IndexingStats> data = getIndexingStatsData(interval, customerId);
      List<List<Object>> out = formatClientData(statistic, data);
      String content = new ObjectMapper().writeValueAsString(out);
      writeJSON(response, content);
    } catch (Exception e) {
      writeError("Error marshaling response", e.getMessage(), response);
    }

    return mapping.findForward(SUCCESS);
  }