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:
022: package org.josso.spring.acegi;
023:
024: import org.acegisecurity.providers.AbstractAuthenticationToken;
025: import org.acegisecurity.GrantedAuthority;
026:
027: /**
028: * Date: Sep 28, 2007
029: * Time: 10:19:38 AM
030: *
031: * @author <a href="mailto:sgonzalez@josso.org">Gianluca Brigandi</a>
032: */
033: public class JOSSOAuthenticationToken extends
034: AbstractAuthenticationToken {
035:
036: //~ Instance fields ================================================================================================
037:
038: private static final long serialVersionUID = 1L;
039: private Object principal;
040:
041: private String jossoSessionId;
042:
043: //~ Constructors ===================================================================================================
044:
045: /**
046: * Constructor.
047: *
048: * @param jossoSessionId to identify if this object made by an authorised client
049: * @param principal the principal (typically a <code>UserDetails</code>)
050: * @param authorities the authorities granted to the principal
051: *
052: * @throws IllegalArgumentException if a <code>null</code> was passed
053: */
054: public JOSSOAuthenticationToken(String jossoSessionId,
055: Object principal, GrantedAuthority[] authorities) {
056: super (authorities);
057:
058: if (principal == null || "".equals(principal)
059: || jossoSessionId == null || "".equals(jossoSessionId)) {
060: throw new IllegalArgumentException(
061: "Cannot pass null or empty values to constructor");
062: }
063:
064: this .principal = principal;
065: this .jossoSessionId = jossoSessionId;
066: setAuthenticated(true);
067: }
068:
069: //~ Methods ========================================================================================================
070:
071: public boolean equals(Object obj) {
072: if (!super .equals(obj)) {
073: return false;
074: }
075:
076: if (obj instanceof JOSSOAuthenticationToken) {
077: JOSSOAuthenticationToken test = (JOSSOAuthenticationToken) obj;
078:
079: if (this .getJossoSessionId().equals(
080: test.getJossoSessionId())) {
081: return false;
082: }
083:
084: return true;
085: }
086:
087: return false;
088: }
089:
090: /**
091: * Always returns an empty <code>String</code>
092: *
093: * @return an empty String
094: */
095: public Object getCredentials() {
096: return "";
097: }
098:
099: public Object getPrincipal() {
100: return this .principal;
101: }
102:
103: public String getJossoSessionId() {
104: return jossoSessionId;
105: }
106: }
|