当前位置: 首页>>代码示例>>Java>>正文


Java FilterChain.doFilter方法代码示例

本文整理汇总了Java中javax.servlet.FilterChain.doFilter方法的典型用法代码示例。如果您正苦于以下问题:Java FilterChain.doFilter方法的具体用法?Java FilterChain.doFilter怎么用?Java FilterChain.doFilter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.servlet.FilterChain的用法示例。


在下文中一共展示了FilterChain.doFilter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doFilterInternal

import javax.servlet.FilterChain; //导入方法依赖的package包/类
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
    // Spring put the CSRF token in session attribute "_csrf"
    CsrfToken csrfToken = (CsrfToken) request.getAttribute("_csrf");

    // Send the cookie only if the token has changed
    String actualToken = request.getHeader("X-CSRF-TOKEN");
    if (actualToken == null || !actualToken.equals(csrfToken.getToken())) {
        // Session cookie that will be used by AngularJS
        String pCookieName = "CSRF-TOKEN";
        Cookie cookie = new Cookie(pCookieName, csrfToken.getToken());
        cookie.setMaxAge(-1);
        cookie.setHttpOnly(false);
        cookie.setPath("/");
        response.addCookie(cookie);
    }
    filterChain.doFilter(request, response);
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:19,代码来源:CsrfCookieGeneratorFilter.java

示例2: doFilter

import javax.servlet.FilterChain; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    // 包装请求和响应
    if (LOGGER.isDebugEnabled()) {
        request = new RequestWrapper((HttpServletRequest) request);
        response = new ResponseWrapper((HttpServletResponse) response);
    }
    try {

        chain.doFilter(request, response);

    } finally {
        if (LOGGER.isDebugEnabled()) {
            // 进行打印
            logRequest((RequestWrapper) request);
            logResponse((ResponseWrapper) response);
        }
    }
}
 
开发者ID:warlock-china,项目名称:wisp,代码行数:22,代码来源:RequestFilter.java

示例3: doFilter

import javax.servlet.FilterChain; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain) throws IOException, ServletException {
    PrintWriter out = response.getWriter();
    out.print(getClass().getName());
    chain.doFilter(request, response);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:8,代码来源:TestStandardContext.java

示例4: doFilter

import javax.servlet.FilterChain; //导入方法依赖的package包/类
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;
    String authorization = httpRequest.getHeader("authorization");
    if (null != authorization && authorization.length() > AUTH_PREFIX.length()) {
        authorization = authorization.substring(AUTH_PREFIX.length(), authorization.length());
        if ((rootUsername + ":" + rootPassword).equals(new String(Base64.decodeBase64(authorization)))) {
            authenticateSuccess(httpResponse, false);
            chain.doFilter(httpRequest, httpResponse);
        } else if ((guestUsername + ":" + guestPassword).equals(new String(Base64.decodeBase64(authorization)))) {
            authenticateSuccess(httpResponse, true);
            chain.doFilter(httpRequest, httpResponse);
        } else {
            needAuthenticate(httpResponse);
        }
    } else {
        needAuthenticate(httpResponse);
    }
}
 
开发者ID:elasticjob,项目名称:elastic-job-cloud,代码行数:21,代码来源:WwwAuthFilter.java

示例5: doFilterInternal

import javax.servlet.FilterChain; //导入方法依赖的package包/类
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
		throws ServletException, IOException {
	if (!registry.isEnabled()) {
		filterChain.doFilter(request, response);
		return;
	}
	final long startTime = registry.getNanos();
	filterChain.doFilter(request, response);
	final long duration = registry.getNanos() - startTime;

	final String username = getUsername();
	registry.increment("spring.Username.Invocations", username);
	registry.add("spring.Username.Durations", username, duration);
}
 
开发者ID:mevdschee,项目名称:tqdev-metrics,代码行数:16,代码来源:MeasureUserActivityFilter.java

示例6: doFilter

