@Override
  public void handle() throws FacesException {
    for (Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator();
        i.hasNext(); ) {
      ExceptionQueuedEvent event = i.next();
      ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();

      Throwable t = context.getException();
      if (t instanceof ViewExpiredException) {
        ViewExpiredException vee = (ViewExpiredException) t;
        FacesContext facesContext = FacesContext.getCurrentInstance();
        Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
        NavigationHandler navigationHandler = facesContext.getApplication().getNavigationHandler();
        try {
          // Push some useful stuff to the request scope for use in the page
          requestMap.put("currentViewId", vee.getViewId());
          navigationHandler.handleNavigation(facesContext, null, "/viewExpired");
          facesContext.renderResponse();
        } finally {
          i.remove();
        }
      }
    }

    // At this point, the queue will not contain any ViewExpiredEvents. Therefore, let the parent
    // handle them.
    getWrapped().handle();
  }
  public static void forward(String jsfPageForward) {

    FacesContext fc = FacesContext.getCurrentInstance();

    NavigationHandler nh = fc.getApplication().getNavigationHandler();

    nh.handleNavigation(fc, null, jsfPageForward);
  }
 public void check() {
   final FacesContext facesContext = FacesContext.getCurrentInstance();
   final HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(true);
   final String currentUser = (String) session.getAttribute(LoginController.LOGIN_KEY);
   if (currentUser == null || currentUser.length() == 0) {
     final NavigationHandler navigationHandler =
         facesContext.getApplication().getNavigationHandler();
     navigationHandler.handleNavigation(facesContext, null, LoginController.LOGIN_VIEW);
   }
 }
 @Override
 public void afterPhase(PhaseEvent event) {
   FacesContext facesContext = event.getFacesContext();
   String currentPage = facesContext.getViewRoot().getViewId();
   boolean isLoginPage = (currentPage.lastIndexOf("/login.xhtml") > -1) ? true : false;
   HttpSession sesion = (HttpSession) facesContext.getExternalContext().getSession(true);
   Object usuario = sesion.getAttribute("usuario");
   if (!isLoginPage && usuario == null) {
     NavigationHandler nh = facesContext.getApplication().getNavigationHandler();
     nh.handleNavigation(facesContext, null, "/login.xhtml");
   }
 }
  @Override
  public void afterPhase(PhaseEvent event) {
    FacesContext fc = event.getFacesContext();

    if (permite(fc)) {
    } else {
      // Verifica se esta na página principal
      boolean paginaLogin = fc.getViewRoot().getViewId().lastIndexOf("index") > -1 ? true : false;
      if (!paginaLogin) {
        NavigationHandler nh = fc.getApplication().getNavigationHandler();
        nh.handleNavigation(fc, null, "naologado");
      }
    }
  }
