1 /* 2 * Copyright (c) 1999, 2001, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.security.auth; 27 28 import java.security.Principal; 29 30 /** 31 * <p> This class implements the <code>Principal</code> interface 32 * and represents the name of the Windows NT domain into which the 33 * user authenticated. This will be a domain name if the user logged 34 * into a Windows NT domain, a workgroup name if the user logged into 35 * a workgroup, or a machine name if the user logged into a standalone 36 * configuration. 37 * 38 * <p> Principals such as this <code>NTDomainPrincipal</code> 39 * may be associated with a particular <code>Subject</code> 40 * to augment that <code>Subject</code> with an additional 41 * identity. Refer to the <code>Subject</code> class for more information 42 * on how to achieve this. Authorization decisions can then be based upon 43 * the Principals associated with a <code>Subject</code>. 44 * 45 * @see java.security.Principal 46 * @see javax.security.auth.Subject 47 */ 48 public class NTDomainPrincipal implements Principal, java.io.Serializable { 49 50 private static final long serialVersionUID = -4408637351440771220L; 51 52 /** 53 * @serial 54 */ 55 private String name; 56 57 /** 58 * Create an <code>NTDomainPrincipal</code> with a Windows NT domain name. 59 * 60 * <p> 61 * 62 * @param name the Windows NT domain name for this user. <p> 63 * 64 * @exception NullPointerException if the <code>name</code> 65 * is <code>null</code>. 66 */ 67 public NTDomainPrincipal(String name) { 68 if (name == null) { 69 java.text.MessageFormat form = new java.text.MessageFormat 70 (sun.security.util.ResourcesMgr.getString 71 ("invalid null input: value", 72 "sun.security.util.AuthResources")); 73 Object[] source = {"name"}; 74 throw new NullPointerException(form.format(source)); 75 } 76 this.name = name; 77 } 78 79 /** 80 * Return the Windows NT domain name for this 81 * <code>NTDomainPrincipal</code>. 82 * 83 * <p> 84 * 85 * @return the Windows NT domain name for this 86 * <code>NTDomainPrincipal</code> 87 */ 88 public String getName() { 89 return name; 90 } 91 92 /** 93 * Return a string representation of this <code>NTDomainPrincipal</code>. 94 * 95 * <p> 96 * 97 * @return a string representation of this <code>NTDomainPrincipal</code>. 98 */ 99 public String toString() { 100 java.text.MessageFormat form = new java.text.MessageFormat 101 (sun.security.util.ResourcesMgr.getString 102 ("NTDomainPrincipal: name", 103 "sun.security.util.AuthResources")); 104 Object[] source = {name}; 105 return form.format(source); 106 } 107 108 /** 109 * Compares the specified Object with this <code>NTDomainPrincipal</code> 110 * for equality. Returns true if the given object is also a 111 * <code>NTDomainPrincipal</code> and the two NTDomainPrincipals 112 * have the same name. 113 * 114 * <p> 115 * 116 * @param o Object to be compared for equality with this 117 * <code>NTDomainPrincipal</code>. 118 * 119 * @return true if the specified Object is equal equal to this 120 * <code>NTDomainPrincipal</code>. 121 */ 122 public boolean equals(Object o) { 123 if (o == null) 124 return false; 125 126 if (this == o) 127 return true; 128 129 if (!(o instanceof NTDomainPrincipal)) 130 return false; 131 NTDomainPrincipal that = (NTDomainPrincipal)o; 132 133 if (name.equals(that.getName())) 134 return true; 135 return false; 136 } 137 138 /** 139 * Return a hash code for this <code>NTDomainPrincipal</code>. 140 * 141 * <p> 142 * 143 * @return a hash code for this <code>NTDomainPrincipal</code>. 144 */ 145 public int hashCode() { 146 return this.getName().hashCode(); 147 } 148 }