use of net.cryptonomica.entities.CryptonomicaUser in project cryptonomica by Cryptonomica.
the class VerificationAPI method getVerificationByWebSafeString.
// end: getVerificationByID
/* --- Get verification info by web-safe key string: */
@ApiMethod(name = "getVerificationByWebSafeString", path = "getVerificationByWebSafeString", httpMethod = ApiMethod.HttpMethod.GET)
@SuppressWarnings("unused")
public VerificationGeneralView getVerificationByWebSafeString(final HttpServletRequest httpServletRequest, final User googleUser, @Named("verificationWebSafeString") final String verificationWebSafeString) throws // see: https://cloud.google.com/appengine/docs/java/endpoints/exceptions
UnauthorizedException, BadRequestException, NotFoundException {
/* --- Check authorization: */
CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaRegisteredUser(googleUser);
/* --- Check input: */
if (verificationWebSafeString == null || verificationWebSafeString.equals("")) {
throw new BadRequestException("Verification ID missing");
}
/* --- Load verification entity from DS: */
Key<Verification> verificationKey = Key.create(verificationWebSafeString);
Verification verification = ofy().load().key(verificationKey).now();
if (verification == null) {
throw new NotFoundException("Verification info not found");
}
/* --- Create new verification info representation: */
VerificationGeneralView verificationGeneralView = new VerificationGeneralView(verification);
LOG.warning(new Gson().toJson(verificationGeneralView));
return verificationGeneralView;
}
use of net.cryptonomica.entities.CryptonomicaUser in project cryptonomica by Cryptonomica.
the class UserTools method ensureNotaryOrCryptonomicaOfficer.
// end of ensureCryptonomicaOfficer method
/* --- Check if user is a notary or IACC officer: */
public static CryptonomicaUser ensureNotaryOrCryptonomicaOfficer(final User googleUser) throws UnauthorizedException {
//
CryptonomicaUser cryptonomicaUser = ensureCryptonomicaRegisteredUser(googleUser);
//
LOG.warning("cryptonomicaUser: ");
LOG.warning(new Gson().toJson(cryptonomicaUser));
// if (cryptonomicaOfficer == null && notary == null) {
LOG.warning("cryptonomicaUser.getCryptonomicaOfficer(): " + cryptonomicaUser.getCryptonomicaOfficer());
LOG.warning("cryptonomicaUser.getNotary(): " + cryptonomicaUser.getNotary());
// if isCryptonomicaOfficer and isNotary are both false or null:
if ((cryptonomicaUser.getCryptonomicaOfficer() == null || !cryptonomicaUser.getCryptonomicaOfficer()) && (cryptonomicaUser.getNotary() == null || !cryptonomicaUser.getNotary())) {
throw new UnauthorizedException("You are not a Notary or Cryptonomica officer");
}
return cryptonomicaUser;
}
use of net.cryptonomica.entities.CryptonomicaUser in project cryptonomica by Cryptonomica.
the class UserTools method ensureCryptonomicaRegisteredUser.
/* --- Check if user is registered user: */
public static CryptonomicaUser ensureCryptonomicaRegisteredUser(final User googleUser) throws UnauthorizedException {
ensureGoogleAuth(googleUser);
CryptonomicaUser cryptonomicaUser = null;
try {
cryptonomicaUser = ofy().load().key(Key.create(CryptonomicaUser.class, googleUser.getUserId())).now();
} catch (Exception e) {
LOG.warning(e.getMessage());
}
if (cryptonomicaUser == null) {
throw new UnauthorizedException("You are not registered on Cryptonomica server");
}
return cryptonomicaUser;
}
use of net.cryptonomica.entities.CryptonomicaUser in project cryptonomica by Cryptonomica.
the class CSUploadHandlerServlet method doPost.
@Override
public void doPost(// User googleUser, // <<< -- not legal here
HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
// ensure registered user // --- NOT WORK with CS Upload Handler Servlet
// UserService userService = UserServiceFactory.getUserService();
// User googleUser = userService.getCurrentUser();
// -----------------
LOG.warning("[Headers values]: ");
LOG.warning("origin: " + req.getHeader("origin"));
LOG.warning("Referer: " + req.getHeader("Referer"));
LOG.warning("Cookie: " + req.getHeader("Cookie"));
LOG.warning("X-AppEngine-BlobUpload: " + req.getHeader("X-AppEngine-BlobUpload"));
LOG.warning("imageUploadKey: " + req.getHeader("imageUploadKey"));
LOG.warning("[Additional: ]");
LOG.warning("req.getQueryString(): " + req.getQueryString());
LOG.warning("req.getRemoteUser()" + req.getRemoteUser());
// -----------------------------------------------------------------
// -----------------------------------------------------------------
String imageUploadKey = req.getHeader("imageUploadKey");
if (imageUploadKey == null) {
throw new ServletException("imageUploadKey == null");
}
List<CryptonomicaUser> cryptonomicaUserList = ofy().load().type(CryptonomicaUser.class).filter("imageUploadKey", imageUploadKey).list();
if (cryptonomicaUserList.size() > 1) {
LOG.warning("Get a list with more than one Cryptonomica user: ");
for (CryptonomicaUser cryptonomicaUser : cryptonomicaUserList) {
LOG.warning(cryptonomicaUser.getEmail().getEmail());
}
throw new ServletException("Get a list with more than one Cryptonomica user");
}
if (cryptonomicaUserList.isEmpty()) {
LOG.warning("cryptonomicaUserList is empty");
throw new ServletException("cryptonomicaUserList is empty");
}
CryptonomicaUser cryptonomicaUser = cryptonomicaUserList.get(0);
// Returns the FileInfo for any files that were uploaded, keyed by the upload form "name" field.
// This method should only be called from within a request served by the destination of a createUploadUrl call.
// https://cloud.google.com/appengine/docs/java/javadoc/com/google/appengine/api/blobstore/BlobstoreService#getFileInfos-HttpServletRequest-
//
java.util.Map<java.lang.String, java.util.List<FileInfo>> fileInfoListsMap = BlobstoreServiceFactory.getBlobstoreService().getFileInfos(req);
LOG.warning("[LOGGER]: " + new Gson().toJson(fileInfoListsMap));
ArrayList<UploadedFileData> uploadedFilesDataList = new ArrayList<>();
for (java.util.List<FileInfo> fileInfoList : fileInfoListsMap.values()) {
for (FileInfo fileInfo : fileInfoList) {
UploadedFileData uploadedFileData = new UploadedFileData();
uploadedFileData.fileInfo = fileInfo;
LOG.warning("uploadedFileData created:" + new Gson().toJson(uploadedFileData));
BlobKey blobKey = BlobstoreServiceFactory.getBlobstoreService().createGsBlobKey(fileInfo.getGsObjectName());
uploadedFileData.BlobKey = blobKey.getKeyString();
uploadedFileData.fileServeServletLink = HOST + "/serve?blob-key=" + blobKey.getKeyString();
// works only for images (PNG, JPEG, GIF, TIFF, BMP, ICO, WEBP)
for (com.google.appengine.api.images.Image.Format type : com.google.appengine.api.images.Image.Format.values()) {
LOG.warning("com.google.appengine.api.images.Image.Format type: " + type.toString());
LOG.warning("fileInfo.getContentType(): " + fileInfo.getContentType());
if (fileInfo.getContentType().toLowerCase().contains(type.toString().toLowerCase())) {
uploadedFileData.servingUrlFromgsObjectName = ImagesServiceFactory.getImagesService().getServingUrl(ServingUrlOptions.Builder.withGoogleStorageFileName(fileInfo.getGsObjectName()));
// should be the same as servingUrlFromGsBlobKey
uploadedFileData.servingUrlFromGsBlobKey = ImagesServiceFactory.getImagesService().getServingUrl(ServingUrlOptions.Builder.withBlobKey(blobKey));
// should be the same as servingUrlFromgsObjectName
}
}
// end for ( type : .values())
uploadedFilesDataList.add(uploadedFileData);
}
// end for (fileInfo : fileInfoList)
}
// end for (fileInfoList : fileInfoListsMap.values())
Link oldImageLink = cryptonomicaUser.getUserCurrentImageLink();
if (oldImageLink != null) {
if (cryptonomicaUser.getOldUserImageLinks() == null) {
cryptonomicaUser.setOldUserImageLinks(new ArrayList<Link>());
}
cryptonomicaUser.getOldUserImageLinks().add(oldImageLink);
}
cryptonomicaUser.setUserCurrentImageLink(new Link(uploadedFilesDataList.get(0).servingUrlFromgsObjectName.replace("http:", "https:")));
cryptonomicaUser.setImageUploadKeyToNull();
ofy().save().entity(cryptonomicaUser).now();
//
ImageData imageData = new ImageData(Key.create(CryptonomicaUser.class, cryptonomicaUser.getUserId()), uploadedFilesDataList.get(0).BlobKey, uploadedFilesDataList.get(0).fileInfo, uploadedFilesDataList.get(0).fileServeServletLink, uploadedFilesDataList.get(0).servingUrlFromgsObjectName, uploadedFilesDataList.get(0).fileInfo.getGsObjectName());
ofy().save().entity(imageData).now();
//
res.setContentType("application/json");
res.setCharacterEncoding("UTF-8");
res.addHeader("Access-Control-Allow-Origin", "*");
// get the stream to write the data
PrintWriter pw = res.getWriter();
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
pw.println(gson.toJson(uploadedFilesDataList));
LOG.warning("uploadedFilesDataMap" + new Gson().toJson(uploadedFilesDataList));
// closing the stream
pw.close();
}
use of net.cryptonomica.entities.CryptonomicaUser in project cryptonomica by Cryptonomica.
the class ArbitratorsAPI method addArbitrator.
@ApiMethod(name = "addArbitrator", path = "addArbitrator", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public ArbitratorGeneralView addArbitrator(final User googleUser, final AddArbitratorForm addArbitratorForm) throws Exception {
/* --- Ensure cryptonomica officer: */
UserTools.ensureCryptonomicaOfficer(googleUser);
/* --- Check form: */
if (addArbitratorForm.getId() == null) {
throw new IllegalArgumentException("User ID is missing");
}
// create arbitrator from form:
Arbitrator arbitrator = new Arbitrator(addArbitratorForm);
// save arbitrator in DS:
Key<Arbitrator> arbitratorKey = ofy().save().entity(arbitrator).now();
// add info to CryptonomicaUser
CryptonomicaUser arbitratorCryptonomicaUser = ofy().load().key(Key.create(CryptonomicaUser.class, arbitrator.getId())).now();
arbitratorCryptonomicaUser.setArbitrator(Boolean.TRUE);
ofy().save().entity(arbitratorCryptonomicaUser).now();
// create ArbitratorGeneralView
ArbitratorGeneralView arbitratorGeneralView = new ArbitratorGeneralView(arbitratorCryptonomicaUser, arbitrator);
LOG.warning("new arbitrator created: " + new Gson().toJson(arbitratorGeneralView));
return arbitratorGeneralView;
}
Aggregations