Пример #1
0
  public void doArtefactConfiguration() {
    if (!pluginBean.isReadableProperty(ARTEFACTS)) {
      return;
    }

    List l = (List) plugin.getProperty(ARTEFACTS);
    for (Object artefact : l) {
      if (artefact instanceof Class) {
        Class artefactClass = (Class) artefact;
        if (ArtefactHandler.class.isAssignableFrom(artefactClass)) {
          try {
            application.registerArtefactHandler((ArtefactHandler) artefactClass.newInstance());
          } catch (InstantiationException e) {
            LOG.error("Cannot instantiate an Artefact Handler:" + e.getMessage(), e);
          } catch (IllegalAccessException e) {
            LOG.error(
                "The constructor of the Artefact Handler is not accessible:" + e.getMessage(), e);
          }
        } else {
          LOG.error("This class is not an ArtefactHandler:" + artefactClass.getName());
        }
      } else {
        if (artefact instanceof ArtefactHandler) {
          application.registerArtefactHandler((ArtefactHandler) artefact);
        } else {
          LOG.error(
              "This object is not an ArtefactHandler:"
                  + artefact
                  + "["
                  + artefact.getClass().getName()
                  + "]");
        }
      }
    }
  }
Пример #2
0
 void btnChangeServer_actionPerformed(ActionEvent e) {
   setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
   JID temp = null;
   try {
     temp = JID.checkedJIDFromString(txtServer.getText());
   } catch (InstantiationException ex) {
     nu.fw.jeti.util.Popups.errorPopup(ex.getMessage(), I18N.gettext("main.error.invalid_server"));
   }
   if (temp == null) return;
   server = temp;
   backend.getItems(server, this);
 }
Пример #3
0
 public static Object newInstance(Class clazz) throws FacesException {
   try {
     return clazz.newInstance();
   } catch (NoClassDefFoundError e) {
     log.error("Class : " + clazz.getName() + " not found.", e);
     throw new FacesException(e);
   } catch (InstantiationException e) {
     log.error(e.getMessage(), e);
     throw new FacesException(e);
   } catch (IllegalAccessException e) {
     log.error(e.getMessage(), e);
     throw new FacesException(e);
   }
 }
Пример #4
0
  public static <T extends PaypalClassicResponseModel> T convertToAPIResponse(
      Map<String, String> mapdata, Class<T> clazz) {
    if (mapdata == null) {
      return null;
    }
    T paypalClassicResponseModel = null;

    try {
      paypalClassicResponseModel = mapToClazz(mapdata, clazz);
    } catch (InstantiationException e) {
      throw new ValidationException(e.getMessage());
    } catch (IllegalAccessException e) {
      throw new ValidationException(e.getMessage());
    } catch (InvocationTargetException e) {
      throw new ValidationException(e.getMessage());
    }

    return paypalClassicResponseModel;
  }
  /**
   * Creates an iterator that returns an {@link Options} containing each possible parameter set
   * defined by these {@link
   * com.biomatters.plugins.barcoding.validator.research.options.BatchOptions}. Note that the {@link
   * Options} object returned is always the same to save on initializing multiple copies. Each time
   * {@link java.util.Iterator#next()} is called the next parameter set is set on the {@link
   * Options}.
   *
   * @return An iterator that will iterate over all possible parameter sets specified by this {@link
   *     com.biomatters.plugins.barcoding.validator.research.options.BatchOptions}
   * @throws DocumentOperationException if there is a problem creating the {@link Options} object
   */
  public Iterator<T> iterator() throws DocumentOperationException {
    List<Set<OptionToSet>> possibleValues = new ArrayList<Set<OptionToSet>>();

    Map<String, MultiValueOption<?>> multiValueOptions = getMultiValueOptions("", options);
    for (Map.Entry<String, MultiValueOption<?>> entry : multiValueOptions.entrySet()) {
      possibleValues.add(getOptionsToSet(entry.getKey(), entry.getValue()));
    }
    Set<List<OptionToSet>> lists = Sets.cartesianProduct(possibleValues);
    final Iterator<List<OptionToSet>> possibilityIterator = lists.iterator();

    final T template;
    try {
      //noinspection unchecked
      template = (T) options.getClass().newInstance(); // getClass() doesn't return Class<T> :(
      template.valuesFromXML(options.valuesToXML(XMLSerializable.ROOT_ELEMENT_NAME));
    } catch (InstantiationException e) {
      throw new DocumentOperationException("Failed to create Options: " + e.getMessage(), e);
    } catch (IllegalAccessException e) {
      throw new DocumentOperationException("Failed to create Options: " + e.getMessage(), e);
    }

    return new Iterator<T>() {
      @Override
      public boolean hasNext() {
        return possibilityIterator.hasNext();
      }

      @Override
      public T next() {
        List<OptionToSet> possibility = possibilityIterator.next();
        for (OptionToSet optionToSet : possibility) {
          template.setValue(optionToSet.name, optionToSet.value);
        }
        return template;
      }

      @Override
      public void remove() {
        new UnsupportedOperationException();
      }
    };
  }
