private void updateProperties(User source, JpaUser converted) { converted.setEntityId(source.getId() == null ? null : Long.parseLong(source.getId())); converted.setUsername(source.getUsername()); converted.setEmail(source.getEmail()); converted.setDisplayName(source.getDisplayName()); converted.setAdditionalName(source.getUsername()); converted.setFamilyName(source.getFamilyName()); converted.setGivenName(source.getGivenName()); converted.setHonorificPrefix(source.getHonorificPrefix()); converted.setHonorificSuffix(source.getHonorificSuffix()); converted.setPreferredName(source.getPreferredName()); converted.setAboutMe(source.getAboutMe()); converted.setStatus(source.getStatus()); converted.setAddresses(source.getAddresses()); converted.setOrganizations(source.getOrganizations()); converted.setProperties(source.getProperties()); converted.setPassword(source.getPassword()); converted.setConfirmPassword(source.getConfirmPassword()); converted.setDefaultPageLayout(source.getDefaultPageLayout()); converted.setDefaultPageLayoutCode(source.getDefaultPageLayoutCode()); converted.setEnabled(source.isEnabled()); converted.setExpired(source.isExpired()); converted.setLocked(source.isLocked()); converted.setOpenId(source.getOpenId()); converted.setForgotPasswordHash(source.getForgotPasswordHash()); converted.setForgotPasswordTime(source.getForgotPasswordTime()); updateAuthorities(source, converted); }
@Override public void createNewAccount(User newUser) throws Exception { final String userName = newUser.getUsername(); final String password = newUser.getPassword(); final String defaultPageLayoutCode = newUser.getDefaultPageLayoutCode(); final String email = newUser.getEmail(); final String givenName = newUser.getGivenName(); final String familyName = newUser.getFamilyName(); final String displayName = newUser.getDisplayName(); final String status = newUser.getStatus(); final String aboutMe = newUser.getAboutMe(); final String openId = newUser.getOpenId(); 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()); user.setGivenName(givenName); user.setFamilyName(familyName); user.setDisplayName(displayName); user.setStatus(status); user.setAboutMe(aboutMe);
public User(org.apache.rave.model.User user) { this.id = user.getId(); this.username = user.getUsername(); this.locked = user.isLocked(); this.enabled = user.isEnabled(); }
public void saveToUser(org.apache.rave.model.User user) { if (user.getId() != null && !user.getId().equals(id)) { throw new RuntimeException("You cannot change the ID of a User object"); } if (username != null) { user.setUsername(username); } if (locked != null) { user.setLocked(locked); } if (enabled != null) { user.setEnabled(enabled); } }
public static String getDisplayName(User user) { String displayName = user.getDisplayName(); return (displayName == null || "".equals(displayName)) ? user.getUsername() : displayName; }
private boolean isCategoryCreatedUserById(Authentication authentication, String userId) { return ((User)authentication.getPrincipal()).getId().equals(userId); }
public static User convert(UserForm form) { User newUser = new UserImpl(form.getId(), form.getUsername()); newUser.setAuthorities(CollectionUtils.<Authority>toBaseTypedCollection(form.getAuthorities())); newUser.setPassword(form.getPassword()); newUser.setConfirmPassword(form.getConfirmPassword()); newUser.setForgotPasswordHash(form.getForgotPasswordHash()); newUser.setDefaultPageLayoutCode(form.getDefaultPageLayoutCode()); newUser.setStatus(form.getStatus()); newUser.setAboutMe(form.getAboutMe()); newUser.setGivenName(form.getGivenName()); newUser.setFamilyName(form.getFamilyName()); newUser.setDisplayName(form.getDisplayName()); newUser.setEmail(form.getEmail()); newUser.setOpenId(form.getOpenId()); newUser.setEnabled(form.isEnabled()); newUser.setExpired(form.isExpired()); newUser.setLocked(form.isLocked()); return newUser; } }
private boolean isWidgetCommentOwnerByUsername(Authentication authentication, String username) { return ((User)authentication.getPrincipal()).getUsername().equals(username); } private boolean isWidgetCommentOwnerById(Authentication authentication, String userId) {
/** * Updates the user's personal information * * @param model {@link Model} map * @param referringPageId page reference id * @param updatedUser Updated user information * @return the view name of the user profile page */ @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(); }
@Override public void sendPasswordReminder(User newUser) { log.debug("Calling send password change link for user {}", newUser); User user = userRepository.getByUserEmail(newUser.getEmail()); if (user == null) { throw new IllegalArgumentException("Could not find user for email " + newUser.getEmail()); } // create user hash: String input = user.getEmail() + user.getUsername() + String.valueOf(user.getId()) + System.nanoTime(); // hash needs to be URL friendly: String safeString = new String(Base64.encode(passwordEncoder.encode(input).getBytes())); String hashedInput = safeString.replaceAll("[/=]", "A"); user.setForgotPasswordHash(hashedInput); user.setForgotPasswordTime(Calendar.getInstance().getTime()); userRepository.save(user); String to = user.getUsername() + " <" + user.getEmail() + '>'; Map<String, Object> templateData = new HashMap<String, Object>(); templateData.put("user", user); templateData.put("reminderUrl", baseUrl + hashedInput); emailService.sendEmail(to, passwordReminderSubject, passwordReminderTemplate, templateData); }
private List<Page> getAllPagesForAuthenticatedUser() { User user = userService.getAuthenticatedUser(); String userId = user.getId(); List<Page> pages = pageService.getAllUserPages(userId); // we add pages to this list which the corresponding pageUser object is not set to "refused" List<Page> viewablePages = new ArrayList<Page>(); for(Page page : pages){ for(PageUser pageUser : page.getMembers()){ if(pageUser != null && pageUser.getUserId().equals(user.getId()) && !pageUser.getPageStatus().equals(PageInvitationStatus.REFUSED)){ viewablePages.add(page); } } } if (viewablePages.isEmpty()) { // create a new default page for the user logger.info("User {} does not have any pages - creating default page", user.getUsername()); pageService.addNewDefaultUserPage(userId); // refresh the pages list which will now have the new page viewablePages = pageService.getAllUserPages(userId); } return viewablePages; }
displayName = firstName + " " + lastName; user.setUsername(username); user.setEmail(email); user.setGivenName(firstName); user.setFamilyName(lastName); user.setDisplayName(displayName); user.setOpenId(openId);
@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"); } }
@Override public void updatePassword(User 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); }
private String getCreator(Page page){ String result=""; User user = userService.getUserById(page.getOwnerId()); result = user.getDisplayName(); if(result == null || result.equals("")){ result = user.getPreferredName(); if(result == null || result.equals("")){ result = user.getUsername(); } } return result; }
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); } }
@Override public void sendUserNameReminder(User 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); }
@Override public SearchResult<Person> getLimitedListOfPersons(int offset, int pageSize) { SearchResult<User> users = getLimitedList(offset, pageSize); int count = users.getTotalResults(); List<Person> people = new ArrayList<Person>(); Person person = null; for(User user : users.getResultSet()){ person = user.toPerson(); person.setId(user.getId()); people.add(person); } return new SearchResult<Person>(people, count); }
private Map<String, User> saveUsers(ModelWrapper wrapper) { Map<String, User> usersByOriginalId = Maps.newHashMap(); if (wrapper.getUsers() != null) { for (User user : wrapper.getUsers()) { String id = user.getId(); user.setId(null); usersByOriginalId.put(id, userRepository.save(user)); } } return usersByOriginalId; }
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); writeResultToLog(errors); }