Example #6
0
  public void logout() {
    menu1 = false;
    menu2 = false;
    menu3 = false;
    adminBean.setLogin("");
    adminBean.setHaslo("");
    prowadzacyBean.setLogin("");
    prowadzacyBean.setPassword("");
    studentBean.setIndex(0);
    studentBean.setHaslo("");

    FacesContext context = FacesContext.getCurrentInstance();
    NavigationHandler navHandler = context.getApplication().getNavigationHandler();
    navHandler.handleNavigation(context, null, "zaloguj");
  }
 /**
  * Perform the navigation to the @LoginView. If not @LoginView is defined, return a 401 response.
  * The original view id requested by the user is stored in the session map, for use after a
  * successful login.
  *
  * @param context
  * @param viewRoot
  */
 private void redirectToLoginPage(FacesContext context, UIViewRoot viewRoot) {
   Map<String, Object> sessionMap = context.getExternalContext().getSessionMap();
   preLoginEvent.fire(new PreLoginEvent(context, sessionMap));
   LoginView loginView = viewConfigStore.getAnnotationData(viewRoot.getViewId(), LoginView.class);
   if (loginView == null || loginView.value() == null || loginView.value().isEmpty()) {
     log.debug("Returning 401 response (login required)");
     context.getExternalContext().setResponseStatus(401);
     context.responseComplete();
     return;
   }
   String loginViewId = loginView.value();
   log.debugf("Redirecting to configured LoginView %s", loginViewId);
   NavigationHandler navHandler = context.getApplication().getNavigationHandler();
   navHandler.handleNavigation(context, "", loginViewId);
   context.renderResponse();
 }
  /**
   * Show results.
   *
   * @throws Exception the exception
   */
  protected void showResults() throws Exception {
    FacesContextBroker broker = new FacesContextBroker();
    String dispatchTo = "";
    String tagName = "com.esri.gpt.control.filter.EncodingFilterTag";
    // will prevent going to front page
    this.getRequestContext().addToSession(tagName, "tag");
    HttpServletRequest httpReq = broker.extractHttpServletRequest();
    HttpServletResponse httpResp = broker.extractHttpServletResponse();
    FacesContext fctx = broker.getFacesContext();
    Application application = fctx.getApplication();

    if (this.isResultsOnly()) {
      dispatchTo = SEARCH_RESULTS_PAGE;

    } else {

      // TODO: Glassfish does not support this section (f=searchpage)
      NavigationHandler navHandler = application.getNavigationHandler();
      navHandler.handleNavigation(fctx, null, "catalog.search.results");
      dispatchTo = fctx.getViewRoot().getViewId();

      String jsfSuffix = SearchConfig.getConfiguredInstance().getJsfSuffix();
      if ("".equals(jsfSuffix)) {
        jsfSuffix = ".page";
      }
      if (jsfSuffix.indexOf('.') < 0) {
        jsfSuffix = "." + jsfSuffix;
      }
      // javax.faces.DEFAULT_SUFFIX
      dispatchTo = dispatchTo.replaceAll(".jsp", jsfSuffix);
      // ViewHandler.DEFAULT_SUFFIX_PARAM_NAME = jsfSuffix;
      // fctx.getExternalContext().dispatch(dispatchTo);
      // httpReq.getRequestDispatcher( dispatchTo).forward(httpReq, httpResp);

    }

    // Synching criteria with session criteria in thread so that search result
    // does
    // not have to wait for synch to complete.
    setExtraCriteriaProperties(httpReq);
    SynchSessionCriteria synchSc = new SynchSessionCriteria(criteria, this.readSessionCriteria());
    synchSc.synch();
    // Thread thread = new Thread(synchSc);
    // thread.start();
    jsfDispatchPage(fctx, dispatchTo);
  }
 /**
  * Perform the navigation to the @AccessDeniedView. If not @AccessDeniedView is defined, return a
  * 401 response
  *
  * @param context
  * @param viewRoot
  */
 private void redirectToAccessDeniedView(FacesContext context, UIViewRoot viewRoot) {
   AccessDeniedView accessDeniedView =
       viewConfigStore.getAnnotationData(viewRoot.getViewId(), AccessDeniedView.class);
   if (accessDeniedView == null
       || accessDeniedView.value() == null
       || accessDeniedView.value().isEmpty()) {
     log.debug("Returning 401 response (access denied)");
     context.getExternalContext().setResponseStatus(401);
     context.responseComplete();
     return;
   }
   String accessDeniedViewId = accessDeniedView.value();
   log.debugf("Redirecting to configured AccessDenied %s", accessDeniedViewId);
   NavigationHandler navHandler = context.getApplication().getNavigationHandler();
   navHandler.handleNavigation(context, "", accessDeniedViewId);
   context.renderResponse();
 }
  public void doIclubLogout() {

    String theme = "";
    String webTheme = "";
    if (IclubWebHelper.getObjectIntoSession(BUNDLE.getString("logged.in.user.theme")) != null) {
      theme =
          IclubWebHelper.getObjectIntoSession(BUNDLE.getString("logged.in.user.theme")).toString();
    }
    if (IclubWebHelper.getObjectIntoSession(BUNDLE.getString("logged.in.user.webTheme")) != null) {
      webTheme =
          IclubWebHelper.getObjectIntoSession(BUNDLE.getString("logged.in.user.webTheme"))
              .toString();
    }
    IclubWebHelper.invalidateSession();
    IclubWebHelper.addObjectIntoSession(BUNDLE.getString("logged.in.user.theme"), theme);
    IclubWebHelper.addObjectIntoSession(BUNDLE.getString("logged.in.user.webTheme"), webTheme);
    FacesContext context = FacesContext.getCurrentInstance();
    NavigationHandler navigationHandler = context.getApplication().getNavigationHandler();

    navigationHandler.handleNavigation(
        context, null, "/templates/login" + theme + ".xhtml?faces-redirect=true");

    String url = "https://testclientapi.fraudcheck.co.za/api/authenticate/test";
    String currentDate = System.currentTimeMillis() + "";

    String fcHash = DigestUtils.md5Hex(FRAUD_CHECK_USERID + FRAUD_CHECK_PWD + currentDate);

    HttpClient client = getHttpClient();

    try {
      HttpPost post = new HttpPost(url);
      post.setHeader("Content-Type", "application/json");
      post.setHeader("FcAccId", FRAUD_CHECK_USERID);
      post.setHeader("FcHash", fcHash);
      post.setHeader("FcDate", currentDate);

      List<NameValuePair> arguments = new ArrayList<>(3);
      arguments.add(new BasicNameValuePair("data", "test"));
      post.setEntity(new UrlEncodedFormEntity(arguments));
      HttpResponse response1 = client.execute(post);
      EntityUtils.toString(response1.getEntity());
    } catch (Exception e) {
      LOGGER.error(e, e);
    }
  }
 /**
  * @param context
  * @param ex
  * @throws IOException
  * @throws ServletException
  */
 public void handleException(final FacesContext context, final Exception ex) {
   // besoin d'exposer la requête pour y mettre dans la session le ExceptionService
   PortletRequest request = (PortletRequest) context.getExternalContext().getRequest();
   ContextUtils.exposeRequest(request);
   ExceptionUtils.markExceptionCaught();
   ExceptionService e = null;
   //		try {
   e = ExceptionUtils.catchException(ex);
   //		} catch (Throwable t) {
   //			handleExceptionHandlingException(t);
   //			// never reached, prevent from warnings
   //			return;
   //		}
   ExceptionUtils.markExceptionCaught(e);
   ContextUtils.unexposeRequest(request);
   NavigationHandler navigation = context.getApplication().getNavigationHandler();
   // Redirection vers la page des erreurs
   navigation.handleNavigation(context, "", e.getExceptionView());
 }
  @Override
  public void handle() throws FacesException {

    final Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator();
    while (i.hasNext()) {
      ExceptionQueuedEvent event = i.next();
      ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();

      // get the exception from context
      Throwable t = context.getException();

      final FacesContext fc = FacesContext.getCurrentInstance();
      final Map<String, Object> requestMap = fc.getExternalContext().getRequestMap();
      final NavigationHandler nav = fc.getApplication().getNavigationHandler();

      // here you do what ever you want with exception
      try {

        if (ExceptionUtils.getRootCause(t) instanceof AccessDeniedException) {
          throw (AccessDeniedException) ExceptionUtils.getRootCause(t);
        }

        log.error("złapano wyjątek: nieprzechwycony przez controller");
        log.error(t.getMessage(), t);
        t.printStackTrace();

        // redirect error page
        requestMap.put("exceptionMessage", t.getMessage());
        nav.handleNavigation(fc, null, "/error");
        fc.renderResponse();

        // remove the comment below if you want to report the error in a jsf error message
        //                JsfUtil.addErrorMessage(t.getMessage());

      } finally {
        // remove it from queue
        i.remove();
      }
    }
    // parent hanle
    getWrapped().handle();
  }
 public void renderView(FacesContext context, UIViewRoot viewRoot)
     throws IOException, FacesException {
   String viewId = viewRoot.getViewId();
   if (!context.getResponseComplete() && isMapped(viewId)) {
     NavigationHandler nh = context.getApplication().getNavigationHandler();
     ViewHandler vh = context.getApplication().getViewHandler();
     String action = (String) context.getExternalContext().getRequestParameterMap().get("action");
     String outcome =
         (String) context.getExternalContext().getRequestParameterMap().get("outcome");
     if (action != null) {
       String method = extractMethodName(action);
       MethodBinding mb =
           context.getApplication().createMethodBinding("#{" + action + "}", new Class[0]);
       outcome = mb.invoke(context, new Object[0]).toString();
       nh.handleNavigation(context, method, outcome);
       if (!context.getResponseComplete() && context.getViewRoot().equals(viewRoot)) {
         throw new FacesException(
             "No navigation rules from viewId="
                 + viewId
                 + ", action="
                 + action
                 + ", outcome="
                 + outcome
                 + " found.");
       }
     } else {
       nh.handleNavigation(context, null, outcome);
       if (!context.getResponseComplete() && context.getViewRoot().equals(viewRoot)) {
         throw new FacesException(
             "No navigation rules from viewId=" + viewId + ", outcome=" + outcome + " found.");
       }
     }
     if (!context.getResponseComplete()) {
       vh.renderView(context, context.getViewRoot());
     }
     ;
   } else {
     viewHandler.renderView(context, viewRoot);
   }
 }
  public void afterPhase(PhaseEvent event) {
    // System.out.println("no after "+ event.getPhaseId());

    FacesContext facesContext = event.getFacesContext();
    String currentPage = facesContext.getViewRoot().getViewId();
    // System.out.println("Imprime pagina atual: " + currentPage);

    boolean isLoginPage = (currentPage.lastIndexOf("login.jsp") > -1);
    HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(true);
    Object currentUser = session.getAttribute("currentUser");

    // System.out.println("pagina atual "+currentPage + " l " + isLoginPage + " u " + currentUser);

    if (!isLoginPage && currentUser == null) {
      System.out.println("no if do after ");
      NavigationHandler nh = facesContext.getApplication().getNavigationHandler();
      nh.handleNavigation(facesContext, null, "professor_voltaLogin");
    }
    /*  else {

                if (!isLoginPage && currentUser != null) {
                System.out.println("no if do after 2 ");

                if(!verificarAutorizacao(currentPage)){

    //seo usuario não possuir acesso dereciona para uma página de erro
                         NavigationHandler nh = facesContext.getApplication().getNavigationHandler();
                         nh.handleNavigation(facesContext, null, "professor_voltaErro");

                            }



            }

            } */
  }
