be.fedict.eid.idp.webapp.SessionLoggingFilter.java Source code

Java tutorial

Introduction

Here is the source code for be.fedict.eid.idp.webapp.SessionLoggingFilter.java

Source

/*
 * eID Identity Provider Project.
 * Copyright (C) 2010 FedICT.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version
 * 3.0 as published by the Free Software Foundation.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, see 
 * http://www.gnu.org/licenses/.
 */

package be.fedict.eid.idp.webapp;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class SessionLoggingFilter implements Filter {

    private static final Log LOG = LogFactory.getLog(SessionLoggingFilter.class);

    public void destroy() {
        LOG.debug("destroy");
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        HttpServletRequest httpRequest = (HttpServletRequest) request;
        HttpSession httpSession = httpRequest.getSession(false);
        if (null != httpSession) {
            String sessionId = httpSession.getId();
            boolean isNew = httpSession.isNew();
            String clientSessionId = httpRequest.getRequestedSessionId();
            LOG.debug("request URI: " + httpRequest.getRequestURI());
            LOG.debug("session id: " + sessionId + "; is new: " + isNew);
            if (null == clientSessionId) {
                LOG.debug("no client session id received");
            } else {
                LOG.debug("client session id: " + clientSessionId);
            }
        }
        chain.doFilter(request, response);
    }

    public void init(FilterConfig config) throws ServletException {
        LOG.debug("init");
    }
}