/** {@inheritDoc} */
 public boolean validate(HttpServletRequest request, HttpServletResponse response) {
   if (requestURIRequiresAuthentication(request)) {
     if (isAuthenticationRequired(request)) {
       invalidate(request, response);
       return false;
     }
     // If URL requires auth and we are authenticated refresh the session.
     // We don't refresh when the URL doesn't require auth because
     // that may invalidate our old session
     pxtDelegate.refreshPxtSession(request, response);
   }
   return true;
 }
Example #2
0
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {

    if (CertificateManager.getInstance().isSatelliteCertExpired()) {
      addMessage(request, "satellite.expired");
      request.setAttribute(LoginSetupAction.HAS_EXPIRED, new Boolean(true));
      return mapping.findForward("failure");
    }

    ActionForward ret = null;
    DynaActionForm f = (DynaActionForm) form;

    // Validate the form
    ActionErrors errors = RhnValidationHelper.validateDynaActionForm(this, f);
    if (!errors.isEmpty()) {
      performGracePeriodCheck(request);
      addErrors(request, errors);
      return mapping.findForward("failure");
    }
    String username = (String) f.get("username");
    String password = (String) f.get("password");
    String urlBounce = (String) f.get("url_bounce");

    ActionErrors e = new ActionErrors();
    User user = loginUser(username, password, request, response, e);
    RequestContext ctx = new RequestContext(request);

    if (e.isEmpty()) {
      if (urlBounce == null || urlBounce.trim().equals("")) {
        if (log.isDebugEnabled()) {
          log.debug("2 - url bounce is empty using [" + DEFAULT_URL_BOUNCE + "]");
        }
        urlBounce = DEFAULT_URL_BOUNCE;
      }
      if (urlBounce.trim().endsWith("Logout.do")) {
        if (log.isDebugEnabled()) {
          log.debug(" - handling special case of url_bounce=Logout.do");
        }
        urlBounce = DEFAULT_URL_BOUNCE;
      }
      if (user != null) {
        try {
          publishUpdateErrataCacheEvent(user.getOrg());
        } catch (ConstraintViolationException ex) {
          log.error(ex);
          User loggedInUser = ctx.getLoggedInUser();
          if (loggedInUser != null) {
            request.setAttribute("loggedInUser", loggedInUser.getLogin());
          }
          ret = mapping.findForward("error");
          return ret;
        }
      }

      if (log.isDebugEnabled()) {
        log.debug("5 - redirecting to [" + urlBounce + "]");
      }
      if (user != null) {
        pxtDelegate.updateWebUserId(request, response, user.getId());

        try {
          response.sendRedirect(urlBounce);
          return null;
        } catch (IOException ioe) {
          throw new RuntimeException("Exception while trying to redirect: " + ioe);
        }
      }
    } else {
      if (log.isDebugEnabled()) {
        log.debug("6 - forwarding to failure");
      }

      performGracePeriodCheck(request);

      addErrors(request, e);
      request.setAttribute("url_bounce", urlBounce);
      ret = mapping.findForward("failure");
    }
    if (log.isDebugEnabled()) {
      log.debug("7 - returning");
    }
    return ret;
  }
 /** {@inheritDoc} */
 public void invalidate(HttpServletRequest request, HttpServletResponse response) {
   pxtDelegate.invalidatePxtSession(request, response);
 }
 private boolean isAuthenticationRequired(HttpServletRequest request) {
   return (!pxtDelegate.isPxtSessionKeyValid(request)
       || pxtDelegate.isPxtSessionExpired(request)
       || pxtDelegate.getWebUserId(request) == null);
 }