Package com.streamreduce.core.model

Examples of com.streamreduce.core.model.User


    @Test
    @Ignore
    public void testDeleteUser() throws Exception {

        // sometimes we fail to delete this... so don't just try it willy nilly.
        User user = null;
        try {
            user = userService.getUser("foobar@nodeable.com");

        } catch (UserNotFoundException unfe) {
        }

        if (user == null) {
            user = new User.Builder()
                    .username("foobar@foo.com")
                    .password("foobar@foo.com")
                    .accountLocked(false)
                    .fullname("Bogus user")
                    .userStatus(User.UserStatus.ACTIVATED)
                    .account(testAccount)
                    .roles(userService.getUserRoles())
                    .accountOriginator(true)
                    .alias(UUID.randomUUID().toString())
                    .build();
            user = userService.createUser(user);
        }
        // create bogus token
        applicationManager.getSecurityService().issueAuthenticationToken(user);

        //TODO:  NFI what this call used to do
//        assertNotNull(applicationManager.getSecurityService().findUserTokens(user));

        // kill user
        String url = getUrl() + "/" + user.getId();
        makeRequest(url, "DELETE", null, authToken);

        try {
            applicationManager.getUserService().getUser(user.getUsername());
            fail();
        } catch (UserNotFoundException e) {
        }

        //TODO:  NFI what this call used to do
View Full Code Here


            }

            JSONObject config = new JSONObjectBuilder().add("icon", "/images/nodebelly.jpg").build();

            // we are bypassing the lifecycle here, but still firing proper events
            User user = new User.Builder()
                    .username(Constants.NODEABLE_SYSTEM_USERNAME)
                    .password(superUserPassword)
                    .accountLocked(false)
                    .fullname("Nodeable")
                    .userStatus(User.UserStatus.ACTIVATED)
                    .roles(userService.getAdminRoles())
                    .account(rootAccount)
                    .alias("nodeable")
                    .userConfig(config)
                    .build();

            userService.createUser(user);
        }

        // create it if it doesn't exist
        if (getUser(Constants.NODEABLE_SUPER_USERNAME) == null) {

            JSONObject config = new JSONObjectBuilder().add("icon", "/images/nodebelly.jpg").build();

            // we are bypassing the lifecycle here, but still firing proper events
            User user = new User.Builder()
                    .username(Constants.NODEABLE_SUPER_USERNAME)
                    .password(superUserPassword)
                    .accountLocked(false)
                    .fullname("Nodeable Insight")
                    .userStatus(User.UserStatus.ACTIVATED)
View Full Code Here

     *
     * @return The requested item.
     */
    @GET
    public Response getCurrentUser() {
        User currentUser = securityService.getCurrentUser();
        UserResponseDTO userResponseDTO = toFullDTO(currentUser);

        return Response.ok(userResponseDTO).build();
    }
View Full Code Here

     */
    @GET
    @Path("{idOrUsername}")
    public Response getUser(@PathParam("idOrUsername") String idOrUsername) {

        User currentUser = securityService.getCurrentUser();
        User requestedUser;

        try {
            if (ObjectId.isValid(idOrUsername)) {
                requestedUser = userService.getUserById(new ObjectId(idOrUsername), currentUser.getAccount());
            } else {
View Full Code Here

    @Test
    @Ignore("Integration Tests depended on sensitive account keys, ignoring until better harness is in place.")
    public void testGetSuperUserReturnsNewUserInstance() {
        //Tests that UserServer.getSuperUser() returns different references to equal SuperUser objects.
        User superUserA = userService.getSuperUser();
        User superUserB = userService.getSuperUser();

        Assert.assertEquals(superUserA,superUserB);
        Assert.assertNotSame(superUserA,superUserB);
    }
View Full Code Here

    @PUT
    @Path("password")
    @Consumes(MediaType.APPLICATION_JSON)
    public Response changePassword(JSONObject json) {
        // update just the password
        User u = securityService.getCurrentUser();
        String password = getJSON(json, "password");

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

        u.setPassword(password);
        userService.updateUser(u);

        return Response
                .status(Response.Status.NO_CONTENT)
                .build();
View Full Code Here

     */
    @PUT
    @Path("profile")
    @Consumes(MediaType.APPLICATION_JSON)
    public Response changeUserProfile(JSONObject json) {
        User user = securityService.getCurrentUser();

        if (isNullOrEmpty(json)) {
            return error("JSON Payload Missing.", Response.status(Response.Status.BAD_REQUEST));
        }

        // Handle alias changes
        if (json.containsKey("alias")) {
            String alias = json.getString("alias");

            if (!alias.equalsIgnoreCase(user.getAlias())) {
                if (!(userService.isAliasAvailable(user.getAccount(), alias))) {
                    ConstraintViolationExceptionResponseDTO dto = new ConstraintViolationExceptionResponseDTO();
                    dto.setViolations(ImmutableMap.of("alias", json.getString("alias") + " is already in use"));
                    return Response.status(Response.Status.CONFLICT).entity(dto).build();
                }
            }
        }

        user.mergeWithJSON(json);

        try {
            userService.updateUser(user);
        } catch (InvalidUserAliasException e) {
            ConstraintViolationExceptionResponseDTO dto = new ConstraintViolationExceptionResponseDTO();
View Full Code Here

    @Ignore
    public void testAccountsAndUsersCreatedProperly() throws Exception {
        Assert.assertNotNull(rootAccount);
        Assert.assertNotNull(integrationsAccount);

        User rootUser = null;

        for (User user : userService.allUsersForAccount(rootAccount)) {
            if (user.getUsername().equals(Constants.NODEABLE_SUPER_USERNAME)) {
                rootUser = user;
            }
View Full Code Here

        // require admin role
        if (!securityService.hasRole(Roles.ADMIN_ROLE)) {
            return error(ErrorMessages.APPLICATION_ACCESS_DENIED, Response.status(Response.Status.UNAUTHORIZED));
        }

        User user = securityService.getCurrentUser();
        Account account = user.getAccount();

        account.mergeWithJSON(json);

        userService.updateAccount(account);
View Full Code Here

    @DELETE
    @Path("{userId}")
    @Consumes(MediaType.APPLICATION_JSON)
    public Response deleteUser(@PathParam("userId") ObjectId userId) {

        User currentUser = securityService.getCurrentUser();

        // require admin role
        if (!securityService.hasRole(Roles.ADMIN_ROLE)) {
            return error(ErrorMessages.APPLICATION_ACCESS_DENIED, Response.status(Response.Status.UNAUTHORIZED));
        }

        try {
            User user = userService.getUserById(userId, currentUser.getAccount());

            if (securityService.getCurrentUser().getId().equals(userId)) {
                return error("You can not delete yourself. Things will get better, hang in there.", Response.status(Response.Status.BAD_REQUEST));
            }
View Full Code Here

TOP

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

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.