use of io.divide.shared.transitory.TransientObject in project divide by HiddenStage.
the class ObjectifyDAO method save.
@Override
public void save(TransientObject... objects) throws DAOException {
logger.info("save(): " + ObjectUtils.v2c(objects));
try {
for (TransientObject bo : objects) {
ofy().save().entities(BackendToOfy.getOfy(bo)).now();
}
} catch (Exception e) {
throw new DAOException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
}
logger.info("Save Complete.");
}
use of io.divide.shared.transitory.TransientObject in project divide by HiddenStage.
the class ObjectifyDAO method exists.
@Override
public boolean exists(TransientObject... objects) {
logger.info("exists: " + ObjectUtils.v2c(objects));
boolean exists = true;
for (TransientObject bo : objects) {
if (!exists(bo.getObjectKey()))
exists = false;
}
return exists;
}
use of io.divide.shared.transitory.TransientObject in project divide by HiddenStage.
the class PushEndpointTest method testUnregister.
//
@Test
public void testUnregister() throws Exception {
Credentials user = AuthenticationEndpointTest.signUpUser(this);
PublicKey key = AuthenticationEndpointTest.getPublicKey(this);
Response tokenResponse = registerToken(user, key, this);
String newAuthToken = tokenResponse.getHeaderString("Authorization");
Response response = target("/push").request().header(ContainerRequest.AUTHORIZATION, "CUSTOM " + newAuthToken).delete();
int statusCode = response.getStatus();
assertEquals(200, statusCode);
Collection<TransientObject> list = container.serverDao.get(Query.safeTable(Credentials.class), user.getObjectKey());
TransientObject o = ObjectUtils.get1stOrNull(list);
user = TestUtils.convert(o, Credentials.class);
assertNotNull(user);
// check the token was actually saved
assertEquals("", user.getPushMessagingKey());
}
use of io.divide.shared.transitory.TransientObject in project divide by HiddenStage.
the class AuthServerLogic method getUserFromRecoveryToken.
public Credentials getUserFromRecoveryToken(String token) throws DAOException {
Query q = new QueryBuilder().select().from(Credentials.class).where(Credentials.RECOVERY_TOKEN_KEY, OPERAND.EQ, token).build();
TransientObject to = ObjectUtils.get1stOrNull(dao.query(q));
if (to != null) {
ServerCredentials sc = new ServerCredentials(to);
sc.setAuthToken(AuthTokenUtils.getNewToken(keyManager.getSymmetricKey(), sc));
sc.setRecoveryToken(AuthTokenUtils.getNewToken(keyManager.getSymmetricKey(), sc));
dao.save(sc);
return sc;
} else {
throw new DAOException(HttpStatus.SC_BAD_REQUEST, "invalid recovery token");
}
}
use of io.divide.shared.transitory.TransientObject in project divide by HiddenStage.
the class AuthServerLogic method validateAccount.
/**
* Validate a user account
* @param token
*/
public boolean validateAccount(String token) throws DAOException {
Query q = new QueryBuilder().select().from(Credentials.class).where("validation", OPERAND.EQ, token).build();
TransientObject to = ObjectUtils.get1stOrNull(dao.query(q));
if (to != null) {
ServerCredentials creds = new ServerCredentials(to);
creds.setValidation("1");
dao.save(creds);
return true;
} else {
return false;
}
}
Aggregations