use of edu.umass.cs.gnscommon.exceptions.client.VerificationException in project GNS by MobilityFirst.
the class CreateMultiGuidClient method main.
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
int node = Integer.parseInt(args[0]);
BENIGN_CLIENT = Integer.parseInt(args[1]);
NUM_CLIENT = Integer.parseInt(args[2]);
boolean flag = Boolean.parseBoolean(args[3]);
//Read in the code and serialize
// String code = new String(Files.readAllBytes(Paths.get(filename)));
// String code64 = Base64.encodeToString(code.getBytes("utf-8"), true);
// String mal_code = new String(Files.readAllBytes(Paths.get(mal_file)));
// String mal_code64 = Base64.encodeToString(mal_code.getBytes("utf-8"), true);
client = new GNSClientCommands();
ExecutorService executor = Executors.newFixedThreadPool(numThread);
for (int i = 0; i < NUM_CLIENT; i++) {
String name = "test" + (node * 1000 + i) + ACCOUNT_ALIAS;
GuidEntry guidAccount = null;
try {
guidAccount = lookupOrCreateAccountGuid(client, name, "password");
} catch (VerificationException e) {
// ignore verification exceptions
} catch (Exception e) {
System.out.println("Exception during accountGuid creation: " + e);
System.exit(1);
}
System.out.println(name + ":" + guidAccount.getGuid());
if (flag) {
if (i < BENIGN_CLIENT) {
executor.execute(new createGuidThread(client, guidAccount.getGuid(), guidAccount));
} else {
executor.execute(new createGuidThread(client, guidAccount.getGuid(), guidAccount));
}
}
}
while (createdGuid < NUM_CLIENT) {
System.out.println(createdGuid + "/" + NUM_CLIENT + " guids have been created ...");
Thread.sleep(1000);
}
System.out.println("Created all " + NUM_CLIENT + " guids.");
System.exit(0);
}
use of edu.umass.cs.gnscommon.exceptions.client.VerificationException in project GNS by MobilityFirst.
the class AccountVerify method parse.
@Override
public void parse(String commandText) throws Exception {
try {
GNSClientCommands client = module.getGnsClient();
StringTokenizer st = new StringTokenizer(commandText.trim());
if (st.countTokens() != 2) {
wrongArguments();
return;
}
String alias = st.nextToken();
GuidEntry guid = KeyPairUtils.getGuidEntry(module.getGnsInstance(), alias);
if (guid == null) {
printString("Unable to retrieve GUID for alias " + alias + "\n");
return;
}
String code = st.nextToken();
try {
if (client.accountGuidVerify(guid, code).startsWith(GNSProtocol.OK_RESPONSE.toString())) {
printString("Account verified.\n");
module.setAccountVerified(true);
return;
}
// this happens if it was already verified, but we didn't notice
} catch (VerificationException e) {
module.setAccountVerified(true);
printString("Account already verified" + "\n");
return;
} catch (Exception e) {
printString("Account not verified: " + e + "\n");
}
} catch (Exception e) {
console.printString("Failed to access GNS ( " + e + ")\n");
}
module.setAccountVerified(false);
}
use of edu.umass.cs.gnscommon.exceptions.client.VerificationException 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);
}
}
Aggregations