001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.actions.system;
020:
021: import java.awt.event.*;
022: import java.net.*;
023: import java.rmi.*;
024:
025: import javax.swing.*;
026: import javax.xml.rpc.*;
027:
028: import org.openharmonise.him.*;
029: import org.openharmonise.him.actions.*;
030: import org.openharmonise.him.authentication.gui.*;
031: import org.openharmonise.him.context.StateHandler;
032: import org.openharmonise.him.harmonise.*;
033: import org.openharmonise.him.window.messages.*;
034: import org.openharmonise.vfs.*;
035: import org.openharmonise.vfs.context.*;
036: import org.openharmonise.vfs.gui.*;
037: import org.openharmonise.vfs.servers.*;
038: import org.openharmonise.webdav.client.*;
039:
040: /**
041: * Action to change the current user's password.
042: *
043: * @author Matthew Large
044: * @version $Revision: 1.2 $
045: *
046: */
047: public class ActionChangeMyPassword extends AbstractHIMAction implements
048: HIMAction {
049:
050: /**
051: *
052: */
053: public ActionChangeMyPassword() {
054: super ();
055: }
056:
057: /**
058: * @param vfFile
059: */
060: public ActionChangeMyPassword(VirtualFile vfFile) {
061: super (vfFile);
062: }
063:
064: /* (non-Javadoc)
065: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
066: */
067: public void actionPerformed(ActionEvent arg0) {
068: boolean bWorked = this .changePassword("Change your password.");
069: if (bWorked) {
070: MessageHandler.getInstance().fireMessageEvent(
071: "Your password has been changed.",
072: MessageHandler.TYPE_CONFIRM);
073: } else {
074: MessageHandler.getInstance().fireMessageEvent(
075: "Your password has not been changed.",
076: MessageHandler.TYPE_ERROR);
077: }
078: }
079:
080: /* (non-Javadoc)
081: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getText()
082: */
083: public String getText() {
084: return "Change my password";
085: }
086:
087: /* (non-Javadoc)
088: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getToolTip()
089: */
090: public String getToolTip() {
091: return "Change the password you use to login";
092: }
093:
094: /* (non-Javadoc)
095: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getIcon()
096: */
097: public Icon getIcon() {
098: return IconManager.getInstance().getIcon("16-blank.gif");
099: }
100:
101: /* (non-Javadoc)
102: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getMnemonic()
103: */
104: public String getMnemonic() {
105: return "M";
106: }
107:
108: /* (non-Javadoc)
109: * @see com.simulacramedia.contentmanager.actions.CMAction#getDescription()
110: */
111: public String getDescription() {
112: return this .getToolTip();
113: }
114:
115: /* (non-Javadoc)
116: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorKeycode()
117: */
118: public int getAcceleratorKeycode() {
119: return 0;
120: }
121:
122: /* (non-Javadoc)
123: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorMask()
124: */
125: public int getAcceleratorMask() {
126: return 0;
127: }
128:
129: /**
130: * Opens a dialog to change the current user's password.
131: *
132: * @param sMessage Message to appear in dialog
133: * @return true if the method was successful
134: */
135: private boolean changePassword(String sMessage) {
136: boolean bWorked = false;
137:
138: Server server = ServerList.getInstance().getHarmoniseServer();
139:
140: URI uri = server.getURI();
141:
142: String sURI = uri.getScheme() + "://" + uri.getHost() + ":"
143: + uri.getPort() + "/webdav/services/HarmoniseService";
144: URL url = null;
145: try {
146: url = new URL(sURI);
147: } catch (MalformedURLException e2) {
148: e2.printStackTrace();
149: System.exit(1);
150: }
151:
152: WebDAVFileSystem m_wdvfs = (WebDAVFileSystem) server.getVFS();
153:
154: JFrame tempFrame = new JFrame();
155: tempFrame.setIconImage(((ImageIcon) IconManager.getInstance()
156: .getIcon("32-sim-logo.gif")).getImage());
157: ChangePasswordDialog dialog = new ChangePasswordDialog(
158: tempFrame);
159: dialog.setUsername(m_wdvfs.getAuthentication().getUsername());
160: dialog.setPassword(m_wdvfs.getAuthentication().getPassword());
161: if (sMessage != null && !sMessage.equals("")) {
162: dialog.setInformationText(sMessage);
163: }
164:
165: dialog.show();
166:
167: String sNewPassword = dialog.getNewPassword();
168: if (!sNewPassword.equals("")) {
169:
170: try {
171: int nRetn = -1;
172: StateHandler.getInstance()
173: .addWait("CHANGE_MY_PASSWORD");
174: try {
175: nRetn = UserConfigClient.setPassword(url, dialog
176: .getUsername(), dialog.getPassword(),
177: dialog.getUsername(), dialog
178: .getNewPassword());
179: } catch (Exception e) {
180: throw e;
181: } finally {
182: StateHandler.getInstance().removeWait(
183: "CHANGE_MY_PASSWORD");
184: }
185:
186: if (nRetn == UserConfigClient.CODE_AUTHENTICATION_FAIL) {
187: this
188: .changePassword("Your current username/password information was incorrect");
189: } else if (nRetn == UserConfigClient.CODE_INVALID_LENGTH) {
190: this
191: .changePassword("Your new password is not long enough");
192: } else if (nRetn == UserConfigClient.CODE_NO_ALPHA_CHAR) {
193: this
194: .changePassword("Your new password must contain at least one letter");
195: } else if (nRetn == UserConfigClient.CODE_NO_CASE_MIX) {
196: this
197: .changePassword("Your new password must contain mixed case letters");
198: } else if (nRetn == UserConfigClient.CODE_NO_NUM_CHAR) {
199: this
200: .changePassword("Your new password must contain at least one number");
201: } else if (nRetn == UserConfigClient.CODE_PWD_REPEAT) {
202: this
203: .changePassword("That password has been used too recently");
204: } else if (nRetn == UserConfigClient.CODE_SUCCESS) {
205: if (m_wdvfs.checkLoginDetails("/webdav", dialog
206: .getUsername(), dialog.getNewPassword())) {
207: m_wdvfs.changeLoginDetails(
208: dialog.getUsername(), sNewPassword);
209: bWorked = true;
210: }
211: }
212: } catch (RemoteException e) {
213: e.printStackTrace();
214: } catch (ServiceException e) {
215: e.printStackTrace();
216: } catch (Exception e) {
217: e.printStackTrace();
218: }
219: }
220:
221: return bWorked;
222: }
223:
224: }
|