Example #15
0
 public static void handleNavigation(FacesContext context, String fromAction, String outCome) {
   NavigationHandler handler = context.getApplication().getNavigationHandler();
   handler.handleNavigation(context, fromAction, outCome);
 }
  public void execute() throws BridgeDefaultViewNotSpecifiedException, BridgeException {

    logger.debug(Logger.SEPARATOR);
    logger.debug("execute(EventRequest, EventResponse) portletName=[{0}]", portletName);

    try {

      // If there is a bridgeEventHandler registered in portlet.xml, then
      String bridgeEventHandlerAttributeName =
          Bridge.BRIDGE_PACKAGE_PREFIX + portletName + "." + Bridge.BRIDGE_EVENT_HANDLER;
      BridgeEventHandler bridgeEventHandler =
          (BridgeEventHandler) portletContext.getAttribute(bridgeEventHandlerAttributeName);

      init(eventRequest, eventResponse, Bridge.PortletPhase.EVENT_PHASE);

      if (bridgeEventHandler != null) {

        // Restore the BridgeRequestScope that may have started during the ACTION_PHASE.
        bridgeRequestScope.restoreState(facesContext);

        // PROPOSED-FOR-BRIDGE3-API: https://issues.apache.org/jira/browse/PORTLETBRIDGE-202
        bridgeRequestScope.setPortletMode(eventRequest.getPortletMode());

        // Execute the JSF lifecycle so that ONLY the RESTORE_VIEW phase executes (note that this
        // this is
        // accomplished by the IPCPhaseListener).
        facesLifecycle.execute(facesContext);

        // If there were any "handled" exceptions queued, then throw a BridgeException.
        Throwable handledException = getJSF2HandledException(facesContext);

        if (handledException != null) {
          throw new BridgeException(handledException);
        }

        // Otherwise, if there were any "unhandled" exceptions queued, then throw a BridgeException.
        Throwable unhandledException = getJSF2UnhandledException(facesContext);

        if (unhandledException != null) {
          throw new BridgeException(unhandledException);
        }

        // Set a flag on the bridge request scope indicating that the Faces Lifecycle has executed.
        bridgeRequestScope.setFacesLifecycleExecuted(true);

        // If there is a bridgeEventHandler registered in portlet.xml, then invoke the handler so
        // that it
        // can process the event payload.

        logger.debug(
            "Invoking {0} for class=[{1}]",
            bridgeEventHandlerAttributeName, bridgeEventHandler.getClass());

        Event event = eventRequest.getEvent();
        EventNavigationResult eventNavigationResult =
            bridgeEventHandler.handleEvent(facesContext, event);

        if (eventNavigationResult != null) {
          String oldViewId = facesContext.getViewRoot().getViewId();
          String fromAction = eventNavigationResult.getFromAction();
          String outcome = eventNavigationResult.getOutcome();
          logger.debug(
              "Invoking navigationHandler fromAction=[{0}] outcome=[{1}]", fromAction, outcome);

          NavigationHandler navigationHandler =
              facesContext.getApplication().getNavigationHandler();
          navigationHandler.handleNavigation(facesContext, fromAction, outcome);

          String newViewId = facesContext.getViewRoot().getViewId();
          bridgeRequestScope.setNavigationOccurred(!oldViewId.equals(newViewId));
        }

        // Save the faces view root and any messages in the faces context so that they can be
        // restored during
        // the RENDER_PHASE of the portlet lifecycle.
        bridgeRequestScope.saveState(facesContext);

        // Assume that the bridge request scope should be maintained from the EVENT_PHASE into the
        // RENDER_PHASE by utilizing render parameters.
        BridgeRequestScope.Transport bridgeRequestScopeTransport =
            BridgeRequestScope.Transport.RENDER_PARAMETER;
        Serializable eventPayload = event.getValue();

        // FACES-1465: If the portlet developer intentionally wrapped the event payload is with an
        // EventPayloadWrapper, then determine whether or not this is happening during a redirect.
        // If this is
        // the case, then the bridge request scope must be maintained from the EVENT_PHASE into the
        // RENDER_PHASE
        // by utilizing a portlet session attribute. This is because render parameters will not
        // survive a
        // redirect.
        if ((eventPayload != null) && (eventPayload instanceof EventPayloadWrapper)) {
          EventPayloadWrapper eventPayloadWrapper = (EventPayloadWrapper) eventPayload;

          if (eventPayloadWrapper.isRedirect()) {

            bridgeRequestScopeTransport = BridgeRequestScope.Transport.PORTLET_SESSION_ATTRIBUTE;
          }
        }

        maintainBridgeRequestScope(eventRequest, eventResponse, bridgeRequestScopeTransport);

        // Process the outgoing public render parameters.
        // TCK TestPage064: eventControllerTest
        processOutgoingPublicRenderParameters(facesLifecycle);
      }

      // Maintain the render parameters set in the ACTION_PHASE so that they carry over to the
      // RENDER_PHASE.
      bridgeContext.getPortletContainer().maintainRenderParameters(eventRequest, eventResponse);

      // Spec 6.6 (Namespacing)
      indicateNamespacingToConsumers(facesContext.getViewRoot(), eventResponse);
    } catch (Throwable t) {
      throw new BridgeException(t);
    } finally {
      cleanup();
    }
  }
