KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > security > auth > NTNumericCredential


1 /*
2  * @(#)NTNumericCredential.java 1.14 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.security.auth;
9
10 /**
11  * <p> This class abstracts an NT security token
12  * and provides a mechanism to do same-process security impersonation.
13  *
14  * @version 1.14, 12/19/03
15  */

16
17 public class NTNumericCredential {
18
19     private long impersonationToken;
20     
21     /**
22      * Create an <code>NTNumericCredential</code> with an integer value.
23      *
24      * <p>
25      *
26      * @param token the Windows NT security token for this user. <p>
27      *
28      */

29     public NTNumericCredential(long token) {
30         this.impersonationToken = token;
31     }
32     
33     /**
34      * Return an integer representation of this
35      * <code>NTNumericCredential</code>.
36      *
37      * <p>
38      *
39      * @return an integer representation of this
40      * <code>NTNumericCredential</code>.
41      */

42     public long getToken() {
43         return impersonationToken;
44     }
45     
46     /**
47      * Return a string representation of this <code>NTNumericCredential</code>.
48      *
49      * <p>
50      *
51      * @return a string representation of this <code>NTNumericCredential</code>.
52      */

53     public String JavaDoc toString() {
54     java.text.MessageFormat JavaDoc form = new java.text.MessageFormat JavaDoc
55         (sun.security.util.ResourcesMgr.getString
56             ("NTNumericCredential: name",
57             "sun.security.util.AuthResources"));
58     Object JavaDoc[] source = {Long.toString(impersonationToken)};
59     return form.format(source);
60     }
61     
62     /**
63      * Compares the specified Object with this <code>NTNumericCredential</code>
64      * for equality. Returns true if the given object is also a
65      * <code>NTNumericCredential</code> and the two NTNumericCredentials
66      * represent the same NT security token.
67      *
68      * <p>
69      *
70      * @param o Object to be compared for equality with this
71      * <code>NTNumericCredential</code>.
72      *
73      * @return true if the specified Object is equal equal to this
74      * <code>NTNumericCredential</code>.
75      */

76     public boolean equals(Object JavaDoc o) {
77     if (o == null)
78         return false;
79
80         if (this == o)
81             return true;
82  
83         if (!(o instanceof NTNumericCredential))
84             return false;
85         NTNumericCredential that = (NTNumericCredential)o;
86
87     if (impersonationToken == that.getToken())
88         return true;
89     return false;
90     }
91  
92     /**
93      * Return a hash code for this <code>NTNumericCredential</code>.
94      *
95      * <p>
96      *
97      * @return a hash code for this <code>NTNumericCredential</code>.
98      */

99     public int hashCode() {
100     return (int)this.impersonationToken;
101     }
102 }
103
Popular Tags