Package org.apache.rave.model

Examples of org.apache.rave.model.User


        return byUsername;
    }

    private void createRaveUserFromLdapInfo(DirContextOperations ctx, String username) {
        User newUser = new UserImpl();
        newUser.setUsername(username);

        if (!ctx.attributeExists(mailAttributeName) || StringUtils.isBlank(ctx.getStringAttribute(mailAttributeName))) {
            throw new RuntimeException("Missing LDAP attribute for email for user " + username);
        }

        newUser.setEmail(ctx.getStringAttribute(mailAttributeName));
        if (ctx.attributeExists(displayNameAttributeName)) {
            newUser.setDisplayName(ctx.getStringAttribute(displayNameAttributeName));
        }
        newUser.setPassword(RandomStringUtils.random(16));
        newUser.setDefaultPageLayoutCode(pageLayoutCode);
        try {
            newAccountService.createNewAccount(newUser);
        } catch (Exception e) {
            throw new RuntimeException("Could not bind LDAP username '{" + username + "}' to a user", e);
        }
View Full Code Here


                                          Collection<? extends GrantedAuthority> authorities) {
        if (StringUtils.isBlank(username)) {
            throw new IllegalArgumentException("Empty username from LDAP");
        }

        User byUsername = userService.getUserByUsername(username);
        if (byUsername == null) {
            createRaveUserFromLdapInfo(ctx, username);
            byUsername = userService.getUserByUsername(username);
        }
View Full Code Here

        return byUsername;
    }

    private void createRaveUserFromLdapInfo(DirContextOperations ctx, String username) {
        User newUser = new UserImpl();
        newUser.setUsername(username);

        if (!ctx.attributeExists(mailAttributeName) || StringUtils.isBlank(ctx.getStringAttribute(mailAttributeName))) {
            throw new RuntimeException("Missing LDAP attribute for email for user " + username);
        }

        newUser.setEmail(ctx.getStringAttribute(mailAttributeName));
        if (ctx.attributeExists(displayNameAttributeName)) {
            newUser.setDisplayName(ctx.getStringAttribute(displayNameAttributeName));
        }
        newUser.setPassword(RandomStringUtils.random(16));
        newUser.setDefaultPageLayoutCode(pageLayoutCode);
        try {
            newAccountService.createNewAccount(newUser);
        } catch (Exception e) {
            throw new RuntimeException("Could not bind LDAP username '{" + username + "}' to a user", e);
        }
View Full Code Here

    }

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
        logger.info("Custom User Service called to get user information");
        final User user = userRepository.getByUsername(username);
        if (user == null) {
            throw new UsernameNotFoundException("User with username '" + username + "' was not found!");
        }
        fetchCustomCredential(user);
        return user;
View Full Code Here

        return User.class.isAssignableFrom(aClass);
    }

    public void validate(Object obj, Errors errors) {
        logger.debug("Validator called");
        User user = (User) obj;

        //check if the password is null or empty
        if (StringUtils.isBlank(user.getPassword())) {
            errors.rejectValue("password", "password.required");
            logger.info("Password required");
        }
        //check if the password length is less than 4
        else if (user.getPassword().length() < 4) {
            errors.rejectValue("password", "password.invalid.length");
            logger.info("Password must be at least 4 characters long");
        }
        //check if the confirm password is null or empty
        if (StringUtils.isBlank(user.getConfirmPassword())) {
            errors.rejectValue("confirmPassword", "confirmPassword.required");
            logger.info("Confirm Password required");
        }

        //check if the confirm password matches the previous entered password
        if (user.getConfirmPassword() != null && !(user.getConfirmPassword().equals(user.getPassword()))) {
            errors.rejectValue("confirmPassword", "confirmPassword.mismatch");
            logger.info("Password mismatch");
        }

        validateEmail(errors, user);
View Full Code Here

    private boolean isInvalidEmailAddress(String emailAddress) {
        return !EmailValidator.getInstance().isValid(emailAddress);
    }

    private boolean isExistingEmailAddress(User user, String email) {
        final User userByEmail = userService.getUserByEmail(email);
        return userByEmail != null && !userByEmail.getId().equals(user.getId());
    }
View Full Code Here

     * @param referringPageId    page reference id (optional)
   * @return the view name of the user profile page
   */
  @RequestMapping(value = {"/{username:.*}"}, method = RequestMethod.GET)
  public String viewProfileByUsername(@PathVariable String username, ModelMap model, @RequestParam(required = false) String referringPageId, HttpServletResponse response) {
        User user = null;
        try{
            user = userService.getUserByUsername(username);
            logger.debug("Viewing person profile for: " + user.getUsername());
            return viewProfileCommon(user, model, referringPageId);
        }catch(Exception e){
            return profileNotFoundErrorHelper(model, referringPageId, response, user, e);
        }
  }
View Full Code Here

       * @param referringPageId    page reference id (optional)
     * @return the view name of the user profile page
     */
  @RequestMapping(value = {"/id/{userid:.*}"}, method = RequestMethod.GET)
  public String viewProfile(@PathVariable String userid, ModelMap model, @RequestParam(required = false) String referringPageId, HttpServletResponse response) {
        User user = null;
        try{
            user = userService.getUserById(userid);
            logger.debug("Viewing person profile for: " + user.getUsername());
            return viewProfileCommon(user, model, referringPageId);
        }catch (Exception e){
            return profileNotFoundErrorHelper(model, referringPageId, response, user, e);
        }
  }
View Full Code Here

    @RequestMapping(method = RequestMethod.POST)
    public String updateProfile(ModelMap model,
                                @RequestParam(required = false) String referringPageId,
                                @ModelAttribute("updatedUser") UserForm updatedUser) {

        User user = userService.getAuthenticatedUser();
        logger.info("Updating " + user.getUsername() + " profile information");

        //set the updated fields for optional information
        user.setGivenName(updatedUser.getGivenName());
        user.setFamilyName(updatedUser.getFamilyName());
        user.setDisplayName(updatedUser.getDisplayName());
        user.setAboutMe(updatedUser.getAboutMe());
        user.setStatus(updatedUser.getStatus());
        user.setEmail(updatedUser.getEmail());

        //update the user profile
        userService.updateUserProfile(user);

        //set about tag page as default page for the changes to be visible
        addAttributesToModel(model, user, referringPageId);

        return ViewNames.REDIRECT + "app/person/" + user.getUsername();
    }
View Full Code Here

    }

    @Override
    public void validate(Object target, Errors errors) {
        log.debug("Password validator called");
        User newUser = (User) target;
        // we only check for existing (and valid) email
        String email = newUser.getEmail();
        validateEmail(errors, email);
        if (errors.hasErrors()) {
            return;
        }
        // check if account exists and if it is locked or expired:
        User user = getUserService().getUserByEmail(email);
        if (user == null) {
            errors.rejectValue(FIELD_EMAIL, "account.invalid");
            log.info("Couldn't find user for email {}", email);
            return;
        }
        if (user.isLocked() || user.isExpired() || !user.isEnabled()) {
            errors.rejectValue(FIELD_EMAIL, "account.invalid");
        }

    }
View Full Code Here

TOP

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