Identity (Java SE 25 & JDK 25)
Description: declaration: module: java.base, package: java.security, class: Identity
Keywords: java.security.Identity class

# Class Identity

java.lang.Object
java.security.Identity

All Implemented Interfaces:
  `Serializable, Principal`

Direct Known Subclasses:
  `IdentityScope, Signer`

@Deprecated(since="1.2", forRemoval=true) public abstract class Identity extends Object implements Principal, Serializable
Deprecated, for removal: This API element is subject to removal in a future version.
This class is deprecated and subject to removal in a future version of Java SE. It has been replaced by `java.security.KeyStore`, the `java.security.cert` package, and `java.security.Principal`.

This class represents identities: real-world objects such as people, companies or organizations whose identities can be authenticated using their public keys. Identities may also be more abstract (or concrete) constructs, such as daemon threads or smart cards.

All `Identity` objects have a name and a public key. Names are immutable. Identities may also be scoped. That is, if an `Identity` is specified to have a particular scope, then the name and public key of the `Identity` are unique within that scope.

An `Identity` also has a set of certificates (all certifying its own public key). The Principal names specified in these certificates need not be the same, only the key.

An `Identity` can be subclassed, to include postal and email addresses, telephone numbers, images of faces and logos, and so on.

Since:
  1.1
