jdk/src/jdk.security.auth/share/classes/com/sun/security/auth/UnixNumericUserPrincipal.java
changeset 30044 bab15bbe2ca3
parent 28059 e576535359cc
child 34894 3248b89d1921
equal deleted inserted replaced
30043:b0dd05ec3db1 30044:bab15bbe2ca3
    26 package com.sun.security.auth;
    26 package com.sun.security.auth;
    27 
    27 
    28 import java.security.Principal;
    28 import java.security.Principal;
    29 
    29 
    30 /**
    30 /**
    31  * <p> This class implements the <code>Principal</code> interface
    31  * This class implements the {@code Principal} interface
    32  * and represents a user's Unix identification number (UID).
    32  * and represents a user's Unix identification number (UID).
    33  *
    33  *
    34  * <p> Principals such as this <code>UnixNumericUserPrincipal</code>
    34  * <p> Principals such as this {@code UnixNumericUserPrincipal}
    35  * may be associated with a particular <code>Subject</code>
    35  * may be associated with a particular {@code Subject}
    36  * to augment that <code>Subject</code> with an additional
    36  * to augment that {@code Subject} with an additional
    37  * identity.  Refer to the <code>Subject</code> class for more information
    37  * identity.  Refer to the {@code Subject} class for more information
    38  * on how to achieve this.  Authorization decisions can then be based upon
    38  * on how to achieve this.  Authorization decisions can then be based upon
    39  * the Principals associated with a <code>Subject</code>.
    39  * the Principals associated with a {@code Subject}.
    40  *
    40  *
    41  * @see java.security.Principal
    41  * @see java.security.Principal
    42  * @see javax.security.auth.Subject
    42  * @see javax.security.auth.Subject
    43  */
    43  */
    44 @jdk.Exported
    44 @jdk.Exported
    51      * @serial
    51      * @serial
    52      */
    52      */
    53     private String name;
    53     private String name;
    54 
    54 
    55     /**
    55     /**
    56      * Create a <code>UnixNumericUserPrincipal</code> using a
    56      * Create a {@code UnixNumericUserPrincipal} using a
    57      * <code>String</code> representation of the
    57      * {@code String} representation of the
    58      * user's identification number (UID).
    58      * user's identification number (UID).
    59      *
       
    60      * <p>
       
    61      *
    59      *
    62      * @param name the user identification number (UID) for this user.
    60      * @param name the user identification number (UID) for this user.
    63      *
    61      *
    64      * @exception NullPointerException if the <code>name</code>
    62      * @exception NullPointerException if the {@code name}
    65      *                  is <code>null</code>.
    63      *                  is {@code null}.
    66      */
    64      */
    67     public UnixNumericUserPrincipal(String name) {
    65     public UnixNumericUserPrincipal(String name) {
    68         if (name == null) {
    66         if (name == null) {
    69             java.text.MessageFormat form = new java.text.MessageFormat
    67             java.text.MessageFormat form = new java.text.MessageFormat
    70                 (sun.security.util.ResourcesMgr.getString
    68                 (sun.security.util.ResourcesMgr.getString
    76 
    74 
    77         this.name = name;
    75         this.name = name;
    78     }
    76     }
    79 
    77 
    80     /**
    78     /**
    81      * Create a <code>UnixNumericUserPrincipal</code> using a
    79      * Create a {@code UnixNumericUserPrincipal} using a
    82      * long representation of the user's identification number (UID).
    80      * long representation of the user's identification number (UID).
    83      *
       
    84      * <p>
       
    85      *
    81      *
    86      * @param name the user identification number (UID) for this user
    82      * @param name the user identification number (UID) for this user
    87      *                  represented as a long.
    83      *                  represented as a long.
    88      */
    84      */
    89     public UnixNumericUserPrincipal(long name) {
    85     public UnixNumericUserPrincipal(long name) {
    90         this.name = Long.toString(name);
    86         this.name = Long.toString(name);
    91     }
    87     }
    92 
    88 
    93     /**
    89     /**
    94      * Return the user identification number (UID) for this
    90      * Return the user identification number (UID) for this
    95      * <code>UnixNumericUserPrincipal</code>.
    91      * {@code UnixNumericUserPrincipal}.
    96      *
       
    97      * <p>
       
    98      *
    92      *
    99      * @return the user identification number (UID) for this
    93      * @return the user identification number (UID) for this
   100      *          <code>UnixNumericUserPrincipal</code>
    94      *          {@code UnixNumericUserPrincipal}
   101      */
    95      */
   102     public String getName() {
    96     public String getName() {
   103         return name;
    97         return name;
   104     }
    98     }
   105 
    99 
   106     /**
   100     /**
   107      * Return the user identification number (UID) for this
   101      * Return the user identification number (UID) for this
   108      * <code>UnixNumericUserPrincipal</code> as a long.
   102      * {@code UnixNumericUserPrincipal} as a long.
   109      *
       
   110      * <p>
       
   111      *
   103      *
   112      * @return the user identification number (UID) for this
   104      * @return the user identification number (UID) for this
   113      *          <code>UnixNumericUserPrincipal</code> as a long.
   105      *          {@code UnixNumericUserPrincipal} as a long.
   114      */
   106      */
   115     public long longValue() {
   107     public long longValue() {
   116         return Long.parseLong(name);
   108         return Long.parseLong(name);
   117     }
   109     }
   118 
   110 
   119     /**
   111     /**
   120      * Return a string representation of this
   112      * Return a string representation of this
   121      * <code>UnixNumericUserPrincipal</code>.
   113      * {@code UnixNumericUserPrincipal}.
   122      *
       
   123      * <p>
       
   124      *
   114      *
   125      * @return a string representation of this
   115      * @return a string representation of this
   126      *          <code>UnixNumericUserPrincipal</code>.
   116      *          {@code UnixNumericUserPrincipal}.
   127      */
   117      */
   128     public String toString() {
   118     public String toString() {
   129         java.text.MessageFormat form = new java.text.MessageFormat
   119         java.text.MessageFormat form = new java.text.MessageFormat
   130                 (sun.security.util.ResourcesMgr.getString
   120                 (sun.security.util.ResourcesMgr.getString
   131                         ("UnixNumericUserPrincipal.name",
   121                         ("UnixNumericUserPrincipal.name",
   134         return form.format(source);
   124         return form.format(source);
   135     }
   125     }
   136 
   126 
   137     /**
   127     /**
   138      * Compares the specified Object with this
   128      * Compares the specified Object with this
   139      * <code>UnixNumericUserPrincipal</code>
   129      * {@code UnixNumericUserPrincipal}
   140      * for equality.  Returns true if the given object is also a
   130      * for equality.  Returns true if the given object is also a
   141      * <code>UnixNumericUserPrincipal</code> and the two
   131      * {@code UnixNumericUserPrincipal} and the two
   142      * UnixNumericUserPrincipals
   132      * UnixNumericUserPrincipals
   143      * have the same user identification number (UID).
   133      * have the same user identification number (UID).
   144      *
   134      *
   145      * <p>
       
   146      *
       
   147      * @param o Object to be compared for equality with this
   135      * @param o Object to be compared for equality with this
   148      *          <code>UnixNumericUserPrincipal</code>.
   136      *          {@code UnixNumericUserPrincipal}.
   149      *
   137      *
   150      * @return true if the specified Object is equal to this
   138      * @return true if the specified Object is equal to this
   151      *          <code>UnixNumericUserPrincipal</code>.
   139      *          {@code UnixNumericUserPrincipal}.
   152      */
   140      */
   153     public boolean equals(Object o) {
   141     public boolean equals(Object o) {
   154         if (o == null)
   142         if (o == null)
   155             return false;
   143             return false;
   156 
   144 
   165             return true;
   153             return true;
   166         return false;
   154         return false;
   167     }
   155     }
   168 
   156 
   169     /**
   157     /**
   170      * Return a hash code for this <code>UnixNumericUserPrincipal</code>.
   158      * Return a hash code for this {@code UnixNumericUserPrincipal}.
   171      *
   159      *
   172      * <p>
   160      * @return a hash code for this {@code UnixNumericUserPrincipal}.
   173      *
       
   174      * @return a hash code for this <code>UnixNumericUserPrincipal</code>.
       
   175      */
   161      */
   176     public int hashCode() {
   162     public int hashCode() {
   177         return name.hashCode();
   163         return name.hashCode();
   178     }
   164     }
   179 }
   165 }