Search in sources :

Example 16 with Credentials

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();
}
Also used : DAOException(io.divide.shared.server.DAO.DAOException) Credentials(io.divide.shared.transitory.Credentials) IOException(java.io.IOException) DAOException(io.divide.shared.server.DAO.DAOException)

Example 17 with Credentials

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();
}
Also used : ServerCredentials(io.divide.server.dao.ServerCredentials) Credentials(io.divide.shared.transitory.Credentials) ServerCredentials(io.divide.server.dao.ServerCredentials) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 18 with Credentials

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;
}
Also used : ServerCredentials(io.divide.server.dao.ServerCredentials) FilePermissions(io.divide.shared.transitory.FilePermissions) Credentials(io.divide.shared.transitory.Credentials) ServerCredentials(io.divide.server.dao.ServerCredentials)

Example 19 with Credentials

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());
}
Also used : Response(javax.ws.rs.core.Response) PublicKey(java.security.PublicKey) TransientObject(io.divide.shared.transitory.TransientObject) Credentials(io.divide.shared.transitory.Credentials) ServerTest(io.divide.server.ServerTest) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Aggregations

Credentials (io.divide.shared.transitory.Credentials)19 ServerTest (io.divide.server.ServerTest)6 JerseyTest (org.glassfish.jersey.test.JerseyTest)6 Test (org.junit.Test)6 ServerDAO (io.divide.dao.ServerDAO)5 UserContext (io.divide.server.auth.UserContext)4 PublicKey (java.security.PublicKey)3 ServerCredentials (io.divide.server.dao.ServerCredentials)2 DAOException (io.divide.shared.server.DAO.DAOException)2 TransientObject (io.divide.shared.transitory.TransientObject)2 Message (com.google.android.gcm.server.Message)1 MulticastResult (com.google.android.gcm.server.MulticastResult)1 Sender (com.google.android.gcm.server.Sender)1 FilePermissions (io.divide.shared.transitory.FilePermissions)1 QueryBuilder (io.divide.shared.transitory.query.QueryBuilder)1 AuthTokenUtils (io.divide.shared.util.AuthTokenUtils)1 AuthenticationException (io.divide.shared.util.AuthTokenUtils.AuthenticationException)1 IOException (java.io.IOException)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1