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());
}
}
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);
}
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);
}
}
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());
}
}
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());
}
}
Aggregations