Ejemplo n.º 1
0
  private GluuAttribute createAttributeFromConfig(String prefix) {
    String attributeName = importConfiguration.getString(prefix + ATTRIBUTE_LDAP_NAME_SUFFIX, null);
    String displayName =
        importConfiguration.getString(prefix + ATTRIBUTE_DISPLAY_NAME_SUFFIX, null);
    String dataType = importConfiguration.getString(prefix + ATTRIBUTE_DATA_TYPE_SUFFIX, null);
    boolean required =
        importConfiguration.getBoolean(prefix + ATTRIBUTE_DATA_REQUIRED_SUFFIX, false);

    if (StringHelper.isNotEmpty(attributeName)
        && StringHelper.isNotEmpty(displayName)
        && StringHelper.isNotEmpty(dataType)) {
      GluuAttributeDataType attributeDataType = GluuAttributeDataType.getByValue(dataType);
      if (attributeDataType != null) {
        GluuAttribute attr = new GluuAttribute();
        attr.setName(attributeName);
        attr.setDisplayName(displayName);
        attr.setDataType(attributeDataType);
        attr.setRequred(required);

        return attr;
      }
    }

    return null;
  }
  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);
  }
Ejemplo n.º 5
0
  private Configuration() {
    FileConfiguration ldapConfiguration = new FileConfiguration(LDAP_PROPERTIES_FILE);

    String confDir = DIR;
    if (ldapConfiguration.isLoaded()) {
      String ldapConfDir = ldapConfiguration.getString("confDir");
      if (StringHelper.isNotEmpty(ldapConfDir)) {
        confDir = ldapConfDir;
      }
    }

    applicationConfiguration =
        new FileConfiguration(confDir + CONFIGURATION_FILE_APPLICATION_CONFIGURATION);
    cryptoConfiguration =
        new FileConfiguration(confDir + CONFIGURATION_FILE_CRYPTO_PROPERTIES_FILE);
  }
Ejemplo n.º 6
0
  private List<GluuAttribute> prepareAttributes() throws Exception {
    List<GluuAttribute> result = new ArrayList<GluuAttribute>();
    if (!this.importConfiguration.isLoaded()) {
      return result;
    }

    Iterator<?> keys = importConfiguration.getProperties().keySet().iterator();
    while (keys.hasNext()) {
      String key = (String) keys.next();

      if (key.endsWith(ATTRIBUTE_LDAP_NAME_SUFFIX)) {
        int index = key.lastIndexOf(ATTRIBUTE_LDAP_NAME_SUFFIX);
        String prefix = key.substring(0, index);

        String attributeName =
            importConfiguration.getString(prefix + ATTRIBUTE_LDAP_NAME_SUFFIX, null);
        boolean required =
            importConfiguration.getBoolean(prefix + ATTRIBUTE_DATA_REQUIRED_SUFFIX, false);

        if (StringHelper.isNotEmpty(attributeName)) {
          GluuAttribute attr = null;
          try {
            attr = attributeService.getAttributeByName(attributeName);
          } catch (EntryPersistenceException ex) {
            log.error("Failed to load attribute '{0}' definition from LDAP", ex, attributeName);
          }
          if (attr == null) {
            log.warn("Failed to find attribute '{0}' definition in LDAP", attributeName);
            attr = createAttributeFromConfig(prefix);
            if (attr == null) {
              log.error(
                  "Failed to find attribute '{0}' definition in '{1}'",
                  attributeName, GLUU_IMPORT_PERSON_PROPERTIES_FILE);
              continue;
            }
          } else {
            attr.setRequred(required);
          }
          result.add(attr);
        }
      }
    }

    return result;
  }
Ejemplo n.º 7
0
  /**
   * @param printJobTimeout the printJobTimeout (ms) before the watchdog terminates the print
   *     process
   * @param printInBackground printing done in the background or blocking
   * @param streamHandler
   * @return a print result handler (implementing a future)
   * @throws IOException the test failed
   */
  public static PrintResultHandler executeProgram(
      CommandLine commandLine,
      String workingDirectory,
      long printJobTimeout,
      boolean printInBackground,
      int successExitValue,
      ExecuteStreamHandler streamHandler)
      throws IOException {
    ExecuteWatchdog watchdog = null;
    PrintResultHandler resultHandler;

    // Create the executor and consider the successExitValue as success
    Executor executor = new DefaultExecutor();
    executor.setExitValue(successExitValue);

    if (StringHelper.isNotEmpty(workingDirectory)) {
      executor.setWorkingDirectory(new File(workingDirectory));
    }

    // Redirect streams if needed
    if (streamHandler != null) {
      executor.setStreamHandler(streamHandler);
    }

    // Create a watchdog if requested
    if (printJobTimeout > 0) {
      watchdog = new ExecuteWatchdog(printJobTimeout);
      executor.setWatchdog(watchdog);
    }

    // Pass a "ExecuteResultHandler" when doing background printing
    if (printInBackground) {
      log.debug(String.format("Executing non-blocking process %s", commandLine.toString()));
      resultHandler = new PrintResultHandler(watchdog);
      executor.execute(commandLine, resultHandler);
    } else {
      log.debug(String.format("Executing blocking process %s", commandLine.toString()));
      successExitValue = executor.execute(commandLine);
      resultHandler = new PrintResultHandler(successExitValue);
    }

    return resultHandler;
  }
  // 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;
  }
Ejemplo n.º 9
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;
  }