public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (!(request instanceof HttpServletRequest)) { throw new ServletException( "Can only process HttpServletRequest"); } if (!(response instanceof HttpServletResponse)) { throw new ServletException( "Can only process HttpServletResponse"); } HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; if (requiresAuthentication(httpRequest, httpResponse)) { if ( logger.isDebugEnabled()) { logger.debug( "Request is to process authentication"); } Authentication authResult; try { onPreAuthentication(httpRequest, httpResponse); authResult = attemptAuthentication(httpRequest); } catch (AuthenticationException failed) { // Authentication failed unsuccessfulAuthentication(httpRequest, httpResponse, failed); return; } // Authentication success if ( continueChainBeforeSuccessfulAuthentication) { chain.doFilter(request, response); } successfulAuthentication(httpRequest, httpResponse, authResult); return; } chain.doFilter(request, response); }
if (!SecurityContextHolder.getContext().getAuthentication().isAuthenticated() || alwaysReauthenticate) { try { authenticated = this. authenticationManager.authenticate(SecurityContextHolder. getContext() .getAuthentication()); } catch (AuthenticationException authenticationException) { throw authenticationException; } // We don‘t authenticated.setAuthentication(true), because each // provider should do that if ( logger.isDebugEnabled()) { logger.debug( "Successfully Authenticated: " + authenticated.toString()); } SecurityContextHolder. getContext().setAuthentication(authenticated); } else { authenticated = SecurityContextHolder.getContext().getAuthentication(); if ( logger.isDebugEnabled()) { logger.debug( "Previously Authenticated: " + authenticated.toString()); } }
acegi security实践教程—form认证之debug调试,布布扣,bubuko.com
acegi security实践教程—form认证之debug调试
原文:http://blog.csdn.net/yuebinghaoyuan/article/details/20392733