Search in sources :

Example 1 with UserContext

use of io.divide.server.auth.UserContext in project divide by HiddenStage.

the class AuthenticationEndpoint method userSignIn.

/**
     * Checks username/password against that stored in DB, if same return
     * token, if token expired create new.
     * @param credentials
     * @return authentication token
     */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response userSignIn(@Context ContainerRequestContext context, Credentials credentials) {
    try {
        Credentials dbCreds = authServerLogic.userSignIn(credentials);
        context.setSecurityContext(new UserContext(context.getUriInfo(), dbCreds));
        logger.info("Login Successful. Returning: " + dbCreds);
        return ok(dbCreds);
    } 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 2 with UserContext

use of io.divide.server.auth.UserContext in project divide by HiddenStage.

the class AuthenticationEndpoint method recoverFromOneTimeToken.

@GET
@Path("/recover/{token}")
@Produces(MediaType.APPLICATION_JSON)
public Response recoverFromOneTimeToken(@Context ContainerRequestContext context, @PathParam("token") String token) {
    try {
        Credentials user = authServerLogic.getUserFromRecoveryToken(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 3 with UserContext

use of io.divide.server.auth.UserContext 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 4 with UserContext

use of io.divide.server.auth.UserContext 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)

Aggregations

ServerDAO (io.divide.dao.ServerDAO)4 UserContext (io.divide.server.auth.UserContext)4 Credentials (io.divide.shared.transitory.Credentials)4