Filter to run for the LegacySecurityRealm is the
ChainServletFilter legacy from /WEB-INF/security/SecurityFilters.groovy.
486714
@Override
    public Filter createFilter(FilterConfig filterConfig) {
        Binding binding = new Binding();
        SecurityComponents sc = this.createSecurityComponents();
        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("legacy");
    }
1016601
public static sslglobal_sslpolicy_binding[] get_filtered(nitro_service service, filtervalue[] filter) throws Exception{
		sslglobal_sslpolicy_binding obj = new sslglobal_sslpolicy_binding();
		options option = new options();
		option.set_filter(filter);
		sslglobal_sslpolicy_binding[] response = (sslglobal_sslpolicy_binding[]) obj.getfiltered(service, option);
		return response;
	}
309583
public Object doFilter(Object object, Method method, Object[] params, AjaxFilterChain chain) throws Exception
    {
        // We allow anyone to authenticate
        if (authenticateName.equals(method.getName()))
        {
            return chain.doFilter(object, method, params);
        }

        Object user = getUser();
        if (user != null)
        {
            return chain.doFilter(object, method, params);
        }

        throw new SecurityException("Not authenticated");
    }
1374574
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
      ServletException
   {
      ExoContainer container = getContainer();

      SessionProviderService providerService =
         (SessionProviderService)container.getComponentInstanceOfType(SessionProviderService.class);
      ConversationRegistry stateRegistry = (ConversationRegistry)container.getComponentInstanceOfType(ConversationRegistry.class);

      HttpServletRequest httpRequest = (HttpServletRequest)request;

      ConversationState state = ConversationState.getCurrent();
      SessionProvider provider = null;

      // NOTE not create new HTTP session, if session is not created yet
      // this means some settings is incorrect, see web.xml for filter
      // org.exoplatform.services.security.web.SetCurrentIdentityFilter
      HttpSession httpSession = httpRequest.getSession(false);
      if (state == null)
      {
         if (LOG.isDebugEnabled())
         {
            LOG.debug("Current conversation state is not set");
         }

         if (httpSession != null)
         {
            StateKey stateKey = new HttpSessionStateKey(httpSession);
            // initialize thread local SessionProvider
            state = stateRegistry.getState(stateKey);
            if (state != null)
            {
               provider = new SessionProvider(state);
            }
            else if (LOG.isDebugEnabled())
            {
               LOG.debug("WARN: Conversation State is null, id  " + httpSession.getId());
            }
         }
      }
      else
      {
         provider = new SessionProvider(state);
      }

      if (provider == null)
      {
         if (LOG.isDebugEnabled())
         {
            LOG.debug("Create SessionProvider for anonymous.");
         }
         provider = SessionProvider.createAnonimProvider();
      }
      try
      {
         if (ConversationState.getCurrent() != null)
         {
            ConversationState.getCurrent().setAttribute(SessionProvider.SESSION_PROVIDER, provider);
         }

         providerService.setSessionProvider(null, provider);

         chain.doFilter(request, response);

      }
      finally
      {
         if (ConversationState.getCurrent() != null)
         {
            try
            {
               ConversationState.getCurrent().removeAttribute(SessionProvider.SESSION_PROVIDER);
            }
            catch (Exception e)
            {
               LOG.warn("An error occured while removing the session provider from the conversation state", e);
            }
         }
         if (providerService.getSessionProvider(null) != null)
         {
            try
            {
               // remove SessionProvider
               providerService.removeSessionProvider(null);
            }
            catch (Exception e)
            {
               LOG.warn("An error occured while cleaning the ThreadLocal", e);
            }
         }
      }
   }
