/*
 * Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library 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 library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */
package com.arsdigita.kernel;

import com.arsdigita.kernel.security.SessionContext;
import com.arsdigita.kernel.security.UserContext;
import com.arsdigita.dispatcher.RedirectException;
import com.arsdigita.dispatcher.RequestContext;
import com.arsdigita.dispatcher.BaseDispatcherServlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;

/**
 * Extends BaseDispatcherServlet to include functionality for
 * user authentication, which is part of Kernel.  Any ACS entry point
 * that needs to authenticate the currently logged-in user should
 * extend this class.
 */
public abstract class KernelDispatcherServlet extends BaseDispatcherServlet {

    public static final String versionId =
        "$Id: KernelDispatcherServlet.java 287 2005-02-22 00:29:02Z sskracic $";

    private static final Logger s_cat =
        Logger.getLogger(KernelDispatcherServlet.class.getName());

    public void init() throws ServletException {
        super.init();
    }

    protected RequestContext authenticateUser(HttpServletRequest req,
                                              HttpServletResponse res,
                                              RequestContext ctx)
        throws RedirectException {
        UserContext user = new UserContext(req, res);
        SessionContext session = user.getSessionContext();
        return new KernelRequestContext(ctx, session, user);
    }
}
