use of javax.servlet.Filter in project steve by RWTH-i5-IDSG.
the class SteveAppContext method addSecurityFilter.
private void addSecurityFilter(WebAppContext ctx) {
// The bean name is not arbitrary, but is as expected by Spring
Filter f = new DelegatingFilterProxy(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME);
ctx.addFilter(new FilterHolder(f), CONFIG.getSpringManagerMapping(), EnumSet.allOf(DispatcherType.class));
}
use of javax.servlet.Filter in project adeptj-modules by AdeptJ.
the class ShiroActivator method start.
/**
* Initializes the Shiro Security Framework.
*/
@Override
public void start(BundleContext context) throws Exception {
cacheProviderTracker = new CacheProviderTracker(context, CacheProvider.class);
cacheProviderTracker.open();
// Register the Shiro EnvironmentLoaderListener first.
Dictionary<String, Object> shiroListenerProps = new Hashtable<>();
shiroListenerProps.put(Constants.SERVICE_VENDOR, "AdeptJ");
shiroListenerProps.put("osgi.http.whiteboard.listener", "true");
servRegShiroListener = context.registerService(ServletContextListener.class, new ExtEnvironmentLoaderListener(), shiroListenerProps);
// Now Register the ShiroFilter.
Dictionary<String, Object> shiroFilterProps = new Hashtable<>();
shiroFilterProps.put(Constants.SERVICE_VENDOR, "AdeptJ");
shiroFilterProps.put("osgi.http.whiteboard.filter.name", "Shiro Filter");
shiroFilterProps.put("osgi.http.whiteboard.filter.pattern", "/*");
shiroFilterProps.put("osgi.http.whiteboard.filter.asyncSupported", "true");
shiroFilterProps.put("osgi.http.whiteboard.filter.dispatcher", new String[] { "REQUEST", "INCLUDE", "FORWARD", "ASYNC", "ERROR" });
servRegShiroFilter = context.registerService(Filter.class, new ShiroFilter(), shiroFilterProps);
}
use of javax.servlet.Filter in project jspwiki by apache.
the class WikiSessionTest method runSecurityFilter.
/**
* "Scaffolding" method that runs the session security filter on a mock request. We do this by creating a
* complete mock servlet context and filter chain, and running the request through it.
* @param engine the wiki engine
* @param request the mock request to pass itnto the
* @throws ServletException
* @throws IOException
*/
private static void runSecurityFilter(WikiEngine engine, HttpServletRequest request) throws ServletException, IOException {
// Create a mock servlet context and stash the wiki engine in it
ServletContext servletCtx = new MockServletContext("JSPWiki");
servletCtx.setAttribute("org.apache.wiki.WikiEngine", engine);
// Create a mock filter configuration and add the servlet context we just created
MockFilterConfig filterConfig = new MockFilterConfig();
filterConfig.setFilterName("WikiServletFilter");
filterConfig.setServletContext(servletCtx);
// Create the security filter and run the request through it
Filter filter = new WikiServletFilter();
MockFilterChain chain = new MockFilterChain();
chain.addFilter(filter);
Servlet servlet = new MockServlet();
chain.setServlet(servlet);
filter.init(filterConfig);
filter.doFilter(request, null, chain);
}
use of javax.servlet.Filter 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);
}
use of javax.servlet.Filter in project motech by motech.
the class SecurityRuleBuilder method addFilters.
private List<Filter> addFilters(MotechURLSecurityRule securityRule) throws ServletException {
List<Filter> filters = new ArrayList<>();
SecurityContextRepository contextRepository = new HttpSessionSecurityContextRepository();
RequestCache requestCache = new HttpSessionRequestCache();
addSecureChannel(filters, securityRule.getProtocol());
addSecurityContextPersistenceFilter(filters, contextRepository);
addLogoutFilter(filters, securityRule);
addAuthenticationFilters(filters, securityRule);
addRequestCacheFilter(filters, requestCache);
addSecurityContextHolderAwareRequestFilter(filters);
addAnonymousAuthenticationFilter(filters);
addSessionManagementFilter(filters, contextRepository);
addExceptionTranslationFilter(filters, requestCache, securityRule.isRest());
addFilterSecurityInterceptor(filters, securityRule);
return filters;
}
Aggregations