/*
 * The contents of this file are subject to the JOnAS Public License Version 
 * 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License on the JOnAS web site.
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied.
 * See the License for the specific terms governing rights and limitations under 
 * the License.
 *
 * The Original Code is JOnAS application server code released July 1999.
 *
 * The Initial Developer of the Original Code is Bull S.A.
 * The Original Code and portions created by Bull S.A. are
 *    Copyright (C) 1999 Bull S.A. All Rights Reserved.
 *
 * Contributor(s): 
 *
 * --------------------------------------------------------------------------
 * $Id$
 * --------------------------------------------------------------------------
 */

package org.objectweb.security.tomcat.interceptor ;

import org.apache.tomcat.modules.aaa.AccessInterceptor;
import org.apache.tomcat.core.Request ;
import org.apache.tomcat.core.Response ;

import org.objectweb.security.context.SecurityCurrent ;
import org.objectweb.security.context.SecurityContext ;

import java.security.Principal ;

public class SecurityCtxInterceptor33 extends  AccessInterceptor {

    public SecurityCtxInterceptor33 () {
	super () ;
    }

     public int authorize( Request req, Response response, String roles[] ) {
	int result = super.authorize (req, response, roles) ;
	if (result == 0) {
	    Principal principal = req.getUserPrincipal() ;
	    SecurityContext ctx = new SecurityContext (principal.getName()) ;
	    SecurityCurrent current = SecurityCurrent.getCurrent () ;
	    current.setSecurityContext(ctx) ;
	}
	return result ;
    }
}
