1 /*
   2  * Copyright (c) 1999, 2013, 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 a user's Solaris identification number (UID).
  33  *
  34  * <p> Principals such as this <code>SolarisNumericUserPrincipal</code>
  35  * may be associated with a particular <code>Subject</code>
  36  * to augment that <code>Subject</code> with an additional
  37  * identity.  Refer to the <code>Subject</code> class for more information
  38  * on how to achieve this.  Authorization decisions can then be based upon
  39  * the Principals associated with a <code>Subject</code>.
  40  * @deprecated As of JDK&nbsp;1.4, replaced by
  41  *             {@link UnixNumericUserPrincipal}.
  42  *             This class is entirely deprecated.
  43  *
  44  * @see java.security.Principal
  45  * @see javax.security.auth.Subject
  46  */
  47 @jdk.Exported(false)
  48 @Deprecated
  49 public class SolarisNumericUserPrincipal implements
  50                                         Principal,
  51                                         java.io.Serializable {
  52 
  53     private static final long serialVersionUID = -3178578484679887104L;
  54 
  55     private static final java.util.ResourceBundle rb =
  56           java.security.AccessController.doPrivileged
  57           (new java.security.PrivilegedAction<java.util.ResourceBundle>() {
  58               public java.util.ResourceBundle run() {
  59                   return (java.util.ResourceBundle.getBundle
  60                                 ("sun.security.util.AuthResources"));
  61               }
  62            });
  63 
  64 
  65     /**
  66      * @serial
  67      */
  68     private String name;
  69 
  70     /**
  71      * Create a <code>SolarisNumericUserPrincipal</code> using a
  72      * <code>String</code> representation of the
  73      * user's identification number (UID).
  74      *
  75      * <p>
  76      *
  77      * @param name the user identification number (UID) for this user.
  78      *
  79      * @exception NullPointerException if the <code>name</code>
  80      *                  is <code>null</code>.
  81      */
  82     public SolarisNumericUserPrincipal(String name) {
  83         if (name == null)
  84             throw new NullPointerException(rb.getString("provided.null.name"));
  85 
  86         this.name = name;
  87     }
  88 
  89     /**
  90      * Create a <code>SolarisNumericUserPrincipal</code> using a
  91      * long representation of the user's identification number (UID).
  92      *
  93      * <p>
  94      *
  95      * @param name the user identification number (UID) for this user
  96      *                  represented as a long.
  97      */
  98     public SolarisNumericUserPrincipal(long name) {
  99         this.name = Long.toString(name);
 100     }
 101 
 102     /**
 103      * Return the user identification number (UID) for this
 104      * <code>SolarisNumericUserPrincipal</code>.
 105      *
 106      * <p>
 107      *
 108      * @return the user identification number (UID) for this
 109      *          <code>SolarisNumericUserPrincipal</code>
 110      */
 111     public String getName() {
 112         return name;
 113     }
 114 
 115     /**
 116      * Return the user identification number (UID) for this
 117      * <code>SolarisNumericUserPrincipal</code> as a long.
 118      *
 119      * <p>
 120      *
 121      * @return the user identification number (UID) for this
 122      *          <code>SolarisNumericUserPrincipal</code> as a long.
 123      */
 124     public long longValue() {
 125         return Long.parseLong(name);
 126     }
 127 
 128     /**
 129      * Return a string representation of this
 130      * <code>SolarisNumericUserPrincipal</code>.
 131      *
 132      * <p>
 133      *
 134      * @return a string representation of this
 135      *          <code>SolarisNumericUserPrincipal</code>.
 136      */
 137     public String toString() {
 138         return(rb.getString("SolarisNumericUserPrincipal.") + name);
 139     }
 140 
 141     /**
 142      * Compares the specified Object with this
 143      * <code>SolarisNumericUserPrincipal</code>
 144      * for equality.  Returns true if the given object is also a
 145      * <code>SolarisNumericUserPrincipal</code> and the two
 146      * SolarisNumericUserPrincipals
 147      * have the same user identification number (UID).
 148      *
 149      * <p>
 150      *
 151      * @param o Object to be compared for equality with this
 152      *          <code>SolarisNumericUserPrincipal</code>.
 153      *
 154      * @return true if the specified Object is equal equal to this
 155      *          <code>SolarisNumericUserPrincipal</code>.
 156      */
 157     public boolean equals(Object o) {
 158         if (o == null)
 159             return false;
 160 
 161         if (this == o)
 162             return true;
 163 
 164         if (!(o instanceof SolarisNumericUserPrincipal))
 165             return false;
 166         SolarisNumericUserPrincipal that = (SolarisNumericUserPrincipal)o;
 167 
 168         if (this.getName().equals(that.getName()))
 169             return true;
 170         return false;
 171     }
 172 
 173     /**
 174      * Return a hash code for this <code>SolarisNumericUserPrincipal</code>.
 175      *
 176      * <p>
 177      *
 178      * @return a hash code for this <code>SolarisNumericUserPrincipal</code>.
 179      */
 180     public int hashCode() {
 181         return name.hashCode();
 182     }
 183 }