Esempio n. 1
0
  /**
   * This method serves the same purpose of rebuildProxyChain, but does not require any kind of
   * security authentication so it should only ever be used by the activator, which does not have an
   * authentication object.
   */
  public void initializeProxyChain() {
    LOGGER.info("Initializing proxy chain");

    MotechSecurityConfiguration securityConfiguration =
        securityRulesDAO.getMotechSecurityConfiguration();
    List<MotechURLSecurityRule> securityRules = securityConfiguration.getSecurityRules();
    List<MotechURLSecurityRule> systemRules = getDefaultSecurityConfiguration().getSecurityRules();

    for (MotechURLSecurityRule rule : systemRules) {
      if (!securityRules.contains(rule)) {
        LOGGER.debug("Found new rule, not present in database. Adding.");
        securityRules.add(rule);
      }
    }

    // remove rules that have origin set to SYSTEM_PLATFORM and are no longer in the default
    // configuration
    Iterator<MotechURLSecurityRule> it = securityRules.iterator();
    while (it.hasNext()) {
      MotechURLSecurityRule ruleFromDb = it.next();
      if (SYSTEM_ORIGIN.equals(ruleFromDb.getOrigin()) && !systemRules.contains(ruleFromDb)) {
        it.remove();
      }
    }

    securityRulesDAO.addOrUpdate(securityConfiguration);

    updateSecurityChain(securityRules);
    LOGGER.info("Initialized proxy chain");
  }