use of org.hyperledger.fabric_ca.sdk.exception.IdentityException in project fabric-sdk-java by hyperledger.
the class HFCAClient method getHFCAIdentities.
/**
* gets all identities that the registrar is allowed to see
*
* @param registrar The identity of the registrar (i.e. who is performing the registration).
* @return the identity that was requested
* @throws IdentityException if adding an identity fails.
* @throws InvalidArgumentException Invalid (null) argument specified
*/
public Collection<HFCAIdentity> getHFCAIdentities(User registrar) throws IdentityException, InvalidArgumentException {
if (registrar == null) {
throw new InvalidArgumentException("Registrar should be a valid member");
}
logger.debug(format("identity url: %s, registrar: %s", url, registrar.getName()));
try {
JsonObject result = httpGet(HFCAIdentity.HFCA_IDENTITY, registrar);
Collection<HFCAIdentity> allIdentities = new ArrayList<HFCAIdentity>();
JsonArray identities = result.getJsonArray("identities");
if (identities != null && !identities.isEmpty()) {
for (int i = 0; i < identities.size(); i++) {
JsonObject identity = identities.getJsonObject(i);
HFCAIdentity idObj = new HFCAIdentity(identity);
allIdentities.add(idObj);
}
}
logger.debug(format("identity url: %s, registrar: %s done.", url, registrar));
return allIdentities;
} catch (HTTPException e) {
String msg = format("[HTTP Status Code: %d] - Error while getting all users from url '%s': %s", e.getStatusCode(), url, e.getMessage());
IdentityException identityException = new IdentityException(msg, e);
logger.error(msg);
throw identityException;
} catch (Exception e) {
String msg = format("Error while getting all users from url '%s': %s", url, e.getMessage());
IdentityException identityException = new IdentityException(msg, e);
logger.error(msg);
throw identityException;
}
}
use of org.hyperledger.fabric_ca.sdk.exception.IdentityException in project fabric-sdk-java by hyperledger.
the class HFCAIdentity method read.
/**
* read retrieves a specific identity
*
* @param registrar The identity of the registrar (i.e. who is performing the registration).
* @return statusCode The HTTP status code in the response
* @throws IdentityException if retrieving an identity fails.
* @throws InvalidArgumentException Invalid (null) argument specified
*/
public int read(User registrar) throws IdentityException, InvalidArgumentException {
if (registrar == null) {
throw new InvalidArgumentException("Registrar should be a valid member");
}
String readIdURL = "";
try {
readIdURL = HFCA_IDENTITY + "/" + enrollmentID;
logger.debug(format("identity url: %s, registrar: %s", readIdURL, registrar.getName()));
JsonObject result = client.httpGet(readIdURL, registrar);
statusCode = result.getInt("statusCode");
if (statusCode < 400) {
type = result.getString("type");
maxEnrollments = result.getInt("max_enrollments");
affiliation = result.getString("affiliation");
JsonArray attributes = result.getJsonArray("attrs");
Collection<Attribute> attrs = new ArrayList<Attribute>();
if (attributes != null && !attributes.isEmpty()) {
for (int i = 0; i < attributes.size(); i++) {
JsonObject attribute = attributes.getJsonObject(i);
Attribute attr = new Attribute(attribute.getString("name"), attribute.getString("value"), attribute.getBoolean("ecert", false));
attrs.add(attr);
}
}
this.attrs = attrs;
logger.debug(format("identity url: %s, registrar: %s done.", readIdURL, registrar));
}
this.deleted = false;
return statusCode;
} catch (HTTPException e) {
String msg = format("[Code: %d] - Error while getting user '%s' from url '%s': %s", e.getStatusCode(), getEnrollmentId(), readIdURL, e.getMessage());
IdentityException identityException = new IdentityException(msg, e);
logger.error(msg);
throw identityException;
} catch (Exception e) {
String msg = format("Error while getting user '%s' from url '%s': %s", enrollmentID, readIdURL, e.getMessage());
IdentityException identityException = new IdentityException(msg, e);
logger.error(msg);
throw identityException;
}
}
use of org.hyperledger.fabric_ca.sdk.exception.IdentityException in project fabric-sdk-java by hyperledger.
the class HFCAIdentity method create.
/**
* create an identity
*
* @param registrar The identity of the registrar (i.e. who is performing the registration).
* @return statusCode The HTTP status code in the response
* @throws IdentityException if creating an identity fails.
* @throws InvalidArgumentException Invalid (null) argument specified
*/
public int create(User registrar) throws IdentityException, InvalidArgumentException {
if (this.deleted) {
throw new IdentityException("Identity has been deleted");
}
if (registrar == null) {
throw new InvalidArgumentException("Registrar should be a valid member");
}
String createURL = "";
try {
createURL = client.getURL(HFCA_IDENTITY);
logger.debug(format("identity url: %s, registrar: %s", createURL, registrar.getName()));
String body = client.toJson(idToJsonObject());
JsonObject result = client.httpPost(createURL, body, registrar);
statusCode = result.getInt("statusCode");
if (statusCode >= 400) {
getHFCAIdentity(result);
logger.debug(format("identity url: %s, registrar: %s done.", createURL, registrar));
}
this.deleted = false;
return statusCode;
} catch (HTTPException e) {
String msg = format("[Code: %d] - Error while creating user '%s' from url '%s': %s", e.getStatusCode(), getEnrollmentId(), createURL, e.getMessage());
IdentityException identityException = new IdentityException(msg, e);
logger.error(msg);
throw identityException;
} catch (Exception e) {
String msg = format("Error while creating user '%s' from url '%s': %s", getEnrollmentId(), createURL, e.getMessage());
IdentityException identityException = new IdentityException(msg, e);
logger.error(msg);
throw identityException;
}
}
use of org.hyperledger.fabric_ca.sdk.exception.IdentityException in project fabric-sdk-java by hyperledger.
the class HFCAIdentity method delete.
/**
* delete an identity
*
* @param registrar The identity of the registrar (i.e. who is performing the registration).
* @return statusCode The HTTP status code in the response
* @throws IdentityException if adding an identity fails.
* @throws InvalidArgumentException Invalid (null) argument specified
*/
public int delete(User registrar) throws IdentityException, InvalidArgumentException {
if (this.deleted) {
throw new IdentityException("Identity has been deleted");
}
if (registrar == null) {
throw new InvalidArgumentException("Registrar should be a valid member");
}
String deleteURL = "";
try {
deleteURL = client.getURL(HFCA_IDENTITY + "/" + getEnrollmentId());
logger.debug(format("identity url: %s, registrar: %s", deleteURL, registrar.getName()));
JsonObject result = client.httpDelete(deleteURL, registrar);
statusCode = result.getInt("statusCode");
if (statusCode < 400) {
getHFCAIdentity(result);
logger.debug(format("identity url: %s, registrar: %s done.", deleteURL, registrar));
}
this.deleted = true;
return statusCode;
} catch (HTTPException e) {
String msg = format("[Code: %d] - Error while deleting user '%s' from url '%s': %s", e.getStatusCode(), getEnrollmentId(), deleteURL, e.getMessage());
IdentityException identityException = new IdentityException(msg, e);
logger.error(msg);
throw identityException;
} catch (Exception e) {
String msg = format("Error while deleting user '%s' from url '%s': %s", getEnrollmentId(), deleteURL, e.getMessage());
IdentityException identityException = new IdentityException(msg, e);
logger.error(msg);
throw identityException;
}
}
use of org.hyperledger.fabric_ca.sdk.exception.IdentityException in project fabric-sdk-java by hyperledger.
the class HFCAIdentity method update.
/**
* update an identity
*
* @param registrar The identity of the registrar (i.e. who is performing the registration).
* @return statusCode The HTTP status code in the response
* @throws IdentityException if adding an identity fails.
* @throws InvalidArgumentException Invalid (null) argument specified
*/
public int update(User registrar) throws IdentityException, InvalidArgumentException {
if (this.deleted) {
throw new IdentityException("Identity has been deleted");
}
if (registrar == null) {
throw new InvalidArgumentException("Registrar should be a valid member");
}
String updateURL = "";
try {
updateURL = client.getURL(HFCA_IDENTITY + "/" + getEnrollmentId());
logger.debug(format("identity url: %s, registrar: %s", updateURL, registrar.getName()));
String body = client.toJson(idToJsonObject());
JsonObject result = client.httpPut(updateURL, body, registrar);
statusCode = result.getInt("statusCode");
if (statusCode < 400) {
getHFCAIdentity(result);
logger.debug(format("identity url: %s, registrar: %s done.", updateURL, registrar));
}
return statusCode;
} catch (HTTPException e) {
String msg = format("[Code: %d] - Error while updating user '%s' from url '%s': %s", e.getStatusCode(), getEnrollmentId(), updateURL, e.getMessage());
IdentityException identityException = new IdentityException(msg, e);
logger.error(msg);
throw identityException;
} catch (Exception e) {
String msg = format("Error while updating user '%s' from url '%s': %s", getEnrollmentId(), updateURL, e.getMessage());
IdentityException identityException = new IdentityException(msg, e);
logger.error(msg);
throw identityException;
}
}
Aggregations