/** * Determine the name to use in the password reset email that identifies the users whose * password has been reset. * * @param person the account that has had its password reset * @return the account holders name */ protected String findDisplayNameFromLocalAccountPerson(ILocalAccountPerson person) { Object name = person.getAttributeValue(ILocalAccountPerson.ATTR_DISPLAY_NAME); if ((name instanceof String) && !StringUtils.isEmpty((String) name)) { return (String) name; } // if display name is not set, just return username. return person.getName(); } }
@Override @Transactional public boolean updatePassword(String user, boolean create) throws IOException { // Make sure user is specified correctly if (StringUtils.isBlank(user)) { System.err.println("You did not specify a valid user name. Please try again."); return false; } // attempt to get the account form the database ILocalAccountPerson account = this.localAccountDao.getPerson(user); if (account == null) { if (!create) { System.err.println("No such user: " + user); return false; } account = this.localAccountDao.createPerson(user); } System.out.print("Enter Password for " + user + ": "); System.out.flush(); // Needed for prompt to appear when running from Ant. final BufferedReader d = new BufferedReader(new InputStreamReader(System.in, UTF_8)); final String spass = d.readLine(); // update the user's password final String encryptedPassword = this.portalPasswordService.encryptPassword(spass); account.setPassword(encryptedPassword); this.localAccountDao.updateAccount(account); System.out.println("Password Updated..."); return true; }
public PersonForm getForm(String username) { ILocalAccountPerson person = accountDao.getPerson(username); PersonForm form = new PersonForm(accountEditAttributes); form.setUsername(person.getName()); form.setId(person.getId()); Set<String> attributeNames = accountDao.getCurrentAttributeNames(); for (String name : attributeNames) { List<String> values = new ArrayList<String>(); List<Object> attrValues = person.getAttributeValues(name); if (attrValues != null) { for (Object value : person.getAttributeValues(name)) { values.add((String) value); } } form.getAttributes().put(name, new StringListAttribute(values)); } return form; }
account = this.localAccountDao.createPerson(username); account.setPassword(password); final Calendar lastPasswordChange = userType.getLastPasswordChange(); if (lastPasswordChange != null) { account.setLastPasswordChange(lastPasswordChange.getTime()); account.removeAttribute(username); for (final Attribute attribute : attributes) { account.setAttribute(attribute.getName(), attribute.getValues());
mappedAttributes.putAll(person.getAttributes()); Collections.<Object>singletonList(person.getName())); final String name = person.getName(); if (name != null) { newPerson = new NamedPersonImpl(name, mappedAttributes);
account.setPassword(passwordService.encryptPassword(password)); account.setLastPasswordChange(new Date()); account.removeAttribute("loginToken"); accountDao.updateAccount(account); if (log.isInfoEnabled()) {
userType.setPassword(localAccountPerson.getPassword()); final Date lastPasswordChange = localAccountPerson.getLastPasswordChange(); if (lastPasswordChange != null) { final Calendar lastPasswordChangeCal = Calendar.getInstance(); localAccountPerson.getAttributes().entrySet()) { final String name = attributeEntry.getKey(); final List<Object> values = attributeEntry.getValue();
if (passwordService.validatePassword(loginPassword, account.getPassword())) { String fullName = (String) account.getAttributeValue("displayName"); this.myPrincipal.FullName = fullName; if (log.isInfoEnabled())
public void deleteAccount(IPerson currentUser, String target) { if (!canDeleteUser(currentUser, target)) { throw new RuntimeException( "Current user " + currentUser.getName() + " does not have permissions to update person " + target); } ILocalAccountPerson person = accountDao.getPerson(target); accountDao.deleteAccount(person); log.info("Account " + person.getName() + " successfully deleted"); }
public boolean validateLoginToken(String username, String token) { ILocalAccountPerson person = accountDao.getPerson(username); if (person != null) { Object recordedToken = person.getAttributeValue("loginToken"); if (recordedToken != null && recordedToken.equals(token)) { if (log.isInfoEnabled()) { log.info("Successfully validated security token for user: " + username); } return true; } else { if (log.isInfoEnabled()) { log.info( "Unable to validate security token; recordedToken=" + recordedToken + ", submitted token=" + token); } } } else { if (log.isInfoEnabled()) { log.info("Unable to validate security token; person not found: " + username); } } return false; }
form.getCurrentPassword(), account.getPassword())) { context.addMessage( new MessageBuilder()
if (!canEditUser(currentUser, account.getName())) { throw new RuntimeException( "Current user " + currentUser.getName() + " does not have permissions to update person " + account.getName()); account.removeAttribute(attributeName); } else { account.setAttribute( attributeName, form.getAttributes().get(attributeName).getValue()); account.setPassword(passwordService.encryptPassword(form.getPassword())); account.setLastPasswordChange(new Date()); account.removeAttribute("loginToken"); log.info("Account " + account.getName() + " successfully updated");
mappedAttributes.putAll(person.getAttributes()); Collections.<Object>singletonList(person.getName())); final String name = person.getName(); if (name != null) { newPerson = new NamedPersonImpl(name, mappedAttributes);
ILocalAccountPerson account = accountStore.getPerson(this.myPrincipal.UID); if (account != null) { first_name = (String) account.getAttributeValue("given"); last_name = (String) account.getAttributeValue("sn"); this.myPrincipal.FullName = first_name + " " + last_name; if (log.isInfoEnabled())
public void sendLoginToken( HttpServletRequest request, ILocalAccountPerson account, IPasswordResetNotification notification) { Locale locale = getCurrentUserLocale(request); IPortalUrlBuilder builder = urlProvider.getPortalUrlBuilderByPortletFName( request, PORTLET_FNAME_LOGIN, UrlType.RENDER); IPortletUrlBuilder portletUrlBuilder = builder.getTargetedPortletUrlBuilder(); portletUrlBuilder.addParameter("username", account.getName()); portletUrlBuilder.addParameter( "loginToken", (String) account.getAttributeValue("loginToken")); portletUrlBuilder.setPortletMode(PortletMode.VIEW); portletUrlBuilder.setWindowState(WindowState.MAXIMIZED); try { String path = fixPortletPath(request, builder); URL url = new URL( request.getScheme(), request.getServerName(), request.getServerPort(), path); notification.sendNotification(url, account, locale); } catch (MalformedURLException e) { log.error(e); } }
@Override public void sendNotification(URL resetUrl, ILocalAccountPerson account, Locale locale) { log.debug("Sending password reset instructions to user with url {}", resetUrl.toString()); try { MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true); String email = (String) account.getAttributeValue(ILocalAccountPerson.ATTR_MAIL); String subject = messageSource.getMessage(subjectMessageKey, new Object[] {}, locale); String body = formatBody(resetUrl, account, locale); helper.addTo(email); helper.setText(body, true); helper.setSubject(subject); helper.setFrom( portalEmailAddress, messageSource.getMessage("portal.name", new Object[] {}, locale)); log.debug( "Sending message to {} from {} subject {}", email, Arrays.toString(message.getFrom()), message.getSubject()); this.mailSender.send(helper.getMimeMessage()); } catch (Exception e) { log.error("Unable to send password reset email", e); } }
@Override @Transactional public void updatePassword(String user, String spass, boolean create) throws IOException { // Make sure user is specified correctly if (StringUtils.isBlank(user)) { throw new IllegalArgumentException( "You did not specify a valid user name. Please try again."); } // attempt to get the account form the database ILocalAccountPerson account = this.localAccountDao.getPerson(user); if (account == null) { if (!create) { throw new IllegalArgumentException("No such user: " + user); } account = this.localAccountDao.createPerson(user); } // update the user's password final String encryptedPassword = this.portalPasswordService.encryptPassword(spass); account.setPassword(encryptedPassword); this.localAccountDao.updateAccount(account); logger.info("Password Updated for: {}", user); } }