KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > editors > UserEditor


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.editors;
20
21 import java.net.*;
22 import java.rmi.*;
23
24 import javax.swing.*;
25 import javax.xml.rpc.*;
26
27 import org.openharmonise.him.*;
28 import org.openharmonise.him.authentication.gui.*;
29 import org.openharmonise.him.context.StateHandler;
30 import org.openharmonise.him.harmonise.*;
31 import org.openharmonise.him.window.messages.*;
32 import org.openharmonise.vfs.*;
33 import org.openharmonise.vfs.context.*;
34 import org.openharmonise.vfs.gui.*;
35 import org.openharmonise.vfs.servers.*;
36 import org.openharmonise.vfs.status.*;
37 import org.openharmonise.webdav.client.*;
38
39
40 /**
41  * Handles editing of users.
42  *
43  * @author Matthew Large
44  * @version $Revision: 1.2 $
45  *
46  */

47 public class UserEditor extends BlankEditor implements Editor {
48
49     /**
50      *
51      */

52     public UserEditor() {
53         super();
54     }
55
56     /* (non-Javadoc)
57      * @see com.simulacramedia.contentmanager.editors.Editor#open(java.lang.String, com.simulacramedia.vfs.AbstractVirtualFileSystem)
58      */

59     public PathStatusWrapper open(String JavaDoc sPath, AbstractVirtualFileSystem vfs) {
60         VirtualFile vfPrincipal = vfs.getVirtualFile(sPath).getResource();
61         this.changePassword("Change " + vfPrincipal.getFileName() + "'s password.", vfPrincipal);
62         return new PathStatusWrapper(null, new VFSStatus());
63     }
64     
65     /**
66      * Opens the change password dialog and deals with the results.
67      *
68      * @param sMessage Message for dialog
69      * @param vfPrincipal Virtual file for principal representing the user
70      * @return true if the method was successful
71      */

72     public boolean changePassword(String JavaDoc sMessage, VirtualFile vfPrincipal) {
73         boolean bWorked = false;
74         
75         Server server = ServerList.getInstance().getHarmoniseServer();
76         
77         URI uri = server.getURI();
78         
79         String JavaDoc sURI = uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort() + "/webdav/services/HarmoniseService";
80         URL url = null;
81         try {
82             url = new URL(sURI);
83         } catch (MalformedURLException e2) {
84             e2.printStackTrace();
85             System.exit(1);
86         }
87         
88         WebDAVFileSystem m_wdvfs = (WebDAVFileSystem) server.getVFS();
89             
90         JFrame tempFrame = new JFrame();
91         tempFrame.setIconImage( ((ImageIcon)IconManager.getInstance().getIcon("32-sim-logo.gif")).getImage() );
92         ChangePasswordDialog dialog = new ChangePasswordDialog(tempFrame);
93         dialog.setUsername(m_wdvfs.getAuthentication().getUsername());
94         dialog.setPassword(m_wdvfs.getAuthentication().getPassword());
95         if(sMessage!=null && !sMessage.equals("")) {
96             dialog.setInformationText(sMessage);
97         }
98         
99         dialog.show();
100                         
101         String JavaDoc sNewPassword = dialog.getNewPassword();
102         if(!sNewPassword.equals("")) {
103             
104             try {
105                 int nRetn = -1;
106                 StateHandler.getInstance().addWait("CHANGE_USER_PASSWORD");
107                 try {
108                     nRetn = UserConfigClient.setPassword(url, dialog.getUsername(), dialog.getPassword(), vfPrincipal.getFileName(), dialog.getNewPassword());
109                 } catch(Exception JavaDoc e) {
110                     throw e;
111                 } finally {
112                     StateHandler.getInstance().removeWait("CHANGE_USER_PASSWORD");
113                 }
114                     
115                 if(nRetn==UserConfigClient.CODE_AUTHENTICATION_FAIL) {
116                     this.changePassword("Your username/password information was incorrect", vfPrincipal);
117                 } else if(nRetn==UserConfigClient.CODE_INVALID_LENGTH) {
118                     this.changePassword("The new password is not long enough", vfPrincipal);
119                 } else if(nRetn==UserConfigClient.CODE_NO_ALPHA_CHAR) {
120                     this.changePassword("The new password must contain at least one letter", vfPrincipal);
121                 } else if(nRetn==UserConfigClient.CODE_NO_CASE_MIX) {
122                     this.changePassword("The new password must contain mixed case letters", vfPrincipal);
123                 } else if(nRetn==UserConfigClient.CODE_NO_NUM_CHAR) {
124                     this.changePassword("The new password must contain at least one number", vfPrincipal);
125                 } else if(nRetn==UserConfigClient.CODE_SUCCESS) {
126                     MessageHandler.getInstance().fireMessageEvent("The password for " + vfPrincipal.getFileName() + " has been changed.", MessageHandler.TYPE_CONFIRM);
127                     bWorked = true;
128                 }
129             } catch (RemoteException e) {
130                 e.printStackTrace();
131             } catch (ServiceException e) {
132                 e.printStackTrace();
133             } catch(Exception JavaDoc e) {
134                 e.printStackTrace();
135             }
136         } else {
137             MessageHandler.getInstance().fireMessageEvent("The user's password not changed.", MessageHandler.TYPE_ERROR);
138         }
139             
140         return bWorked;
141     }
142     
143 }
Popular Tags