APIdia Launch Partner
Top Description Fields Constructors Methods
javax.security.auth.kerberos

public final Class KeyTab

extends Object
Class Inheritance
Imports
java.io.File, java.util.Objects, sun.security.krb5.EncryptionKey, .KerberosSecrets, .PrincipalName, .RealmException

This class encapsulates a keytab file.

A Kerberos JAAS login module that obtains long term secret keys from a keytab file should use this class. The login module will store an instance of this class in the private credential set of a Subject during the commit phase of the authentication process.

If a KeyTab object is obtained from getUnboundInstance() or getUnboundInstance(java.io.File), it is unbound and thus can be used by any service principal. Otherwise, if it's obtained from getInstance(KerberosPrincipal) or getInstance(KerberosPrincipal, java.io.File), it is bound to the specific service principal and can only be used by it.

Please note the constructors getInstance() and getInstance(java.io.File) were created when there was no support for unbound keytabs. These methods should not be used anymore. An object created with either of these methods are considered to be bound to an unknown principal, which means, its isBound() returns true and getPrincipal() returns null.

The keytab file format is described at http://www.ioplex.com/utilities/keytab.txt.

Since
1.7

Field Summary

Modifier and TypeField and Description
private final boolean
private final File
private final KerberosPrincipal

Constructor Summary

AccessConstructor and Description
private
KeyTab(KerberosPrincipal princ, File file, boolean bound)

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the specified object is equal to this KeyTab
equals
(Object
the object to compare to
other
)

Overrides java.lang.Object.equals.

Compares the specified object with this KeyTab for equality.

public boolean

Returns:

true if the keytab file exists; false otherwise.
exists
()

Checks if the keytab file exists.

pack-priv EncryptionKey[]
public static KeyTab

Returns:

the keytab instance
getInstance
(File
the keytab File object, must not be null
file
)

Returns a KeyTab instance from a File object that is bound to an unknown service principal.

public static KeyTab

Returns:

the keytab instance
getInstance
(KerberosPrincipal
the bound service principal, must not be null
princ
,
File
the keytab File object, must not be null
file
)

Returns a KeyTab instance from a File object that is bound to the specified service principal.

public static KeyTab

Returns:

the default keytab instance.
getInstance
()

Returns the default KeyTab instance that is bound to an unknown service principal.

public static KeyTab

Returns:

the default keytab instance
getInstance
(KerberosPrincipal
the bound service principal, must not be null
princ
)

Returns the default KeyTab instance that is bound to the specified service principal.

public KerberosKey[]

Returns:

the keys (never null, may be empty)
getKeys
(KerberosPrincipal
the Kerberos principal, must not be null.
principal
)

Returns fresh keys for the given Kerberos principal.

public KerberosPrincipal

Returns:

the service principal
getPrincipal
()

Returns the service principal this KeyTab object is bound to.

public static KeyTab

Returns:

the keytab instance
getUnboundInstance
(File
the keytab File object, must not be null
file
)

Returns an unbound KeyTab instance from a File object.

public static KeyTab

Returns:

the default keytab instance
getUnboundInstance
()

Returns the default unbound KeyTab instance.

public int

Returns:

a hash code for this KeyTab
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code for this KeyTab.

public boolean

Returns:

if the keytab is bound to a principal
isBound
()

Returns if the keytab is bound to a principal

pack-priv KeyTab
public String

Returns:

an informative textual representation of this KeyTab.
toString
()

Overrides java.lang.Object.toString.

Returns an informative textual representation of this KeyTab.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

boundback to summary
private final boolean bound
fileback to summary
private final File file
princback to summary
private final KerberosPrincipal princ

Constructor Detail

KeyTabback to summary
private KeyTab(KerberosPrincipal princ, File file, boolean bound)

Method Detail

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Compares the specified object with this KeyTab for equality. Returns true if the given object is also a KeyTab and the two KeyTab instances are equivalent.

Parameters
other:Object

the object to compare to

Returns:boolean

true if the specified object is equal to this KeyTab

Annotations
@Override
existsback to summary
public boolean exists()

Checks if the keytab file exists. Implementation of this method should make sure that the result matches the latest status of the keytab file.

Returns:boolean

true if the keytab file exists; false otherwise.

getEncryptionKeysback to summary
pack-priv EncryptionKey[] getEncryptionKeys(PrincipalName principal)
getInstanceback to summary
public static KeyTab getInstance(File file)

