use of edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.AccountInfo in project GNS by MobilityFirst.
the class SetPassword 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 password = json.getString(GNSProtocol.PASSWORD.toString());
String signature = json.getString(GNSProtocol.SIGNATURE.toString());
String message = json.getString(GNSProtocol.SIGNATUREFULLMESSAGE.toString());
AccountInfo accountInfo = AccountAccess.lookupAccountInfoFromGuidLocally(header, guid, handler);
Date timestamp = json.has(GNSProtocol.TIMESTAMP.toString()) ? Format.parseDateISO8601UTC(json.getString(GNSProtocol.TIMESTAMP.toString())) : // can be null on older client
null;
if (accountInfo == null) {
return new CommandResponse(ResponseCode.BAD_ACCOUNT_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_ACCOUNT.toString() + " " + guid);
} else if (!accountInfo.isVerified()) {
return new CommandResponse(ResponseCode.VERIFICATION_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.VERIFICATION_ERROR.toString() + " Account not verified");
}
return AccountAccess.setPassword(header, commandPacket, accountInfo, password, guid, signature, message, timestamp, handler);
}
use of edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.AccountInfo 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.AccountInfo 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.AccountInfo 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());
}
}
}
use of edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.AccountInfo in project GNS by MobilityFirst.
the class LookupRandomGuids 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());
int count = json.getInt(GNSProtocol.GUIDCNT.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) {
List<String> guids = acccountInfo.getGuids();
if (count >= guids.size()) {
return new CommandResponse(ResponseCode.NO_ERROR, new JSONArray(guids).toString());
} else {
Random rand = new Random();
List<String> result = new ArrayList<>();
for (int i = 0; i < count; i++) {
result.add(guids.get(rand.nextInt(guids.size())));
}
return new CommandResponse(ResponseCode.NO_ERROR, new JSONArray(result).toString());
}
} else {
return new CommandResponse(ResponseCode.BAD_GUID_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_GUID.toString() + " " + guid);
}
// }
}
Aggregations