Search in sources :

Example 91 with Filter

use of javax.servlet.Filter in project hudson-2.x by hudson.

the class SecurityRealm method createFilter.

/**
 * Creates {@link Filter} that all the incoming HTTP requests will go through
 * for authentication.
 * <p/>
 * <p/>
 * The default implementation uses {@link #getSecurityComponents()} and builds
 * a standard filter chain from /WEB-INF/security/SecurityFilters.groovy.
 * But subclasses can override this to completely change the filter sequence.
 * <p/>
 * <p/>
 * For other plugins that want to contribute {@link Filter}, see
 * {@link PluginServletFilter}.
 *
 * @since 1.271
 */
public Filter createFilter(FilterConfig filterConfig) {
    LOGGER.entering(SecurityRealm.class.getName(), "createFilter");
    Binding binding = new Binding();
    SecurityComponents sc = getSecurityComponents();
    binding.setVariable("securityComponents", sc);
    binding.setVariable("securityRealm", this);
    BeanBuilder builder = new BeanBuilder();
    builder.parse(filterConfig.getServletContext().getResourceAsStream("/WEB-INF/security/SecurityFilters.groovy"), binding);
    WebApplicationContext context = builder.createApplicationContext();
    return (Filter) context.getBean("filter");
}
Also used : Binding(groovy.lang.Binding) BeanBuilder(hudson.util.spring.BeanBuilder) Filter(javax.servlet.Filter) PluginServletFilter(hudson.util.PluginServletFilter) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 92 with Filter

use of javax.servlet.Filter in project tomee by apache.

the class HttpUtil method addFilter.

public static boolean addFilter(final String classname, final WebContext wc, final String mapping, final FilterConfig config) {
    final HttpListenerRegistry registry = SystemInstance.get().getComponent(HttpListenerRegistry.class);
    if (registry == null || mapping == null) {
        return false;
    }
    final FilterListener listener;
    try {
        listener = new FilterListener((Filter) wc.newInstance(wc.getClassLoader().loadClass(classname)), wc.getContextRoot());
        listener.getDelegate().init(config);
    } catch (Exception e) {
        throw new OpenEJBRuntimeException(e);
    }
    registry.addHttpFilter(listener, pattern(wc.getContextRoot(), mapping));
    return true;
}
Also used : OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) FilterListener(org.apache.openejb.server.httpd.FilterListener) Filter(javax.servlet.Filter) HttpListenerRegistry(org.apache.openejb.server.httpd.HttpListenerRegistry) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException)

Example 93 with Filter

use of javax.servlet.Filter in project tomee by apache.

the class HttpUtil method removeFilter.

public static void removeFilter(final String mapping, final WebContext wc) {
    final HttpListenerRegistry registry = SystemInstance.get().getComponent(HttpListenerRegistry.class);
    if (registry == null || mapping == null) {
        return;
    }
    final Collection<HttpListener> filters = registry.removeHttpFilter(pattern(wc.getContextRoot(), mapping));
    for (HttpListener listener : filters) {
        final Filter filter = ((FilterListener) listener).getDelegate();
        filter.destroy();
        wc.destroy(filter);
    }
    filters.clear();
}
Also used : FilterListener(org.apache.openejb.server.httpd.FilterListener) Filter(javax.servlet.Filter) HttpListener(org.apache.openejb.server.httpd.HttpListener) HttpListenerRegistry(org.apache.openejb.server.httpd.HttpListenerRegistry)

Example 94 with Filter

use of javax.servlet.Filter in project midpoint by Evolveum.

the class MidpointAutowiredBeanFactoryObjectPostProcessor method destroyAndRemoveFilters.

public void destroyAndRemoveFilters(List<Filter> filters) {
    synchronized (this) {
        for (Filter filter : filters) {
            if (filter instanceof DisposableBean && this.disposableBeans.contains(filter)) {
                filter.destroy();
                disposableBeans.remove(filter);
            }
        }
    }
}
Also used : Filter(javax.servlet.Filter) DisposableBean(org.springframework.beans.factory.DisposableBean)

Example 95 with Filter

use of javax.servlet.Filter in project midpoint by Evolveum.

the class Saml2ModuleFactory method createModuleFilter.

