KerberosKeypublic class KerberosKey extends Object implements SecretKey, DestroyableThis class encapsulates a long term secret key for a Kerberos
principal.
All Kerberos JAAS login modules that obtain a principal's password and
generate the secret key from it should use this class. Where available,
the login module might even read this secret key directly from a
Kerberos "keytab". Sometimes, such as when authenticating a server in
the absence of user-to-user authentication, the login module will store
an instance of this class in the private credential set of a
{@link javax.security.auth.Subject Subject} during the commit phase of the
authentication process.
It might be necessary for the application to be granted a
{@link javax.security.auth.PrivateCredentialPermission
PrivateCredentialPermission} if it needs to access the KerberosKey
instance from a Subject. This permission is not needed when the
application depends on the default JGSS Kerberos mechanism to access the
KerberosKey. In that case, however, the application will need an
appropriate
{@link javax.security.auth.kerberos.ServicePermission ServicePermission}. |
Fields Summary |
---|
private static final long | serialVersionUID | private KerberosPrincipal | principalThe principal that this secret key belongs to. | private int | versionNumthe version number of this secret key | private KeyImpl | keyKeyImpl is serialized by writing out the ASN1 Encoded bytes
of the encryption key. The ASN1 encoding is defined in
RFC1510 and as follows:
EncryptionKey ::= SEQUENCE {
keytype[0] INTEGER,
keyvalue[1] OCTET STRING
}
| private transient boolean | destroyed |
Constructors Summary |
---|
public KerberosKey(KerberosPrincipal principal, byte[] keyBytes, int keyType, int versionNum)Constructs a KerberosKey from the given bytes when the key type and
key version number are known. This can be used when reading the secret
key information from a Kerberos "keytab".
this.principal = principal;
this.versionNum = versionNum;
key = new KeyImpl(keyBytes, keyType);
| public KerberosKey(KerberosPrincipal principal, char[] password, String algorithm)Constructs a KerberosKey from a principal's password.
this.principal = principal;
// Pass principal in for salt
key = new KeyImpl(principal, password, algorithm);
|
Methods Summary |
---|
public void | destroy()Destroys this key. A call to any of its other methods after this
will cause an IllegalStateException to be thrown.
if (!destroyed) {
key.destroy();
principal = null;
destroyed = true;
}
| public final java.lang.String | getAlgorithm()Returns the standard algorithm name for this key. For
example, "DES" would indicate that this key is a DES key.
See Appendix A in the
Java Cryptography Architecture API Specification & Reference
for information about standard algorithm names.
if (destroyed)
throw new IllegalStateException("This key is no longer valid");
return key.getAlgorithm();
| public final byte[] | getEncoded()Returns the key material of this secret key.
if (destroyed)
throw new IllegalStateException("This key is no longer valid");
return key.getEncoded();
| public final java.lang.String | getFormat()Returns the name of the encoding format for this secret key.
if (destroyed)
throw new IllegalStateException("This key is no longer valid");
return key.getFormat();
| public final int | getKeyType()Returns the key type for this long-term key.
if (destroyed)
throw new IllegalStateException("This key is no longer valid");
return key.getKeyType();
| public final javax.security.auth.kerberos.KerberosPrincipal | getPrincipal()Returns the principal that this key belongs to.
if (destroyed)
throw new IllegalStateException("This key is no longer valid");
return principal;
| public final int | getVersionNumber()Returns the key version number.
if (destroyed)
throw new IllegalStateException("This key is no longer valid");
return versionNum;
| public boolean | isDestroyed()Determines if this key has been destroyed.
return destroyed;
| public java.lang.String | toString()
return "Kerberos Principal " + principal.toString() +
"Key Version " + versionNum +
"key " + key.toString();
|
|