import javax.servlet.FilterChain; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain) throws IOException, ServletException {

    // This filter only needs to handle WebSocket upgrade requests
    if (!sc.areEndpointsRegistered() ||
            !UpgradeUtil.isWebSocketUpgradeRequest(request, response)) {
        chain.doFilter(request, response);
        return;
    }

    // HTTP request with an upgrade header for WebSocket present
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse resp = (HttpServletResponse) response;

    // Check to see if this WebSocket implementation has a matching mapping
    String path;
    String pathInfo = req.getPathInfo();
    if (pathInfo == null) {
        path = req.getServletPath();
    } else {
        path = req.getServletPath() + pathInfo;
    }
    WsMappingResult mappingResult = sc.findMapping(path);

    if (mappingResult == null) {
        // No endpoint registered for the requested path. Let the
        // application handle it (it might redirect or forward for example)
        chain.doFilter(request, response);
        return;
    }

    UpgradeUtil.doUpgrade(sc, req, resp, mappingResult.getConfig(),
            mappingResult.getPathParams());
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:36,代码来源:WsFilter.java

示例7: doFilter

import javax.servlet.FilterChain; //导入方法依赖的package包/类
public void doFilter(ServletRequest request, ServletResponse response,
                     FilterChain chain) throws IOException, ServletException {

    HttpServletResponse resp = (HttpServletResponse) response;
    resp.setHeader("Expires", "Tue, 03 Jul 2001 06:00:00 GMT");
    resp.setDateHeader("Last-Modified", new Date().getTime());
    resp.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
    resp.setHeader("Pragma", "no-cache");

    chain.doFilter(request, response);
}
 
开发者ID:trf2-jus-br,项目名称:intelijus,代码行数:12,代码来源:CacheControlFilter.java

示例8: doFilter

import javax.servlet.FilterChain; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
    throws IOException, ServletException {
    HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
    String jwt = resolveToken(httpServletRequest);
    if (StringUtils.hasText(jwt) && this.tokenProvider.validateToken(jwt)) {
        Authentication authentication = this.tokenProvider.getAuthentication(jwt);
        SecurityContextHolder.getContext().setAuthentication(authentication);
    }
    filterChain.doFilter(servletRequest, servletResponse);
}
 
开发者ID:torgcrm,项目名称:TorgCRM-Server,代码行数:12,代码来源:JWTFilter.java

示例9: doFilter

import javax.servlet.FilterChain; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
	if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) {
		String agent = ((HttpServletRequest)request).getHeader("user-agent");
		if (agent != null && iUserAgent.matcher(agent).find())
			response = new HttpServletResponseWrapper((HttpServletResponse)response).createResponse();
	}
	chain.doFilter(request,response);
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:10,代码来源:NoCacheFilter.java

示例10: doFilter

import javax.servlet.FilterChain; //导入方法依赖的package包/类
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
  throws IOException, ServletException
{
  HttpServletResponse response = (HttpServletResponse) res;
  response.setHeader("Access-Control-Allow-Origin", "*");
  response.setHeader("Access-Control-Allow-Methods", "GET");
  response.setHeader("Access-Control-Max-Age", "3600");
  response.setHeader("Access-Control-Allow-Headers", "x-requested-with");
  chain.doFilter(req, res);
}
 
开发者ID:fetox74,项目名称:wormboard-backend,代码行数:11,代码来源:SimpleCORSFilter.java

示例11: doFilterInternal

import javax.servlet.FilterChain; //导入方法依赖的package包/类
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
    String requestURI = request.getRequestURI();
    requestURI = requestURI.replaceAll("/+", "/").replaceAll("/+", "/");
    LOG.info("LoginFilter receive request uri : " + requestURI);

    if (requestURI.equals("/")||requestURI.equals("/web/login")||requestURI.equals("/web/doLogin")||requestURI.startsWith("/resources")|| requestURI.startsWith("/terminal/")) {
        filterChain.doFilter(request, response);
        return;
    }
    String path = request.getContextPath();
    this.basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";

    HttpSession session = request.getSession();

    BumblebeeUser user=(BumblebeeUser) session.getAttribute("curUser");
    if(null==user){
        java.io.PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<script>");
        out.println("window.open ('"+basePath+"','_top')");
        out.println("</script>");
        out.println("</html>");
    }else{
        filterChain.doFilter(request, response);
        return;
    }


}
 
开发者ID:gy-games,项目名称:bumblebee,代码行数:31,代码来源:LoginFilter.java

示例12: doFilterInternal

