@Test public void testShouldRequireMethodsSupported() { configException.expect(SecurityConfigException.class); configException.expectMessage(SecurityRuleBuilder.NO_METHODS_REQUIRED_EXCEPTION_MESSAGE); MotechURLSecurityRule securityRule = new MotechURLSecurityRule(); securityRule.setPattern("pattern"); securityRule.setProtocol(HTTP); securityRule.setSupportedSchemes(Arrays.asList(USERNAME_PASSWORD)); securityBuilder.buildSecurityChain(securityRule, GET); }
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); }
SecurityRuleBuilder { 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); } }
SecurityRuleBuilder { 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); }  }
SecurityRuleBuilder { 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); }  synchronized SecurityFilterChain buildSecurityChain(MotechURLSecurityRule securityRule, HTTPMethod method); @Autowired void setChannelDecisionManager(ChannelDecisionManager channelDecisionManager); @Autowired void setAuthenticationManager(AuthenticationManager authenticationManager); @Autowired void setSettingsFacade(SettingsFacade settingsFacade); @Autowired void setUsernamePasswordAuthenticationFilter(UsernamePasswordAuthenticationFilter usernamePasswordAuthenticationFilter); @Autowired void setOpenIDAuthenticationFilter(OpenIDAuthenticationFilter openIDAuthenticationFilter); @Autowired void setMotechLogoutHandler(MotechLogoutSuccessHandler motechLogoutHandler); @Autowired @Qualifier("basicAuthenticationEntryPoint") void setBasicAuthenticationEntryPoint(AuthenticationEntryPoint basicAuthenticationEntryPoint); @Autowired @Qualifier("loginFormAuthentication") void setLoginAuthenticationEntryPoint(AuthenticationEntryPoint loginAuthenticationEntryPoint); }
SecurityRuleBuilder { 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); }  synchronized SecurityFilterChain buildSecurityChain(MotechURLSecurityRule securityRule, HTTPMethod method); @Autowired void setChannelDecisionManager(ChannelDecisionManager channelDecisionManager); @Autowired void setAuthenticationManager(AuthenticationManager authenticationManager); @Autowired void setSettingsFacade(SettingsFacade settingsFacade); @Autowired void setUsernamePasswordAuthenticationFilter(UsernamePasswordAuthenticationFilter usernamePasswordAuthenticationFilter); @Autowired void setOpenIDAuthenticationFilter(OpenIDAuthenticationFilter openIDAuthenticationFilter); @Autowired void setMotechLogoutHandler(MotechLogoutSuccessHandler motechLogoutHandler); @Autowired @Qualifier("basicAuthenticationEntryPoint") void setBasicAuthenticationEntryPoint(AuthenticationEntryPoint basicAuthenticationEntryPoint); @Autowired @Qualifier("loginFormAuthentication") void setLoginAuthenticationEntryPoint(AuthenticationEntryPoint loginAuthenticationEntryPoint); static final String NO_PATTERN_EXCEPTION_MESSAGE; static final String NO_PROTOCOL_EXCEPTION_MESSAGE; static final String NO_SUPPORTED_SCHEMES_EXCEPTION_MESSAGE; static final String NO_METHODS_REQUIRED_EXCEPTION_MESSAGE; }