use of edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse in project GNS by MobilityFirst.
the class CreateList 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());
// the opt hair below is for the subclasses... cute, huh?
// 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, new ResultValue(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());
}
}
use of edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse in project GNS by MobilityFirst.
the class SetCode 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 code = json.getString(GNSProtocol.AC_CODE.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.setCode(header, commandPacket, guid, action, code, 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 | JSONException 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 GetGroupMembers 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());
// reader might be same as guid
String reader = json.optString(GNSProtocol.READER.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;
return new CommandResponse(ResponseCode.NO_ERROR, new JSONArray(GroupAccess.lookup(header, commandPacket, guid, reader, signature, message, timestamp, handler)).toString());
}
use of edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse in project GNS by MobilityFirst.
the class AddToGroup 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 member = json.getString(GNSProtocol.MEMBER.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, member, 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 ResendAuthenticationEmail method execute.
@Override
public CommandResponse execute(InternalRequestHeader header, CommandPacket commandPacket, ClientRequestHandlerInterface handler) throws InvalidKeyException, InvalidKeySpecException, JSONException, NoSuchAlgorithmException, SignatureException, ParseException, UnsupportedEncodingException {
JSONObject json = commandPacket.getCommand();
String guid = json.getString(GNSProtocol.GUID.toString());
String signature = json.getString(GNSProtocol.SIGNATURE.toString());
String message = json.getString(GNSProtocol.SIGNATUREFULLMESSAGE.toString());
GuidInfo guidInfo;
if ((guidInfo = AccountAccess.lookupGuidInfoLocally(header, guid, handler)) == null) {
return new CommandResponse(ResponseCode.BAD_GUID_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_GUID.toString() + " " + guid);
}
if (!NSAccessSupport.verifySignature(guidInfo.getPublicKey(), signature, message)) {
return new CommandResponse(ResponseCode.SIGNATURE_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_SIGNATURE.toString());
}
AccountInfo accountInfo;
if ((accountInfo = AccountAccess.lookupAccountInfoFromGuidLocally(header, guid, handler)) == null) {
return new CommandResponse(ResponseCode.BAD_ACCOUNT_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_ACCOUNT.toString() + " " + guid);
} else {
try {
return AccountAccess.resendAuthenticationEmail(header, commandPacket, accountInfo, guid, signature, message, handler);
} catch (UnknownHostException e) {
return new CommandResponse(ResponseCode.UNSPECIFIED_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.UNSPECIFIED_ERROR.toString() + " " + e.getMessage());
}
}
}
Aggregations