本文整理汇总了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);
}
示例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);
}
}
}
示例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);
}
示例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);
}
}
示例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);
}
示例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());
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
}
}