private SessionId removeSessionId(
      String sessionId, HttpServletRequest httpRequest, HttpServletResponse httpResponse) {

    SessionId ldapSessionId = null;

    try {
      String id = sessionId;
      if (StringHelper.isEmpty(id)) {
        id = sessionIdService.getSessionIdFromCookie(httpRequest);
      }

      if (StringHelper.isNotEmpty(id)) {
        ldapSessionId = sessionIdService.getSessionId(id);
        if (ldapSessionId != null) {
          boolean result = sessionIdService.remove(ldapSessionId);
          if (!result) {
            log.error("Failed to remove session_id '{0}' from LDAP", id);
          }
        } else {
          log.error("Failed to load session from LDAP by session_id: '{0}'", id);
        }
      }
    } catch (Exception e) {
      log.error(e.getMessage(), e);
    } finally {
      sessionIdService.removeSessionIdCookie(httpResponse);
    }
    return ldapSessionId;
  }
  /**
   * Build DN string for sector identifier
   *
   * @param inum Sector Identifier Inum
   * @return DN string for specified sector identifier or DN for sector identifiers branch if inum
   *     is null
   * @throws Exception
   */
  public String getDnForSectorIdentifier(String inum) {
    String sectorIdentifierDn = staticConfiguration.getBaseDn().getSectorIdentifiers();
    if (StringHelper.isEmpty(inum)) {
      return sectorIdentifierDn;
    }

    return String.format("inum=%s,%s", inum, sectorIdentifierDn);
  }
  private void removeSessionId(
      String sessionId, HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
    String id = sessionId;
    if (StringHelper.isEmpty(id)) {
      id = sessionIdService.getSessionIdFromCookie(httpRequest);
    }

    if (StringHelper.isNotEmpty(id)) {
      SessionId ldapSessionId = sessionIdService.getSessionId(id);
      if (ldapSessionId != null) {
        boolean result = sessionIdService.remove(ldapSessionId);
        if (!result) {
          log.error("Failed to remove session_id '{0}' from LDAP", id);
        }
      } else {
        log.error("Failed to load session from LDAP by session_id: '{0}'", id);
      }
    }

    sessionIdService.removeSessionIdCookie(httpResponse);
  }
  // TODO: Yuriy Movchan: Use @Min property annotation + convert type from String to Integer
  private boolean vdsCacheRefreshPollingInterval() {
    String intervalString = this.appliance.getVdsCacheRefreshPollingInterval();
    if (StringHelper.isEmpty(intervalString)) {
      return true;
    }

    Integer interval = null;
    try {
      interval = Integer.valueOf(intervalString);
    } catch (NumberFormatException ex) {
    }

    if ((interval == null) || (interval < 0)) {
      log.error("Invalid cache refresh pooling interval specified: {0}", intervalString);
      ValidationUtil.addErrorMessageToInput(
          "vdsCacheRefreshPollingIntervalId", "Invalid cache refresh pooling interval specified");
      return false;
    }

    return true;
  }
Esempio n. 5
0
  public String start() {
    if (initialized) {
      return OxTrustConstants.RESULT_SUCCESS;
    }
    HttpServletRequest request = (HttpServletRequest) extCtx.getRequest();
    relyingPartyId = request.getHeader("relyingPartyId");
    setActionUrl(request.getHeader("actionUrl"));
    log.debug("relyingPartyId is" + relyingPartyId);
    log.debug("actionUrl is" + actionUrl);
    if (StringHelper.isEmpty(relyingPartyId)) {
      facesMessages.add(Severity.ERROR, "Direct access to this page is not supported");
      // return Configuration.RESULT_FAILURE;
    }

    try {
      log.debug("Getting SSL HTTP Client");
      // Create HTTP local context

      // Bind cookie store to the local context

      // Add user cookies
      log.debug("Setting HTTP Client cookies from user session");

    } catch (Exception ex) {
      log.error("Failed to initialize HTTP Client", ex);
      facesMessages.add(Severity.ERROR, "Failed to prepare login form");

      // return Configuration.RESULT_FAILURE;
    }

    initialized = true;

    RuleBase ruleBase = null;

    try {
      log.info("Checking for customized login pages");
      InputStream is = getClass().getClassLoader().getResourceAsStream("selection.drl");
      if (is != null) {
        log.info("Login page customization rules found.");
        Reader reader = new InputStreamReader(is);
        try {
          ruleBase = RuleBaseLoader.getInstance().loadFromReader(reader);

          WorkingMemory workingMemory = ruleBase.newStatefulSession();

          workingMemory.insert(relyingPartyId);
          // workingMemory.insert(contextKey);
          // workingMemory.insert(relayState);
          // workingMemory.insert(relayStateValue);
          // workingMemory.insert(requestedSessionId);
          List<String> viewId = new ArrayList<String>();
          workingMemory.insert(viewId);
          workingMemory.fireAllRules();
          if (viewId.size() > 0) {
            log.info("Login page customization rules fired: " + viewId.get(0));
            extCtx.redirect(viewId.get(0));
          }
        } finally {
          IOUtils.closeQuietly(reader);
        }
      }
    } catch (CheckedDroolsException e) {
      e.printStackTrace();
    } catch (IOException e) {
      log.warn("There were error reading selection.drl");
    }

    return OxTrustConstants.RESULT_SUCCESS;
  }