Search in sources :

Example 6 with CommandResponse

use of edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse in project GNS by MobilityFirst.

the class RegisterAccountSecured method execute.

@Override
public CommandResponse execute(InternalRequestHeader header, CommandPacket commandPacket, ClientRequestHandlerInterface handler) throws InvalidKeyException, InvalidKeySpecException, JSONException, NoSuchAlgorithmException, SignatureException, UnsupportedEncodingException, InternalRequestException {
    JSONObject json = commandPacket.getCommand();
    String name = json.getString(GNSProtocol.NAME.toString());
    String publicKey = json.getString(GNSProtocol.PUBLIC_KEY.toString());
    String password = json.getString(GNSProtocol.PASSWORD.toString());
    String signature = json.optString(GNSProtocol.SIGNATURE.toString(), null);
    String message = json.optString(GNSProtocol.SIGNATUREFULLMESSAGE.toString(), null);
    String guid = SharedGuidUtils.createGuidStringFromBase64PublicKey(publicKey);
    if (!NSAccessSupport.verifySignature(publicKey, signature, message)) {
        return new CommandResponse(ResponseCode.SIGNATURE_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_SIGNATURE.toString());
    }
    try {
        // Add the account but don't enable email verification
        CommandResponse result = AccountAccess.addAccount(header, commandPacket, handler.getHttpServerHostPortString(), name, guid, publicKey, password, false, handler);
        if (result.getExceptionOrErrorCode().isOKResult()) {
            // Everything is hunkey dorey so return the new guid
            return new CommandResponse(ResponseCode.NO_ERROR, guid);
        } else {
            assert (result.getExceptionOrErrorCode() != null);
            // Otherwise return the error response.
            return result;
        }
    } catch (ClientException | IOException e) {
        return new CommandResponse(ResponseCode.UNSPECIFIED_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.UNSPECIFIED_ERROR.toString() + " " + e.getMessage());
    }
}
Also used : JSONObject(org.json.JSONObject) CommandResponse(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException)

Example 7 with CommandResponse

use of edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse in project GNS by MobilityFirst.

the class RemoveAccountSecured method execute.

@Override
public CommandResponse execute(InternalRequestHeader header, CommandPacket commandPacket, ClientRequestHandlerInterface handler) throws InvalidKeyException, InvalidKeySpecException, JSONException, NoSuchAlgorithmException, SignatureException, UnsupportedEncodingException, InternalRequestException {
    JSONObject json = commandPacket.getCommand();
    // The name of the account we are removing.
    String name = json.getString(GNSProtocol.NAME.toString());
    // The guid of this account.
    String guid = AccountAccess.lookupGuidAnywhere(header, name, handler);
    if (guid == null) {
        // Removing a non-existant guid is not longer an error.
        return new CommandResponse(ResponseCode.NO_ERROR, GNSProtocol.OK_RESPONSE.toString());
    }
    AccountInfo accountInfo = AccountAccess.lookupAccountInfoFromNameAnywhere(header, name, handler);
    if (accountInfo == null) {
        return new CommandResponse(ResponseCode.BAD_ACCOUNT_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_ACCOUNT.toString());
    }
    // And... we're done.
    return AccountAccess.removeAccount(header, commandPacket, accountInfo, handler);
}
Also used : JSONObject(org.json.JSONObject) CommandResponse(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse) AccountInfo(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.AccountInfo)

Example 8 with CommandResponse

use of edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse in project GNS by MobilityFirst.

the class RemoveAccountWithPassword method execute.

@Override
public CommandResponse execute(InternalRequestHeader header, CommandPacket commandPacket, ClientRequestHandlerInterface handler) throws InvalidKeyException, InvalidKeySpecException, JSONException, NoSuchAlgorithmException, SignatureException, UnsupportedEncodingException, InternalRequestException {
    JSONObject json = commandPacket.getCommand();
    // The name of the account we are removing.
    String name = json.getString(GNSProtocol.NAME.toString());
    // The guid of this account.
    String password = json.getString(GNSProtocol.PASSWORD.toString());
    String guid = AccountAccess.lookupGuidAnywhere(header, name, handler);
    if (guid == null) {
        // Removing a non-existant guid is not longer an error.
        return new CommandResponse(ResponseCode.NO_ERROR, GNSProtocol.OK_RESPONSE.toString());
    }
    AccountInfo accountInfo = AccountAccess.lookupAccountInfoFromNameAnywhere(header, name, handler);
    if (accountInfo == null) {
        return new CommandResponse(ResponseCode.BAD_ACCOUNT_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_ACCOUNT.toString());
    }
    if (!password.equals(accountInfo.getPassword())) {
        return new CommandResponse(ResponseCode.ACCESS_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.ACCESS_DENIED.toString());
    } else {
        return AccountAccess.removeAccount(header, commandPacket, accountInfo, handler);
    }
}
Also used : JSONObject(org.json.JSONObject) CommandResponse(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse) AccountInfo(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.AccountInfo)

Example 9 with CommandResponse

use of edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse in project GNS by MobilityFirst.

the class FieldDeleteAcl method execute.

