1 19 package org.openharmonise.him.authentication; 20 21 import java.awt.*; 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.authentication.gui.*; 30 import org.openharmonise.him.configuration.*; 31 import org.openharmonise.him.harmonise.*; 32 import org.openharmonise.him.harmonise.authentication.HarmoniseUser; 33 import org.openharmonise.swing.*; 34 import org.openharmonise.vfs.authentication.*; 35 import org.openharmonise.vfs.gui.*; 36 import org.openharmonise.vfs.servers.*; 37 import org.openharmonise.webdav.client.*; 38 39 40 50 public class LoginSequence { 51 52 55 private AuthInfo m_authInfo = null; 56 57 60 private URL m_url = null; 61 62 65 private WebDAVFileSystem m_wdvfs = null; 66 67 70 private int m_nLoginAttempts = 0; 71 72 75 public LoginSequence() { 76 super(); 77 } 78 79 85 public boolean runSequence(AbstractAuthenticationStore authStore) { 86 String sValue = ConfigStore.getInstance().getPropertyValue("HARMONISE_SERVER"); 87 if(sValue==null || sValue.equals("")) { 88 JFrame frame = new JFrame(); 89 frame.setIconImage( ((ImageIcon)IconManager.getInstance().getIcon("32-sim-logo.gif")).getImage() ); 90 91 SingleTextEntryDialog dialog = new SingleTextEntryDialog(frame, "Harmonise Server"); 92 dialog.setLabelText("Enter the address of the Harmonise server (http(s)://...)"); 93 dialog.show(); 94 95 if(dialog.getTextValue()!=null) { 96 sValue = dialog.getTextValue(); 97 ConfigStore.getInstance().setProperty("HARMONISE_SERVER", dialog.getTextValue().trim()); 98 } else { 99 System.exit(1); 100 } 101 } 102 103 Server server = null; 104 try { 105 server = 106 new Server(new URI(sValue),"org.openharmonise.webdav.client.WebDAVFileSystem",authStore); 107 ServerList.getInstance().addHarmoniseServer(server); 108 } catch (URISyntaxException e) { 109 e.printStackTrace(); 110 System.exit(1); 111 } 112 113 URI uri = server.getURI(); 114 115 String sURI = uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort() + "/webdav/services/HarmoniseService"; 116 try { 117 m_url = new URL(sURI); 118 } catch (MalformedURLException e2) { 119 e2.printStackTrace(); 120 System.exit(1); 121 } 122 123 m_wdvfs = (WebDAVFileSystem) server.getVFS(); 124 125 boolean bLoginWorked = this.login(); 126 127 if(bLoginWorked) { 128 VFSUser user = new HarmoniseUser(ServerList.getInstance().getHarmoniseServer().getVFS(), this.m_wdvfs.currentUserResourcePath(this.m_authInfo));; 129 this.m_authInfo.setUser( user ); 130 } 131 132 return bLoginWorked; 133 } 134 135 140 public AuthInfo getAuthInfo() { 141 return this.m_authInfo; 142 } 143 144 150 private boolean login() { 151 boolean bWorked = false; 152 153 if(this.m_nLoginAttempts<3) { 154 JFrame tempFrame = new JFrame(); 155 tempFrame.setTitle("Harmonise - Login"); 156 tempFrame.setIconImage( ((ImageIcon)IconManager.getInstance().getIcon("32-sim-logo.gif")).getImage() ); 157 Dimension dims = tempFrame.getGraphicsConfiguration().getBounds().getSize(); 158 tempFrame.setLocation(dims.width,dims.height); 159 tempFrame.setVisible(true); 160 LoginDialog loginDialog = new LoginDialog(tempFrame); 161 if(this.m_nLoginAttempts>0) { 162 loginDialog.setMessage("Warning incorrect username/password, reenter details"); 163 } 164 loginDialog.show(); 165 166 this.m_nLoginAttempts++; 167 168 String sUsername = loginDialog.getUsername(); 169 String sPassword = loginDialog.getPassword(); 170 171 if(loginDialog.changePassword()) { 172 bWorked = this.changePassword("Change your password."); 173 if(!bWorked) { 174 this.login(); 175 } 176 }else if(!sPassword.equals("")) { 177 bWorked = m_wdvfs.checkLoginDetails("/webdav", sUsername, sPassword); 178 if(bWorked) { 179 this.m_authInfo = new AuthInfo(); 180 this.m_authInfo.setUsername(sUsername); 181 this.m_authInfo.setPassword(sPassword); 182 } else { 183 boolean bExpired = false; 184 try { 185 bExpired = this.hasExpired(sUsername, sPassword); 186 } catch(Exception e) { 187 e.printStackTrace(); 188 } 189 if(bExpired) { 190 bWorked = this.changePassword("Your password has expired, please change it."); 191 } else { 192 bWorked = this.login(); 193 } 194 if(!bWorked) { 195 this.m_authInfo = null; 196 } 197 } 198 } 199 } else if(!bWorked) { 200 JFrame tempFrame = new JFrame(); 201 tempFrame.setIconImage( ((ImageIcon)IconManager.getInstance().getIcon("32-sim-logo.gif")).getImage() ); 202 LoginMessageDialog messageDialog = new LoginMessageDialog(tempFrame); 203 messageDialog.setMessage("\n\n\tYou are locked out of the Harmonise system, please contact your system\n\tadministrator for further details."); 204 messageDialog.show(); 205 } 206 207 return bWorked; 208 } 209 210 217 private boolean hasExpired(String sUsername, String sPassword) { 218 boolean bRetn = false; 219 try { 220 bRetn = UserConfigClient.hasPasswordExpired(m_url, sUsername, sPassword); 221 } catch (RemoteException e1) { 222 e1.printStackTrace(); 223 } catch (ServiceException e1) { 224 e1.printStackTrace(); 225 } 226 227 return bRetn; 228 } 229 230 237 private boolean changePassword(String sMessage) { 238 boolean bWorked = false; 239 240 JFrame tempFrame = new JFrame(); 241 tempFrame.setTitle("Harmonise - Change Password"); 242 tempFrame.setIconImage( ((ImageIcon)IconManager.getInstance().getIcon("32-sim-logo.gif")).getImage() ); 243 Dimension dims = tempFrame.getGraphicsConfiguration().getBounds().getSize(); 244 tempFrame.setLocation(dims.width,dims.height); 245 tempFrame.setVisible(true); 246 ChangePasswordDialog dialog = new ChangePasswordDialog(tempFrame); 247 if(sMessage!=null && !sMessage.equals("")) { 248 dialog.setInformationText(sMessage); 249 } 250 dialog.show(); 251 252 String sNewPassword = dialog.getNewPassword(); 253 if(!sNewPassword.equals("")) { 254 try { 255 int nRetn = UserConfigClient.setPassword(m_url, dialog.getUsername(), dialog.getPassword(), dialog.getUsername(), dialog.getNewPassword()); 256 String sChangePasswordMessage = null; 257 if(nRetn==UserConfigClient.CODE_AUTHENTICATION_FAIL) { 258 sChangePasswordMessage = "Your current username/password information was incorrect"; 259 } else if(nRetn==UserConfigClient.CODE_INVALID_LENGTH) { 260 sChangePasswordMessage = "Your new password is not long enough"; 261 } else if(nRetn==UserConfigClient.CODE_NO_ALPHA_CHAR) { 262 sChangePasswordMessage = "Your new password must contain at least one letter"; 263 } else if(nRetn==UserConfigClient.CODE_NO_CASE_MIX) { 264 sChangePasswordMessage = "Your new password must contain mixed case letters"; 265 } else if(nRetn==UserConfigClient.CODE_NO_NUM_CHAR) { 266 sChangePasswordMessage = "Your new password must contain at least one number"; 267 } else if(nRetn==UserConfigClient.CODE_INVALID_USER_STATE) { 268 } else if(nRetn==UserConfigClient.CODE_PWD_REPEAT) { 271 sChangePasswordMessage = "That password has been used too recently"; 272 } else if(nRetn==UserConfigClient.CODE_SUCCESS) { 273 if(this.m_wdvfs.checkLoginDetails("/webdav", dialog.getUsername(), dialog.getNewPassword())) { 274 this.m_authInfo = new AuthInfo(); 275 this.m_authInfo.setUsername(dialog.getUsername()); 276 this.m_authInfo.setPassword(dialog.getNewPassword()); 277 bWorked = true; 278 } 279 } 280 if(sChangePasswordMessage != null){ 281 this.m_authInfo = null; 282 bWorked = changePassword(sChangePasswordMessage); 283 } 284 } catch (RemoteException e) { 285 e.printStackTrace(); 286 } catch (ServiceException e) { 287 e.printStackTrace(); 288 } 289 } else { 290 this.m_nLoginAttempts--; 291 } 292 293 return bWorked; 294 } 295 296 } 297 | Popular Tags |