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

public final Class KerberosPrincipal

extends Object
implements Principal, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.security.Principal
Imports
java.io.*, sun.security.krb5.KrbException, .PrincipalName, .Realm, sun.security.util.*

This class encapsulates a Kerberos principal.
Author
Mayank Upadhyay
Since
1.4

Field Summary

Modifier and TypeField and Description
private transient String
public static final int
KRB_NT_ENTERPRISE

Enterprise name (alias)

public static final int
KRB_NT_PRINCIPAL

user principal name type.

public static final int
KRB_NT_SRV_HST

service with host name as instance (telnet, rcommands) name type.

public static final int
KRB_NT_SRV_INST

service and other unique instance (krbtgt) name type.

public static final int
KRB_NT_SRV_XHST

service with host as remaining components name type.

public static final int
KRB_NT_UID

unique ID name type.

public static final int
KRB_NT_UNKNOWN

unknown name type.

private transient int
private transient String
private static final long

Constructor Summary

AccessConstructor and Description
public
KerberosPrincipal(String
the principal name
name
)

Constructs a KerberosPrincipal from the provided string input.

public
KerberosPrincipal(String
the principal name
name
,
int
the name type of the principal
nameType
)

Constructs a KerberosPrincipal from the provided string and name type input.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the object passed in represents the same principal as this one, false otherwise.
equals
(Object
the object to compare to
obj
)

Overrides java.lang.Object.equals.

Implements java.security.Principal.equals.

Compares the specified object with this principal for equality.

public String

Returns:

the principal name.
getName
()

Implements java.security.Principal.getName.

The returned string corresponds to the single-string representation of a Kerberos Principal name as specified in Section 2.1 of RFC 1964.

public int

Returns:

the name type.
getNameType
()

Returns the name type of the KerberosPrincipal.

public String

Returns:

the realm component of this Kerberos principal.
getRealm
()

Returns the realm component of this Kerberos principal.

public int

Returns:

a hash code for this KerberosPrincipal
hashCode
()

Overrides java.lang.Object.hashCode.

Implements java.security.Principal.hashCode.

Returns a hash code for this KerberosPrincipal.

private void
readObject(ObjectInputStream
the ObjectInputStream from which data is read
ois
)

Reads this object from a stream (i.e., deserializes it)

public String

Returns:

an informative textual representation of this KerberosPrincipal.
toString
()

Overrides java.lang.Object.toString.

Implements java.security.Principal.toString.

Returns an informative textual representation of this KerberosPrincipal.

private void
writeObject(ObjectOutputStream
the ObjectOutputStream to which data is written
oos
)

Save the KerberosPrincipal object to a stream

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

fullNameback to summary
private transient String fullName
KRB_NT_ENTERPRISEback to summary
public static final int KRB_NT_ENTERPRISE

Enterprise name (alias)

Since
13
KRB_NT_PRINCIPALback to summary
public static final int KRB_NT_PRINCIPAL

user principal name type.

KRB_NT_SRV_HSTback to summary
public static final int KRB_NT_SRV_HST

service with host name as instance (telnet, rcommands) name type.

KRB_NT_SRV_INSTback to summary
public static final int KRB_NT_SRV_INST

service and other unique instance (krbtgt) name type.

KRB_NT_SRV_XHSTback to summary
public static final int KRB_NT_SRV_XHST

service with host as remaining components name type.

KRB_NT_UIDback to summary
public static final int KRB_NT_UID

unique ID name type.

KRB_NT_UNKNOWNback to summary
public static final int KRB_NT_UNKNOWN

unknown name type.

nameTypeback to summary
private transient int nameType
realmback to summary
private transient String realm
serialVersionUIDback to summary
private static final long serialVersionUID
Annotations
@Serial

Constructor Detail

KerberosPrincipalback to summary
public KerberosPrincipal(String name)

Constructs a KerberosPrincipal from the provided string input. The name type for this principal defaults to KRB_NT_PRINCIPAL This string is assumed to contain a name in the format that is specified in Section 2.1.1. (Kerberos Principal Name Form) of RFC 1964 (for example, [email protected], where duke represents a principal, and FOO.COM represents a realm).

