use of net.cryptonomica.returns.OnlineVerificationView in project cryptonomica by Cryptonomica.
the class OnlineVerificationAPI method getOnlineVerificationByFingerprint.
/* --- Get online verification info by OpenPGP Public Key fingerprint : */
@ApiMethod(name = "getOnlineVerificationByFingerprint", path = "getOnlineVerificationByFingerprint", httpMethod = ApiMethod.HttpMethod.GET)
@SuppressWarnings("unused")
public OnlineVerificationView getOnlineVerificationByFingerprint(final HttpServletRequest httpServletRequest, final User googleUser, @Named("fingerprint") final String fingerprint) throws // see: https://cloud.google.com/appengine/docs/java/endpoints/exceptions
UnauthorizedException, BadRequestException, NotFoundException {
/* --- Check input: */
if (fingerprint == null || fingerprint.equals("") || fingerprint.length() != 40) {
throw new BadRequestException("fingerprint is missing or invalid");
}
PGPPublicKeyData pgpPublicKeyData = ofy().load().type(PGPPublicKeyData.class).filter("fingerprintStr", fingerprint).first().now();
if (pgpPublicKeyData == null) {
throw new NotFoundException("Key with fingerprint " + fingerprint + " not found");
}
/* --- Check authorization: */
// only allowed users can get verification data:
// << registered user
CryptonomicaUser requester = UserTools.ensureCryptonomicaRegisteredUser(googleUser);
LOG.warning(GSON.toJson(requester));
// >>>>>>>>>>>>>>>>>> New OnlineVerifications are created here !!!
// (user first have to request verification to make changes to it)
OnlineVerification onlineVerification = ofy().load().key(Key.create(OnlineVerification.class, fingerprint)).now();
if (onlineVerification == null) {
if (requester.getUserId().equalsIgnoreCase(pgpPublicKeyData.getCryptonomicaUserId())) {
onlineVerification = new OnlineVerification(pgpPublicKeyData);
ofy().save().entity(onlineVerification).now();
} else {
throw new NotFoundException("Online verification data for fingerprint " + fingerprint + " not found");
}
}
if (requester.getUserId().equalsIgnoreCase(pgpPublicKeyData.getCryptonomicaUserId()) || (requester.getCryptonomicaOfficer() != null && requester.getCryptonomicaOfficer()) || // || (requester.getNotary() != null && requester.getNotary()) // TODO: should all notaries have access?
(onlineVerification.getAllowedUsers().contains(requester.getUserId()))) {
LOG.warning("user " + requester.getUserId() + "is allowed to get online verification data for key " + fingerprint);
} else {
throw new UnauthorizedException("you are not allowed to get online verification data for key " + fingerprint);
}
LOG.warning(GSON.toJson(onlineVerification));
ArrayList<VerificationDocument> verificationDocumentArrayList = new ArrayList<>();
int verificationDocumentsListSize = ofy().load().type(VerificationDocument.class).filter("fingerprint", fingerprint).filter("hidden", false).list().size();
LOG.warning("verificationDocumentsListSize: " + verificationDocumentsListSize);
if (verificationDocumentsListSize > 0) {
List<VerificationDocument> verificationDocumentList = ofy().load().type(VerificationDocument.class).filter("fingerprint", fingerprint).filter("hidden", false).list();
verificationDocumentArrayList.addAll(verificationDocumentList);
LOG.warning(GSON.toJson(verificationDocumentArrayList));
}
OnlineVerificationView onlineVerificationView = new OnlineVerificationView(onlineVerification, verificationDocumentArrayList);
LOG.warning("onlineVerificationView:");
LOG.warning(onlineVerificationView.toString());
return onlineVerificationView;
}
Aggregations