Search in sources :

Example 1 with CryptonomicaUser

use of net.cryptonomica.entities.CryptonomicaUser 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 2 with CryptonomicaUser

use of net.cryptonomica.entities.CryptonomicaUser 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 3 with CryptonomicaUser

use of net.cryptonomica.entities.CryptonomicaUser 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 4 with CryptonomicaUser

use of net.cryptonomica.entities.CryptonomicaUser 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)

Example 5 with CryptonomicaUser

use of net.cryptonomica.entities.CryptonomicaUser in project cryptonomica by Cryptonomica.

the class VisitorAPI method showAllNotaries.

@ApiMethod(name = "searchForNotaries", path = "searchForNotaries", httpMethod = ApiMethod.HttpMethod.POST)
public ArrayList<NotaryGeneralView> showAllNotaries(final User googleUser) throws Exception {
    // ensure authorization
    UserTools.ensureCryptonomicaRegisteredUser(googleUser);
    // 
    List<Notary> notaryList = ofy().load().type(Notary.class).list();
    // 
    ArrayList<NotaryGeneralView> notaryGeneralViewArrayList = new ArrayList<>();
    if (notaryList != null) {
        for (Notary notary : notaryList) {
            Key<CryptonomicaUser> notaryCUkey = Key.create(CryptonomicaUser.class, notary.getId());
            // 
            CryptonomicaUser notaryCryptonomicaUser = ofy().load().key(notaryCUkey).now();
            // 
            UserProfileGeneralView notaryUserProfileGeneralView = new UserProfileGeneralView(notaryCryptonomicaUser);
            // 
            notaryGeneralViewArrayList.add(new NotaryGeneralView(notaryUserProfileGeneralView, notary));
        }
    }
    // 
    LOG.warning("notaryGeneralViewArrayList: " + new Gson().toJson(notaryGeneralViewArrayList));
    // 
    return notaryGeneralViewArrayList;
}
Also used : UserProfileGeneralView(net.cryptonomica.returns.UserProfileGeneralView) ArrayList(java.util.ArrayList) Notary(net.cryptonomica.entities.Notary) Gson(com.google.gson.Gson) NotaryGeneralView(net.cryptonomica.returns.NotaryGeneralView) CryptonomicaUser(net.cryptonomica.entities.CryptonomicaUser) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Aggregations

CryptonomicaUser (net.cryptonomica.entities.CryptonomicaUser)24 ApiMethod (com.google.api.server.spi.config.ApiMethod)19 Gson (com.google.gson.Gson)13 ArrayList (java.util.ArrayList)7 HTTPResponse (com.google.appengine.api.urlfetch.HTTPResponse)6 PGPPublicKeyData (net.cryptonomica.entities.PGPPublicKeyData)6 UnauthorizedException (com.google.api.server.spi.response.UnauthorizedException)5 AppSettings (net.cryptonomica.entities.AppSettings)5 UserProfileGeneralView (net.cryptonomica.returns.UserProfileGeneralView)5 StringWrapperObject (net.cryptonomica.returns.StringWrapperObject)4 GsonBuilder (com.google.gson.GsonBuilder)3 BooleanWrapperObject (net.cryptonomica.returns.BooleanWrapperObject)3 PGPPublicKeyGeneralView (net.cryptonomica.returns.PGPPublicKeyGeneralView)3 PGPPublicKey (org.bouncycastle.openpgp.PGPPublicKey)3 BadRequestException (com.google.api.server.spi.response.BadRequestException)2 NotFoundException (com.google.api.server.spi.response.NotFoundException)2 Queue (com.google.appengine.api.taskqueue.Queue)2 Arbitrator (net.cryptonomica.entities.Arbitrator)2 Verification (net.cryptonomica.entities.Verification)2 ArbitratorGeneralView (net.cryptonomica.returns.ArbitratorGeneralView)2