Search in sources :

Example 1 with SecurityRuleComparator

use of org.motechproject.security.domain.SecurityRuleComparator in project motech by motech.

the class MotechURLSecurityServiceImpl method findAllSecurityRules.

@Override
@Transactional
public List<SecurityRuleDto> findAllSecurityRules() {
    List<MotechURLSecurityRule> rules = allSecurityRules.getRules();
    Collections.sort(rules, new SecurityRuleComparator());
    return toSecurityRuleDtoList(rules);
}
Also used : MotechURLSecurityRule(org.motechproject.security.domain.MotechURLSecurityRule) SecurityRuleComparator(org.motechproject.security.domain.SecurityRuleComparator) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with SecurityRuleComparator

use of org.motechproject.security.domain.SecurityRuleComparator in project motech by motech.

the class MotechProxyManager method updateSecurityChain.

/**
 * 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.");
}
Also used : SecurityFilterChain(org.springframework.security.web.SecurityFilterChain) FilterChainProxy(org.springframework.security.web.FilterChainProxy) HTTPMethod(org.motechproject.security.constants.HTTPMethod) MotechURLSecurityRule(org.motechproject.security.domain.MotechURLSecurityRule) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) SecurityRuleComparator(org.motechproject.security.domain.SecurityRuleComparator)

Aggregations

MotechURLSecurityRule (org.motechproject.security.domain.MotechURLSecurityRule)2 SecurityRuleComparator (org.motechproject.security.domain.SecurityRuleComparator)2 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 HTTPMethod (org.motechproject.security.constants.HTTPMethod)1 FilterChainProxy (org.springframework.security.web.FilterChainProxy)1 SecurityFilterChain (org.springframework.security.web.SecurityFilterChain)1 Transactional (org.springframework.transaction.annotation.Transactional)1