Package com.streamreduce.core.model

Examples of com.streamreduce.core.model.User$Builder


        if (isEmpty(username)) {
            return error("Username path param can not be empty.", Response.status(Response.Status.BAD_REQUEST));
        }
        logger.debug("Get user by username " + username);
        User user;
        try {
            user = userService.getUser(username);
        } catch (UserNotFoundException e) {
            return error(e.getMessage(), Response.status(Response.Status.NOT_FOUND));
        }
View Full Code Here


            return error("Username '" + username + "' is currently in use.", Response.status(Response.Status.BAD_REQUEST));
        }

        boolean adminRole = (json.containsKey("role") && json.getString("role").equals("admin"));

        User user = new User.Builder()
                .fullname(getJSON(json, "fullname"))
                .password(getJSON(json, "password"))
                .username(username)
                .roles(adminRole ? userService.getAdminRoles() : userService.getUserRoles())
                .account(account)
View Full Code Here

        if (isEmpty(username)) {
            return error("Username path param can not be empty.", Response.status(Response.Status.BAD_REQUEST));
        }
        try {
            User user = userService.getUser(username);
            if (user.getUserStatus().equals(User.UserStatus.ACTIVATED)) {
                return error("User has already been activated.", Response.status(Response.Status.BAD_REQUEST));
            }
            userService.recreateUserRequest(user);
        } catch (UserNotFoundException e) {
            return error("User not found.", Response.status(Response.Status.NOT_FOUND));
View Full Code Here

                                           @DefaultValue("false") @QueryParam("mobile") boolean mobile) {

        if (isEmpty(username)) {
            return error("Username path param can not be empty.", Response.status(Response.Status.BAD_REQUEST));
        }
        User user;
        try {
            user = userService.getUser(username);
            // this can only be done for for active users
            if (!user.getUserStatus().equals(User.UserStatus.ACTIVATED)) {
                return error("User has not been activated, perhaps you need to resend the activation email?", Response.status(Response.Status.BAD_REQUEST));
            }

            // TODO: SOBA-421 check the activity log to see how many times this has been done.
            // if it's > N in the last X hours, return an error

            // create a secret key for the email
            // it will allow us to confirm and identify the user
            String secretKey = (SecurityUtil.generateRandomString());
            user.setSecretKey(secretKey);

            // email will be sent on event
            userService.resetUserPassword(user, mobile);

        } catch (UserNotFoundException e) {
View Full Code Here

     */
    @DELETE
    @Path("{id}")
    public Response removeUser(@PathParam("id") ObjectId userId) {
        try {
            User user = userService.getUserById(userId);

            if (user.getUserStatus().equals(User.UserStatus.PENDING)) {
                // lightweight delete since user hasn't been totally setup
                userService.deletePendingUser(user);
            } else {
                userService.deleteUser(user);
            }
View Full Code Here

    protected void setUp(boolean startAMQ) throws Exception {

        // Create the test account and user
        // sometimes we fail to delete this... so don't just try it willy nilly.
        User user = null;
        try {
            user = userService.getUser(testUsername);
            testUser = user;
            testAccount = testUser.getAccount();
View Full Code Here

        if (isEmpty(key) || isEmpty(userId)) {
            return error("Path params missing", Response.status(Response.Status.BAD_REQUEST));
        }

        User user;
        try {
            user = applicationManager.getUserService().getUserById(new ObjectId(userId));

        } catch (UserNotFoundException e) {
            return error(e.getMessage(), Response.status(Response.Status.NOT_FOUND));
        }

        // verify the secret key matches
        if (!(user.getSecretKey().equals(key))) {
            logger.debug("Password identity confirmation failure: userId and secret key pair does NOT match.");
            return error("Password Identity Confirmation Failed", Response.status(Response.Status.BAD_REQUEST));
        }

        // send the password back to the client.
        return Response
                .ok()
                .entity(user.getUsername())
                .build();
    }
View Full Code Here

    @Consumes(MediaType.APPLICATION_JSON)
    public Response completePasswordResetProcess(@PathParam("key") String key,
                                                 @PathParam("userId") String userId,
                                                 JSONObject json) {

        User user;
        try {
            user = applicationManager.getUserService().getUserById(new ObjectId(userId));
        } catch (UserNotFoundException e) {
            return error(e.getMessage(), Response.status(Response.Status.NOT_FOUND));
        }

        // verify the secret key matches
        if (!(user.getSecretKey().equals(key))) {
            logger.debug("Password change confirmation failure: userId and secret key pair does NOT match.");
            return error("Password Change Confirmation Failed", Response.status(Response.Status.BAD_REQUEST));
        }

        String password = getJSON(json, "password");

        // validate password
        if (!SecurityUtil.isValidPassword(password)) {
            return error(ErrorMessages.INVALID_PASSWORD_ERROR, Response.status(Response.Status.BAD_REQUEST));
        }

        // we want to make this a one time thing, blow away the secret key
        user.setSecretKey(null);

        // update the password in the db
        user.setPassword(password);
        applicationManager.getUserService().updateUser(user);

        // send the password back to the client.
        return Response
                .status(Response.Status.CREATED)
View Full Code Here

     * @resource.representation.200.doc if the operation was a success
     * @resource.representation.404.doc returned if the account to get users for is not found
     */
    @GET
    public Response getAccount() {
        User currentUser = applicationManager.getSecurityService().getCurrentUser();

        Account account;
        try {
            account = applicationManager.getUserService().getAccount(currentUser.getAccount().getId());
        } catch (AccountNotFoundException e) {
            return error(e.getMessage(), Response.status(Response.Status.NOT_FOUND));
        }

        return Response.ok(toDTO(account)).build();
View Full Code Here

                                             @PathParam("accountId") String accountId) {
        // check for missing required values
        if (isEmpty(inviteKey) || isEmpty(accountId)) {
            return error("Required path params missing", Response.status(Response.Status.BAD_REQUEST));
        }
        User user;
        try {

            user = applicationManager.getUserService().getUserFromInvite(inviteKey, accountId);

            // this account is already active!
            if (user.getUserStatus().equals(User.UserStatus.ACTIVATED)) {
                return error("User is already activated", Response.status(Response.Status.NOT_ACCEPTABLE));
            }

        } catch (UserNotFoundException e) {
            return error("Invalid Invite " + inviteKey + ":" + accountId, Response.status(Response.Status.NOT_FOUND));
        }

        // user created, they can now login
        return Response
                .ok()
                .entity(user.getUsername())
                .build();
    }
View Full Code Here

TOP

Related Classes of com.streamreduce.core.model.User$Builder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.