Search in sources :

Example 36 with ResponseCode

use of edu.umass.cs.gnscommon.ResponseCode in project GNS by MobilityFirst.

the class AddMembersToGroup 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 members = json.getString(GNSProtocol.MEMBERS.toString());
    // writer might be same as guid
    String writer = json.optString(GNSProtocol.WRITER.toString(), guid);
    // signature and message can be empty for unsigned cases
    String signature = json.optString(GNSProtocol.SIGNATURE.toString(), null);
    String message = json.optString(GNSProtocol.SIGNATUREFULLMESSAGE.toString(), null);
    Date timestamp = json.has(GNSProtocol.TIMESTAMP.toString()) ? Format.parseDateISO8601UTC(json.getString(GNSProtocol.TIMESTAMP.toString())) : // can be null on older client
    null;
    ResponseCode responseCode;
    try {
        if (!(responseCode = GroupAccess.addToGroup(header, guid, new ResultValue(members), 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());
        }
    } catch (ClientException | IOException | InternalRequestException e) {
        return new CommandResponse(ResponseCode.UNSPECIFIED_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.UNSPECIFIED_ERROR.toString() + " " + e.getMessage());
    }
}
Also used : ResponseCode(edu.umass.cs.gnscommon.ResponseCode) JSONObject(org.json.JSONObject) InternalRequestException(edu.umass.cs.gnscommon.exceptions.server.InternalRequestException) ResultValue(edu.umass.cs.gnsserver.utils.ResultValue) CommandResponse(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) Date(java.util.Date)

Example 37 with ResponseCode

use of edu.umass.cs.gnscommon.ResponseCode in project GNS by MobilityFirst.

the class FieldCreateAcl 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 create 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.createField(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 38 with ResponseCode

use of edu.umass.cs.gnscommon.ResponseCode in project GNS by MobilityFirst.

the class ClearCode 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 writer = json.getString(GNSProtocol.WRITER.toString());
    String action = json.getString(GNSProtocol.AC_ACTION.toString());
    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;
    try {
        ResponseCode response = ActiveCode.clearCode(header, commandPacket, guid, action, writer, signature, message, timestamp, handler);
        if (!response.isExceptionOrError()) {
            return new CommandResponse(ResponseCode.NO_ERROR, GNSProtocol.OK_RESPONSE.toString());
        } else {
            return new CommandResponse(response, GNSProtocol.BAD_RESPONSE.toString() + " " + response.getProtocolCode());
        }
    } catch (IllegalArgumentException e) {
        return new CommandResponse(ResponseCode.UNSPECIFIED_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + ResponseCode.UNSPECIFIED_ERROR.getProtocolCode() + " " + e.getMessage());
    }
}
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)

Example 39 with ResponseCode

use of edu.umass.cs.gnscommon.ResponseCode in project GNS by MobilityFirst.

the class Create 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());
    // the opt hair below is for the subclasses... cute, huh?
    // value might be null
    String value = json.optString(GNSProtocol.VALUE.toString(), null);
    // writer might be same as 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;
    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.createField(header, commandPacket, guid, field, (value == null ? new ResultValue() : new ResultValue(Arrays.asList(value))), 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) ResultValue(edu.umass.cs.gnsserver.utils.ResultValue) CommandResponse(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse) Date(java.util.Date)

Example 40 with ResponseCode

use of edu.umass.cs.gnscommon.ResponseCode in project GNS by MobilityFirst.

the class AbstractUpdate 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.optString(GNSProtocol.FIELD.toString(), null);
    String value = json.optString(GNSProtocol.VALUE.toString(), null);
    String oldValue = json.optString(GNSProtocol.OLD_VALUE.toString(), null);
    int index = json.optInt(GNSProtocol.N.toString(), -1);
    JSONObject userJSON = json.has(GNSProtocol.USER_JSON.toString()) ? new JSONObject(json.getString(GNSProtocol.USER_JSON.toString())) : null;
    // writer might be unspecified so we use the guid
    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 = json.has(GNSProtocol.TIMESTAMP.toString()) ? Format.parseDateISO8601UTC(json.getString(GNSProtocol.TIMESTAMP.toString())) : // can be null on older client
    null;
    if (json.has("originalBase64")) {
        ClientCommandProcessorConfig.getLogger().log(Level.WARNING, "||||||||||||||||||||||||||| message:{0} original{1}", new Object[] { message, new String(Base64.decode(json.getString("originalBase64"))) });
    }
    ResponseCode responseCode;
    if (field == null) {
        responseCode = FieldAccess.updateUserJSON(header, commandPacket, guid, userJSON, writer, signature, message, timestamp, handler);
        if (!responseCode.isExceptionOrError()) {
            return new CommandResponse(ResponseCode.NO_ERROR, GNSProtocol.OK_RESPONSE.toString());
        } else {
            return new CommandResponse(responseCode, GNSProtocol.BAD_RESPONSE.toString() + " " + responseCode.getProtocolCode());
        }
    } else // single field update
    {
        if (!(responseCode = FieldAccess.update(header, commandPacket, guid, field, // special case for the ops which do not need a value
        value != null ? new ResultValue(Arrays.asList(value)) : new ResultValue(), oldValue != null ? new ResultValue(Arrays.asList(oldValue)) : null, index, 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) CommandResponse(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse) ResultValue(edu.umass.cs.gnsserver.utils.ResultValue) Date(java.util.Date)

Aggregations

ResponseCode (edu.umass.cs.gnscommon.ResponseCode)40 JSONObject (org.json.JSONObject)28 Date (java.util.Date)18 CommandResponse (edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse)16 JSONException (org.json.JSONException)14 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)13 ResultValue (edu.umass.cs.gnsserver.utils.ResultValue)8 FailedDBOperationException (edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException)7 InternalRequestException (edu.umass.cs.gnscommon.exceptions.server.InternalRequestException)7 IOException (java.io.IOException)7 MetaDataTypeName (edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.MetaDataTypeName)6 RandomString (edu.umass.cs.gnscommon.utils.RandomString)5 ValuesMap (edu.umass.cs.gnsserver.utils.ValuesMap)5 GuidInfo (edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.GuidInfo)4 CreateServiceName (edu.umass.cs.reconfiguration.reconfigurationpackets.CreateServiceName)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 InvalidKeyException (java.security.InvalidKeyException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 SignatureException (java.security.SignatureException)3 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)3