Search in sources :

Example 6 with ApiMethod

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

the class PGPPublicKeyAPI method uploadNewPGPPublicKey.

// end of getPGPPublicKeyByFingerprint()
@ApiMethod(name = "uploadNewPGPPublicKey", path = "uploadNewPGPPublicKey", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public PGPPublicKeyUploadReturn uploadNewPGPPublicKey(// final HttpServletRequest httpServletRequest,
final User googleUser, final PGPPublicKeyUploadForm pgpPublicKeyUploadForm) throws Exception {
    // authorization
    CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaRegisteredUser(googleUser);
    // 
    if (pgpPublicKeyUploadForm == null || pgpPublicKeyUploadForm.getAsciiArmored() == null || pgpPublicKeyUploadForm.getAsciiArmored().length() == 0) {
        throw new Exception("ASCII-armored key is empty");
    }
    // --- LOG request form: (after check if not null)
    LOG.warning(GSON.toJson(pgpPublicKeyUploadForm));
    String asciiArmored = pgpPublicKeyUploadForm.getAsciiArmored();
    PGPPublicKey pgpPublicKey = PGPTools.readPublicKeyFromString(asciiArmored);
    // -> throws IOException, PGPException
    LOG.warning(GSON.toJson(pgpPublicKey));
    PGPPublicKeyData pgpPublicKeyData = PGPTools.checkPublicKey(pgpPublicKey, asciiArmored, cryptonomicaUser);
    pgpPublicKeyData.setUserBirthday(cryptonomicaUser.getBirthday());
    // -- add @Parent value: ---
    pgpPublicKeyData.setCryptonomicaUserKey(Key.create(CryptonomicaUser.class, googleUser.getUserId()));
    // save key
    Key<PGPPublicKeyData> pgpPublicKeyDataKey = ofy().save().entity(pgpPublicKeyData).now();
    // load key from DB and and create return object
    String messageToUser = "Key " + pgpPublicKeyData.getFingerprint() + " saved in data base";
    PGPPublicKeyGeneralView pgpPublicKeyGeneralView = new PGPPublicKeyGeneralView(ofy().load().key(pgpPublicKeyDataKey).now());
    PGPPublicKeyUploadReturn pgpPublicKeyUploadReturn = new PGPPublicKeyUploadReturn(messageToUser, pgpPublicKeyGeneralView);
    return pgpPublicKeyUploadReturn;
}
Also used : PGPPublicKeyData(net.cryptonomica.entities.PGPPublicKeyData) PGPPublicKeyGeneralView(net.cryptonomica.returns.PGPPublicKeyGeneralView) PGPPublicKey(org.bouncycastle.openpgp.PGPPublicKey) PGPPublicKeyUploadReturn(net.cryptonomica.returns.PGPPublicKeyUploadReturn) CryptonomicaUser(net.cryptonomica.entities.CryptonomicaUser) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 7 with ApiMethod

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

the class PGPPublicKeyAPI method getMyKeys.

@ApiMethod(name = "getMyKeys", path = "getMyKeys", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public // 4) by first and last names
SearchPGPPublicKeysReturn getMyKeys(// final HttpServletRequest httpServletRequest,
final User googleUser) throws Exception {
    // authorization
    UserTools.ensureCryptonomicaRegisteredUser(googleUser);
    // 
    Key<CryptonomicaUser> cryptonomicaUserKey = Key.create(CryptonomicaUser.class, googleUser.getUserId());
    List<PGPPublicKeyData> result = ofy().load().type(PGPPublicKeyData.class).ancestor(cryptonomicaUserKey).list();
    SearchPGPPublicKeysReturn searchPGPPublicKeysReturn;
    if (result.size() > 0) {
        searchPGPPublicKeysReturn = new SearchPGPPublicKeysReturn("this is list of your keys, if any:", new ArrayList<>(result));
    } else {
        searchPGPPublicKeysReturn = new SearchPGPPublicKeysReturn("You have no keys, yet.", new ArrayList<>(result));
    }
    return searchPGPPublicKeysReturn;
}
Also used : PGPPublicKeyData(net.cryptonomica.entities.PGPPublicKeyData) SearchPGPPublicKeysReturn(net.cryptonomica.returns.SearchPGPPublicKeysReturn) ArrayList(java.util.ArrayList) CryptonomicaUser(net.cryptonomica.entities.CryptonomicaUser) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 8 with ApiMethod

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

the class UploadAPI method getCsUploadURL.

@ApiMethod(name = "getCsUploadURL", path = "getCsUploadURL", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public GetCSuploadURLreturn getCsUploadURL(User googleUser) throws Exception {
    CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaRegisteredUser(googleUser);
    // 
    String imageUploadUrl = BlobstoreServiceFactory.getBlobstoreService().createUploadUrl(// upload handler servlet address
    "/cs-user-image-upload", UploadOptions.Builder.withGoogleStorageBucketName(// Cloud Storage bucket name (f.e. "cryptonomica-test.appspot.com")
    Constants.GAE_PROJECT_DOMAIN));
    String imageUploadKey = randomAlphanumeric(9);
    // 
    cryptonomicaUser.setImageUploadLink(imageUploadUrl);
    cryptonomicaUser.setImageUploadKey(imageUploadKey);
    // 
    Key<CryptonomicaUser> cryptonomicaUserKey = ofy().save().entity(cryptonomicaUser).now();
    LOG.warning("Upload URL: " + imageUploadUrl);
    LOG.warning("Saved for user: " + cryptonomicaUserKey.getName());
    LOG.warning("With imageUploadKey: " + imageUploadKey);
    return new GetCSuploadURLreturn(imageUploadUrl, imageUploadKey, null);
}
Also used : GetCSuploadURLreturn(net.cryptonomica.returns.GetCSuploadURLreturn) CryptonomicaUser(net.cryptonomica.entities.CryptonomicaUser) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 9 with ApiMethod

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

the class UserSearchAndViewAPI method echo.

// end of getUserProfileById @ApiMethod
@ApiMethod(name = "echo", path = "echo", httpMethod = ApiMethod.HttpMethod.GET)
public /* >>>>>>>>>>>>>> this is for testing only
    * curl -H "Content-Type: application/json" -X GET -d '{"message":"hello world"}' https://cryptonomica-server.appspot.com/_ah/api/userSearchAndViewAPI/v1/echo
    * */
StringWrapperObject echo(@Named("message") String message, @Named("n") @Nullable Integer n) {
    StringWrapperObject stringWrapperObject = new StringWrapperObject();
    if (n != null && n >= 0) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            if (i > 0) {
                sb.append(" ");
            }
            sb.append(message);
        }
        stringWrapperObject.setMessage(sb.toString());
    }
    return stringWrapperObject;
}
Also used : StringWrapperObject(net.cryptonomica.returns.StringWrapperObject) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 10 with ApiMethod

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

the class VerificationAPI method getVerificationByID.

/* --- Get verification info by verification ID: */
@ApiMethod(name = "getVerificationByID", path = "getVerificationByID", httpMethod = ApiMethod.HttpMethod.GET)
@SuppressWarnings("unused")
public VerificationGeneralView getVerificationByID(final HttpServletRequest httpServletRequest, final User googleUser, @Named("verificationID") final String verificationID) throws // see: https://cloud.google.com/appengine/docs/java/endpoints/exceptions
UnauthorizedException, BadRequestException, NotFoundException {
    /* --- Check authorization: */
    CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaRegisteredUser(googleUser);
    /* --- Check input: */
    if (verificationID == null || verificationID.equals("")) {
        throw new BadRequestException("Verification ID missing");
    }
    /* --- Load verification entity from DS: */
    Verification verification = ofy().load().key(Key.create(Verification.class, verificationID)).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;
}
Also used : BadRequestException(com.google.api.server.spi.response.BadRequestException) NotFoundException(com.google.api.server.spi.response.NotFoundException) Gson(com.google.gson.Gson) Verification(net.cryptonomica.entities.Verification) VerificationGeneralView(net.cryptonomica.returns.VerificationGeneralView) CryptonomicaUser(net.cryptonomica.entities.CryptonomicaUser) 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