import javax.servlet.FilterChain; //导入方法依赖的package包/类
@Override
public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {

    String authToken = tokenHelper.getToken(request);
    if (authToken != null && !skipPathRequest(request, pathsToSkip)) {
        // get username from token
        String username = null;
        try {
            username = tokenHelper.getUsernameFromToken(authToken);
            logger.info("[TokenAuthenticationFilter->doFilterInternal] authToken is {} and username is {}",
                        authToken,
                        username);
            if (username != null && SecurityContextHolder.getContext().getAuthentication() == null) {
                User user = cacheHelper.getSessionUser("session_" + username);
                if (cacheHelper.getSessionUser("session_" + username) == null) {
                    throw new BadCredentialsException("回话失效,请重新登录");
                }
                    // get user
                UserDetails userDetails = (UserDetails) user;//userDetailsService.loadUserByUsername(username);
                // create authentication
                TokenBasedAuthentication authentication = new TokenBasedAuthentication(userDetails);
                authentication.setToken(authToken);
                SecurityContextHolder.getContext().setAuthentication(authentication);
            }
        } catch (Exception e) {
            logger.error("[TokenAuthenticationFilter->doFilterInternal] authToken is {} and username is {};" +
                    " error:",
                    authToken, username, e);
            SecurityContextHolder.getContext().setAuthentication(new AnonAuthentication());
        }
    } else {
        SecurityContextHolder.getContext().setAuthentication(new AnonAuthentication());
    }
    chain.doFilter(request, response);
}
 
开发者ID:pandboy,项目名称:pingguopai,代码行数:36,代码来源:TokenAuthenticationFilter.java

示例13: doFilter

import javax.servlet.FilterChain; //导入方法依赖的package包/类
@Override
public void doFilter(final ServletRequest request, final ServletResponse response,
        final FilterChain filterChain) throws IOException, ServletException {

    final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;
    logger.info("Felix Filter: request for {}", slingRequest.getRequestPathInfo().getResourcePath());

    filterChain.doFilter(request, response);
}
 
开发者ID:nateyolles,项目名称:aem-osgi-annotation-demo,代码行数:10,代码来源:SampleFelixFilter.java

示例14: doFilter

import javax.servlet.FilterChain; //导入方法依赖的package包/类
/**
 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
 */
public void doFilter(
        ServletRequest request, 
        ServletResponse response,
		FilterChain chain ) throws IOException, ServletException {
    
	if (filterConfig==null) return;
	
	if (request.getAttribute("TimeStamp")==null)
		request.setAttribute("TimeStamp", new Double(JProf.currentTimeSec()));
	
	try {
		// Process request
		chain.doFilter(request,response);

       	_BaseRootDAO.closeCurrentThreadSessions();
	} catch (Throwable ex) {
		_BaseRootDAO.rollbackCurrentThreadSessions();

           if (ex instanceof ServletException) throw (ServletException)ex;
           if (ex instanceof IOException) throw (IOException)ex;
		if (ex instanceof RuntimeException) throw (RuntimeException)ex;

           // Let others handle it... maybe another interceptor for exceptions?
           throw new ServletException(ex);
       }
		
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:31,代码来源:HibSessionFilter.java

示例15: doFilter

import javax.servlet.FilterChain; //导入方法依赖的package包/类
/**
 * This {@code doFilter} implementation stores a request attribute for
 * "already filtered", proceeding without filtering again if the attribute is already
 * there.
 * @param request the request
 * @param response the response
 * @param filterChain the filter chain
 * @throws ServletException if request is not HTTP request
 * @throws IOException in case of I/O operation exception
 */
public final void doFilter(ServletRequest request, ServletResponse response,
		FilterChain filterChain) throws ServletException, IOException {

	if (!(request instanceof HttpServletRequest)
			|| !(response instanceof HttpServletResponse)) {
		throw new ServletException(
				"OncePerRequestFilter just supports HTTP requests");
	}
	HttpServletRequest httpRequest = (HttpServletRequest) request;
	HttpServletResponse httpResponse = (HttpServletResponse) response;
	boolean hasAlreadyFilteredAttribute = request
			.getAttribute(this.alreadyFilteredAttributeName) != null;

	if (hasAlreadyFilteredAttribute) {

		// Proceed without invoking this filter...
		filterChain.doFilter(request, response);
	}
	else {
		// Do invoke this filter...
		request.setAttribute(this.alreadyFilteredAttributeName, Boolean.TRUE);
		try {
			doFilterInternal(httpRequest, httpResponse, filterChain);
		}
		finally {
			// Remove the "already filtered" request attribute for this request.
			request.removeAttribute(this.alreadyFilteredAttributeName);
		}
	}
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:41,代码来源:OncePerRequestFilter.java


注:本文中的javax.servlet.FilterChain.doFilter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。