Search in sources :

Example 26 with ApiMethod

use of com.google.api.server.spi.config.ApiMethod in project cryptonomica by Cryptonomica.

the class OnlineVerificationAPI method approve.

// end of acceptTerms();
// /* --- Approve online verification (for Cryptonomica Complience Officer)  */
@ApiMethod(name = "approve", path = "approve", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public BooleanWrapperObject approve(// final HttpServletRequest httpServletRequest,
final User googleUser, @Named("onlineVerificationApproved") final Boolean onlineVerificationApproved, @Named("verificationNotes") final String verificationNotes, @Named("fingerprint") final String fingerprint) throws // see: https://cloud.google.com/appengine/docs/java/endpoints/exceptions
UnauthorizedException, BadRequestException, NotFoundException, NumberParseException, IllegalArgumentException {
    /* --- Check authorization : CRYPTONOMICA OFFICER ONLY !!! */
    CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaOfficer(googleUser);
    /* --- Check input: */
    if (fingerprint == null || fingerprint.equals("") || fingerprint.length() != 40) {
        throw new BadRequestException("fingerprint is missing or invalid");
    }
    if (onlineVerificationApproved == null) {
        throw new IllegalArgumentException("onlineVerificationApproved is null");
    } else if (onlineVerificationApproved == false) {
        throw new BadRequestException("onlineVerificationApproved (checkbox): false");
    }
    // Check if OnlineVerification entity exists:
    OnlineVerification onlineVerification = ofy().load().key(Key.create(OnlineVerification.class, fingerprint)).now();
    if (onlineVerification == null) {
        throw new NotFoundException("OnlineVeriication entity for fingerprint " + fingerprint + " does not exist in data base");
    } else if (onlineVerification.getOnlineVerificationDataVerified() != null && onlineVerification.getOnlineVerificationDataVerified()) {
        throw new BadRequestException("OnlineVerification already approved");
    }
    // mark Online Verification as approved:
    // <<<<<< !!!
    onlineVerification.setOnlineVerificationDataVerified(onlineVerificationApproved);
    onlineVerification.setVerifiedById(googleUser.getUserId());
    onlineVerification.setVerifiedByFirstNameLastName(cryptonomicaUser.getFirstName() + " " + cryptonomicaUser.getLastName());
    onlineVerification.setVerifiedOn(new Date());
    onlineVerification.setVerificationNotes(verificationNotes);
    // mark key as verified:
    PGPPublicKeyData pgpPublicKeyData = ofy().load().type(PGPPublicKeyData.class).filter("fingerprintStr", fingerprint).first().now();
    if (pgpPublicKeyData == null) {
        throw new NotFoundException("Key with fingerprint " + fingerprint + " not found");
    }
    // 
    pgpPublicKeyData.setOnlineVerificationFinished(Boolean.TRUE);
    pgpPublicKeyData.setNationality(onlineVerification.getNationality().toUpperCase());
    // save data to data store:
    ofy().save().entity(onlineVerification).now();
    ofy().save().entity(pgpPublicKeyData).now();
    // Send email to user:
    final Queue queue = QueueFactory.getDefaultQueue();
    queue.add(TaskOptions.Builder.withUrl("/_ah/SendGridServlet").param("email", onlineVerification.getUserEmail().getEmail()).param("emailCC", "verification@cryptonomica.net").param("messageSubject", "[cryptonomica] Online verification for key: " + onlineVerification.getKeyID() + " approved").param("messageText", "Congratulation! \n\n" + onlineVerification.getFirstName().toUpperCase() + " " + onlineVerification.getLastName().toUpperCase() + ",\n\n" + "your request for online verification for key with fingerprint : " + fingerprint + " approved! \n\n" + "See verification information on:\n" + "https://cryptonomica.net/#/onlineVerificationView/" + fingerprint + "\n" + "(information is not public, you have to login with your google account " + onlineVerification.getUserEmail().getEmail() + ")\n\n" + "Best regards, \n\n" + "Cryptonomica team\n\n" + new Date().toString() + "\n\n" + "if you think it's wrong or it is an error, " + "please write to support@cryptonomica.net\n\n"));
    // create result object:
    BooleanWrapperObject result = new BooleanWrapperObject(onlineVerificationApproved, "Online Verification for key " + fingerprint + " approved");
    return result;
}
Also used : BadRequestException(com.google.api.server.spi.response.BadRequestException) NotFoundException(com.google.api.server.spi.response.NotFoundException) BooleanWrapperObject(net.cryptonomica.returns.BooleanWrapperObject) Queue(com.google.appengine.api.taskqueue.Queue) Date(java.util.Date) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 27 with ApiMethod

use of com.google.api.server.spi.config.ApiMethod in project cryptonomica by Cryptonomica.

the class PGPPublicKeyAPI method getPGPPublicKeyByFingerprint.

@ApiMethod(name = "getPGPPublicKeyByFingerprint", path = "getPGPPublicKeyByFingerprint", httpMethod = ApiMethod.HttpMethod.GET)
@SuppressWarnings("unused")
public // get key by by fingerprint
PGPPublicKeyGeneralView getPGPPublicKeyByFingerprint(final User googleUser, @Named("fingerprint") final String fingerprint) throws Exception {
    /* Log request: */
    LOG.warning("Request: @Named(\"fingerprint\") : " + fingerprint);
    /* Check authorization: */
    UserTools.ensureCryptonomicaRegisteredUser(googleUser);
    // GET Key from DataBase by fingerprint:
    PGPPublicKeyData pgpPublicKeyData = PGPTools.getPGPPublicKeyDataFromDataBaseByFingerprint(fingerprint);
    // make key representation, return result
    PGPPublicKeyGeneralView pgpPublicKeyGeneralView = new PGPPublicKeyGeneralView(pgpPublicKeyData);
    LOG.warning("Result: " + GSON.toJson(pgpPublicKeyGeneralView));
    return pgpPublicKeyGeneralView;
}
Also used : PGPPublicKeyData(net.cryptonomica.entities.PGPPublicKeyData) PGPPublicKeyGeneralView(net.cryptonomica.returns.PGPPublicKeyGeneralView) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 28 with ApiMethod

use of com.google.api.server.spi.config.ApiMethod in project cryptonomica by Cryptonomica.

the class PGPPublicKeyAPI method getUsersKeysByUserId.

@ApiMethod(name = "getUsersKeysByUserId", path = "getUsersKeysByUserId", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public // get keys by user ID
SearchPGPPublicKeysReturn getUsersKeysByUserId(// final HttpServletRequest httpServletRequest,
final User googleUser, final GetUsersKeysByUserIdForm getUsersKeysByUserIdForm) throws Exception {
    // authorization
    UserTools.ensureCryptonomicaRegisteredUser(googleUser);
    // 
    SearchPGPPublicKeysReturn searchPGPPublicKeysReturn = new SearchPGPPublicKeysReturn("this are keys of user: " + getUsersKeysByUserIdForm.getUserId(), new ArrayList<>(ofy().load().type(PGPPublicKeyData.class).ancestor(Key.create(CryptonomicaUser.class, getUsersKeysByUserIdForm.getUserId())).list()));
    return searchPGPPublicKeysReturn;
}
Also used : SearchPGPPublicKeysReturn(net.cryptonomica.returns.SearchPGPPublicKeysReturn) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 29 with ApiMethod

use of com.google.api.server.spi.config.ApiMethod in project cryptonomica by Cryptonomica.

the class PGPPublicKeyAPI method getPGPPublicKeyByWebSafeString.

@ApiMethod(name = "getPGPPublicKeyByWebSafeString", path = "getPGPPublicKeyByWebSafeString", httpMethod = ApiMethod.HttpMethod.GET)
@SuppressWarnings("unused")
public // get key by by WebSafeString
PGPPublicKeyGeneralView getPGPPublicKeyByWebSafeString(final User googleUser, @Named("websafestring") final String webSafeString) throws Exception {
    /* Check authorization */
    UserTools.ensureCryptonomicaRegisteredUser(googleUser);
    /* Validate form: */
    LOG.warning("@Named(\"websafestring\") : " + webSafeString);
    if (webSafeString == null || webSafeString.length() < 1) {
        throw new Exception("Invalid public key in request");
    }
    /* Load PGPPublicKeyData from DB*/
    Key<PGPPublicKeyData> pgpPublicKeyDataKey = Key.create(webSafeString);
    PGPPublicKeyData pgpPublicKeyData = null;
    try {
        pgpPublicKeyData = ofy().load().key(pgpPublicKeyDataKey).now();
    } catch (Exception e) {
        LOG.warning("Load PGPPublicKeyData from DB failed: " + e.getMessage());
    }
    if (pgpPublicKeyData == null) {
        LOG.warning("pgpPublicKeyData == null");
        throw new Exception("Public PGP key not found");
    }
    return new PGPPublicKeyGeneralView(pgpPublicKeyData);
}
Also used : PGPPublicKeyData(net.cryptonomica.entities.PGPPublicKeyData) PGPPublicKeyGeneralView(net.cryptonomica.returns.PGPPublicKeyGeneralView) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 30 with ApiMethod

use of com.google.api.server.spi.config.ApiMethod in project cryptonomica by Cryptonomica.

the class PGPPublicKeyAPI method searchPGPPublicKeys.

@ApiMethod(name = "searchPGPPublicKeys", path = "searchPGPPublicKeys", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public // 4) by first and last names
SearchPGPPublicKeysReturn searchPGPPublicKeys(// final HttpServletRequest httpServletRequest,
final User googleUser, final SearchPGPPublicKeysForm searchPGPPublicKeysForm) throws Exception {
    // authorization
    UserTools.ensureCryptonomicaRegisteredUser(googleUser);
    // 
    String fingerprint = searchPGPPublicKeysForm.getFingerprint();
    String keyID = searchPGPPublicKeysForm.getKeyID();
    String userID = searchPGPPublicKeysForm.getUserID();
    String firstName = searchPGPPublicKeysForm.getFirstName();
    String lastName = searchPGPPublicKeysForm.getLastName();
    String cryptonomicaUserId = searchPGPPublicKeysForm.getCryptonomicaUserId();
    Email userEmail = null;
    if (searchPGPPublicKeysForm.getUserEmail() != null) {
        userEmail = new Email(searchPGPPublicKeysForm.getUserEmail());
    }
    List<? extends PGPPublicKeyData> result;
    if (fingerprint != null) {
        result = ofy().load().type(PGPPublicKeyData.class).filter("fingerprint", fingerprint).list();
    } else if (keyID != null) {
        result = ofy().load().type(PGPPublicKeyData.class).filter("keyID", keyID).list();
    } else if (userEmail != null) {
        result = ofy().load().type(PGPPublicKeyData.class).filter("userEmail", userEmail).list();
    } else if (firstName != null && lastName != null) {
        result = ofy().load().type(PGPPublicKeyData.class).filter("firstName", firstName).filter("lastName", lastName).list();
    } else if (cryptonomicaUserId != null) {
        result = ofy().load().type(PGPPublicKeyData.class).filter("cryptonomicaUserId", cryptonomicaUserId).list();
    } else {
        throw new Exception("invalid search query: " + new Gson().toJson(searchPGPPublicKeysForm));
    }
    SearchPGPPublicKeysReturn searchPGPPublicKeysReturn = new SearchPGPPublicKeysReturn();
    if (result.size() > 0) {
        searchPGPPublicKeysReturn.PublicKeyDatasToGeneralViews(new ArrayList<PGPPublicKeyData>(result));
        searchPGPPublicKeysReturn.setMessageToUser("search results:");
    } else {
        searchPGPPublicKeysReturn.PublicKeyDatasToGeneralViews(new ArrayList<PGPPublicKeyData>());
        searchPGPPublicKeysReturn.setMessageToUser("no records found");
    }
    return searchPGPPublicKeysReturn;
}
Also used : PGPPublicKeyData(net.cryptonomica.entities.PGPPublicKeyData) Email(com.google.appengine.api.datastore.Email) SearchPGPPublicKeysReturn(net.cryptonomica.returns.SearchPGPPublicKeysReturn) Gson(com.google.gson.Gson) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Aggregations

ApiMethod (com.google.api.server.spi.config.ApiMethod)54 CryptonomicaUser (net.cryptonomica.entities.CryptonomicaUser)19 Gson (com.google.gson.Gson)16 UserData (com.google.samples.apps.iosched.server.userdata.db.UserData)10 PGPPublicKeyData (net.cryptonomica.entities.PGPPublicKeyData)10 ArrayList (java.util.ArrayList)9 StringWrapperObject (net.cryptonomica.returns.StringWrapperObject)9 NotFoundException (com.google.api.server.spi.response.NotFoundException)8 BadRequestException (com.google.api.server.spi.response.BadRequestException)7 UnauthorizedException (com.google.api.server.spi.response.UnauthorizedException)7 Queue (com.google.appengine.api.taskqueue.Queue)7 HTTPResponse (com.google.appengine.api.urlfetch.HTTPResponse)6 Device (com.google.samples.apps.iosched.server.gcm.db.models.Device)6 MessageSender (com.google.samples.apps.iosched.server.gcm.device.MessageSender)5 AppSettings (net.cryptonomica.entities.AppSettings)5 PGPPublicKeyGeneralView (net.cryptonomica.returns.PGPPublicKeyGeneralView)5 UserProfileGeneralView (net.cryptonomica.returns.UserProfileGeneralView)5 BookmarkedSession (com.google.samples.apps.iosched.server.userdata.db.BookmarkedSession)4 BooleanWrapperObject (net.cryptonomica.returns.BooleanWrapperObject)4 PGPPublicKey (org.bouncycastle.openpgp.PGPPublicKey)4