use of org.motechproject.security.chain.MotechSecurityFilterChain in project motech by motech.
the class SecurityRuleBuilder method buildSecurityChain.
/**
* Builds SecurityFilterChain which is capable of being
* matched against HttpServletRequest in order to decide
* whether it applies to that request
*
* @param securityRule that will be used as pattern
* @param method to be used in filter
* @return new filter chain with security rule, matcher and filters
*/
public synchronized SecurityFilterChain buildSecurityChain(MotechURLSecurityRule securityRule, HTTPMethod method) {
LOGGER.info("Building security chain for rule: {} and method: {}", securityRule.getPattern(), method);
List<Filter> filters = new ArrayList<>();
RequestMatcher matcher;
validateRule(securityRule);
String pattern = securityRule.getPattern();
if (pattern.equals(SecurityConfigConstants.ANY_PATTERN) || "/**".equals(pattern) || "**".equals(pattern)) {
matcher = AnyRequestMatcher.INSTANCE;
} else if (ANY == method) {
matcher = new AntPathRequestMatcher(pattern);
} else {
matcher = new AntPathRequestMatcher(pattern, method.name());
}
if (!noSecurity(securityRule)) {
try {
filters = addFilters(securityRule);
} catch (ServletException e) {
LOGGER.error("Cannot create {} in {} security rule.", SecurityContextHolderAwareRequestFilter.class, securityRule.getPattern(), e);
}
}
LOGGER.info("Built security chain for rule: {} and method: {}", securityRule.getPattern(), method);
return new MotechSecurityFilterChain(securityRule, matcher, filters);
}
Aggregations