001: /**
002: * $Id: PASPrincipal.java,v 1.3 2005/02/11 23:56:27 yue Exp $
003: * Copyright 2004 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.admin.server;
014:
015: import java.io.Serializable;
016: import java.security.Principal;
017:
018: import com.iplanet.sso.SSOToken;
019: import com.sun.cacao.agent.auth.UserPrincipal;
020:
021: /**
022: * This principal class represents a Portal Admin Server user. It
023: * contains a SSO token if the user has been successfully
024: * authenticated by Access Manager.
025: */
026: public class PASPrincipal extends UserPrincipal implements Serializable {
027: private String domainID;
028: private SSOToken token = null;
029:
030: /**
031: * Constructs a PASPrincipal using the given name and portal
032: * domain ID.
033: *
034: * @param name user name (DN) of the Portal Admin Server user.
035: * @param portalDomainID ID of the portal domain the PAS user belongs to.
036: * @exception NullPointerException if name or portalDomainID is
037: * <code>null</code>.
038: */
039: public PASPrincipal(String name, String portalDomainID) {
040: super (name);
041:
042: if (name == null) {
043: throw new NullPointerException("name is null.");
044: }
045:
046: if (portalDomainID == null) {
047: throw new NullPointerException("portalDomainID is null.");
048: }
049:
050: domainID = portalDomainID;
051: }
052:
053: /**
054: * Compares this <code>PASPrincipal</code> object to the specified
055: * object. Returns <code>true</code> if the given object is a
056: * <code>PASPrincipal</code> object, and has the same user name
057: * and belongs to the same portal domain.
058: *
059: * @param another another principal to compare with.
060: *
061: * @return <code>true</code> if the given principal is the same as
062: * that encapsulated by this <code>PASPrincipal</code>,
063: * and <code>false</code> otherwise.
064: */
065: public boolean equals(Object another) {
066: if (another == null) {
067: return false;
068: }
069:
070: if (another == this ) {
071: return true;
072: }
073:
074: if (!(another instanceof PASPrincipal)) {
075: return false;
076: }
077:
078: PASPrincipal other = (PASPrincipal) another;
079:
080: return other.getName().equals(getName())
081: && other.getPortalDomainID()
082: .equals(getPortalDomainID());
083: }
084:
085: /**
086: * Returns a string representation of this <code>PASPrincipal</code>.
087: *
088: * @return a string representation of this <code>PASPrincipal</code>.
089: */
090: public String toString() {
091: return "PASPrincipal: " + getName() + ":"
092: + getPortalDomainID();
093: }
094:
095: /**
096: * Returns a hashcode for this <code>PASPrincipal</code>.
097: *
098: * @return a hashcode for this <code>PASPrincipal</code>.
099: */
100: public int hashCode() {
101: return toString().hashCode();
102: }
103:
104: /**
105: * Returns the ID of the portal domain this user belongs to.
106: *
107: * @return the portal domain ID of this <code>PASPrincipal</code>.
108: */
109: public String getPortalDomainID() {
110: return domainID;
111: }
112:
113: /**
114: * Returns the SSO token of this Portal Admin Server user. If the
115: * user has not been authenticated, <code>null</code> is returned.
116: *
117: * @return the SSO token of this Portal Admin Server user;
118: * <code>null</code> if the user has not been authenticated.
119: */
120: public SSOToken getSSOToken() {
121: return token;
122: }
123:
124: /**
125: * Sets the SSO token of this Portal Admin Server user to the give
126: * SSO token. This should be done after the user has been
127: * successfully authenticated by Access Manager.
128: *
129: * @param token the SSO token of this user to be set to.
130: */
131: public void setSSOToken(SSOToken token) {
132: this.token = token;
133: }
134: }
|