Skip to content

Instantly share code, notes, and snippets.

Created May 17, 2012 15:12
SerletFilter
@Override
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
HttpSession session = request.getSession();
LOGGER.info("Invoking Authorization Filter");
LOGGER.info("Destination URL is: " + request.getRequestURI());
if (filterConfig == null)
return;
// get the Google user
AppUser appUser = LoginService.login(request, response);
if (appUser != null) {
session.setAttribute(Constant.AUTH_USER, appUser);
}
// identify if user has an OAuth accessToken - it not, will set in motion
// oauth procedure
if (appUser.getCredentials() == null) {
// need to save the target URI in session so we can forward to it when
// oauth is completed
session.setAttribute(Constant.TARGET_URI, request.getRequestURI());
OAuthRequestService.requestOAuth(request, response, session);
return;
} else
// store DocService in the session so it can be reused
session.setAttribute(Constant.DOC_SESSION_ID,
LoginService.docServiceFactory(appUser));
chain.doFilter(request, response);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment