Example usage for javax.servlet FilterChain doFilter

List of usage examples for javax.servlet FilterChain doFilter

Introduction

In this page you can find the example usage for javax.servlet FilterChain doFilter.

Prototype

public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException;

Source Link

Document

Causes the next filter in the chain to be invoked, or if the calling filter is the last filter in the chain, causes the resource at the end of the chain to be invoked.

Usage

From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.WebAnnoLoggingFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
        throws IOException, ServletException {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (authentication != null) {
        setLoggingUsername(authentication.getName());
    }/*from w  w w.  jav  a 2  s  . c  o m*/
    try {
        chain.doFilter(req, resp);
    } finally {
        if (authentication != null) {
            clearLoggingUsername();
        }
    }
}

From source file:com.hp.security.jauth.core.filter.AuthFilter.java

private boolean setAllPassed(ServletRequest servletRequest, ServletResponse servletResponse,
        FilterChain filterchain) throws IOException, ServletException {
    ContextHolder.setPassed(true);// w  w w .  jav a 2s .co m
    filterchain.doFilter(servletRequest, servletResponse);
    return true;
}

From source file:org.italiangrid.storm.webdav.server.MiltonFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    if (isWebDAVMethod(request)) {
        doMilton((HttpServletRequest) request, (HttpServletResponse) response);
    } else/*from  ww  w .ja v a2 s . com*/
        chain.doFilter(request, response);

}

From source file:it.unipmn.di.dcs.sharegrid.web.servlet.MultipartFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    if (request.getAttribute(MultipartFilter.DoFilterCalledAttr) != null) {
        chain.doFilter(request, response);
        return;/*from   ww w  .  j a v  a2 s  .  c om*/
    }

    request.setAttribute(MultipartFilter.DoFilterCalledAttr, "true");

    // sanity check
    if (!(response instanceof HttpServletResponse)) {
        chain.doFilter(request, response);
        return;
    }

    HttpServletRequest httpReq = (HttpServletRequest) request;

    if (!ServletFileUpload.isMultipartContent(httpReq)) {
        chain.doFilter(request, response);
        return;
    }

    // Wraps the current request into a multipart request object
    // for handling multipart form parameters.

    MultipartRequestWrapper reqWrapper = null;

    reqWrapper = new MultipartRequestWrapper(httpReq, this.maxSize, this.maxFileSize, this.thresholdSize,
            this.repositoryPath);

    chain.doFilter(reqWrapper, response);
}

From source file:net.big_oh.hibernate.web.filter.HibernateOpenSessionInViewFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    try {//from   w  ww  .ja va  2  s.co m
        log.info("Starting a database transaction");
        sf.getCurrentSession().beginTransaction();

        // Call the next filter (continue request processing)
        chain.doFilter(request, response);

        // Commit and cleanup
        log.info("Committing the database transaction");
        sf.getCurrentSession().getTransaction().commit();

    } catch (Throwable ex) {
        HibernateUtil.rollback(ex, sf, log);

        // Let others handle it... maybe another interceptor for exceptions?
        throw new ServletException(ex);
    }
}

From source file:grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter.java

@Override
public void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain)
        throws IOException, ServletException {

    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;

    if (!requiresLogout(request, response)) {
        chain.doFilter(request, response);
        return;//ww  w  .j  ava2s  .com
    }

    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    log.debug("Logging out user '{}' and transferring to logout destination", auth);

    for (LogoutHandler handler : handlers) {
        handler.logout(request, response, auth);
    }

    logoutSuccessHandler.onLogoutSuccess(request, response, auth);
}

From source file:org.apache.cxf.fediz.service.idp.service.security.GrantedAuthorityEntitlements.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    try {//from   w  w w .jav  a2 s .c  o m
        Authentication currentAuth = SecurityContextHolder.getContext().getAuthentication();
        if (currentAuth == null) {
            chain.doFilter(request, response);
            return;
        }

        final Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();
        if (currentAuth.getAuthorities() != null) {
            authorities.addAll(currentAuth.getAuthorities());
        }

        Iterator<? extends GrantedAuthority> authIt = currentAuth.getAuthorities().iterator();
        while (authIt.hasNext()) {
            GrantedAuthority ga = authIt.next();
            String roleName = ga.getAuthority();

            try {
                Role role = roleDAO.getRole(roleName.substring(5), Arrays.asList("all"));
                for (Entitlement e : role.getEntitlements()) {
                    authorities.add(new SimpleGrantedAuthority(e.getName()));
                }
            } catch (Exception ex) {
                LOG.error("Role '" + roleName + "' not found");
            }
        }

        if (LOG.isDebugEnabled()) {
            LOG.debug(authorities.toString());
        }
        UsernamePasswordAuthenticationToken enrichedAuthentication = new UsernamePasswordAuthenticationToken(
                currentAuth.getName(), currentAuth.getCredentials(), authorities);
        enrichedAuthentication.setDetails(currentAuth.getDetails());

        SecurityContextHolder.getContext().setAuthentication(enrichedAuthentication);
        LOG.info("Enriched AuthenticationToken added");

    } catch (Exception ex) {
        LOG.error("Failed to enrich security context with entitlements", ex);
    }

    chain.doFilter(request, response);
}

From source file:org.trustedanalytics.metadata.parser.AuthenticationDisabler.java

private String authenticateEverything(InvocationOnMock invocation) throws IOException, ServletException {

    ServletRequest req = (ServletRequest) invocation.getArguments()[0];
    ServletResponse res = (ServletResponse) invocation.getArguments()[1];
    FilterChain filterChain = (FilterChain) invocation.getArguments()[2];

    Authentication authentication = mock(Authentication.class);
    when(authentication.isAuthenticated()).thenReturn(true);
    SecurityContextHolder.getContext().setAuthentication(authentication);

    filterChain.doFilter(req, res);

    return "method called";
}

From source file:com.example.securelogin.app.common.filter.InputValidationFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    if (request != null) {
        validateRequestParams(request);/*w  w w  . j  av a  2s  .c  o m*/

        if (request instanceof MultipartRequest) {
            validateFileNames((MultipartRequest) request);
        }
    }
    filterChain.doFilter(request, response);
}

From source file:net.duckling.ddl.web.filter.VWBFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws IOException, ServletException {
    request.setCharacterEncoding(encoding);
    response.setCharacterEncoding(encoding);
    if (request instanceof HttpServletRequest) {
        findTeam((HttpServletRequest) request);
        filterChain.doFilter(request, response);
        VWBContext.setCurrentTid(-1);//from  w w  w  . j  a v a  2s  . c om
    }
}