use of io.divide.shared.transitory.Credentials in project divide by HiddenStage.
the class PushEndpoint method register.
/*
currently failing as the decryption key is probably different
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response register(@Context Session session, EncryptedEntity.Reader entity) {
try {
Credentials credentials = session.getUser();
entity.setKey(keyManager.getPrivateKey());
credentials.setPushMessagingKey(entity.get("token"));
dao.save(credentials);
} catch (DAOException e) {
logger.severe(ExceptionUtils.getStackTrace(e));
return fromDAOExpection(e);
} catch (Exception e) {
logger.severe(ExceptionUtils.getStackTrace(e));
return Response.serverError().entity("Shit").build();
}
return Response.ok().build();
}
use of io.divide.shared.transitory.Credentials in project divide by HiddenStage.
the class TestEndpoint method setup.
@Produces(MediaType.APPLICATION_JSON)
@GET
@Path("/setup")
public Response setup() throws Exception {
// logger.info("setup");
// Credentials user = TestUtils.getTestUser();
// user = new ServerCredentials(user);
// user.setPassword(BCrypt.hashpw(user.getPassword(), BCrypt.gensalt(10)));
ServerCredentials toSave = new ServerCredentials(TestUtils.getTestUser());
// String en = toSave.getPassword();
// toSave.decryptPassword(keyManager.getPrivateKey()); //decrypt the password
// String de = toSave.getPassword();
String ha = BCrypt.hashpw(toSave.getPassword(), BCrypt.gensalt(10));
//hash the password for storage
toSave.setPassword(ha);
toSave.setAuthToken(AuthTokenUtils.getNewToken(securityManager.getSymmetricKey(), toSave));
toSave.setRecoveryToken(AuthTokenUtils.getNewToken(securityManager.getSymmetricKey(), toSave));
toSave.setOwnerId(dao.count(Credentials.class.getName()) + 1);
dao.save(toSave);
return Response.ok().entity(toSave).build();
}
use of io.divide.shared.transitory.Credentials in project divide by HiddenStage.
the class TestUtils method getTestUser.
public static Credentials getTestUser() {
Credentials c = new Credentials("someUsername", "someEmail", "somePassword");
ServerCredentials sc = new ServerCredentials(c);
sc.setOwnerId(1);
FilePermissions fp = sc.getFilePermissions();
fp.setReadable(true, FilePermissions.Level.WORLD);
fp.setWritable(true, FilePermissions.Level.WORLD);
sc.setFilePermissions(fp);
sc.setAuthToken(AuthTokenUtils.getNewToken(KEY, sc));
sc.setRecoveryToken(AuthTokenUtils.getNewToken(KEY, sc));
return sc;
}
use of io.divide.shared.transitory.Credentials 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());
}
Aggregations