Java AFS API v1.4

org.openafs.jafs
Class Token

java.lang.Object
  |
  +--org.openafs.jafs.Token
All Implemented Interfaces:
Comparable, Serializable

public class Token
extends Object
implements Serializable, Comparable

An abstract representation of an AFS authentication token. It conveniently maintains the handle associated with token and the cell to which the token is authenticated.

Constructing a Token object results in an immediate attempt to authenticate the user within the specified cell. If this attempt fails, an AFSException will be thrown. Therefore, if the construction of the object succeeds without an exception, then the Token is considered authenticated. The construction of a Token object acts as an entry point for authentication into the AFS system. Thus, when you construct a Cell object, you must pass in an instance of a Token that has been authenticated within the AFS cell that Cell is intended to represent. You will only be allowed to perform actions that the user, used to authenticate Token, is authorized to perform. You must construct a Token object before constructing a Cell object, which is required by all other objects within this package either directly or indirectly.

If an error occurs during a method call, an AFSException will be thrown. This class is the Java equivalent of errors thrown by AFS; see AFSException for a complete description.

The following is a simple example of how to construct and use a Token object. It shows how to construct a Cell using a Token. See Cell for a more detailed example of constructing and using a Cell object.

 import org.openafs.jafs.AFSException;
 import org.openafs.jafs.Cell;
 import org.openafs.jafs.Token;
 ...
 public class ...
 {
   ...
   private Cell cell;
   private Token token;
   ...
   public static void main(String[] args) throws Exception
   {
     String username   = arg[0];
     String password   = arg[1];
     String cellName   = arg[2];
     String serverName = arg[3];
 
     token = new Token(username, password, cellName);
     cell   = new Cell(token);
     ...
   }
   ...
 }
 

See Also:
Serialized Form

Field Summary
static int ANYUSER_PAG_ID
           
 
Constructor Summary
Token(String username, String password, String cellName)
          Constructs a new Token object instance given the name of the AFS cell it represents and the username and password of the user to be Tokend for administrative access.
 
Method Summary
 void close()
          Closes the given currently open token.
 int compareTo(Object obj)
          Comparable interface method.
 int compareTo(Token token)
          Compares two ACL objects respective to their paths and does not factor any other attribute.
 boolean equals(Token token)
          Tests whether two Cell objects are equal, based on their names.
 String getCellName()
          Returns the name of the AFS cell that this Token was authenticated against.
 long getExpiration()
          Gets the expiration time for a given token.
 String getUsername()
          Returns the username of user to whom this token belongs.
 void klog()
          Authenticates a user in kas, and binds that authentication to the current process.
 void login()
          Authenticates a user in KAS, and binds that authentication to the current process.
 String toString()
          Returns the name of this Cell
 void unlog()
          Manually discards all AFS credentials associated with the bound user.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ANYUSER_PAG_ID

public static int ANYUSER_PAG_ID
Constructor Detail

Token

public Token(String username,
             String password,
             String cellName)
      throws AFSException
Constructs a new Token object instance given the name of the AFS cell it represents and the username and password of the user to be Tokend for administrative access.

Parameters:
username - the name of the user to Token with
password - the password of that user
cellName - the name of the cell to Token into
Throws:
AFSException - If an error occurs in the native code
Method Detail

getCellName

public String getCellName()
Returns the name of the AFS cell that this Token was authenticated against.

Returns:
the name of the AFS cell associated with this Token.
Throws:
AFSException - If an error occurs in the native code

getUsername

public String getUsername()
Returns the username of user to whom this token belongs.

Returns:
the username of the user represented by this Token
Throws:
AFSException - If an error occurs in the native code

close

public void close()
           throws AFSException
Closes the given currently open token.

Throws:
AFSException - If an error occurs in the native code

getExpiration

public long getExpiration()
                   throws AFSException
Gets the expiration time for a given token.

Returns:
a long representing the UTC time for the token expiration
Throws:
AFSException - If an error occurs in the native code

klog

public void klog()
          throws AFSException
Authenticates a user in kas, and binds that authentication to the current process.

Throws:
AFSException - If an error occurs in the native code

login

public void login()
           throws AFSException
Authenticates a user in KAS, and binds that authentication to the current process.

Throws:
AFSException - If an error occurs in the native code

compareTo

public int compareTo(Token token)
Compares two ACL objects respective to their paths and does not factor any other attribute. Alphabetic case is significant in comparing names.

Returns:
Zero if the argument is equal to this ACL's path, a value less than zero if this ACL's path is lexicographically less than the argument, or a value greater than zero if this ACL's path is lexicographically greater than the argument

compareTo

public int compareTo(Object obj)
Comparable interface method.

Specified by:
compareTo in interface Comparable
See Also:
compareTo(Token)

equals

public boolean equals(Token token)
Tests whether two Cell objects are equal, based on their names. Does not test whether the objects are actually the same representational instance of the AFS cell.

Returns:
whether the specifed user is the same as this user

toString

public String toString()
Returns the name of this Cell

Overrides:
toString in class Object
Returns:
the name of this Cell

unlog

public void unlog()
           throws AFSException
Manually discards all AFS credentials associated with the bound user.

Throws:
AFSException - If an error occurs in the native code

Java AFS API (jafs) for OpenAFS

Copyright (c) 2001-2002 International Business Machines Corp.
All rights reserved.
See copyright statement.