001: /*
002: * Copyright 1999-2002 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.security.auth;
027:
028: /**
029: * <p> This class abstracts an NT security token
030: * and provides a mechanism to do same-process security impersonation.
031: *
032: * @version 1.21, 05/05/07
033: */
034:
035: public class NTNumericCredential {
036:
037: private long impersonationToken;
038:
039: /**
040: * Create an <code>NTNumericCredential</code> with an integer value.
041: *
042: * <p>
043: *
044: * @param token the Windows NT security token for this user. <p>
045: *
046: */
047: public NTNumericCredential(long token) {
048: this .impersonationToken = token;
049: }
050:
051: /**
052: * Return an integer representation of this
053: * <code>NTNumericCredential</code>.
054: *
055: * <p>
056: *
057: * @return an integer representation of this
058: * <code>NTNumericCredential</code>.
059: */
060: public long getToken() {
061: return impersonationToken;
062: }
063:
064: /**
065: * Return a string representation of this <code>NTNumericCredential</code>.
066: *
067: * <p>
068: *
069: * @return a string representation of this <code>NTNumericCredential</code>.
070: */
071: public String toString() {
072: java.text.MessageFormat form = new java.text.MessageFormat(
073: sun.security.util.ResourcesMgr.getString(
074: "NTNumericCredential: name",
075: "sun.security.util.AuthResources"));
076: Object[] source = { Long.toString(impersonationToken) };
077: return form.format(source);
078: }
079:
080: /**
081: * Compares the specified Object with this <code>NTNumericCredential</code>
082: * for equality. Returns true if the given object is also a
083: * <code>NTNumericCredential</code> and the two NTNumericCredentials
084: * represent the same NT security token.
085: *
086: * <p>
087: *
088: * @param o Object to be compared for equality with this
089: * <code>NTNumericCredential</code>.
090: *
091: * @return true if the specified Object is equal equal to this
092: * <code>NTNumericCredential</code>.
093: */
094: public boolean equals(Object o) {
095: if (o == null)
096: return false;
097:
098: if (this == o)
099: return true;
100:
101: if (!(o instanceof NTNumericCredential))
102: return false;
103: NTNumericCredential that = (NTNumericCredential) o;
104:
105: if (impersonationToken == that.getToken())
106: return true;
107: return false;
108: }
109:
110: /**
111: * Return a hash code for this <code>NTNumericCredential</code>.
112: *
113: * <p>
114: *
115: * @return a hash code for this <code>NTNumericCredential</code>.
116: */
117: public int hashCode() {
118: return (int) this.impersonationToken;
119: }
120: }
|