Esempio n. 1
0
  /**
   * Updates security chain with given {@link
   * org.motechproject.security.domain.MotechURLSecurityRule}
   *
   * @param securityRules list that contains new security rules
   */
  private void updateSecurityChain(List<MotechURLSecurityRule> securityRules) {
    LOGGER.debug("Updating security chain");

    // sort rules by priority descending
    TreeSet<MotechURLSecurityRule> sortedRules = new TreeSet<>(new SecurityRuleComparator());
    sortedRules.addAll(securityRules);

    List<SecurityFilterChain> newFilterChains = new ArrayList<>();

    for (MotechURLSecurityRule securityRule : sortedRules) {
      if (securityRule.isActive() && !securityRule.isDeleted()) {
        LOGGER.debug("Creating SecurityFilterChain for: {}", securityRule.getPattern());
        for (HTTPMethod method : securityRule.getMethodsRequired()) {
          newFilterChains.add(securityRuleBuilder.buildSecurityChain(securityRule, method));
        }
        LOGGER.debug("Created SecurityFilterChain for: {}", securityRule.getPattern());
      }
    }

    proxy = new FilterChainProxy(newFilterChains);
    LOGGER.debug("Updated security chain.");
  }