Пример #6
0
  /**
   * Return a new strategy (Design Pattern Abstract Factory)
   *
   * @return a new strategy
   */
  public static Strategy newStrategy() {
    Strategy strategy = null;
    Class stratClass;

    // FIXME: When you do a new Solution() it get an error because the strategies weren't
    // initialized before to do a newStrategy().
    if (allStrategies == null) {
      Hocli.initStrategies();
      setStrategy("FR");
    }
    stratClass = allStrategies.get(Hocli.strategyTag.toUpperCase());
    if (stratClass == null) {
      stopError("Hocli.newStrategy(Solution) : Unknown strategy class '" + Hocli.strategyTag + "'");
    }
    try {
      strategy = (Strategy) stratClass.newInstance();
    } catch (IllegalAccessException ex) {
      stopError(ex.getMessage());
    } catch (InstantiationException ex) {
      stopError(ex.getMessage());
    }
    return strategy;
  }
Пример #7
0
  /**
   * An HTTP WebEvent handler that checks to see is a userLogin is logged in. If not, the user is
   * forwarded to the login page.
   *
   * @param request The HTTP request object for the current JSP or Servlet request.
   * @param response The HTTP response object for the current JSP or Servlet request.
   * @return String
   */
  public static String checkLogin(HttpServletRequest request, HttpServletResponse response) {
    GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
    // anonymous shoppers are not logged in
    if (userLogin != null && "anonymous".equals(userLogin.getString("userLoginId"))) {
      userLogin = null;
    }

    // user is logged in; check to see if they have globally logged out if not
    // check if they have permission for this login attempt; if not log them out
    if (userLogin != null) {
      Element rootElement = getRootElement(request);
      boolean hasLdapLoggedOut = false;
      if (rootElement != null) {
        String className =
            UtilXml.childElementValue(
                rootElement,
                "AuthenticationHandler",
                "org.ofbiz.ldap.openldap.OFBizLdapAuthenticationHandler");
        try {
          Class<?> handlerClass = Class.forName(className);
          InterfaceOFBizAuthenticationHandler authenticationHandler =
              (InterfaceOFBizAuthenticationHandler) handlerClass.newInstance();
          hasLdapLoggedOut = authenticationHandler.hasLdapLoggedOut(request, response, rootElement);
        } catch (ClassNotFoundException e) {
          Debug.logError(e, "Error calling checkLogin service", module);
          Map<String, String> messageMap = UtilMisc.toMap("errorMessage", e.getMessage());
          String errMsg =
              UtilProperties.getMessage(
                  resourceWebapp,
                  "loginevents.following_error_occurred_during_login",
                  messageMap,
                  UtilHttp.getLocale(request));
          request.setAttribute("_ERROR_MESSAGE_", errMsg);
        } catch (InstantiationException e) {
          Debug.logError(e, "Error calling checkLogin service", module);
          Map<String, String> messageMap = UtilMisc.toMap("errorMessage", e.getMessage());
          String errMsg =
              UtilProperties.getMessage(
                  resourceWebapp,
                  "loginevents.following_error_occurred_during_login",
                  messageMap,
                  UtilHttp.getLocale(request));
          request.setAttribute("_ERROR_MESSAGE_", errMsg);
        } catch (IllegalAccessException e) {
          Debug.logError(e, "Error calling checkLogin service", module);
          Map<String, String> messageMap = UtilMisc.toMap("errorMessage", e.getMessage());
          String errMsg =
              UtilProperties.getMessage(
                  resourceWebapp,
                  "loginevents.following_error_occurred_during_login",
                  messageMap,
                  UtilHttp.getLocale(request));
          request.setAttribute("_ERROR_MESSAGE_", errMsg);
        } catch (Exception e) {
          Debug.logError(e, "Error calling checkLogin service", module);
          Map<String, String> messageMap = UtilMisc.toMap("errorMessage", e.getMessage());
          String errMsg =
              UtilProperties.getMessage(
                  resourceWebapp,
                  "loginevents.following_error_occurred_during_login",
                  messageMap,
                  UtilHttp.getLocale(request));
          request.setAttribute("_ERROR_MESSAGE_", errMsg);
        }
      }

      if (!hasBasePermission(userLogin, request)
          || isFlaggedLoggedOut(userLogin)
          || hasLdapLoggedOut) {
        Debug.logInfo("User does not have permission or is flagged as logged out", module);
        doBasicLogout(userLogin, request, response);
        userLogin = null;
      }
    }

    if (userLogin == null) {
      return login(request, response);
    }

    return "success";
  }
