Ejemplo n.º 1
0
 public void checkRoles(ComponentSystemEvent event) {
   if (getUserAuth() == null
       && JSFUtils.getUserName() != null
       && !JSFUtils.getUserName().isEmpty()) {
     userAuth = userRepository.findByUsername(JSFUtils.getUserName());
     setUserAuth(userAuth);
     logOperationsController.save("LOGIN", JSFUtils.getUserName(), "LOGIN");
   }
   String acl = "" + event.getComponent().getAttributes().get("roles");
   for (String a : acl.split(",")) {
     if ("ANY".equalsIgnoreCase(a)) {
       if (JSFUtils.getUserName() != null && JSFUtils.getUserName().length() > 0) {
         return;
       }
     }
     if (isInRole(a.trim())) {
       return;
     }
   }
   try {
     logger.info(acl + " - non consentito!");
     FacesContext context = FacesContext.getCurrentInstance();
     ConfigurableNavigationHandler handler =
         (ConfigurableNavigationHandler) context.getApplication().getNavigationHandler();
     handler.performNavigation("administration");
   } catch (Exception e) {
     e.printStackTrace();
     // Se siamo qui il redirect è fallito.
     // A questo punto, piuttosto che lasciare andare l'utente dove
     // non deve.. runtime exception!
     throw new RuntimeException("Accesso non consentito");
   }
 }
Ejemplo n.º 2
0
  /* When this method is called, we know that there is a component
   * with a script renderer somewhere in the view.  We need to make it
   * so that when an element with a name given by the value of the optional
   * "target" component attribute is encountered, this component
   * can be called upon to render itself.
   * This method will add the component (associated with this Renderer)
   * to a facet in the view only if a "target" component attribute is set.
   *
   */
  public void processEvent(ComponentSystemEvent event) throws AbortProcessingException {
    UIComponent component = event.getComponent();
    FacesContext context = FacesContext.getCurrentInstance();

    String target = (String) component.getAttributes().get("target");
    if (target != null) {
      context.getViewRoot().addComponentResource(context, component, target);
    }
  }
  public void processEvent(ComponentSystemEvent event) throws AbortProcessingException {
    // http://javaserverfaces.java.net/nonav/docs/2.0/pdldocs/facelets/index.html
    // Finally make sure the component is only rendered in the header of the
    // HTML document.
    UIComponent component = event.getComponent();
    FacesContext context = FacesContext.getCurrentInstance();
    if (log.isLoggable(Level.FINER)) {
      log.finer("processEvent for component = " + component.getClass().getName());
    }
    context.getViewRoot().addComponentResource(context, component, HTML.HEAD_ELEM);

    ClientDescriptor client =
        ClientDescriptor.getInstance(
            (HttpServletRequest) context.getExternalContext().getRequest());
    String themeParam = context.getExternalContext().getRequestParameterMap().get("theme");
    Theme theme = null;
    if (client.isIE9orLessBrowser()) {
      theme = Theme.ARCHAIC;
    } else {
      theme =
          Theme.getEnum(
              themeParam != null
                  ? themeParam
                  : (String) event.getComponent().getAttributes().get("theme"));
      if (theme == null) {
        String targetView = (String) event.getComponent().getAttributes().get("view");
        theme = CSSUtils.deriveTheme(targetView, JSFUtils.getRequest());
      }
    }

    // android and honeycomb themes deprecated
    if (theme == Theme.ANDROID || theme == Theme.HONEYCOMB) {
      theme = Theme.ANDROID_DARK;
    }
    context.getExternalContext().getSessionMap().put(MOBI_THEME_KEY, theme);
  }
Ejemplo n.º 4
0
  // Multi field validation with <f:event>
  // Rule: first two digits of PIN must match last two digits of the year of
  // birth
  public void validatePinDob(ComponentSystemEvent event) {

    UIForm form = (UIForm) event.getComponent();
    UIInput pin = (UIInput) form.findComponent("zip");
    UIInput dob = (UIInput) form.findComponent("zip");

    if (pin.getValue() != null
        && dob.getValue() != null
        && pin.getValue().toString().length() >= 2) {
      String twoDigitsOfPin = pin.getValue().toString().substring(0, 2);
      Calendar cal = Calendar.getInstance();
      cal.setTime(((Date) dob.getValue()));

      String lastDigitsOfDob = ((Integer) cal.get(Calendar.YEAR)).toString().substring(2);

      if (!twoDigitsOfPin.equals(lastDigitsOfDob)) {
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(form.getClientId(), new FacesMessage("PIN doesn't match date of birth"));
        context.renderResponse();
      }
    }
  }