See Also:
  - `IdentityScope`
  - `Signer`
  - `Principal`
  - Serialized Form

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `Identity()`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Constructor for serialization only.
  ``
  `Identity(String name)`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Constructs an `Identity` with the specified name and no scope.
  ``
  `Identity(String name, IdentityScope scope)`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Constructs an `Identity` with the specified name and scope.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addCertificate(Certificate certificate)`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Adds a certificate for this `Identity`.
  `Certificate[]`
  `certificates()`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Returns a copy of all the certificates for this `Identity`.
  `final boolean`
  `equals(Object identity)`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Tests for equality between the specified object and this `Identity`.
  `String`
  `getInfo()`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Returns general information previously specified for this `Identity`.
  `final String`
  `getName()`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Returns this identity's name.
  `PublicKey`
  `getPublicKey()`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Returns this identity's public key.
  `final IdentityScope`
  `getScope()`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Returns this identity's scope.
  `int`
  `hashCode()`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Returns the hashcode for this `Identity`.
  `protected boolean`
  `identityEquals(Identity identity)`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Tests for equality between the specified `Identity` and this `Identity`.
  `void`
  `removeCertificate(Certificate certificate)`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Removes a certificate from this `Identity`.
  `void`
  `setInfo(String info)`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Specifies a general information string for this `Identity`.
  `void`
  `setPublicKey(PublicKey key)`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Sets this identity's public key.
  `String`
  `toString()`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Returns a short string describing this `Identity`, telling its name and its scope (if any).
  `String`
  `toString(boolean detailed)`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Returns a string representation of this `Identity`, with optionally more details than that provided by the `toString` method without any arguments.

  ### Methods declared in class Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

  ### Methods declared in interface Principal

  `implies`

- ## Constructor Details

  - ### Identity

    protected Identity()
    Deprecated, for removal: This API element is subject to removal in a future version.
    Constructor for serialization only.

  - ### Identity

    public Identity(String name, IdentityScope scope) throws KeyManagementException
    Deprecated, for removal: This API element is subject to removal in a future version.
    Constructs an `Identity` with the specified name and scope.
    Parameters:
      `name` - the `Identity` name.
      `scope` - the scope of the `Identity`.
    Throws:
      `KeyManagementException` - if there is already an `Identity` with the same name in the scope.

  - ### Identity

    public Identity(String name)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Constructs an `Identity` with the specified name and no scope.
    Parameters:
      `name` - the identity name.

- ## Method Details

  - ### getName

    public final String getName()
    Deprecated, for removal: This API element is subject to removal in a future version.
    Returns this identity's name.
    Specified by:
      `getName` in interface `Principal`
    Returns:
      the name of this `Identity`.

  - ### getScope

    public final IdentityScope getScope()
    Deprecated, for removal: This API element is subject to removal in a future version.
    Returns this identity's scope.
    Returns:
      the scope of this `Identity`.

  - ### getPublicKey

    public PublicKey getPublicKey()
    Deprecated, for removal: This API element is subject to removal in a future version.
    Returns this identity's public key.
    Returns:
      the public key for this `Identity`.
    See Also:
      - `setPublicKey(PublicKey)`

  - ### setPublicKey

    public void setPublicKey(PublicKey key) throws KeyManagementException
    Deprecated, for removal: This API element is subject to removal in a future version.
    Sets this identity's public key. The old key and all of this identity's certificates are removed by this operation.
    Parameters:
      `key` - the public key for this `Identity`.
    Throws:
      `KeyManagementException` - if another identity in the identity's scope has the same public key, or if another exception occurs.
    See Also:
      - `getPublicKey()`

  - ### setInfo

    public void setInfo(String info)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Specifies a general information string for this `Identity`.
    Parameters:
      `info` - the information string.
    See Also:
      - `getInfo()`

  - ### getInfo

    public String getInfo()
    Deprecated, for removal: This API element is subject to removal in a future version.
    Returns general information previously specified for this `Identity`.
    Returns:
      general information about this `Identity`.
    See Also:
      - `setInfo(String)`

  - ### addCertificate

    public void addCertificate(Certificate certificate) throws KeyManagementException
    Deprecated, for removal: This API element is subject to removal in a future version.
    Adds a certificate for this `Identity`. If the `Identity` has a public key, the public key in the certificate must be the same, and if the `Identity` does not have a public key, the identity's public key is set to be that specified in the certificate.
    Parameters:
      `certificate` - the certificate to be added.
    Throws:
      `KeyManagementException` - if the certificate is not valid, if the public key in the certificate being added conflicts with this identity's public key, or if another exception occurs.

  - ### removeCertificate

    public void removeCertificate(Certificate certificate) throws KeyManagementException
    Deprecated, for removal: This API element is subject to removal in a future version.
    Removes a certificate from this `Identity`.
    Parameters:
      `certificate` - the certificate to be removed.
    Throws:
      `KeyManagementException` - if the certificate is missing, or if another exception occurs.

  - ### certificates

    public Certificate[] certificates()
    Deprecated, for removal: This API element is subject to removal in a future version.
    Returns a copy of all the certificates for this `Identity`.
    Returns:
      a copy of all the certificates for this `Identity`.

  - ### equals

    public final boolean equals(Object identity)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Tests for equality between the specified object and this `Identity`. This first tests to see if the entities actually refer to the same object, in which case it returns `true`. Next, it checks to see if the entities have the same name and the same scope. If they do, the method returns `true`. Otherwise, it calls `identityEquals`, which subclasses should override.
    Specified by:
      `equals` in interface `Principal`
    Overrides:
      `equals` in class `Object`
    Parameters:
      `identity` - the object to test for equality with this `Identity`.
    Returns:
      `true` if the objects are considered equal, `false` otherwise.
    See Also:
      - `identityEquals(Identity)`

  - ### identityEquals

    protected boolean identityEquals(Identity identity)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Tests for equality between the specified `Identity` and this `Identity`. This method should be overridden by subclasses to test for equality. The default behavior is to return `true` if the names and public keys are equal.
    Parameters:
      `identity` - the identity to test for equality with this `identity`.
    Returns:
      `true` if the identities are considered equal, `false` otherwise.
    See Also:
      - `equals(Object)`

  - ### toString

    public String toString()
    Deprecated, for removal: This API element is subject to removal in a future version.
    Returns a short string describing this `Identity`, telling its name and its scope (if any).
    Specified by:
      `toString` in interface `Principal`
    Overrides:
      `toString` in class `Object`
    Returns:
      information about this `Identity`, such as its name and the name of its scope (if any).

  - ### toString

    public String toString(boolean detailed)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Returns a string representation of this `Identity`, with optionally more details than that provided by the `toString` method without any arguments.
    Parameters:
      `detailed` - whether or not to provide detailed information.
    Returns:
      information about this `Identity`. If `detailed` is `true`, then this method returns more information than that provided by the `toString` method without any arguments.
    See Also:
      - `toString()`

  - ### hashCode

    public int hashCode()
    Deprecated, for removal: This API element is subject to removal in a future version.
    Returns the hashcode for this `Identity`.
    Specified by:
      `hashCode` in interface `Principal`
    Overrides:
      `hashCode` in class `Object`
    Returns:
      the hashcode for this `Identity`
    See Also:
      - `Object.equals(java.lang.Object)`
      - `System.identityHashCode(Object)`