If the input name does not contain a realm, the default realm is used. The default realm can be specified either in a Kerberos configuration file or via the java.security.krb5.realm system property. For more information, see the Kerberos Requirements.

Note that when this class or any other Kerberos-related class is initially loaded and initialized, it may read and cache the default realm from the Kerberos configuration file or via the java.security.krb5.realm system property (the value will be empty if no default realm is specified), such that any subsequent calls to set or change the default realm by setting the java.security.krb5.realm system property may be ignored.

Parameters
name:String

the principal name

Exceptions
IllegalArgumentException:
if name is improperly formatted, if name is null, or if name does not contain the realm to use and the default realm is not specified in either a Kerberos configuration file or via the java.security.krb5.realm system property.
KerberosPrincipalback to summary
public KerberosPrincipal(String name, int nameType)

Constructs a KerberosPrincipal from the provided string and name type input. The string is assumed to contain a name in the format that is specified in Section 2.1 (Mandatory Name Forms) of RFC 1964. Valid name types are specified in Section 6.2 (Principal Names) of RFC 4120. The input name must be consistent with the provided name type. (for example, [email protected], is a valid input string for the name type, KRB_NT_PRINCIPAL where duke represents a principal, and FOO.COM represents a realm).

If the input name does not contain a realm, the default realm is used. The default realm can be specified either in a Kerberos configuration file or via the java.security.krb5.realm system property. For more information, see the Kerberos Requirements.

Note that when this class or any other Kerberos-related class is initially loaded and initialized, it may read and cache the default realm from the Kerberos configuration file or via the java.security.krb5.realm system property (the value will be empty if no default realm is specified), such that any subsequent calls to set or change the default realm by setting the java.security.krb5.realm system property may be ignored.

Parameters
name:String

the principal name

nameType:int

the name type of the principal

Exceptions
IllegalArgumentException:
if name is improperly formatted, if name is null, if the nameType is not supported, or if name does not contain the realm to use and the default realm is not specified in either a Kerberos configuration file or via the java.security.krb5.realm system property.

Method Detail

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Implements java.security.Principal.equals.

Compares the specified object with this principal for equality. Returns true if the given object is also a KerberosPrincipal and the two KerberosPrincipal instances are equivalent. More formally two KerberosPrincipal instances are equal if the values returned by getName() are equal.

Parameters
obj:Object

the object to compare to

Returns:boolean

true if the object passed in represents the same principal as this one, false otherwise.

Annotations
@Override
getNameback to summary
public String getName()

Implements java.security.Principal.getName.

The returned string corresponds to the single-string representation of a Kerberos Principal name as specified in Section 2.1 of RFC 1964.

Returns:String

the principal name.

getNameTypeback to summary
public int getNameType()

Returns the name type of the KerberosPrincipal. Valid name types are specified in Section 6.2 of RFC4120.

Returns:int

the name type.

getRealmback to summary
public String getRealm()

Returns the realm component of this Kerberos principal.

Returns:String

the realm component of this Kerberos principal.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements java.security.Principal.hashCode.

Returns a hash code for this KerberosPrincipal. The hash code is defined to be the result of the following calculation:

hashCode = getName().hashCode();
Returns:int

a hash code for this KerberosPrincipal

Annotations
@Override
readObjectback to summary
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException

Reads this object from a stream (i.e., deserializes it)

Parameters
ois:ObjectInputStream

the ObjectInputStream from which data is read

Annotations
@Serial
Exceptions
IOException:
if an I/O error occurs
ClassNotFoundException:
if a serialized class cannot be loaded
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Implements java.security.Principal.toString.

Returns an informative textual representation of this KerberosPrincipal.

Returns:String

an informative textual representation of this KerberosPrincipal.

writeObjectback to summary
private void writeObject(ObjectOutputStream oos) throws IOException

Save the KerberosPrincipal object to a stream

Parameters
oos:ObjectOutputStream

the ObjectOutputStream to which data is written

Annotations
@Serial
Exceptions
IOException:
if an I/O error occurs
Serial data
this KerberosPrincipal is serialized by writing out the PrincipalName and the Realm in their DER-encoded form as specified in Section 5.2.2 of RFC4120.