8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2007 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: EmailPassword.java,v 1.2 2008/06/25 05:43:41 qcheng Exp $
92813213f3a80b0a65195e59993b49b66d160f69Peter Major * Portions Copyrighted 2013 ForgeRock, Inc.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.password.ui.model.PWResetException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.password.ui.model.PWResetModel;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.password.ui.model.PWResetModelImpl;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.password.ui.model.PWResetResBundleCacher;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <code>EmailPassword</code> defines a set of methods
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * that are required to notify a user when a password is changed.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class EmailPassword implements NotifyPassword {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private PWResetModel model = new PWResetModelImpl();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static private G11NSettings g11nSettings = G11NSettings.getInstance();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static private String bundleName = PWResetModel.DEFAULT_RB;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Notifies user when password is changed.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param user <code>AMIdentity</code> object
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param password new password
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param locale user locale
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws PWResetException if password cannot be notified
92813213f3a80b0a65195e59993b49b66d160f69Peter Major public void notifyPassword(AMIdentity user, String password, Locale locale) throws PWResetException {
92813213f3a80b0a65195e59993b49b66d160f69Peter Major Set<String> set = user.getAttribute(model.getMailAttribute(user.getRealm()));
92813213f3a80b0a65195e59993b49b66d160f69Peter Major Set<String> localeSet = user.getAttribute(Constants.USER_LOCALE_ATTR);
92813213f3a80b0a65195e59993b49b66d160f69Peter Major userLocale = com.sun.identity.shared.locale.Locale.getLocale(localeStr);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster rb = PWResetResBundleCacher.getBundle(bundleName, userLocale);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster model.debugWarning("There is no email address for this user.");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new PWResetException(rb.getString("noEmail.message"));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster model.debugWarning("EmailPassword.notifyPassword", e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster model.debugWarning("EmailPassword.notifyPassword", e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster model.debugWarning("EmailPassword.notifyPassword", e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new PWResetException(rb.getString("sendEmailFailed.message"));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster model.debugWarning ("EmailPassword.notifyPassword", e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Sents reset password email to the user.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param emailAddres email address of the user
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param password new password
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void sendEmailToUser(String emailAddress, String password)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ResourceBundle rb = PWResetResBundleCacher.getBundle(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster rb.getString("resetPassMail.message"), (Object[])obj);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String subject = rb.getString("resetSubject.message");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String from = rb.getString("fromAddress.label");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String charset = g11nSettings.getDefaultCharsetForLocale(userLocale);