@Override
public CommandResponse execute(InternalRequestHeader header, CommandPacket commandPacket, ClientRequestHandlerInterface handler) throws InvalidKeyException, InvalidKeySpecException, JSONException, NoSuchAlgorithmException, SignatureException, ParseException {
    JSONObject json = commandPacket.getCommand();
    String guid = json.getString(GNSProtocol.GUID.toString());
    String field = json.getString(GNSProtocol.FIELD.toString());
    String accessType = json.getString(GNSProtocol.ACL_TYPE.toString());
    // allows someone other than guid to delete acl, defaults to guid
    String writer = json.optString(GNSProtocol.WRITER.toString(), guid);
    String signature = json.getString(GNSProtocol.SIGNATURE.toString());
    String message = json.getString(GNSProtocol.SIGNATUREFULLMESSAGE.toString());
    Date timestamp = json.has(GNSProtocol.TIMESTAMP.toString()) ? Format.parseDateISO8601UTC(json.getString(GNSProtocol.TIMESTAMP.toString())) : // can be null on older client
    null;
    MetaDataTypeName access;
    if ((access = MetaDataTypeName.valueOf(accessType)) == null) {
        return new CommandResponse(ResponseCode.BAD_ACL_TYPE_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_ACL_TYPE.toString() + "Should be one of " + Arrays.toString(MetaDataTypeName.values()));
    }
    ResponseCode responseCode;
    if (!(responseCode = FieldMetaData.deleteField(header, commandPacket, access, guid, field, writer, signature, message, timestamp, handler)).isExceptionOrError()) {
        return new CommandResponse(ResponseCode.NO_ERROR, GNSProtocol.OK_RESPONSE.toString());
    } else {
        return new CommandResponse(responseCode, GNSProtocol.BAD_RESPONSE.toString() + " " + responseCode.getProtocolCode());
    }
}
Also used : ResponseCode(edu.umass.cs.gnscommon.ResponseCode) JSONObject(org.json.JSONObject) CommandResponse(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse) Date(java.util.Date) MetaDataTypeName(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.MetaDataTypeName)

Example 10 with CommandResponse

use of edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse in project GNS by MobilityFirst.

the class AbstractUpdateList method execute.

@Override
public CommandResponse execute(InternalRequestHeader header, CommandPacket commandPacket, ClientRequestHandlerInterface handler) throws InvalidKeyException, InvalidKeySpecException, JSONException, NoSuchAlgorithmException, SignatureException, ParseException {
    JSONObject json = commandPacket.getCommand();
    String guid = json.getString(GNSProtocol.GUID.toString());
    String field = json.getString(GNSProtocol.FIELD.toString());
    String value = json.getString(GNSProtocol.VALUE.toString());
    String oldValue = json.optString(GNSProtocol.OLD_VALUE.toString(), null);
    int argument = json.optInt(GNSProtocol.ARGUMENT.toString(), -1);
    String writer = json.optString(GNSProtocol.WRITER.toString(), guid);
    String signature = json.optString(GNSProtocol.SIGNATURE.toString(), null);
    String message = json.optString(GNSProtocol.SIGNATUREFULLMESSAGE.toString(), null);
    Date timestamp;
    if (json.has(GNSProtocol.TIMESTAMP.toString())) {
        // can be null on older client
        timestamp = json.has(GNSProtocol.TIMESTAMP.toString()) ? Format.parseDateISO8601UTC(json.getString(GNSProtocol.TIMESTAMP.toString())) : null;
    } else {
        timestamp = null;
    }
    ResponseCode responseCode;
    if (!(responseCode = FieldAccess.update(header, commandPacket, guid, field, JSONUtils.JSONArrayToResultValue(new JSONArray(value)), oldValue != null ? JSONUtils.JSONArrayToResultValue(new JSONArray(oldValue)) : null, argument, getUpdateOperation(), writer, signature, message, timestamp, handler)).isExceptionOrError()) {
        return new CommandResponse(ResponseCode.NO_ERROR, GNSProtocol.OK_RESPONSE.toString());
    } else {
        return new CommandResponse(responseCode, GNSProtocol.BAD_RESPONSE.toString() + " " + responseCode.getProtocolCode());
    }
}
Also used : ResponseCode(edu.umass.cs.gnscommon.ResponseCode) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) CommandResponse(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse) Date(java.util.Date)

Aggregations

CommandResponse (edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse)41 JSONObject (org.json.JSONObject)41 Date (java.util.Date)25 ResponseCode (edu.umass.cs.gnscommon.ResponseCode)16 AccountInfo (edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.AccountInfo)13 GuidInfo (edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.GuidInfo)11 MetaDataTypeName (edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.MetaDataTypeName)9 JSONArray (org.json.JSONArray)8 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)7 IOException (java.io.IOException)7 ResultValue (edu.umass.cs.gnsserver.utils.ResultValue)5 JSONException (org.json.JSONException)5 InternalRequestException (edu.umass.cs.gnscommon.exceptions.server.InternalRequestException)4 CommandType (edu.umass.cs.gnscommon.CommandType)1 FailedDBOperationException (edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException)1 CommandPacket (edu.umass.cs.gnscommon.packets.CommandPacket)1 AbstractCommand (edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commands.AbstractCommand)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1