Search in sources :

Example 6 with MotechSecurityConfiguration

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

the class MotechProxyManager method initializeProxyChain.

/**
 * 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.
 */
@Transactional
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");
}
Also used : MotechSecurityConfiguration(org.motechproject.security.domain.MotechSecurityConfiguration) MotechURLSecurityRule(org.motechproject.security.domain.MotechURLSecurityRule) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

MotechSecurityConfiguration (org.motechproject.security.domain.MotechSecurityConfiguration)6 MotechURLSecurityRule (org.motechproject.security.domain.MotechURLSecurityRule)4 Transactional (org.springframework.transaction.annotation.Transactional)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Test (org.junit.Test)1 MotechException (org.motechproject.commons.api.MotechException)1 HTTPMethod (org.motechproject.security.constants.HTTPMethod)1 Scheme (org.motechproject.security.constants.Scheme)1 MotechProxyManager (org.motechproject.security.service.MotechProxyManager)1