/**
   * Constructs an instance of a PortletWebApplicationImpl from a supplied ui application name and
   * corresponding <code>ServletContext</code>
   *
   * @param webApplicationName the the web application name
   * @param context the <code>ServletContext</code>
   */
  public PortletWebApplicationImpl(String webApplicationName, ServletContext context)
      throws PortletException {
    super(context);
    this.webApplicationName = webApplicationName;
    // get the servlet context for the coreportlets webapp
    String contextURIPath;
    if (webApplicationName.startsWith("/")) {
      contextURIPath = webApplicationName;
      this.webApplicationName = webApplicationName.substring(1);
    } else {
      contextURIPath = "/" + webApplicationName;
    }

    // Get the cross context servlet context
    ServletContext ctx = context.getContext(contextURIPath);
    // System.err.println("contextURIPath: " + contextURIPath);
    // System.err.println("contextName: " + ctx.getServletContextName());
    // System.err.println("context path: " + ctx.getRealPath(""));

    // System.err.println("testing example portlets");
    // ServletContext testsc = context.getContext("/exampleportlets");
    // System.err.println("description: " + ctx.getServletContextName());
    // System.err.println("testing core portlets");
    // testsc = context.getContext("/coreportlets");
    // System.err.println("description: " + testsc.getServletContextName());
    // System.err.println("context path: " + te.getRealPath(""));

    if (ctx == null) {
      log.error(webApplicationName + ": Unable to get ServletContext for: " + contextURIPath);
      throw new PortletException(
          webApplicationName + ": Unable to get ServletContext for: " + contextURIPath);
    }
    log.debug("context path: " + ctx.getRealPath(""));
    this.webAppDescription = ctx.getServletContextName();

    // load portlet.xml
    loadPortlets(ctx, Thread.currentThread().getContextClassLoader());
    // load services xml
    if (!isJSR) loadServices(ctx, Thread.currentThread().getContextClassLoader());
    // load roles.xml
    if (!isJSR) loadRoles(ctx);
    // load group.xml (and if found load layout.xml)
    if (!isJSR) loadGroup(ctx);
  }
  public void validateSuppliedPassword(User user, String value) throws InvalidPasswordException {
    PasswordImpl password = getPasswordImpl(user);
    if (password == null) {
      _log.debug("No password found for user");
      throw new InvalidPasswordException("No password found for user!");
    }
    // _log.debug("Stored value is " + password.getValue());
    // _log.debug("Provided value is " + value);

    // MD5 hash of password value
    try {
      MessageDigest md5 = MessageDigest.getInstance("MD5");
      md5.update(value.getBytes());
      value = toHex(md5.digest());

      // _log.debug("Hash of value is " + value);
      if (!password.getValue().equals(value)) {
        throw new InvalidPasswordException("Supplied password does not match user password!");
      }
    } catch (NoSuchAlgorithmException e) {
      _log.error("No such algorithm: MD5", e);
    }
  }