use of edu.umass.cs.gnscommon.exceptions.client.InvalidGuidException in project GNS by MobilityFirst.
the class CommandUtils method checkResponse.
/**
*
* @param command
*
* @param responsePacket
* @return Response as a string.
* @throws ClientException
*/
public static ResponsePacket checkResponse(ResponsePacket responsePacket, CommandPacket command) throws ClientException {
ResponseCode code = responsePacket.getErrorCode();
String returnValue = responsePacket.getReturnValue();
// wants to return a null value.
if (code.isOKResult()) {
return (returnValue.startsWith(GNSProtocol.NULL_RESPONSE.toString())) ? null : //returnValue;
responsePacket;
}
// else error
String errorSummary = code + ": " + returnValue + //+ ": " + responsePacket.getSummary()
(command != null ? " for command " + command.getSummary() : "");
switch(code) {
case SIGNATURE_ERROR:
throw new EncryptionException(code, errorSummary);
case BAD_GUID_ERROR:
case BAD_ACCESSOR_ERROR:
case BAD_ACCOUNT_ERROR:
throw new InvalidGuidException(code, errorSummary);
case FIELD_NOT_FOUND_ERROR:
throw new FieldNotFoundException(code, errorSummary);
case ACCESS_ERROR:
throw new AclException(code, errorSummary);
case VERIFICATION_ERROR:
throw new VerificationException(code, errorSummary);
case ALREADY_VERIFIED_EXCEPTION:
throw new VerificationException(code, errorSummary);
case DUPLICATE_ID_EXCEPTION:
//case DUPLICATE_NAME_EXCEPTION:
throw new DuplicateNameException(code, errorSummary);
case DUPLICATE_FIELD_EXCEPTION:
throw new InvalidFieldException(code, errorSummary);
case ACTIVE_REPLICA_EXCEPTION:
throw new InvalidGuidException(code, errorSummary);
case NONEXISTENT_NAME_EXCEPTION:
throw new InvalidGuidException(code, errorSummary);
case TIMEOUT:
case RECONFIGURATION_EXCEPTION:
throw new ClientException(code, errorSummary);
default:
throw new ClientException(code, "Error received with an unknown response code: " + errorSummary);
}
}
use of edu.umass.cs.gnscommon.exceptions.client.InvalidGuidException in project GNS by MobilityFirst.
the class GuidCreate method parse.
@Override
public void parse(String commandText) throws Exception {
GuidEntry accountGuid = module.getCurrentGuid();
StringTokenizer st = new StringTokenizer(commandText.trim());
if ((st.countTokens() != 1)) {
wrongArguments();
return;
}
String aliasName = st.nextToken();
try {
GNSClientCommands gnsClient = module.getGnsClient();
try {
gnsClient.lookupGuid(aliasName);
printString("Alias " + aliasName + " already exists.\n");
return;
} catch (ClientException expected) {
// The alias does not exists, that's good, let's create it
}
if (!module.isSilent()) {
printString("Looking for alias " + aliasName + " GUID and certificates...\n");
}
GuidEntry myGuid = KeyPairUtils.getGuidEntry(module.getGnsInstance(), aliasName);
if (myGuid != null) {
try {
PublicKey pk = gnsClient.publicKeyLookupFromGuid(myGuid.getGuid());
if (myGuid.getPublicKey().equals(pk)) {
// We already have the key but the alias is missing in the GNS,
// re-add the alias
printString("Alias info found locally but missing in GNS, re-adding alias to the GNS\n");
gnsClient.guidCreate(myGuid, aliasName);
} else {
printString("Old certificates found locally and not matching key in GNS, deleting local keys\n");
KeyPairUtils.removeKeyPair(module.getGnsInstance(), aliasName);
}
} catch (InvalidGuidException e) {
KeyPairUtils.removeKeyPair(module.getGnsInstance(), aliasName);
}
}
if (!module.isSilent()) {
printString("Generating new GUID and keys for account " + accountGuid.getEntityName() + " \n");
}
myGuid = gnsClient.guidCreate(accountGuid, aliasName);
if (!module.isSilent()) {
printString("Created GUID " + myGuid.getGuid() + "\n");
}
if (module.getCurrentGuid() == null) {
module.setCurrentGuidAndCheckForVerified(myGuid);
module.setPromptString(ConsoleModule.CONSOLE_PROMPT + aliasName + ">");
}
} catch (IOException | ClientException e) {
printString("Failed to create new guid ( " + e + ")\n");
}
}
use of edu.umass.cs.gnscommon.exceptions.client.InvalidGuidException in project GNS by MobilityFirst.
the class AccountCreate method parse.
@Override
public void parse(String commandText) throws Exception {
StringTokenizer st = new StringTokenizer(commandText.trim());
if ((st.countTokens() != 2)) {
wrongArguments();
return;
}
String aliasName = st.nextToken();
String password = st.nextToken();
try {
GNSClientCommands gnsClient = module.getGnsClient();
try {
gnsClient.lookupGuid(aliasName);
if (!module.isSilent()) {
printString("Alias " + aliasName + " already exists.\n");
}
return;
} catch (Exception expected) {
// The alias does not exists, that's good, let's create it
}
GuidEntry myGuid = KeyPairUtils.getGuidEntry(module.getGnsInstance(), aliasName);
if (myGuid != null) {
try {
PublicKey pk = gnsClient.publicKeyLookupFromGuid(myGuid.getGuid());
if (myGuid.getPublicKey().equals(pk)) {
// We already have the key but the alias is missing in the GNS,
// re-add the alias
printString("Alias info found locally but missing in GNS, re-adding alias to the GNS\n");
gnsClient.guidCreate(myGuid, aliasName);
} else {
printString("Old certificates found locally and not matching key in GNS, deleting local keys\n");
KeyPairUtils.removeKeyPair(module.getGnsInstance(), aliasName);
}
} catch (InvalidGuidException e) {
KeyPairUtils.removeKeyPair(module.getGnsInstance(), aliasName);
}
}
myGuid = gnsClient.accountGuidCreate(aliasName, password);
if (!module.isSilent()) {
printString("Created an account with GUID " + myGuid.getGuid() + ".\n");
}
if (module.getCurrentGuid() == null) {
module.setCurrentGuidAndCheckForVerified(myGuid);
if (KeyPairUtils.getDefaultGuidEntry(module.getGnsInstance()) == null) {
KeyPairUtils.setDefaultGuidEntry(module.getGnsInstance(), aliasName);
module.printString(aliasName + " saved as default GUID \n");
}
module.setPromptString(ConsoleModule.CONSOLE_PROMPT + aliasName + ">");
}
} catch (Exception e) {
e.printStackTrace();
printString("Failed to create new guid ( " + e + ")\n");
}
}
Aggregations