001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.krad.web.filter;
017
018import org.apache.log4j.Logger;
019
020import javax.servlet.Filter;
021import javax.servlet.FilterChain;
022import javax.servlet.FilterConfig;
023import javax.servlet.ServletException;
024import javax.servlet.ServletRequest;
025import javax.servlet.ServletResponse;
026import javax.servlet.http.HttpServletRequest;
027import java.io.IOException;
028
029public class SessionFilter implements Filter {
030    private static final Logger LOG = Logger.getLogger(SessionFilter.class);
031
032    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
033        try {
034            ((HttpServletRequest) request).getSession();
035        }
036        catch (IllegalStateException ise) {
037            LOG.info("A user was denied a session");
038            throw new IllegalStateException(new StringBuffer("Thank you for visiting Kuali Test Drive!\n\n").append("To ensure that test drivers of the Kuali System demo site have a safe and uneventful trip, we must limit the number of concurrent users and, unfortunately, that number has been reached.\n\n").append("Please check back later.\n\n").append("Questions can be submitted to the Kuali Test Drive listserv at mailto:kualitestdrive@oncourse.iu.edu").toString());
039        }
040        filterChain.doFilter(request, response);
041    }
042
043    public void init(FilterConfig filterConfig) throws ServletException {
044        LOG.info("Initialized");
045    }
046
047    public void destroy() {
048        LOG.info("Destroyed");
049    }
050}