Class ClientIdentity

java.lang.Object
org.hyperledger.fabric.contract.ClientIdentity

public final class ClientIdentity extends Object
ClientIdentity represents information about the identity that submitted a transaction. Chaincodes can use this class to obtain information about the submitting identity including a unique ID, the MSP (Membership Service Provider) ID, and attributes. Such information is useful in enforcing access control by the chaincode.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates new ClientIdentity helper.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    assertAttributeValue(String attrName, String attrValue)
    assertAttributeValue verifies that the invoking identity has the attribute named `attrName` with a value of `attrValue`.
    getAttributeValue returns the value of the client's attribute named `attrName`.
    getId returns the ID associated with the invoking identity.
    getMSPID returns the MSP ID of the invoking identity.
    getX509Certificate returns the X509 certificate associated with the invoking identity, or null if it was not identified by an X509 certificate, for instance if the MSP is implemented with an alternative to PKI such as [Identity Mixer](https://jira.hyperledger.org/browse/FAB-5673).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • getId

      public String getId()
      getId returns the ID associated with the invoking identity. This ID is guaranteed to be unique within the MSP.
      Returns:
      {String} A string in the format: "x509::{subject DN}::{issuer DN}"
    • getMSPID

      public String getMSPID()
      getMSPID returns the MSP ID of the invoking identity.
      Returns:
      {String}
    • getAttributeValue

      public String getAttributeValue(String attrName)
      getAttributeValue returns the value of the client's attribute named `attrName`. If the invoking identity possesses the attribute, returns the value of the attribute. If the invoking identity does not possess the attribute, returns null.
      Parameters:
      attrName - Name of the attribute to retrieve the value from the identity's credentials (such as x.509 certificate for PKI-based MSPs).
      Returns:
      {String | null} Value of the attribute or null if the invoking identity does not possess the attribute.
    • assertAttributeValue

      public boolean assertAttributeValue(String attrName, String attrValue)
      assertAttributeValue verifies that the invoking identity has the attribute named `attrName` with a value of `attrValue`.
      Parameters:
      attrName - Name of the attribute to retrieve the value from the identity's credentials (such as x.509 certificate for PKI-based MSPs)
      attrValue - Expected value of the attribute
      Returns:
      {boolean} True if the invoking identity possesses the attribute and the attribute value matches the expected value. Otherwise, returns false.
    • getX509Certificate

      public X509Certificate getX509Certificate()
      getX509Certificate returns the X509 certificate associated with the invoking identity, or null if it was not identified by an X509 certificate, for instance if the MSP is implemented with an alternative to PKI such as [Identity Mixer](https://jira.hyperledger.org/browse/FAB-5673).
      Returns:
      {X509Certificate | null}