1063925
private Predicate<com.datastax.driver.core.Host> getHostFilterPredicate(String hostFilterPolicy)
    {
        Predicate<com.datastax.driver.core.Host> predicate = null;
        Method getter = null;
        Class<?> hostFilterClazz = null;
        try
        {

            hostFilterClazz = Class.forName(hostFilterPolicy);
            getter = hostFilterClazz.getDeclaredMethod(GET_INSTANCE);

            predicate = (Predicate<com.datastax.driver.core.Host>) getter.invoke(KunderaCoreUtils
                    .createNewInstance(hostFilterClazz));
        }
        catch (ClassNotFoundException e)
        {
            logger.error(e.getMessage());
            throw new KunderaException("Please make sure class " + hostFilterPolicy
                    + " set in property file exists in classpath " + e.getMessage());
        }
        catch (IllegalAccessException e)
        {
            logger.error(e.getMessage());
            throw new KunderaException("Method " + getter.getName() + " must be declared public " + e.getMessage());
        }
        catch (NoSuchMethodException e)
        {
            logger.error(e.getMessage());
            throw new KunderaException("Please make sure getter method of " + hostFilterClazz.getSimpleName()
                    + " is named \"getInstance()\"");
        }
        catch (InvocationTargetException e)
        {
            logger.error(e.getMessage());
            throw new KunderaException("Error while executing \"getInstance()\" method of Class "
                    + hostFilterClazz.getSimpleName() + ": " + e.getMessage());
        }
        catch (SecurityException e)
        {
            logger.error(e.getMessage());
            throw new KunderaException("Encountered security exception while accessing the method: "
                    + "\"getInstance()\"" + e.getMessage());
        }
        return predicate;
    }
1191396
def iter_filters_in(target):
    # type: (Any) -> Generator[Tuple[Text, Type[BaseFilter]]]
    
    global legacy_warned
    if not legacy_warned:
        # Set the global flag to ``True`` first, in case the user has
        # ``simplefilter('error')`` set.
        legacy_warned = True

        warn(
            'Legacy extension loader is deprecated and will be removed in '
                'Filters v1.4.  '
                'See http://filters.readthedocs.io/en/latest/extensions.html#legacy-extensions-loader '
                'for more information.',

            DeprecationWarning,
        )

    ift_result = is_filter_type(target)

    if ift_result is True:
        logger.debug(
            'Registering extension filter '
            '{cls.__module__}.{cls.__name__}.'.format(
                cls = target,
            ),
        )

        yield target.__name__, target
    elif is_module(target):
        for member_name, member in get_members(target):
            member_ift_result = is_filter_type(member)

            if member_ift_result is True:
                logger.debug(
                    'Registering extension filter '
                    '{cls.__module__}.{cls.__name__}.'.format(
                        cls = member,
                    ),
                )

                yield member.__name__, member
            else:
                logger.debug(
                    'Ignoring {module}.{name} ({reason})'.format(
                        module  = target.__name__,
                        name    = member_name,
                        reason  = member_ift_result,
                    ),
                )
    elif is_class(target):
        logger.debug(
            'Ignoring {cls.__module__}.{cls.__name__} ({reason}).'.format(
                cls     = target,
                reason  = ift_result,
            ),
        )
    else:
        logger.debug(
            'Ignoring {target!r} ({reason}).'.format(
                reason  = ift_result,
                target  = target,
            ),
        )
341942
public void doFilter(ServletRequest request,
                         ServletResponse response,
                         FilterChain chain)
	throws IOException, ServletException
    {
        String path=((HttpServletRequest)request).getServletPath();
        if (welcome!=null && path.endsWith("/"))
            request.getRequestDispatcher(path+welcome).forward(request,response);
        else
            chain.doFilter(request, response);
    }
859439
public static sslpolicylabel[] get_filtered(nitro_service service, String filter) throws Exception{
		sslpolicylabel obj = new sslpolicylabel();
		options option = new options();
		option.set_filter(filter);
		sslpolicylabel[] response = (sslpolicylabel[]) obj.getfiltered(service, option);
		return response;
	}
615656
public static sslwrapkey[] get_filtered(nitro_service service, String filter) throws Exception{
		sslwrapkey obj = new sslwrapkey();
		options option = new options();
		option.set_filter(filter);
		sslwrapkey[] response = (sslwrapkey[]) obj.getfiltered(service, option);
		return response;
	}