@Override
public AuthModule createModuleFilter(AbstractAuthenticationModuleType moduleType, String sequenceSuffix, ServletRequest request, Map<Class<?>, Object> sharedObjects, AuthenticationModulesType authenticationsPolicy, CredentialsPolicyType credentialPolicy, AuthenticationChannel authenticationChannel) throws Exception {
    if (!(moduleType instanceof Saml2AuthenticationModuleType)) {
        LOGGER.error("This factory support only Saml2AuthenticationModuleType, but modelType is " + moduleType);
        return null;
    }
    isSupportedChannel(authenticationChannel);
    SamlModuleWebSecurityConfiguration.setProtector(getProtector());
    SamlModuleWebSecurityConfiguration configuration = SamlModuleWebSecurityConfiguration.build((Saml2AuthenticationModuleType) moduleType, sequenceSuffix, getPublicUrlPrefix(request), request);
    configuration.setSequenceSuffix(sequenceSuffix);
    configuration.addAuthenticationProvider(getObjectObjectPostProcessor().postProcess(new Saml2Provider()));
    SamlModuleWebSecurityConfigurer<SamlModuleWebSecurityConfiguration> module = getObjectObjectPostProcessor().postProcess(new SamlModuleWebSecurityConfigurer<>(configuration));
    HttpSecurity http = getNewHttpSecurity(module);
    setSharedObjects(http, sharedObjects);
    ModuleAuthenticationImpl moduleAuthentication = createEmptyModuleAuthentication(configuration, request);
    moduleAuthentication.setFocusType(moduleType.getFocusType());
    SecurityFilterChain filter = http.build();
    for (Filter f : filter.getFilters()) {
        if (f instanceof Saml2WebSsoAuthenticationRequestFilter) {
            ((Saml2WebSsoAuthenticationRequestFilter) f).setRedirectMatcher(new AntPathRequestMatcher(module.getPrefix() + RemoteModuleAuthenticationImpl.AUTHENTICATION_REQUEST_PROCESSING_URL_SUFFIX_WITH_REG_ID));
            break;
        }
    }
    return AuthModuleImpl.build(filter, configuration, moduleAuthentication);
}
Also used : SecurityFilterChain(org.springframework.security.web.SecurityFilterChain) Saml2ModuleAuthenticationImpl(com.evolveum.midpoint.authentication.impl.module.authentication.Saml2ModuleAuthenticationImpl) ModuleAuthenticationImpl(com.evolveum.midpoint.authentication.impl.module.authentication.ModuleAuthenticationImpl) RemoteModuleAuthenticationImpl(com.evolveum.midpoint.authentication.impl.module.authentication.RemoteModuleAuthenticationImpl) Saml2WebSsoAuthenticationRequestFilter(org.springframework.security.saml2.provider.service.servlet.filter.Saml2WebSsoAuthenticationRequestFilter) Saml2Provider(com.evolveum.midpoint.authentication.impl.provider.Saml2Provider) HttpSecurity(org.springframework.security.config.annotation.web.builders.HttpSecurity) Saml2WebSsoAuthenticationRequestFilter(org.springframework.security.saml2.provider.service.servlet.filter.Saml2WebSsoAuthenticationRequestFilter) Filter(javax.servlet.Filter) AntPathRequestMatcher(org.springframework.security.web.util.matcher.AntPathRequestMatcher) SamlModuleWebSecurityConfiguration(com.evolveum.midpoint.authentication.impl.module.configuration.SamlModuleWebSecurityConfiguration)

Aggregations

Filter (javax.servlet.Filter)185 FilterChain (javax.servlet.FilterChain)67 Test (org.junit.Test)57 HttpServletRequest (javax.servlet.http.HttpServletRequest)53 HttpServletResponse (javax.servlet.http.HttpServletResponse)44 ServletRequest (javax.servlet.ServletRequest)43 ServletResponse (javax.servlet.ServletResponse)43 ServletException (javax.servlet.ServletException)28 FilterConfig (javax.servlet.FilterConfig)25 IOException (java.io.IOException)23 ServletContext (javax.servlet.ServletContext)20 Injector (com.google.inject.Injector)17 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)16 OncePerRequestFilter (org.springframework.web.filter.OncePerRequestFilter)13 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)12 Map (java.util.Map)9 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)9 ArrayList (java.util.ArrayList)8 Hashtable (java.util.Hashtable)8 DispatcherType (javax.servlet.DispatcherType)8