KerberosPrincipalpublic final class KerberosPrincipal extends Object implements Principal, SerializableThis class encapsulates a Kerberos principal. |
Fields Summary |
---|
private static final long | serialVersionUID | public static final int | KRB_NT_UNKNOWNunknown name type. | public static final int | KRB_NT_PRINCIPALuser principal name type. | public static final int | KRB_NT_SRV_INSTservice and other unique instance (krbtgt) name type. | public static final int | KRB_NT_SRV_HSTservice with host name as instance (telnet, rcommands) name type. | public static final int | KRB_NT_SRV_XHSTservice with host as remaining components name type. | public static final int | KRB_NT_UIDunique ID name type. | private transient String | fullName | private transient String | realm | private transient int | nameType | private static final char | NAME_REALM_SEPARATOR |
Constructors Summary |
---|
public KerberosPrincipal(String name)Constructs a KerberosPrincipal from the provided string input. The
name type for this principal defaults to
{@link #KRB_NT_PRINCIPAL 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, duke@FOO.COM, 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,
Kerberos Requirements
PrincipalName krb5Principal = null;
try {
// Appends the default realm if it is missing
krb5Principal = new PrincipalName(name, KRB_NT_PRINCIPAL);
} catch (KrbException e) {
throw new IllegalArgumentException(e.getMessage());
}
nameType = KRB_NT_PRINCIPAL; // default name type
fullName = krb5Principal.toString();
realm = krb5Principal.getRealmString();
| 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 7.2 (Principal Names) of
RFC 1510.
The input name must be consistent with the provided name type.
(for example, duke@FOO.COM, 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
Kerberos Requirements.
PrincipalName krb5Principal = null;
try {
// Appends the default realm if it is missing
krb5Principal = new PrincipalName(name,nameType);
} catch (KrbException e) {
throw new IllegalArgumentException(e.getMessage());
}
this.nameType = nameType;
fullName = krb5Principal.toString();
realm = krb5Principal.getRealmString();
|
Methods Summary |
---|
public boolean | equals(java.lang.Object other)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 and the
values returned by getNameType() are equal.
if (other == this)
return true;
if (! (other instanceof KerberosPrincipal)) {
return false;
} else {
String myFullName = getName();
String otherFullName = ((KerberosPrincipal) other).getName();
if (nameType == ((KerberosPrincipal)other).nameType &&
myFullName.equals(otherFullName)) {
return true;
}
}
return false;
| public java.lang.String | getName()The returned string corresponds to the single-string
representation of a Kerberos Principal name as specified in
Section 2.1 of RFC 1964.
return fullName;
| public int | getNameType()Returns the name type of the KerberosPrincipal. Valid name types
are specified in Section 7.2 of
RFC1510.
return nameType;
| public java.lang.String | getRealm()Returns the realm component of this Kerberos principal.
return realm;
| public int | hashCode()Returns a hashcode for this principal. The hash code is defined to
be the result of the following calculation:
hashCode = getName().hashCode();
return getName().hashCode();
| private void | readObject(java.io.ObjectInputStream ois)Reads this object from a stream (i.e., deserializes it)
byte[] asn1EncPrincipal = (byte [])ois.readObject();
byte[] encRealm = (byte [])ois.readObject();
try {
PrincipalName krb5Principal = new PrincipalName(new
DerValue(asn1EncPrincipal));
realm = (new Realm(new DerValue(encRealm))).toString();
fullName = krb5Principal.toString() + NAME_REALM_SEPARATOR +
realm.toString();
nameType = krb5Principal.getNameType();
} catch (Exception e) {
IOException ioe = new IOException(e.getMessage());
ioe.initCause(e);
throw ioe;
}
| public java.lang.String | toString()
return getName();
| private void | writeObject(java.io.ObjectOutputStream oos)Save the KerberosPrincipal object to a stream
PrincipalName krb5Principal = null;
try {
krb5Principal = new PrincipalName(fullName,nameType);
oos.writeObject(krb5Principal.asn1Encode());
oos.writeObject(krb5Principal.getRealm().asn1Encode());
} catch (Exception e) {
IOException ioe = new IOException(e.getMessage());
ioe.initCause(e);
throw ioe;
}
|
|