Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/security/auth/SolarisNumericGroupPrincipal.java
38924 views
/*1* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.security.auth;2627import java.security.Principal;2829/**30* <p> This class implements the <code>Principal</code> interface31* and represents a user's Solaris group identification number (GID).32*33* <p> Principals such as this <code>SolarisNumericGroupPrincipal</code>34* may be associated with a particular <code>Subject</code>35* to augment that <code>Subject</code> with an additional36* identity. Refer to the <code>Subject</code> class for more information37* on how to achieve this. Authorization decisions can then be based upon38* the Principals associated with a <code>Subject</code>.3940* @deprecated As of JDK 1.4, replaced by41* {@link UnixNumericGroupPrincipal}.42* This class is entirely deprecated.43*44* @see java.security.Principal45* @see javax.security.auth.Subject46*/47@jdk.Exported(false)48@Deprecated49public class SolarisNumericGroupPrincipal implements50Principal,51java.io.Serializable {5253private static final long serialVersionUID = 2345199581042573224L;5455private static final java.util.ResourceBundle rb =56java.security.AccessController.doPrivileged57(new java.security.PrivilegedAction<java.util.ResourceBundle>() {58public java.util.ResourceBundle run() {59return (java.util.ResourceBundle.getBundle60("sun.security.util.AuthResources"));61}62});6364/**65* @serial66*/67private String name;6869/**70* @serial71*/72private boolean primaryGroup;7374/**75* Create a <code>SolarisNumericGroupPrincipal</code> using a76* <code>String</code> representation of the user's77* group identification number (GID).78*79* <p>80*81* @param name the user's group identification number (GID)82* for this user. <p>83*84* @param primaryGroup true if the specified GID represents the85* primary group to which this user belongs.86*87* @exception NullPointerException if the <code>name</code>88* is <code>null</code>.89*/90public SolarisNumericGroupPrincipal(String name, boolean primaryGroup) {91if (name == null)92throw new NullPointerException(rb.getString("provided.null.name"));9394this.name = name;95this.primaryGroup = primaryGroup;96}9798/**99* Create a <code>SolarisNumericGroupPrincipal</code> using a100* long representation of the user's group identification number (GID).101*102* <p>103*104* @param name the user's group identification number (GID) for this user105* represented as a long. <p>106*107* @param primaryGroup true if the specified GID represents the108* primary group to which this user belongs.109*110*/111public SolarisNumericGroupPrincipal(long name, boolean primaryGroup) {112this.name = (new Long(name)).toString();113this.primaryGroup = primaryGroup;114}115116/**117* Return the user's group identification number (GID) for this118* <code>SolarisNumericGroupPrincipal</code>.119*120* <p>121*122* @return the user's group identification number (GID) for this123* <code>SolarisNumericGroupPrincipal</code>124*/125public String getName() {126return name;127}128129/**130* Return the user's group identification number (GID) for this131* <code>SolarisNumericGroupPrincipal</code> as a long.132*133* <p>134*135* @return the user's group identification number (GID) for this136* <code>SolarisNumericGroupPrincipal</code> as a long.137*/138public long longValue() {139return ((new Long(name)).longValue());140}141142/**143* Return whether this group identification number (GID) represents144* the primary group to which this user belongs.145*146* <p>147*148* @return true if this group identification number (GID) represents149* the primary group to which this user belongs,150* or false otherwise.151*/152public boolean isPrimaryGroup() {153return primaryGroup;154}155156/**157* Return a string representation of this158* <code>SolarisNumericGroupPrincipal</code>.159*160* <p>161*162* @return a string representation of this163* <code>SolarisNumericGroupPrincipal</code>.164*/165public String toString() {166return((primaryGroup ?167rb.getString168("SolarisNumericGroupPrincipal.Primary.Group.") + name :169rb.getString170("SolarisNumericGroupPrincipal.Supplementary.Group.") + name));171}172173/**174* Compares the specified Object with this175* <code>SolarisNumericGroupPrincipal</code>176* for equality. Returns true if the given object is also a177* <code>SolarisNumericGroupPrincipal</code> and the two178* SolarisNumericGroupPrincipals179* have the same group identification number (GID).180*181* <p>182*183* @param o Object to be compared for equality with this184* <code>SolarisNumericGroupPrincipal</code>.185*186* @return true if the specified Object is equal equal to this187* <code>SolarisNumericGroupPrincipal</code>.188*/189public boolean equals(Object o) {190if (o == null)191return false;192193if (this == o)194return true;195196if (!(o instanceof SolarisNumericGroupPrincipal))197return false;198SolarisNumericGroupPrincipal that = (SolarisNumericGroupPrincipal)o;199200if (this.getName().equals(that.getName()) &&201this.isPrimaryGroup() == that.isPrimaryGroup())202return true;203return false;204}205206/**207* Return a hash code for this <code>SolarisNumericGroupPrincipal</code>.208*209* <p>210*211* @return a hash code for this <code>SolarisNumericGroupPrincipal</code>.212*/213public int hashCode() {214return toString().hashCode();215}216}217218219