Search in sources :

Example 1 with MotechURLSecurityRule

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

the class SecurityRuleBuilderTest method testShouldRequireSupportedScheme.

@Test
public void testShouldRequireSupportedScheme() {
    configException.expect(SecurityConfigException.class);
    configException.expectMessage(SecurityRuleBuilder.NO_SUPPORTED_SCHEMES_EXCEPTION_MESSAGE);
    MotechURLSecurityRule securityRule = new MotechURLSecurityRule();
    securityRule.setPattern("pattern");
    securityRule.setProtocol(HTTP);
    securityBuilder.buildSecurityChain(securityRule, GET);
}
Also used : MotechURLSecurityRule(org.motechproject.security.domain.MotechURLSecurityRule) Test(org.junit.Test)

Example 2 with MotechURLSecurityRule

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

the class SecurityRuleBuilderTest method testShouldRequirePattern.

@Test
public void testShouldRequirePattern() {
    configException.expect(SecurityConfigException.class);
    configException.expectMessage(SecurityRuleBuilder.NO_PATTERN_EXCEPTION_MESSAGE);
    MotechURLSecurityRule securityRule = new MotechURLSecurityRule();
    securityBuilder.buildSecurityChain(securityRule, GET);
}
Also used : MotechURLSecurityRule(org.motechproject.security.domain.MotechURLSecurityRule) Test(org.junit.Test)

Example 3 with MotechURLSecurityRule

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

the class SecurityRuleBuilderTest method testMinimalRequirements.

@Test
public void testMinimalRequirements() {
    MotechURLSecurityRule securityRule = new MotechURLSecurityRule();
    securityRule.setPattern("pattern");
    securityRule.setProtocol(HTTP);
    securityRule.setSupportedSchemes(Arrays.asList(USERNAME_PASSWORD));
    securityRule.setMethodsRequired(Arrays.asList(ANY));
    SecurityFilterChain filterChain = securityBuilder.buildSecurityChain(securityRule, GET);
    assertNotNull(filterChain);
    assertEquals(10, filterChain.getFilters().size());
}
Also used : SecurityFilterChain(org.springframework.security.web.SecurityFilterChain) MotechURLSecurityRule(org.motechproject.security.domain.MotechURLSecurityRule) Test(org.junit.Test)

Example 4 with MotechURLSecurityRule

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

the class SecurityRuleBuilderTest method testShouldRequireProtocol.

@Test
public void testShouldRequireProtocol() {
    configException.expect(SecurityConfigException.class);
    configException.expectMessage(SecurityRuleBuilder.NO_PROTOCOL_EXCEPTION_MESSAGE);
    MotechURLSecurityRule securityRule = new MotechURLSecurityRule();
    securityRule.setPattern("pattern");
    securityBuilder.buildSecurityChain(securityRule, GET);
}
Also used : MotechURLSecurityRule(org.motechproject.security.domain.MotechURLSecurityRule) Test(org.junit.Test)

Example 5 with MotechURLSecurityRule

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

the class SecurityTestConfigBuilder method buildConfig.

public static MotechSecurityConfiguration buildConfig(String testOption, Object configOption, String configOption2) {
    List<MotechURLSecurityRule> newRules = new ArrayList<MotechURLSecurityRule>();
    List<Scheme> supportedSchemes = new ArrayList<>();
    List<HTTPMethod> methodsRequired = new ArrayList<>();
    List<String> permissionAccess = new ArrayList<>();
    List<String> userAccess = new ArrayList<>();
    MotechURLSecurityRule rule1 = new MotechURLSecurityRule();
    MotechURLSecurityRule rule2 = new MotechURLSecurityRule();
    rule1.setPattern("/**/web-api/**");
    rule1.setOrigin("test");
    rule1.setProtocol(HTTP);
    rule1.setRest(true);
    rule1.setVersion("1");
    rule2.setPattern("/**");
    rule2.setOrigin("test");
    rule2.setProtocol(HTTP);
    rule2.setRest(true);
    rule2.setVersion("1");
    newRules.add(rule1);
    newRules.add(rule2);
    switch(testOption) {
        case USER_ACCESS_TEST:
            userAccess.add((String) configOption);
            rule1.setUserAccess(userAccess);
            supportedSchemes.add(Scheme.BASIC);
            methodsRequired.add(HTTPMethod.ANY);
            break;
        case PERMISSION_ACCESS_TEST:
            permissionAccess.add((String) configOption);
            rule1.setPermissionAccess(permissionAccess);
            supportedSchemes.add(Scheme.BASIC);
            methodsRequired.add(HTTPMethod.ANY);
            break;
        case METHOD_SPECIFIC_TEST:
            supportedSchemes.add(Scheme.BASIC);
            methodsRequired.add((HTTPMethod) configOption);
            permissionAccess.add(configOption2);
            rule1.setPermissionAccess(permissionAccess);
            break;
        case LOGIN_ACCESS_TEST:
            supportedSchemes.add(Scheme.USERNAME_PASSWORD);
            supportedSchemes.add(Scheme.OPEN_ID);
            methodsRequired.add(HTTPMethod.ANY);
            rule1.setRest(false);
            break;
        case NO_SECURITY_TEST:
            newRules.remove(rule1);
            supportedSchemes.add(Scheme.NO_SECURITY);
            methodsRequired.add(HTTPMethod.ANY);
            break;
        default:
            break;
    }
    rule1.setMethodsRequired(methodsRequired);
    rule1.setSupportedSchemes(supportedSchemes);
    rule1.setActive(true);
    rule2.setMethodsRequired(methodsRequired);
    rule2.setSupportedSchemes(supportedSchemes);
    rule2.setActive(true);
    return new MotechSecurityConfiguration(newRules);
}
Also used : MotechSecurityConfiguration(org.motechproject.security.domain.MotechSecurityConfiguration) Scheme(org.motechproject.security.constants.Scheme) HTTPMethod(org.motechproject.security.constants.HTTPMethod) MotechURLSecurityRule(org.motechproject.security.domain.MotechURLSecurityRule) ArrayList(java.util.ArrayList)

Aggregations

MotechURLSecurityRule (org.motechproject.security.domain.MotechURLSecurityRule)18 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)6 Transactional (org.springframework.transaction.annotation.Transactional)6 HTTPMethod (org.motechproject.security.constants.HTTPMethod)4 MotechSecurityConfiguration (org.motechproject.security.domain.MotechSecurityConfiguration)4 Scheme (org.motechproject.security.constants.Scheme)3 Collection (java.util.Collection)2 SecurityRuleComparator (org.motechproject.security.domain.SecurityRuleComparator)2 SecurityRuleDto (org.motechproject.security.model.SecurityRuleDto)2 SecurityFilterChain (org.springframework.security.web.SecurityFilterChain)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1 InOrder (org.mockito.InOrder)1 Resource (org.springframework.core.io.Resource)1 FilterChainProxy (org.springframework.security.web.FilterChainProxy)1