1 19 package org.openharmonise.him.actions.file; 20 21 import java.awt.event.*; 22 import java.net.*; 23 import java.rmi.*; 24 25 import javax.swing.*; 26 import javax.xml.rpc.*; 27 28 import org.openharmonise.him.*; 29 import org.openharmonise.him.actions.*; 30 import org.openharmonise.him.actions.rules.*; 31 import org.openharmonise.him.authentication.gui.*; 32 import org.openharmonise.him.context.StateHandler; 33 import org.openharmonise.him.harmonise.*; 34 import org.openharmonise.him.window.messages.*; 35 import org.openharmonise.vfs.*; 36 import org.openharmonise.vfs.authentication.*; 37 import org.openharmonise.vfs.context.*; 38 import org.openharmonise.vfs.gui.*; 39 import org.openharmonise.vfs.servers.*; 40 import org.openharmonise.webdav.client.*; 41 42 43 50 public class ActionChangeUserPassword 51 extends AbstractHIMAction 52 implements HIMAction { 53 54 55 58 public ActionChangeUserPassword() { 59 super(); 60 this.setup(); 61 } 62 63 66 public ActionChangeUserPassword(VirtualFile vfFile) { 67 super(vfFile); 68 } 69 70 74 private void setup() { 75 RuleGroup andGroup = new RuleGroup(); 76 andGroup.setGroupType(RuleGroup.GROUPTYPE_AND); 77 78 andGroup.addEnableRule( new PathRule("/webdav/Users") ); 79 IsDirectoryRule dirRule = new IsDirectoryRule(); 80 dirRule.setResultComparator(false); 81 andGroup.addEnableRule( dirRule ); 82 83 super.addEnableRule(andGroup); 84 } 85 86 89 public void actionPerformed(ActionEvent arg0) { 90 VirtualFile vfPrincipal = super.getLastContextFile(); 91 this.changePassword("Change " + vfPrincipal.getFileName() + "'s password.", vfPrincipal); 92 } 93 94 97 public String getText() { 98 return "Change user's password"; 99 } 100 101 104 public String getToolTip() { 105 return "Change the user's login password"; 106 } 107 108 111 public Icon getIcon() { 112 return IconManager.getInstance().getIcon("16-blank.gif"); 113 } 114 115 118 public String getMnemonic() { 119 return "p"; 120 } 121 122 125 public String getDescription() { 126 return this.getToolTip(); 127 } 128 129 132 public int getAcceleratorKeycode() { 133 return 0; 134 } 135 136 139 public int getAcceleratorMask() { 140 return 0; 141 } 142 143 146 public boolean isEnabled(ContextEvent ce) { 147 if(!this.m_bUserChecked) { 148 this.checkUser(); 149 } 150 this.setEnabled(super.isEnabled(ce) && this.m_bShow); 151 return this.m_bShow; 152 } 153 154 161 public boolean changePassword(String sMessage, VirtualFile vfPrincipal) { 162 boolean bWorked = false; 163 164 Server server = ServerList.getInstance().getHarmoniseServer(); 165 166 URI uri = server.getURI(); 167 168 String sURI = uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort() + "/webdav/services/HarmoniseService"; 169 URL url = null; 170 try { 171 url = new URL(sURI); 172 } catch (MalformedURLException e2) { 173 e2.printStackTrace(); 174 System.exit(1); 175 } 176 177 WebDAVFileSystem m_wdvfs = (WebDAVFileSystem) server.getVFS(); 178 179 JFrame tempFrame = new JFrame(); 180 tempFrame.setIconImage( ((ImageIcon)IconManager.getInstance().getIcon("32-sim-logo.gif")).getImage() ); 181 ChangePasswordDialog dialog = new ChangePasswordDialog(tempFrame); 182 dialog.setUsername(m_wdvfs.getAuthentication().getUsername()); 183 dialog.setPassword(m_wdvfs.getAuthentication().getPassword()); 184 if(sMessage!=null && !sMessage.equals("")) { 185 dialog.setInformationText(sMessage); 186 } 187 188 dialog.show(); 189 190 String sNewPassword = dialog.getNewPassword(); 191 if(!sNewPassword.equals("")) { 192 193 try { 194 int nRetn = -1; 195 StateHandler.getInstance().addWait("CHANGE_USER_PASSWORD"); 196 try { 197 nRetn = UserConfigClient.setPassword(url, dialog.getUsername(), dialog.getPassword(), vfPrincipal.getFileName(), dialog.getNewPassword()); 198 } catch(Exception e) { 199 throw e; 200 } finally { 201 StateHandler.getInstance().removeWait("CHANGE_USER_PASSWORD"); 202 } 203 204 if(nRetn==UserConfigClient.CODE_AUTHENTICATION_FAIL) { 205 this.changePassword("Your username/password information was incorrect", vfPrincipal); 206 } else if(nRetn==UserConfigClient.CODE_INVALID_LENGTH) { 207 this.changePassword("The new password is not long enough", vfPrincipal); 208 } else if(nRetn==UserConfigClient.CODE_NO_ALPHA_CHAR) { 209 this.changePassword("The new password must contain at least one letter", vfPrincipal); 210 } else if(nRetn==UserConfigClient.CODE_NO_CASE_MIX) { 211 this.changePassword("The new password must contain mixed case letters", vfPrincipal); 212 } else if(nRetn==UserConfigClient.CODE_NO_NUM_CHAR) { 213 this.changePassword("The new password must contain at least one number", vfPrincipal); 214 } else if(nRetn==UserConfigClient.CODE_SUCCESS) { 215 bWorked = true; 216 } 217 } catch (RemoteException e) { 218 e.printStackTrace(); 219 } catch (ServiceException e) { 220 e.printStackTrace(); 221 } catch(Exception e) { 222 e.printStackTrace(); 223 } 224 } else { 225 MessageHandler.getInstance().fireMessageEvent("The user's password not changed.", MessageHandler.TYPE_ERROR); 226 } 227 228 return bWorked; 229 } 230 231 } 232 | Popular Tags |