| Method from org.jboss.web.tomcat.tc4.authenticator.SingleSignOn Detail: |
public void addLifecycleListener(LifecycleListener listener) {
lifecycle.addLifecycleListener(listener);
}
Add a lifecycle event listener to this component. |
void associate(String ssoId,
Session session) {
if (session == null)
return;
if (debug >= 1)
log("Associate sso id " + ssoId + " with session " + session);
SingleSignOnEntry sso = lookup(ssoId);
if (sso != null)
sso.addSession(this, session);
synchronized (reverse)
{
reverse.put(session, ssoId);
}
}
Associate the specified single sign on identifier with the
specified Session. |
void deregister(String ssoId) {
if (debug >= 1)
log("Deregistering sso id '" + ssoId + "'");
// Look up and remove the corresponding SingleSignOnEntry
SingleSignOnEntry sso = null;
synchronized (cache)
{
sso = (SingleSignOnEntry) cache.remove(ssoId);
}
if (sso == null)
return;
// Expire any associated sessions
Session sessions[] = sso.findSessions();
for (int i = 0; i < sessions.length; i++)
{
if (sessions[i] == null)
continue;
if (debug >= 2)
log(" Invalidating session " + sessions[i]);
// Remove from reverse cache first to avoid recursion
synchronized (reverse)
{
reverse.remove(sessions[i]);
}
// Invalidate this session
sessions[i].expire();
}
// NOTE: Clients may still possess the old single sign on cookie,
// but it will be removed on the next request since it is no longer
// in the cache
}
Deregister the specified single sign on identifier, and invalidate
any associated sessions. |
public LifecycleListener[] findLifecycleListeners() {
return lifecycle.findLifecycleListeners();
}
Get the lifecycle listeners associated with this lifecycle. If this
Lifecycle has no listeners registered, a zero-length array is returned. |
public int getDebug() {
// ------------------------------------------------------------- Properties
return (this.debug);
}
Return the debugging detail level. |
public String getInfo() {
return (info);
}
Return descriptive information about this Valve implementation. |
public void invoke(Request request,
Response response,
ValveContext context) throws IOException, ServletException {
// If this is not an HTTP request and response, just pass them on
if (!(request instanceof HttpRequest) ||
!(response instanceof HttpResponse))
{
context.invokeNext(request, response);
return;
}
HttpServletRequest hreq =
(HttpServletRequest) request.getRequest();
HttpServletResponse hres =
(HttpServletResponse) response.getResponse();
request.removeNote(Constants.REQ_SSOID_NOTE);
// Has a valid user already been authenticated?
if (debug >= 1)
log("Process request for '" + hreq.getRequestURI() + "'");
if (hreq.getUserPrincipal() != null)
{
if (debug >= 1)
log(" Principal '" + hreq.getUserPrincipal().getName() +
"' has already been authenticated");
context.invokeNext(request, response);
return;
}
// Check for the single sign on cookie
if (debug >= 1)
log(" Checking for SSO cookie");
Cookie cookie = null;
Cookie cookies[] = hreq.getCookies();
if (cookies == null)
cookies = new Cookie[0];
for (int i = 0; i < cookies.length; i++)
{
if (Constants.SINGLE_SIGN_ON_COOKIE.equals(cookies[i].getName()))
{
cookie = cookies[i];
break;
}
}
if (cookie == null)
{
if (debug >= 1)
log(" SSO cookie is not present");
context.invokeNext(request, response);
return;
}
// Look up the cached Principal associated with this cookie value
String ssoId = cookie.getValue();
if (debug >= 1)
log(" Checking for cached principal for " + ssoId);
SingleSignOnEntry entry = lookup(ssoId);
if (entry != null)
{
if (debug >= 1)
{
log(" Found cached principal '" +
entry.getPrincipal().getName() + "' with auth type '" +
entry.getAuthType() + "'");
}
request.setNote(Constants.REQ_SSOID_NOTE, ssoId);
}
else
{
if (debug >= 1)
log(" No currently valid cached principal found, "
+ "erasing SSO cookie");
cookie.setMaxAge(0);
hres.addCookie(cookie);
}
// Invoke the next Valve in our pipeline
context.invokeNext(request, response);
}
Perform single-sign-on support processing for this request. |
protected void log(String message) {
Logger logger = container.getLogger();
if (logger != null)
logger.log(this.toString() + ": " + message);
else
System.out.println(this.toString() + ": " + message);
}
Log a message on the Logger associated with our Container (if any). |
protected void log(String message,
Throwable throwable) {
Logger logger = container.getLogger();
if (logger != null)
logger.log(this.toString() + ": " + message, throwable);
else
{
System.out.println(this.toString() + ": " + message);
throwable.printStackTrace(System.out);
}
}
Log a message on the Logger associated with our Container (if any). |
protected SingleSignOnEntry lookup(String ssoId) {
synchronized (cache)
{
return ((SingleSignOnEntry) cache.get(ssoId));
}
}
Look up and return the cached SingleSignOn entry associated with this
sso id value, if there is one; otherwise return null. |
void register(String ssoId,
Principal principal,
String authType,
String username,
String password) {
if (debug >= 1)
log("Registering sso id '" + ssoId + "' for user '" +
principal.getName() + "' with auth type '" + authType + "'");
synchronized (cache)
{
cache.put(ssoId, new SingleSignOnEntry(principal, authType,
username, password));
}
}
Register the specified Principal as being associated with the specified
value for the single sign on identifier. |
public void removeLifecycleListener(LifecycleListener listener) {
lifecycle.removeLifecycleListener(listener);
}
Remove a lifecycle event listener from this component. |
void removeSession(String ssoId,
Session session) {
if (debug >= 1)
{
log("Removing session " + session.toString() + " from sso id " +
ssoId );
}
// Get a reference to the SingleSignOn
SingleSignOnEntry entry = lookup(ssoId);
if (entry == null)
{
return;
}
// Remove the inactive session from SingleSignOnEntry
entry.removeSession(session);
// Remove the inactive session from the 'reverse' Map.
synchronized(reverse)
{
reverse.remove(session);
}
// If there are not sessions left in the SingleSignOnEntry,
// deregister the entry.
if (entry.findSessions().length == 0)
{
deregister(ssoId);
}
}
Remove a single Session from a SingleSignOn. Called when
a session is timed out and no longer active. |
public void sessionEvent(SessionEvent event) {
// We only care about session destroyed events
if (!Session.SESSION_DESTROYED_EVENT.equals(event.getType()))
return;
// Look up the single session id associated with this session (if any)
Session session = event.getSession();
if (debug >= 1)
log("Process session destroyed on " + session);
String ssoId = null;
synchronized (reverse)
{
ssoId = (String) reverse.get(session);
}
if (ssoId == null)
return;
/*
* Was the session destroyed as the result of a timeout?
* If so, we'll just remove the expired session from the
* SSO. If the session was logged out, we'll log out
* of all session associated with the SSO.
*/
if (System.currentTimeMillis() - session.getLastAccessedTime() >=
session.getMaxInactiveInterval() * 1000) {
removeSession(ssoId, session);
}
else {
// The session was logged out.
// Deregister this single session id, invalidating associated sessions
deregister(ssoId);
}
}
Acknowledge the occurrence of the specified event. |
public void setDebug(int debug) {
this.debug = debug;
}
Set the debugging detail level. |
public void start() throws LifecycleException {
// Validate and update our current component state
if (started)
throw new LifecycleException
(sm.getString("authenticator.alreadyStarted"));
lifecycle.fireLifecycleEvent(START_EVENT, null);
started = true;
if (debug >= 1)
log("Started");
}
Prepare for the beginning of active use of the public methods of this
component. This method should be called after configure(),
and before any of the public methods of the component are utilized. |
public void stop() throws LifecycleException {
// Validate and update our current component state
if (!started)
throw new LifecycleException
(sm.getString("authenticator.notStarted"));
lifecycle.fireLifecycleEvent(STOP_EVENT, null);
started = false;
if (debug >= 1)
log("Stopped");
}
Gracefully terminate the active use of the public methods of this
component. This method should be the last one called on a given
instance of this component. |
public String toString() {
StringBuffer sb = new StringBuffer();
if (getContainer() != null)
{
sb.append("SingleSignOn[");
sb.append(getContainer().getName());
sb.append(']");
}
else
{
sb.append(getClass().getName());
sb.append('@");
sb.append(Integer.toHexString(hashCode()));
}
return (sb.toString());
}
Updates the Jakarta version by ensuring that member
container is not null before using it.
If getContainer() returns null, this method
functions as per Object.toString() .
Otherwise, it functions as per
the superclass version . |
void update(String ssoId,
Principal principal,
String authType,
String username,
String password) {
SingleSignOnEntry sso = lookup(ssoId);
if (sso != null && !sso.getCanReauthenticate())
{
if (debug >= 1)
log("Update sso id " + ssoId + " to auth type " + authType);
synchronized (sso)
{
sso.updateCredentials(principal, authType, username, password);
}
}
}
Updates any SingleSignOnEntry found under key
ssoId with the given authentication data.
The purpose of this method is to allow an SSO entry that was
established without a username/password combination (i.e. established
following DIGEST or CLIENT-CERT authentication) to be updated with
a username and password if one becomes available through a subsequent
BASIC or FORM authentication. The SSO entry will then be usable for
reauthentication.
NOTE: Only updates the SSO entry if a call to
SingleSignOnEntry.getCanReauthenticate() returns
false; otherwise, it is assumed that the SSO entry already
has sufficient information to allow reauthentication and that no update
is needed. |