use of net.cryptonomica.entities.PGPPublicKeyData 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;
}
use of net.cryptonomica.entities.PGPPublicKeyData 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);
}
use of net.cryptonomica.entities.PGPPublicKeyData 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;
}
use of net.cryptonomica.entities.PGPPublicKeyData in project cryptonomica by Cryptonomica.
the class UserSearchAndViewAPI method getMyProfile.
// end of getUserProfileById @ApiMethod
@// <<< --- not used, use getMyUserData in CryptonomicaUserAPI
ApiMethod(name = "getMyProfile", path = "getMyProfile", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public // returns list of user profiles
UserProfileGeneralView getMyProfile(final User googleUser) throws Exception {
// ensure authorization
UserTools.ensureCryptonomicaRegisteredUser(googleUser);
//
Key<CryptonomicaUser> myKey = Key.create(CryptonomicaUser.class, googleUser.getUserId());
CryptonomicaUser profile = ofy().load().key(myKey).now();
UserProfileGeneralView userProfileGeneralView = new UserProfileGeneralView(profile);
List<PGPPublicKeyData> pgpPublicKeyDataList = ofy().load().type(PGPPublicKeyData.class).ancestor(myKey).list();
ArrayList<PGPPublicKeyGeneralView> pgpPublicKeyGeneralViews = new ArrayList<>();
for (PGPPublicKeyData pgpPublicKeyData : pgpPublicKeyDataList) {
pgpPublicKeyGeneralViews.add(new PGPPublicKeyGeneralView(pgpPublicKeyData));
}
userProfileGeneralView.setPgpPublicKeyGeneralViews(pgpPublicKeyGeneralViews);
return userProfileGeneralView;
}
use of net.cryptonomica.entities.PGPPublicKeyData in project cryptonomica by Cryptonomica.
the class UserSearchAndViewAPI method getUserProfileById.
// end of generalSearchUserProfiles @ApiMethod
@ApiMethod(name = "getUserProfileById", path = "getUserProfileById", httpMethod = ApiMethod.HttpMethod.GET)
@SuppressWarnings("unused")
public // returns list of user profiles
UserProfileGeneralView getUserProfileById(final User googleUser, @Named("id") final String id) throws Exception {
/* Check authorization: */
UserTools.ensureCryptonomicaRegisteredUser(googleUser);
/* Validate form: */
LOG.warning("@Named(\"id\"): " + id);
if (id == null || id.length() < 1) {
throw new Exception("User id is empty");
}
/* Load CryptonomicaUser from DB */
// create key
Key<CryptonomicaUser> cryptonomicaUserKey = Key.create(CryptonomicaUser.class, id);
// get user with given Id from DB:
CryptonomicaUser profile = ofy().load().key(cryptonomicaUserKey).now();
// check result:
if (profile == null) {
LOG.warning("User with not found");
throw new Exception("User not found");
}
/* Create UserProfileGeneralView object to return */
// find his public keys:
List<PGPPublicKeyData> pgpPublicKeyDataList = ofy().load().type(PGPPublicKeyData.class).filter("cryptonomicaUserId", id).list();
// check keys found, if no webSafeString add and store in DB :
LOG.info("pgpPublicKeyDataList: " + new Gson().toJson(pgpPublicKeyDataList));
for (PGPPublicKeyData k : pgpPublicKeyDataList) {
if (k.getWebSafeString() == null) {
if (k.getCryptonomicaUserKey() != null) {
k.setWebSafeString(Key.create(k.getCryptonomicaUserKey(), PGPPublicKeyData.class, k.getFingerprint()).toWebSafeString());
} else {
// for old keys without parent
k.setWebSafeString(Key.create(PGPPublicKeyData.class, k.getFingerprint()).toWebSafeString());
}
// async !
ofy().save().entity(k);
}
}
// create obj to return:
UserProfileGeneralView userProfileGeneralView = new UserProfileGeneralView(profile, pgpPublicKeyDataList);
LOG.warning("userProfileGeneralView: " + userProfileGeneralView.toJson());
return userProfileGeneralView;
}
Aggregations