/*
* JOSSO: Java Open Single Sign-On
*
* Copyright 2004-2009, Atricore, Inc.
*
* This 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 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, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*
*/
package org.josso.jetty6.agent;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.josso.agent.SSOAgentRequest;
import org.josso.agent.SingleSignOnEntry;
import org.josso.agent.http.JOSSOSecurityContext;
import org.josso.agent.http.NativeHttpSSOAgent;
import org.josso.gateway.identity.SSORole;
import org.josso.servlet.agent.GenericServletLocalSession;
import org.josso.servlet.agent.GenericServletSSOAgent;
import org.josso.servlet.agent.GenericServletSSOAgentRequest;
import org.mortbay.jetty.Request;
import javax.security.auth.Subject;
import java.security.Principal;
/**
* Native JOSSO Agent implementation for Jetty 6.
*
* @author <a href="mailto:gbrigand@josso.org">Gianluca Brigandi</a>
* @org.apache.xbean.XBean element="jetty6-agent"
*/
public class JettySSOAgent extends GenericServletSSOAgent {
private static final Log log = LogFactory.getLog(JettySSOAgent.class);
/**
* This extension will delegate processing to super class and publish JOSSO Security Context
* instance in the LocalSession associated to the request.
*/
protected SingleSignOnEntry execute(SSOAgentRequest request) {
GenericServletSSOAgentRequest r = (GenericServletSSOAgentRequest) request;
GenericServletLocalSession localSession = (GenericServletLocalSession) r.getLocalSession();
SingleSignOnEntry entry = super.execute(request);
if (entry != null) {
if (r.getSecurityContext() != null) {
if (log.isDebugEnabled())
log.debug("Publishing JOSSO Security Context instance in session [" + (entry != null ? entry.ssoId : "<NO-SSO-ID>") + "]");
localSession.setSecurityContext(r.getSecurityContext());
((Request)r.getRequest()).setUserPrincipal(r.getSecurityContext().getCurrentPrincipal());
}
} else {
if (localSession != null) {
if (log.isDebugEnabled())
log.debug("Clearing JOSSO Security Context for session [" + localSession.getId() + "]");
localSession.setSecurityContext(null);
r.setSecurityContext(null);
}
}
return entry;
}
@Override
protected boolean isAuthenticationAlwaysRequired() {
return true;
}
protected void log(String message) {
log.debug(message);
}
protected void log(String message, Throwable throwable) {
log.debug(message, throwable);
}
}