Example #17
0
 public static void handleNoNavigation(FacesContext context) {
   NavigationHandler handler = context.getApplication().getNavigationHandler();
   handler.handleNavigation(context, null, null);
 }
Example #18
0
  public String zaloguj() {
    String whereTo = "";
    menu1 = false;
    menu2 = false;
    menu3 = false;
    if (typ.equalsIgnoreCase("0")) {
      adminBean.setLogin(pole1);
      adminBean.setHaslo(pole2);
      adminBean.zaloguj(pole1, pole2);
      // logika czy zalogowanie sie powiodlo
      if (adminBean.getId() > 0) {
        menu1 = true;
        whereTo = "adminHome";
      } else {
        menu1 = false;
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(
            null, new FacesMessage("B³¹d logowania", "Podano b³êdny login lub has³o"));
      }
    }
    if (typ.equalsIgnoreCase("1")) {

      prowadzacyBean.setLogin(pole1);
      prowadzacyBean.setPassword(pole2);
      prowadzacyBean.zaloguj(pole1, pole2);
      // logika czy zalogowanie sie powiodlo
      if (prowadzacyBean.getId() > 0) {
        menu2 = true;
        whereTo = "prowadzacypf";
        System.out.println("zalogowano");
      } else {
        menu2 = false;
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(
            null, new FacesMessage("B³¹d logowania", "Podano b³êdny login lub has³o"));
      }
    }
    if (typ.equalsIgnoreCase("2")) {
      int nrIdx = 0;
      try {
        nrIdx = Integer.parseInt(pole1);
      } catch (NumberFormatException e) {
        nrIdx = -1;
      }
      if (nrIdx > 0) {
        studentBean.setIndex(nrIdx);
        studentBean.setHaslo(pole2);
        studentBean.zaloguj(nrIdx, pole2);
        if (studentBean.getId() > 0) {
          menu3 = true;
          whereTo = "studentpf";

        } else {
          menu3 = false;
          FacesContext context = FacesContext.getCurrentInstance();
          context.addMessage(
              null, new FacesMessage("B³¹d logowania", "Podano b³êdny login lub has³o"));
        }
      } else {
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(
            null, new FacesMessage("B³¹d logowania", "Zaloguj siê u¿ywaj¹c numeru indeksu!"));
      }
    }

    // redirection bo PF
    if (!whereTo.equalsIgnoreCase("")) {
      System.out.println("Proba nawigacji");
      FacesContext context = FacesContext.getCurrentInstance();
      NavigationHandler navHandler = context.getApplication().getNavigationHandler();
      navHandler.handleNavigation(context, null, whereTo);
    }
    return "Bledne";
  }