Search in sources :

Example 11 with Credentials

use of io.divide.shared.transitory.Credentials in project divide by HiddenStage.

the class AuthServerLogic method recieveUserData.

public void recieveUserData(String userId, Map<String, ?> data) throws DAOException {
    Credentials user = getUserById(userId);
    user.removeAll();
    user.putAll(data);
    dao.save(user);
}
Also used : Credentials(io.divide.shared.transitory.Credentials)

Example 12 with Credentials

use of io.divide.shared.transitory.Credentials in project divide by HiddenStage.

the class AuthenticationEndpoint method getUserFromToken.

@GET
@Path("/from/{token}")
@Produces(MediaType.APPLICATION_JSON)
public Response getUserFromToken(@Context ContainerRequestContext context, @PathParam("token") String token) {
    try {
        logger.warning("getUserFromToken");
        Credentials user = authServerLogic.getUserFromAuthToken(token);
        context.setSecurityContext(new UserContext(context.getUriInfo(), user));
        return Response.ok(user).build();
    } catch (ServerDAO.DAOException e) {
        e.printStackTrace();
        logger.severe(ExceptionUtils.getStackTrace(e));
        return fromDAOExpection(e);
    }
}
Also used : ServerDAO(io.divide.dao.ServerDAO) UserContext(io.divide.server.auth.UserContext) Credentials(io.divide.shared.transitory.Credentials)

Example 13 with Credentials

use of io.divide.shared.transitory.Credentials in project divide by HiddenStage.

the class AuthenticationEndpoint method userSignUp.

/*
     * Saves user credentials
     */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response userSignUp(@Context ContainerRequestContext context, Credentials credentials) {
    try {
        Credentials toSave = authServerLogic.userSignUp(credentials);
        context.setSecurityContext(new UserContext(context.getUriInfo(), toSave));
        logger.info("SignUp Successful. Returning: " + toSave);
        return ok(toSave);
    } catch (ServerDAO.DAOException e) {
        logger.severe(ExceptionUtils.getStackTrace(e));
        return fromDAOExpection(e);
    } catch (Exception e) {
        logger.severe(ExceptionUtils.getStackTrace(e));
        return Response.serverError().build();
    }
}
Also used : ServerDAO(io.divide.dao.ServerDAO) UserContext(io.divide.server.auth.UserContext) Credentials(io.divide.shared.transitory.Credentials)

Example 14 with Credentials

use of io.divide.shared.transitory.Credentials in project divide by HiddenStage.

the class PushEndpoint method unregister.

@DELETE
public Response unregister(@Context Session session) {
    try {
        Credentials credentials = session.getUser();
        credentials.setPushMessagingKey("");
        dao.save(credentials);
    } catch (ServerDAO.DAOException e) {
        logger.severe(ExceptionUtils.getStackTrace(e));
        return fromDAOExpection(e);
    }
    return Response.ok().build();
}
Also used : ServerDAO(io.divide.dao.ServerDAO) Credentials(io.divide.shared.transitory.Credentials)

Example 15 with Credentials

use of io.divide.shared.transitory.Credentials in project divide by HiddenStage.

the class PushEndpoint method sendMessageToDevice.

private String sendMessageToDevice(String email, String input) throws ServerDAO.DAOException, IOException {
    Credentials user = getUserByEmail(dao, email);
    Sender sender = new Sender(keyManager.getPushKey());
    Message message = new Message.Builder().addData("body", input).build();
    MulticastResult result = sender.send(message, Arrays.asList(user.getPushMessagingKey()), 5);
    System.out.println("Result = " + result);
    return result.toString();
}
Also used : Sender(com.google.android.gcm.server.Sender) Message(com.google.android.gcm.server.Message) MulticastResult(com.google.android.gcm.server.MulticastResult) Credentials(io.divide.shared.transitory.Credentials)

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