Пример #8
0
  /**
   * An HTTP WebEvent handler that logs out a userLogin by clearing the session.
   *
   * @param request The HTTP request object for the current request.
   * @param response The HTTP response object for the current request.
   * @return Return a boolean which specifies whether or not the calling request should generate its
   *     own content. This allows an event to override the default content.
   */
  public static String logout(HttpServletRequest request, HttpServletResponse response) {
    // run the before-logout events
    RequestHandler rh = RequestHandler.getRequestHandler(request.getSession().getServletContext());
    rh.runBeforeLogoutEvents(request, response);

    // invalidate the security group list cache
    GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");

    doBasicLogout(userLogin, request, response);

    Element rootElement = getRootElement(request);

    String result = "error";
    if (rootElement != null) {
      String className =
          UtilXml.childElementValue(
              rootElement,
              "AuthenticationHandler",
              "org.ofbiz.ldap.openldap.OFBizLdapAuthenticationHandler");
      try {
        Class<?> handlerClass = Class.forName(className);
        InterfaceOFBizAuthenticationHandler authenticationHandler =
            (InterfaceOFBizAuthenticationHandler) handlerClass.newInstance();
        result = authenticationHandler.logout(request, response, rootElement);
      } catch (ClassNotFoundException e) {
        Debug.logError(e, "Error calling userLogin service", module);
        Map<String, String> messageMap = UtilMisc.toMap("errorMessage", e.getMessage());
        String errMsg =
            UtilProperties.getMessage(
                resourceWebapp,
                "loginevents.following_error_occurred_during_login",
                messageMap,
                UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
      } catch (InstantiationException e) {
        Debug.logError(e, "Error calling userLogin service", module);
        Map<String, String> messageMap = UtilMisc.toMap("errorMessage", e.getMessage());
        String errMsg =
            UtilProperties.getMessage(
                resourceWebapp,
                "loginevents.following_error_occurred_during_login",
                messageMap,
                UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
      } catch (IllegalAccessException e) {
        Debug.logError(e, "Error calling userLogin service", module);
        Map<String, String> messageMap = UtilMisc.toMap("errorMessage", e.getMessage());
        String errMsg =
            UtilProperties.getMessage(
                resourceWebapp,
                "loginevents.following_error_occurred_during_login",
                messageMap,
                UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
      } catch (Exception e) {
        Debug.logError(e, "Error calling userLogin service", module);
        Map<String, String> messageMap = UtilMisc.toMap("errorMessage", e.getMessage());
        String errMsg =
            UtilProperties.getMessage(
                resourceWebapp,
                "loginevents.following_error_occurred_during_login",
                messageMap,
                UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
      }
    }

    if (request.getAttribute("_AUTO_LOGIN_LOGOUT_") == null) {
      return autoLoginCheck(request, response);
    }
    return result;
  }
Пример #9
0
  /**
   * An HTTP WebEvent handler that logs in a userLogin. This should run before the security check.
   *
   * @param request The HTTP request object for the current JSP or Servlet request.
   * @param response The HTTP response object for the current JSP or Servlet request.
   * @return Return a boolean which specifies whether or not the calling Servlet or JSP should
   *     generate its own content. This allows an event to override the default content.
   */
  public static String login(HttpServletRequest request, HttpServletResponse response) {

    Element rootElement = getRootElement(request);
    String result = "error";
    if (rootElement != null) {
      String className =
          UtilXml.childElementValue(
              rootElement,
              "AuthenticationHandler",
              "org.ofbiz.ldap.openldap.OFBizLdapAuthenticationHandler");
      try {
        Class<?> handlerClass = Class.forName(className);
        InterfaceOFBizAuthenticationHandler authenticationHandler =
            (InterfaceOFBizAuthenticationHandler) handlerClass.newInstance();
        result = authenticationHandler.login(request, response, rootElement);
      } catch (ClassNotFoundException e) {
        Debug.logError(e, "Error calling userLogin service", module);
        Map<String, String> messageMap = UtilMisc.toMap("errorMessage", e.getMessage());
        String errMsg =
            UtilProperties.getMessage(
                resourceWebapp,
                "loginevents.following_error_occurred_during_login",
                messageMap,
                UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
      } catch (InstantiationException e) {
        Debug.logError(e, "Error calling userLogin service", module);
        Map<String, String> messageMap = UtilMisc.toMap("errorMessage", e.getMessage());
        String errMsg =
            UtilProperties.getMessage(
                resourceWebapp,
                "loginevents.following_error_occurred_during_login",
                messageMap,
                UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
      } catch (IllegalAccessException e) {
        Debug.logError(e, "Error calling userLogin service", module);
        Map<String, String> messageMap = UtilMisc.toMap("errorMessage", e.getMessage());
        String errMsg =
            UtilProperties.getMessage(
                resourceWebapp,
                "loginevents.following_error_occurred_during_login",
                messageMap,
                UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
      } catch (NamingException e) {
        Debug.logError(e, "Error calling userLogin service", module);
        Map<String, String> messageMap = UtilMisc.toMap("errorMessage", e.getMessage());
        String errMsg =
            UtilProperties.getMessage(
                resourceWebapp,
                "loginevents.following_error_occurred_during_login",
                messageMap,
                UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
      } catch (Exception e) {
        Debug.logError(e, "Error calling userLogin service", module);
        Map<String, String> messageMap = UtilMisc.toMap("errorMessage", e.getMessage());
        String errMsg =
            UtilProperties.getMessage(
                resourceWebapp,
                "loginevents.following_error_occurred_during_login",
                messageMap,
                UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
      }
    }

    if (result.equals("error")) {
      boolean useOFBizLoginWhenFail =
          Boolean.getBoolean(
              UtilXml.childElementValue(rootElement, "UseOFBizLoginWhenLDAPFail", "false"));
      if (useOFBizLoginWhenFail) {
        return LoginWorker.login(request, response);
      }
    }
    return result;
  }