Package org.hyperledger.fabric.contract
Class ClientIdentity
- java.lang.Object
-
- org.hyperledger.fabric.contract.ClientIdentity
-
public final class ClientIdentity extends java.lang.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 ClientIdentity(ChaincodeStub stub)
Creates new ClientIdentity helper.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
assertAttributeValue(java.lang.String attrName, java.lang.String attrValue)
assertAttributeValue verifies that the invoking identity has the attribute named `attrName` with a value of `attrValue`.java.lang.String
getAttributeValue(java.lang.String attrName)
getAttributeValue returns the value of the client's attribute named `attrName`.java.lang.String
getId()
getId returns the ID associated with the invoking identity.java.lang.String
getMSPID()
getMSPID returns the MSP ID of the invoking identity.java.security.cert.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).
-
-
-
Constructor Detail
-
ClientIdentity
public ClientIdentity(ChaincodeStub stub) throws java.security.cert.CertificateException, org.json.JSONException, java.io.IOException
Creates new ClientIdentity helper.- Parameters:
stub
-- Throws:
java.security.cert.CertificateException
org.json.JSONException
java.io.IOException
-
-
Method Detail
-
getId
public java.lang.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 java.lang.String getMSPID()
getMSPID returns the MSP ID of the invoking identity.- Returns:
- {String}
-
getAttributeValue
public java.lang.String getAttributeValue(java.lang.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(java.lang.String attrName, java.lang.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 java.security.cert.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}
-
-