Package org.apache.rave.portal.model

Examples of org.apache.rave.portal.model.User


  }

    @Test(expected = UsernameNotFoundException.class)
    public void viewPersonProfile_invalidUser() {
        //creating a mock user
        final User user = null;
        final ModelMap model = new ModelMap();
        final int modelSize = 4;
        final String username="Canonical";
        Page personProfile = new Page();
        PageLayout pageLayout = new PageLayout();
View Full Code Here


    final long referringPageId = 1L;
        final String USERNAME = "canonical";
    String userProfile = new String(ModelKeys.USER_PROFILE);
   
    //creating a mock authenticated user
    final User authUser = new User();
        authUser.setUsername(USERNAME);
    //set existing status
    authUser.setStatus("Single");
    //set other paramters
    authUser.setGivenName("Test");
    authUser.setFamilyName("Rave");
    authUser.setAboutMe("Test User");
    authUser.setEmail("testuser@rave.com");
   
    //creating a mock updated user
    final User updatedUser = new User();
    //set the updated status
    updatedUser.setStatus("Married");
    updatedUser.setGivenName("Test");
    updatedUser.setFamilyName("Rave");
    updatedUser.setAboutMe("Test User");
    updatedUser.setEmail("testuser@rave.com");
   
    expect(userService.getAuthenticatedUser()).andReturn(authUser).anyTimes();
    userService.updateUserProfile(authUser);
    replay(userService);
   
    String view = profileController.updateProfile(model, referringPageId, updatedUser);
   
    //assert that the model is not null
    assertThat(model, CoreMatchers.notNullValue());
 
    //assert that the model size is three
    assertThat(model.size(), CoreMatchers.equalTo(modelSize));
   
    //assert that the model does contain an attribute associated with the authenticated user
    assertThat(model.containsAttribute(userProfile), CoreMatchers.equalTo(true));
   
    //assert that the model does not contain authenticated user as null
    assertThat(model.get(userProfile), CoreMatchers.notNullValue());
   
    //assert that the status of user is updated
    assertEquals(updatedUser.getStatus(), authUser.getStatus());
       
        assertThat(view, is("redirect:/app/person/" + USERNAME));
   
    verify(userService);
   
View Full Code Here

        final String status = newUser.getStatus();
        final String aboutMe = newUser.getAboutMe();

        throwExceptionIfUserExists(userName, email);
               
        User user = new User();
        //set the required fields
        user.setUsername(userName);
        user.setEmail(email);
        String hashedPassword = passwordEncoder.encode(password);
        user.setPassword(hashedPassword);

        user.setExpired(false);
        user.setLocked(false);
        user.setEnabled(true);
        user.setDefaultPageLayout(pageLayoutService.getPageLayoutByCode(defaultPageLayoutCode));       
        user.setAuthorities(authorityService.getDefaultAuthorities().getResultSet());
       
        //set the optional fields
        user.setGivenName(givenName);
        user.setFamilyName(familyName);
        user.setDisplayName(displayName);
        user.setStatus(status);
        user.setAboutMe(aboutMe);
       
        userService.registerNewUser(user)
    }
View Full Code Here

       
        userService.registerNewUser(user)
    }

    private void throwExceptionIfUserExists(String userName, String email) {
        User existingUser = userService.getUserByUsername(userName);
        if (existingUser != null) {
            throw new IllegalArgumentException("A user already exists for username " + userName);
        }

        //Implementors who use an alternative store for profile data probably wont be including email when creating new
View Full Code Here

    }

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
        log.debug("loadUserByUsername called with: {}", username);
        final User user = userRepository.getByUsername(username);
        if (user == null) {
            throw new UsernameNotFoundException("User with username '" + username + "' was not found!");
        }
        return user;
    }
View Full Code Here

        }
    }

    @Override
    public void setAuthenticatedUser(long userId) {
        final User user = userRepository.get(userId);
        if (user == null) {
            throw new UsernameNotFoundException("User with id '" + userId + "' was not found!");
        }
        SecurityContext securityContext = createContext(user);
        SecurityContextHolder.setContext(securityContext);
View Full Code Here

    }

    @Override
    @Transactional
    public void registerNewUser(User user) {
        User managedUser = userRepository.save(user);
        pageRepository.createPersonPageForUser(managedUser, pageTemplateRepository.getDefaultPersonPage());
    }
View Full Code Here

    @Override
    @Transactional
    // TODO RAVE-300: add security check that is is called by admin or the user itself
    public void deleteUser(Long userId) {
        log.info("about to delete userId: " + userId);
        User user = userRepository.get(userId);
        if (user == null) {
            log.warn("unable to find userId " + userId + " to delete");
            return;
        }

        final String username = user.getUsername();

        // delete all User type pages
        int numDeletedPages = pageRepository.deletePages(userId, PageType.USER);
        // delete all person pages
        int numDeletedPersonPages = pageRepository.deletePages(userId, PageType.PERSON_PROFILE);
View Full Code Here

    }

    @Override
    public void updatePassword(NewUser newUser) {
        log.debug("Changing password  for user {}", newUser);
        User user = userRepository.getByForgotPasswordHash(newUser.getForgotPasswordHash());
        if (user == null) {
            throw new IllegalArgumentException("Could not find user for forgotPasswordHash " + newUser.getForgotPasswordHash());
        }
        String saltedHashedPassword = passwordEncoder.encode(newUser.getPassword());
        user.setPassword(saltedHashedPassword);
        // reset password hash and time
        user.setForgotPasswordHash(null);
        user.setForgotPasswordTime(null);
        userRepository.save(user);

    }
View Full Code Here


    @Override
    public void sendUserNameReminder(NewUser newUser) {
        log.debug("Calling send username  {}", newUser);
        User user = userRepository.getByUserEmail(newUser.getEmail());
        if (user == null) {
            throw new IllegalArgumentException("Could not find user for email " + newUser.getEmail());
        }
        String to = user.getUsername() + " <" + user.getEmail() + '>';
        Map<String, Object> templateData = new HashMap<String, Object>();
        templateData.put("user", user);
        emailService.sendEmail(to, userNameReminderSubject, userNameReminderTemplate, templateData);

    }
View Full Code Here

TOP

Related Classes of org.apache.rave.portal.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.