/** * Get authorized users list * * @param adminUser the admin user * @param plugin the plugin * @return a list of users */ public List<DatabaseUser> getAuthorizedUsers(AdminUser adminUser, Plugin plugin) { Collection<DatabaseUser> userList = DatabaseUserHome.findDatabaseUsersList(plugin); List<DatabaseUser> authorizedUserList = new ArrayList<DatabaseUser>(); for (DatabaseUser user : userList) { if (isAuthorized(user, adminUser, plugin)) { authorizedUserList.add(user); } } return authorizedUserList; }
/** * Change all user's password and notify them with an email. * * @param strBaseURL The base url of the application * @param plugin The plugin * @param locale The locale to use */ public void changeUserPasswordAndNotify(String strBaseURL, Plugin plugin, Locale locale) { // Alert all users their password have been reinitialized. Collection<DatabaseUser> listUsers = DatabaseUserHome.findDatabaseUsersList(plugin); for (DatabaseUser user : listUsers) { // Makes password String strPassword = SecurityUtils.makePassword(_userParamService, plugin); doModifyPassword(user, strPassword, plugin); if (StringUtils.isNotBlank(user.getEmail())) { // Sends password by e-mail ReferenceItem referenceItem = _userParamService.findByKey(PARAMETER_MAIL_PASSWORD_ENCRYPTION_CHANGED_SENDER, plugin); String strSenderEmail = (referenceItem == null) ? StringUtils.EMPTY : referenceItem.getName(); referenceItem = _userParamService.findByKey(PARAMETER_MAIL_PASSWORD_ENCRYPTION_CHANGED_SUBJECT, plugin); String strEmailSubject = (referenceItem == null) ? StringUtils.EMPTY : referenceItem.getName(); Map<String, Object> model = new HashMap<String, Object>(); model.put(MARK_NEW_PASSWORD, strPassword); model.put( MARK_LOGIN_URL, strBaseURL + AdminAuthenticationService.getInstance().getLoginPageUrl()); model.put(MARK_SITE_LINK, MailService.getSiteLink(strBaseURL, true)); String strTemplate = DatabaseTemplateService.getTemplateFromKey(PARAMETER_MAIL_PASSWORD_ENCRYPTION_CHANGED); HtmlTemplate template = AppTemplateService.getTemplateFromStringFtl(strTemplate, locale, model); MailService.sendMailHtml( user.getEmail(), strSenderEmail, strSenderEmail, strEmailSubject, template.getHtml()); } } }