use of edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse 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());
}
}
use of edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse in project GNS by MobilityFirst.
the class FieldAclExists 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 read acl, defaults to guid
String reader = json.optString(GNSProtocol.READER.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()));
}
return new CommandResponse(ResponseCode.NO_ERROR, Boolean.toString(FieldMetaData.fieldExists(access, guid, field, reader, signature, message, timestamp, handler)));
}
use of edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse 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());
}
}
use of edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse 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());
}
}
use of edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse in project GNS by MobilityFirst.
the class LookupAccountRecord method execute.
@Override
public CommandResponse execute(InternalRequestHeader header, CommandPacket commandPacket, ClientRequestHandlerInterface handler) throws JSONException {
JSONObject json = commandPacket.getCommand();
String guid = json.getString(GNSProtocol.GUID.toString());
AccountInfo acccountInfo;
if ((acccountInfo = AccountAccess.lookupAccountInfoFromGuidLocally(header, guid, handler)) == null) {
return new CommandResponse(ResponseCode.BAD_ACCOUNT_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_ACCOUNT.toString() + " " + guid);
}
if (acccountInfo != null) {
try {
// Like the verification code or the list of guids which might be too big to send back to the client
return new CommandResponse(ResponseCode.NO_ERROR, acccountInfo.toJSONObject(true).toString());
} catch (JSONException e) {
return new CommandResponse(ResponseCode.JSON_PARSE_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.JSON_PARSE_ERROR.toString());
}
} else {
return new CommandResponse(ResponseCode.BAD_GUID_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_GUID.toString() + " " + guid);
}
}
Aggregations