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);
}
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);
}
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());
}
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);
}
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);
}
Aggregations