001: /*
002: * JOSSO: Java Open Single Sign-On
003: *
004: * Copyright 2004-2008, Atricore, Inc.
005: *
006: * This is free software; you can redistribute it and/or modify it
007: * under the terms of the GNU Lesser General Public License as
008: * published by the Free Software Foundation; either version 2.1 of
009: * the License, or (at your option) any later version.
010: *
011: * This software is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this software; if not, write to the Free
018: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
020: */
021: package org.josso.gateway.event.security;
022:
023: import org.apache.commons.logging.Log;
024: import org.apache.commons.logging.LogFactory;
025: import org.josso.Lookup;
026: import org.josso.auth.Credential;
027: import org.josso.gateway.event.BaseSSOEvent;
028:
029: import java.security.Principal;
030:
031: /**
032: * Represents an authorizantion event, like authorization success or authorization failure.
033: *
034: * @author <a href="mailto:sgonzalez@josso.org">Sebastian Gonzalez Oyuela</a>
035: * @version $Id: SSOIdentityEvent.java 508 2008-02-18 13:32:29Z sgonzalez $
036: */
037: public class SSOIdentityEvent extends BaseSSOEvent {
038:
039: private static final Log logger = LogFactory
040: .getLog(SSOIdentityEvent.class);
041:
042: /**
043: * The AuthenticationEvent event type when a user is successfully authenticated.
044: */
045: public static final String LOGIN_SUCCESS_EVENT = "authenticationSuccess";
046:
047: /**
048: * The AuthenticationEvent event type when a user authentication fails.
049: */
050: public static final String LOGIN_FAILED_EVENT = "authenticationFailed";
051:
052: /**
053: * The AuthenticationEvent event type when a user logout fails.
054: */
055: public static final String LOGOUT_FAILED_EVENT = "logoutFailed";
056:
057: /**
058: * The AuthenticationEvent event type when a user logout success.
059: */
060: public static final String LOGOUT_SUCCESS_EVENT = "logoutSuccess";
061:
062: private String username;
063: private String remoteHost;
064: private String scheme;
065: private String sessionId;
066:
067: /**
068: * Constructs an LOGIN_SUCCESS_EVENT event
069: *
070: * @param username the authenticated user
071: * @param sessionId the session associated with the new authenticated user.
072: */
073: public SSOIdentityEvent(String remoteHost, String scheme,
074: String username, String sessionId) {
075: super (LOGIN_SUCCESS_EVENT, username);
076: this .sessionId = sessionId;
077: this .scheme = scheme;
078: this .remoteHost = remoteHost;
079: this .username = username;
080:
081: }
082:
083: /**
084: * Constructs an LOGIN_FAILED_EVENT event
085: *
086: * @param credentials that failed when attemting to authenticate a user.
087: */
088: public SSOIdentityEvent(String remoteHost, String scheme,
089: Credential[] credentials, Throwable error) {
090: super (LOGIN_FAILED_EVENT, credentials, error);
091: this .remoteHost = remoteHost;
092: this .scheme = scheme;
093: // Try to guess provided username ... !
094: try {
095: Principal p = Lookup.getInstance().lookupSecurityDomain()
096: .getAuthenticator().getPrincipal(scheme,
097: credentials);
098: this .username = p.getName();
099: } catch (Exception e) {
100: logger
101: .warn("Cannot derive principal name based on credentials ...");
102: }
103:
104: }
105:
106: /**
107: * Constructs an LOGOUT_SUCCESS_EVENT event
108: *
109: * @param username the authenticated user
110: * @param sessionId the session associated with the new authenticated user.
111: */
112: public SSOIdentityEvent(String remoteHost, String username,
113: String sessionId) {
114: super (LOGOUT_SUCCESS_EVENT, username);
115: this .sessionId = sessionId;
116: this .remoteHost = remoteHost;
117: this .username = username;
118: }
119:
120: /**
121: * Constructs an LOGOUT_SUCCESS_EVENT event
122: *
123: * @param username the authenticated user
124: * @param sessionId the session associated with the new authenticated user.
125: */
126: public SSOIdentityEvent(String remoteHost, String username,
127: String sessionId, Throwable error) {
128: super (LOGOUT_FAILED_EVENT, username, error);
129: this .sessionId = sessionId;
130: this .remoteHost = remoteHost;
131: this .username = username;
132: }
133:
134: public String getUsername() {
135: return username;
136: }
137:
138: public String getRemoteHost() {
139: return remoteHost;
140: }
141:
142: public String getSessionId() {
143: return sessionId;
144: }
145:
146: public String getScheme() {
147: return scheme;
148: }
149:
150: /**
151: * Return a string representation of this event.
152: */
153: public String toString() {
154: return ("SSOIdentityEvent['" + getType() + "']");
155: }
156:
157: }
|