Returns a KeyTab instance from a File object that is bound to an unknown service principal.

The result of this method is never null. This method only associates the returned KeyTab object with the file and does not read it.

Developers should call getInstance(KerberosPrincipal, File) when the bound service principal is known.

Parameters
file:File

the keytab File object, must not be null

Returns:KeyTab

the keytab instance

Exceptions
NullPointerException:
if the file argument is null
getInstanceback to summary
public static KeyTab getInstance(KerberosPrincipal princ, File file)

Returns a KeyTab instance from a File object that is bound to the specified service principal.

The result of this method is never null. This method only associates the returned KeyTab object with the file and does not read it.

Parameters
princ:KerberosPrincipal

the bound service principal, must not be null

file:File

the keytab File object, must not be null

Returns:KeyTab

the keytab instance

Exceptions
NullPointerException:
if either of the arguments is null
Since
1.8
getInstanceback to summary
public static KeyTab getInstance()

Returns the default KeyTab instance that is bound to an unknown service principal.

The result of this method is never null. This method only associates the returned KeyTab object with the default keytab file and does not read it.

Developers should call getInstance(KerberosPrincipal) when the bound service principal is known.

Returns:KeyTab

the default keytab instance.

getInstanceback to summary
public static KeyTab getInstance(KerberosPrincipal princ)

Returns the default KeyTab instance that is bound to the specified service principal.

The result of this method is never null. This method only associates the returned KeyTab object with the default keytab file and does not read it.

Parameters
princ:KerberosPrincipal

the bound service principal, must not be null

Returns:KeyTab

the default keytab instance

Exceptions
NullPointerException:
if princ is null
Since
1.8
getKeysback to summary
public KerberosKey[] getKeys(KerberosPrincipal principal)

Returns fresh keys for the given Kerberos principal.

Implementation of this method should make sure the returned keys match the latest content of the keytab file. The result is a newly created copy that can be modified by the caller without modifying the keytab object. The caller should destroy the result keys after they are used.

Please note that the keytab file can be created after the KeyTab object is instantiated and its content may change over time. Therefore, an application should call this method only when it needs to use the keys. Any previous result from an earlier invocation could potentially be expired.

If there is any error (say, I/O error or format error) during the reading process of the keytab file, a saved result should be returned. If there is no saved result (say, this is the first time this method is called, or, all previous read attempts failed), an empty array should be returned. This can make sure the result is not drastically changed during the (probably slow) update of the keytab file.

Each time this method is called and the reading of the file succeeds with no exception (say, I/O error or file format error), the result should be saved for principal. The implementation can also save keys for other principals having keys in the same keytab object if convenient.

Any unsupported key read from the keytab is ignored and not included in the result.

If this keytab is bound to a specific principal, calling this method on another principal will return an empty array.

Parameters
principal:KerberosPrincipal

the Kerberos principal, must not be null.

Returns:KerberosKey[]

the keys (never null, may be empty)

Exceptions
NullPointerException:
if the principal argument is null
getPrincipalback to summary
public KerberosPrincipal getPrincipal()

Returns the service principal this KeyTab object is bound to. Returns null if it's not bound.

Please note the deprecated constructors create a KeyTab object bound for some unknown principal. In this case, this method also returns null. User can call isBound() to verify this case.

Returns:KerberosPrincipal

the service principal

Since
1.8
getUnboundInstanceback to summary
public static KeyTab getUnboundInstance(File file)

Returns an unbound KeyTab instance from a File object.

The result of this method is never null. This method only associates the returned KeyTab object with the file and does not read it.

Parameters
file:File

the keytab File object, must not be null

Returns:KeyTab

the keytab instance

Exceptions
NullPointerException:
if the file argument is null
Since
1.8
getUnboundInstanceback to summary
public static KeyTab getUnboundInstance()

Returns the default unbound KeyTab instance.

The result of this method is never null. This method only associates the returned KeyTab object with the default keytab file and does not read it.

Returns:KeyTab

the default keytab instance

Since
1.8
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code for this KeyTab.

Returns:int

a hash code for this KeyTab

Annotations
@Override
isBoundback to summary
public boolean isBound()

Returns if the keytab is bound to a principal

Returns:boolean

if the keytab is bound to a principal

Since
1.8
takeSnapshotback to summary
pack-priv KeyTab takeSnapshot()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns an informative textual representation of this KeyTab.

Returns:String

an informative textual representation of this KeyTab.