001/* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2008-2009 Sun Microsystems, Inc. 025 * Portions Copyright 2014-2015 ForgeRock AS 026 */ 027 028package org.opends.guitools.controlpanel.ui; 029 030import static org.opends.messages.AdminToolMessages.*; 031 032import java.awt.Component; 033import java.awt.GridBagConstraints; 034import java.util.ArrayList; 035 036import javax.swing.JLabel; 037import javax.swing.JPasswordField; 038 039import org.opends.guitools.controlpanel.browser.BrowserController; 040import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent; 041import org.opends.guitools.controlpanel.task.ResetUserPasswordTask; 042import org.opends.guitools.controlpanel.task.Task; 043import org.opends.guitools.controlpanel.ui.nodes.BasicNode; 044import org.opends.guitools.controlpanel.util.Utilities; 045import org.forgerock.i18n.LocalizableMessage; 046 047/** 048 * Panel that appears when the user wants to change the password of a user. 049 * 050 */ 051public class ResetUserPasswordPanel extends StatusGenericPanel 052{ 053 private static final long serialVersionUID = 8733172823605832626L; 054 private JLabel dn = Utilities.createDefaultLabel(); 055 private JLabel name = Utilities.createDefaultLabel(); 056 private JLabel lPassword = Utilities.createPrimaryLabel(); 057 private JLabel lConfirmPassword = Utilities.createPrimaryLabel(); 058 private JPasswordField password = Utilities.createPasswordField(25); 059 private JPasswordField confirmPassword = Utilities.createPasswordField(25); 060 061 private BasicNode node; 062 private BrowserController controller; 063 064 /** 065 * Constructor of the panel. 066 * 067 */ 068 public ResetUserPasswordPanel() 069 { 070 super(); 071 createLayout(); 072 } 073 074 /** 075 * Sets the node representing the entry that the user wants to modify the 076 * password from. 077 * @param node the node. 078 * @param controller the browser controller. 079 */ 080 public void setValue(BasicNode node, BrowserController controller) 081 { 082 this.node = node; 083 this.controller = controller; 084 setPrimaryValid(lPassword); 085 setPrimaryValid(lConfirmPassword); 086 087 dn.setText(node.getDN()); 088 name.setText(node.getDisplayName()); 089 090 password.setText(""); 091 confirmPassword.setText(""); 092 093 packParentDialog(); 094 } 095 096 /** {@inheritDoc} */ 097 public Component getPreferredFocusComponent() 098 { 099 return password; 100 } 101 102 /** {@inheritDoc} */ 103 public void okClicked() 104 { 105 final ArrayList<LocalizableMessage> errors = new ArrayList<>(); 106 107 setPrimaryValid(lPassword); 108 setPrimaryValid(lConfirmPassword); 109 110 String pwd1 = new String(password.getPassword()); 111 String pwd2 = new String(confirmPassword.getPassword()); 112 113 if (pwd1.length() == 0) 114 { 115 errors.add(ERR_CTRL_PANEL_NEW_PASSWORD_REQUIRED.get()); 116 setPrimaryInvalid(lPassword); 117 } 118 else if (!pwd1.equals(pwd2)) 119 { 120 errors.add(ERR_CTRL_PANEL_PASSWORD_DO_NOT_MATCH.get()); 121 setPrimaryInvalid(lPassword); 122 setPrimaryInvalid(lConfirmPassword); 123 } 124 if (errors.isEmpty()) 125 { 126 ProgressDialog dlg = new ProgressDialog( 127 Utilities.createFrame(), 128 Utilities.getParentDialog(this), 129 INFO_CTRL_PANEL_RESET_USER_PASSWORD_TITLE.get(), getInfo()); 130 ResetUserPasswordTask newTask = 131 new ResetUserPasswordTask(getInfo(), dlg, node, controller, 132 password.getPassword()); 133 for (Task task : getInfo().getTasks()) 134 { 135 task.canLaunch(newTask, errors); 136 } 137 if (errors.isEmpty()) 138 { 139 launchOperation(newTask, 140 INFO_CTRL_PANEL_RESETTING_USER_PASSWORD_SUMMARY.get(), 141 INFO_CTRL_PANEL_RESETTING_USER_PASSWORD_SUCCESSFUL_SUMMARY.get(), 142 INFO_CTRL_PANEL_RESETTING_USER_PASSWORD_SUCCESSFUL_DETAILS.get(), 143 ERR_CTRL_PANEL_RESETTING_USER_PASSWORD_ERROR_SUMMARY.get(), 144 ERR_CTRL_PANEL_RESETTING_USER_PASSWORD_ERROR_DETAILS.get(), 145 null, 146 dlg); 147 Utilities.getParentDialog(this).setVisible(false); 148 dlg.setVisible(true); 149 } 150 } 151 if (!errors.isEmpty()) 152 { 153 displayErrorDialog(errors); 154 } 155 } 156 157 /** {@inheritDoc} */ 158 public LocalizableMessage getTitle() 159 { 160 return INFO_CTRL_PANEL_RESET_USER_PASSWORD_TITLE.get(); 161 } 162 163 /** {@inheritDoc} */ 164 public void configurationChanged(ConfigurationChangeEvent ev) 165 { 166 } 167 168 /** 169 * Creates the layout of the panel (but the contents are not populated here). 170 */ 171 private void createLayout() 172 { 173 GridBagConstraints gbc = new GridBagConstraints(); 174 gbc.gridx = 0; 175 gbc.gridy = 0; 176 gbc.weightx = 0.0; 177 gbc.weighty = 0.0; 178 gbc.fill = GridBagConstraints.HORIZONTAL; 179 180 LocalizableMessage[] strings = 181 { 182 INFO_CTRL_PANEL_RESET_USER_PASSWORD_DN_LABEL.get(), 183 INFO_CTRL_PANEL_RESET_USER_PASSWORD_NAME_LABEL.get(), 184 INFO_CTRL_PANEL_RESET_USER_PASSWORD_PWD_LABEL.get(), 185 INFO_CTRL_PANEL_RESET_USER_PASSWORD_CONFIRM_LABEL.get() 186 }; 187 JLabel[] labels = {null, null, lPassword, lConfirmPassword}; 188 Component[] comps = {dn, name, password, confirmPassword}; 189 190 for (int i=0; i<strings.length; i++) 191 { 192 if (labels[i] == null) 193 { 194 labels[i] = Utilities.createPrimaryLabel(strings[i]); 195 } 196 else 197 { 198 labels[i].setText(strings[i].toString()); 199 } 200 201 gbc.gridx = 0; 202 gbc.insets.left = 0; 203 gbc.weightx = 0.0; 204 add(labels[i], gbc); 205 gbc.insets.left = 10; 206 gbc.gridx ++; 207 gbc.weightx = 1.0; 208 add(comps[i], gbc); 209 210 gbc.insets.top = 10; 211 gbc.gridy ++; 212 } 213 214 addBottomGlue(gbc); 215 } 216}