org.apache.hadoop.security
Class UnixUserGroupInformation

java.lang.Object
  extended by org.apache.hadoop.security.UserGroupInformation
      extended by org.apache.hadoop.security.UnixUserGroupInformation
All Implemented Interfaces:
Writable

public class UnixUserGroupInformation
extends UserGroupInformation

An implementation of UserGroupInformation in the Unix system


Field Summary
static String UGI_PROPERTY_NAME
           
 
Fields inherited from class org.apache.hadoop.security.UserGroupInformation
LOG
 
Constructor Summary
UnixUserGroupInformation()
          Default constructor
UnixUserGroupInformation(String[] ugi)
          Constructor with parameter user/group names
UnixUserGroupInformation(String userName, String[] groupNames)
          Constructor with parameters user name and its group names.
 
Method Summary
static UnixUserGroupInformation createImmutable(String[] ugi)
          Create an immutable UnixUserGroupInformation object.
 boolean equals(Object other)
          Decide if two UGIs are the same
 String[] getGroupNames()
          Return an array of group names
 String getUserName()
          Return the user's name
 int hashCode()
          Returns a hash code for this UGI.
static UnixUserGroupInformation login()
          Get current user's name and the names of all its groups from Unix.
static UnixUserGroupInformation login(Configuration conf)
          Equivalent to login(conf, false).
static UnixUserGroupInformation login(Configuration conf, boolean save)
          Get a user's name & its group names from the given configuration; If it is not defined in the configuration, get the current user's information from Unix.
 void readFields(DataInput in)
          Deserialize this object First check if this is a UGI in the string format.
static UnixUserGroupInformation readFromConf(Configuration conf, String attr)
          Read a UGI from the given conf The object is expected to store with the property name attr as a comma separated string that starts with the user name followed by group names.
static void saveToConf(Configuration conf, String attr, UnixUserGroupInformation ugi)
          Store the given ugi as a comma separated string in conf as a property attr The String starts with the user name followed by the default group names, and other group names.
 String toString()
          Convert this object to a string
 void write(DataOutput out)
          Serialize this object First write a string marking that this is a UGI in the string format, then write this object's serialized form to the given data output
 
Methods inherited from class org.apache.hadoop.security.UserGroupInformation
getCurrentUGI, readFrom, setCurrentUGI
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

UGI_PROPERTY_NAME

public static final String UGI_PROPERTY_NAME
See Also:
Constant Field Values
Constructor Detail

UnixUserGroupInformation

public UnixUserGroupInformation()
Default constructor


UnixUserGroupInformation

public UnixUserGroupInformation(String userName,
                                String[] groupNames)
Constructor with parameters user name and its group names. The first entry in the groups list is the default group.

Parameters:
userName - a user's name
groupNames - groups list, first of which is the default group
Throws:
IllegalArgumentException - if any argument is null

UnixUserGroupInformation

public UnixUserGroupInformation(String[] ugi)
Constructor with parameter user/group names

Parameters:
ugi - an array containing user/group names, the first element of which is the user name, the second of which is the default group name.
Throws:
IllegalArgumentException - if the array size is less than 2 or any element is null.
Method Detail

createImmutable

public static UnixUserGroupInformation createImmutable(String[] ugi)
Create an immutable UnixUserGroupInformation object.


getGroupNames

public String[] getGroupNames()
Return an array of group names

Specified by:
getGroupNames in class UserGroupInformation
Returns:
an array of group names

getUserName

public String getUserName()
Return the user's name

Specified by:
getUserName in class UserGroupInformation
Returns:
the user's name

readFields

public void readFields(DataInput in)
                throws IOException
Deserialize this object First check if this is a UGI in the string format. If no, throw an IOException; otherwise set this object's fields by reading them from the given data input

Parameters:
in - input stream
Throws:
IOException - is thrown if encounter any error when reading

write

public void write(DataOutput out)
           throws IOException
Serialize this object First write a string marking that this is a UGI in the string format, then write this object's serialized form to the given data output

Parameters:
out - output stream
Throws:
IOException - if encounter any error during writing

saveToConf

public static void saveToConf(Configuration conf,
                              String attr,
                              UnixUserGroupInformation ugi)
Store the given ugi as a comma separated string in conf as a property attr The String starts with the user name followed by the default group names, and other group names.

Parameters:
conf - configuration
attr - property name
ugi - a UnixUserGroupInformation

readFromConf

public static UnixUserGroupInformation readFromConf(Configuration conf,
                                                    String attr)
                                             throws LoginException
Read a UGI from the given conf The object is expected to store with the property name attr as a comma separated string that starts with the user name followed by group names. If the property name is not defined, return null. It's assumed that there is only one UGI per user. If this user already has a UGI in the ugi map, return the ugi in the map. Otherwise, construct a UGI from the configuration, store it in the ugi map and return it.

Parameters:
conf - configuration
attr - property name
Returns:
a UnixUGI
Throws:
LoginException - if the stored string is ill-formatted.

login

public static UnixUserGroupInformation login()
                                      throws LoginException
Get current user's name and the names of all its groups from Unix. It's assumed that there is only one UGI per user. If this user already has a UGI in the ugi map, return the ugi in the map. Otherwise get the current user's information from Unix, store it in the map, and return it.

Throws:
LoginException

login

public static UnixUserGroupInformation login(Configuration conf)
                                      throws LoginException
Equivalent to login(conf, false).

Throws:
LoginException

login

public static UnixUserGroupInformation login(Configuration conf,
                                             boolean save)
                                      throws LoginException
Get a user's name & its group names from the given configuration; If it is not defined in the configuration, get the current user's information from Unix. If the user has a UGI in the ugi map, return the one in the UGI map.

Parameters:
conf - either a job configuration or client's configuration
save - saving it to conf?
Returns:
UnixUserGroupInformation a user/group information
Throws:
LoginException - if not able to get the user/group information

equals

public boolean equals(Object other)
Decide if two UGIs are the same

Overrides:
equals in class Object
Parameters:
other - other object
Returns:
true if they are the same; false otherwise.

hashCode

public int hashCode()
Returns a hash code for this UGI. The hash code for a UGI is the hash code of its user name string.

Overrides:
hashCode in class Object
Returns:
a hash code value for this UGI.

toString

public String toString()
Convert this object to a string

Overrides:
toString in class Object
Returns:
a comma separated string containing the user name and group names


Copyright © 2008 The Apache Software Foundation