Search in sources :

Example 21 with GNSClientCommands

use of edu.umass.cs.gnsclient.client.GNSClientCommands 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);
}
Also used : StringTokenizer(java.util.StringTokenizer) GNSClientCommands(edu.umass.cs.gnsclient.client.GNSClientCommands) VerificationException(edu.umass.cs.gnscommon.exceptions.client.VerificationException) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry) VerificationException(edu.umass.cs.gnscommon.exceptions.client.VerificationException)

Example 22 with GNSClientCommands

use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.

the class AclAdd method parse.

@Override
public void parse(String commandText) throws Exception {
    try {
        GNSClientCommands gnsClient = module.getGnsClient();
        StringTokenizer st = new StringTokenizer(commandText.trim());
        if (st.countTokens() != 3) {
            wrongArguments();
            return;
        }
        String field = st.nextToken();
        boolean isWrite = "write".equalsIgnoreCase(st.nextToken());
        String guid = st.nextToken();
        // Set ACL
        gnsClient.aclAdd(isWrite ? AclAccessType.WRITE_WHITELIST : AclAccessType.READ_WHITELIST, module.getCurrentGuid(), field, "+ALL+".equals(guid) ? null : guid);
        // Then read ACLs
        JSONArray write = gnsClient.aclGet(isWrite ? AclAccessType.WRITE_WHITELIST : AclAccessType.READ_WHITELIST, module.getCurrentGuid(), field, module.getCurrentGuid().getGuid());
        console.printString("New ACL is: " + write.toString());
        console.printNewline();
    } catch (Exception e) {
        console.printString("Failed to access GNS ( " + e + ")\n");
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) GNSClientCommands(edu.umass.cs.gnsclient.client.GNSClientCommands) JSONArray(org.json.JSONArray)

Example 23 with GNSClientCommands

use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.

the class AliasLookup method parse.

@Override
public void parse(String commandText) throws Exception {
    try {
        StringTokenizer st = new StringTokenizer(commandText.trim());
        if (st.countTokens() != 1) {
            wrongArguments();
            return;
        }
        String guid = st.nextToken();
        GNSClientCommands gnsClient = module.getGnsClient();
        JSONObject entityInfo = gnsClient.lookupGuidRecord(guid);
        String alias = entityInfo.getString(GNSProtocol.GUID_RECORD_NAME.toString());
        console.printString(guid + " has alias " + alias);
        console.printNewline();
    } catch (IOException | ClientException | JSONException e) {
        console.printString("Failed to access GNS ( " + e + ")\n");
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) GNSClientCommands(edu.umass.cs.gnsclient.client.GNSClientCommands) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) IOException(java.io.IOException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException)

Example 24 with GNSClientCommands

use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.

the class AclExists method parse.

@Override
public void parse(String commandText) throws Exception {
    try {
        GNSClientCommands gnsClient = module.getGnsClient();
        StringTokenizer st = new StringTokenizer(commandText.trim());
        if (st.countTokens() != 2) {
            wrongArguments();
            return;
        }
        String field = st.nextToken();
        boolean isWrite = "write".equalsIgnoreCase(st.nextToken());
        // Set ACL
        boolean exists = gnsClient.fieldAclExists(isWrite ? AclAccessType.WRITE_WHITELIST : AclAccessType.READ_WHITELIST, module.getCurrentGuid(), field);
        if (exists) {
            // Then read ACLs
            JSONArray acl = gnsClient.aclGet(isWrite ? AclAccessType.WRITE_WHITELIST : AclAccessType.READ_WHITELIST, module.getCurrentGuid(), field, module.getCurrentGuid().getGuid());
            console.printString((isWrite ? "Write" : "Read") + " ACL is: " + acl.toString());
            console.printNewline();
        } else {
            console.printString((isWrite ? "Write" : "Read") + " ACL for field " + field + " does not exist");
            console.printNewline();
        }
    } catch (IOException | ClientException e) {
        console.printString("Failed to access GNS ( " + e + ")\n");
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) GNSClientCommands(edu.umass.cs.gnsclient.client.GNSClientCommands) JSONArray(org.json.JSONArray) IOException(java.io.IOException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException)

Example 25 with GNSClientCommands

use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.

the class FieldCreateList method parse.

@Override
public void parse(String commandText) throws Exception {
    try {
        StringTokenizer st = new StringTokenizer(commandText.trim());
        if ((st.countTokens() != 1) && (st.countTokens() != 2)) {
            wrongArguments();
            return;
        }
        String field = st.nextToken();
        String value = "";
        if (st.hasMoreTokens()) {
            value = st.nextToken();
        }
        GNSClientCommands gnsClient = module.getGnsClient();
        gnsClient.fieldCreateList(module.getCurrentGuid().getGuid(), field, new JSONArray().put(value), module.getCurrentGuid());
        console.printString("New field " + field + " created with value '" + value + "'");
        console.printNewline();
    } catch (IOException | ClientException e) {
        console.printString("Failed to access GNS ( " + e + ")\n");
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) GNSClientCommands(edu.umass.cs.gnsclient.client.GNSClientCommands) JSONArray(org.json.JSONArray) IOException(java.io.IOException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException)

Aggregations

GNSClientCommands (edu.umass.cs.gnsclient.client.GNSClientCommands)70 IOException (java.io.IOException)55 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)50 StringTokenizer (java.util.StringTokenizer)35 GuidEntry (edu.umass.cs.gnsclient.client.util.GuidEntry)28 JSONArray (org.json.JSONArray)13 JSONException (org.json.JSONException)11 DuplicateNameException (edu.umass.cs.gnscommon.exceptions.client.DuplicateNameException)10 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)10 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)9 JSONObject (org.json.JSONObject)9 InvalidKeyException (java.security.InvalidKeyException)8 SignatureException (java.security.SignatureException)8 GNSClient (edu.umass.cs.gnsclient.client.GNSClient)6 PublicKey (java.security.PublicKey)6 HashSet (java.util.HashSet)6 BeforeClass (org.junit.BeforeClass)6 RandomString (edu.umass.cs.gnscommon.utils.RandomString)5 File (java.io.File)5 FileInputStream (java.io.FileInputStream)5