コード例 #1
0
  protected void processServicePrePrincipalException(
      Throwable t, long userId, HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {

    if (userId > 0) {
      sendError(HttpServletResponse.SC_UNAUTHORIZED, t, request, response);

      return;
    }

    String redirect = PortalUtil.getPathMain().concat("/portal/login");

    String currentURL = PortalUtil.getCurrentURL(request);

    redirect = HttpUtil.addParameter(redirect, "redirect", currentURL);

    long plid = ParamUtil.getLong(request, "p_l_id");

    if (plid > 0) {
      try {
        Layout layout = LayoutLocalServiceUtil.getLayout(plid);

        Group group = layout.getGroup();

        plid = group.getDefaultPublicPlid();

        if ((plid == LayoutConstants.DEFAULT_PLID) || group.isStagingGroup()) {

          Group guestGroup =
              GroupLocalServiceUtil.getGroup(layout.getCompanyId(), GroupConstants.GUEST);

          plid = guestGroup.getDefaultPublicPlid();
        }

        redirect = HttpUtil.addParameter(redirect, "p_l_id", plid);
      } catch (Exception e) {
      }
    }

    response.sendRedirect(redirect);
  }