Ejemplo n.º 5
0
 public void processEvent(ComponentSystemEvent event) throws AbortProcessingException {
   if (event.getClass() == PRERENDER_EVENT_CLASS) {
     LOGGER.debug("Prerender event {0} caught", event);
     // FIXME seriously, do it!
     FacesContext ctx = FacesContext.getCurrentInstance();
     UIViewRoot viewRoot = ctx.getViewRoot();
     if (viewRoot != null) {
       ServiceRegisterJSComponent comp;
       if ((comp = findServiceRegister(ctx)) == null) {
         LOGGER.debug("Cannot find a service register register component, adding one");
         viewRoot
             .getChildren()
             .add(
                 ctx.getApplication()
                     .createComponent(ServiceRegisterJSComponent.COMPONENT_TYPE));
         viewRoot.markInitialState();
       } else {
         LOGGER.debug("Found service register component with clientId {0}", comp.getClientId());
       }
     } else {
       LOGGER.error("Could not find a view root");
     }
   }
 }
Ejemplo n.º 6
0
 public void postValidateCCType(ComponentSystemEvent event) throws AbortProcessingException {
   creditCardTypeInput = (UIInput) event.getComponent();
 }
Ejemplo n.º 7
0
  // validates the form to find any errors regarding the user input
  // "never trust any user"
  public void validate(ComponentSystemEvent event) {
    UIForm form = (UIForm) event.getComponent();
    UIInput pw1 = (UIInput) form.findComponent("password1");
    UIInput pw2 = (UIInput) form.findComponent("password2");
    UIInput zipCode = (UIInput) form.findComponent("zip");
    UIInput accountNo = (UIInput) form.findComponent("accountNo");
    UIInput bankCode = (UIInput) form.findComponent("bankCode");

    // check if a password has been entered
    if (pw1 == null || pw1.getValue() == null) {
      FacesContext fc = FacesContext.getCurrentInstance();
      fc.renderResponse();
      return;
    }

    // check further that both passwords are equal
    // if not, a message should be shown to the user telling him
    // that both passwords do not match
    if (!(pw1.getValue().equals(pw2.getValue()))) {
      pw1.setValue("");
      pw2.setValue("");
      FacesContext fc = FacesContext.getCurrentInstance();
      ResourceBundle bundle = fc.getApplication().getResourceBundle(fc, "m");
      message.setText(
          bundle.getString("register_passwordDifferent"),
          bundle.getString("register_passwordDifferentDetail"),
          FacesMessage.SEVERITY_ERROR,
          pw1.getClientId());
      fc.renderResponse();
    }

    String zip = (String) zipCode.getValue();
    if (zip.length() > 8 || zip.length() < 4) {
      zipCode.setValue("");
      FacesContext fc = FacesContext.getCurrentInstance();
      ResourceBundle bundle = fc.getApplication().getResourceBundle(fc, "m");
      message.setText(
          bundle.getString("register_zipError"),
          null,
          FacesMessage.SEVERITY_ERROR,
          zipCode.getClientId());
      fc.renderResponse();
    }

    String accountNumber = (String) accountNo.getValue();
    if (accountNumber.length() > 12 || accountNumber.length() < 5) {
      accountNo.setValue("");
      FacesContext fc = FacesContext.getCurrentInstance();
      ResourceBundle bundle = fc.getApplication().getResourceBundle(fc, "m");
      message.setText(
          bundle.getString("register_accountNoError"),
          null,
          FacesMessage.SEVERITY_ERROR,
          accountNo.getClientId());
      fc.renderResponse();
    }

    String bankcode = (String) bankCode.getValue();
    if (bankcode.length() > 7 || bankcode.length() < 5) {
      bankCode.setValue("");
      FacesContext fc = FacesContext.getCurrentInstance();
      ResourceBundle bundle = fc.getApplication().getResourceBundle(fc, "m");
      message.setText(
          bundle.getString("register_bankCodeError"),
          null,
          FacesMessage.SEVERITY_ERROR,
          bankCode.getClientId());
      fc.renderResponse();
    }
  }