294610
public static mps_ssl_certkey[] get_filtered(nitro_service service, filtervalue[] filter) throws Exception
	{
		mps_ssl_certkey obj = new mps_ssl_certkey();
		options option = new options();
		option.set_filter(filter);
		mps_ssl_certkey[] response = (mps_ssl_certkey[]) obj.getfiltered(service, option);
		return response;
	}
1216585
protected RequestSecurityProcessor getLastProcessorInChain(final FilterChain chain) {
        return new RequestSecurityProcessor() {

            public void processRequest(RequestContext context, RequestSecurityProcessorChain processorChain) throws
                Exception {
                chain.doFilter(context.getRequest(), context.getResponse());
            }

        };
    }
81141
public static JspParameterFilters getJspParameterFilters(
      String userFilter,
      String poolGroupFilter,
      String poolInfoFilter) {
    JspParameterFilters filters = new JspParameterFilters();
    if (userFilter != null && !userFilter.equals("null")) {
      filters.getUserFilterSet().addAll(Arrays.asList(userFilter.split(",")));
      filters.getHtmlOutput().append(("<b>users:</b> " + userFilter + "<br>"));
    }
    if (poolGroupFilter != null && !poolGroupFilter.equals("null")) {
      filters.getPoolGroupFilterSet().addAll(
          Arrays.asList(poolGroupFilter.split(",")));
      filters.getHtmlOutput().append("<b>poolGroups:</b> " + poolGroupFilter +
          "<br>");
    }
    if (poolInfoFilter != null && !poolInfoFilter.equals("null")) {
      filters.getHtmlOutput().append(
          "<b>poolInfos:</b> " + poolInfoFilter + "<br>");
      for (String poolInfoString : poolInfoFilter.split(",")) {
        String[] poolInfoStrings = poolInfoString.split("[.]");
        if (poolInfoStrings.length == 2) {
          filters.getPoolInfoFilterSet().add(new PoolInfo(poolInfoStrings[0],
              poolInfoStrings[1]));
        }
      }
    }
    return filters;
  }
283289
@Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse) res;
        response.setHeader("Access-Control-Allow-Origin", allowOrigin);
        response.setHeader("Access-Control-Allow-Methods", allowMethod);
        response.setHeader("Access-Control-Max-Age", maxAge);
        response.setHeader("Access-Control-Allow-Headers", allowHeaders);
        chain.doFilter(req, res);
    }
809056
public static ns_ssl_certkey[] get_filtered(nitro_service service, String filter) throws Exception
	{
		ns_ssl_certkey obj = new ns_ssl_certkey();
		options option = new options();
		option.set_filter(filter);
		ns_ssl_certkey[] response = (ns_ssl_certkey[]) obj.getfiltered(service, option);
		return response;
	}
475748
@Override
    public void doFilter(ServletRequest request,
                         ServletResponse response,
                         FilterChain chain) throws IOException,
            ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse res = (HttpServletResponse) response;

        // This is a hack to skip challenge authentication of API-A methods via the
        // REST API if API-A AuthN is off (as indicated by the "authnAPIA"
        // filter init-param).
        // If API-A AuthN is off, for all GET requests via the REST API,
        // except those which are known to be part of API-M, don't challenge for authentication
        // (but do pick up any preemptive credentials that are supplied)
        // FIXME: As other servlets that require authn also go through this filter,
        // there's probably a neater way to ensure we are only catching API-A methods
        // currently we are explicitly testing for other management URLs/paths
        // (probably should test fullPath for {appcontext}/objects (REST API) and then
        // test path for API-A methods, maybe regex to make it explicit)
        boolean doChallenge = true;
        if (!authnAPIA) {
            if (req.getMethod().equals("GET") || req.getMethod().equals("HEAD")) {
                String requestPath = req.getPathInfo();
                if (requestPath == null) requestPath = ""; // null is returned eg for /fedora/objects? - API-A, so we still want to do the below...
                String fullPath = req.getRequestURI();
                // API-M methods
                // potentially extra String evals, but aiming for clarity
                boolean isExport = requestPath.endsWith("/export");
                boolean isObjectXML = requestPath.endsWith("/objectXML");
                boolean isGetDatastream =
                        requestPath.contains("/datastreams/")
                                && !requestPath.endsWith("/content");
                isGetDatastream = isGetDatastream || (requestPath.endsWith("/datastreams")
                                && Boolean.valueOf(request.getParameter("profiles")));
                boolean isGetRelationships =
                        requestPath.endsWith("/relationships");
                boolean isValidate = requestPath.endsWith("/validate");
                // management get methods (LITE API, control)
                boolean isManagement =
                        fullPath.endsWith("/management/control")
                                || fullPath.endsWith("/management/getNextPID");
                // user servlet
                boolean isUserServlet = fullPath.endsWith("/user");
                // challenge if API-M or one of the above other services (otherwise we assume it is API-A)
                doChallenge =
                        isExport || isObjectXML || isGetDatastream
                                || isGetRelationships || isValidate
                                || isManagement || isUserServlet;
            }
        }

        if (logger.isDebugEnabled()) {
            logger.debug("incoming filter: {}", this.getClass().getName());
            logger.debug("session-id: {}", req.getSession().getId());
        }

        Subject subject = authenticate(req);

        if (subject == null) {
            if (doChallenge) {
                loginForm(res);
                return;
            } else {
                // no auth required, and none supplied, do rest of chain
                chain.doFilter(request, response);
                return;
            }
        }

        // obtain the user principal from the subject and add to servlet.
        Principal userPrincipal = getUserPrincipal(subject);

        // obtain the user roles from the subject and add to servlet.
        Set<String> userRoles = getUserRoles(subject);

        // wrap the request in one that has the ability to store role
        // and principal information and store this information.
        AuthHttpServletRequestWrapper authRequest =
                new AuthHttpServletRequestWrapper(req);
        authRequest.setUserPrincipal(userPrincipal);
        authRequest.setUserRoles(userRoles);

        // add the roles that were obtained to the Subject.
        addRolesToSubject(subject, userRoles);

        // populate FEDORA_AUX_SUBJECT_ATTRIBUTES with fedoraRole
        // and any additional Subject attributes
        populateFedoraAttributes(subject, userRoles, authRequest);

        chain.doFilter(authRequest, response);

        if (logger.isDebugEnabled()) {
            logger.debug("outgoing filter: " + this.getClass().getName());
        }
    }
618690
public Object doFilter(Object obj, Method method, Object[] params, AjaxFilterChain chain) throws Exception
    {
        if (System.currentTimeMillis() % 2 == 1)
        {
            return chain.doFilter(obj, method, params);
        }
        else
        {
            throw new SecurityException("Wrong time. Try again later");
        }
    }
1096625
@SuppressWarnings("unchecked")
    private static Filter<ArchivePath> getFilterInstance(final String filterClassName, final Class<?>[] ctorTypes,
        final Object[] ctorArguments) {
        // Precondition checks
        assert filterClassName != null && filterClassName.length() > 0 : "Filter class name must be specified";
        assert ctorTypes != null : "Construction types must be specified";
        assert ctorArguments != null : "Construction arguments must be specified";
        assert ctorTypes.length == ctorArguments.length : "The number of ctor arguments and their types must match";

        // Find the filter impl class in the configured CLs
        final Class<Filter<ArchivePath>> filterClass;
        try {
            filterClass = (Class<Filter<ArchivePath>>) ClassLoaderSearchUtil.findClassFromClassLoaders(filterClassName,
                ShrinkWrap.getDefaultDomain().getConfiguration().getClassLoaders());
        } catch (final ClassNotFoundException cnfe) {
            throw new IllegalStateException("Could not find filter implementation class " + filterClassName
                + " in any of the configured CLs", cnfe);
        }

        // Make the new instance
        return SecurityActions.newInstance(filterClass, ctorTypes, ctorArguments, Filter.class);
    }