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.file;
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.actions.rules.*;
031: import org.openharmonise.him.authentication.gui.*;
032: import org.openharmonise.him.context.StateHandler;
033: import org.openharmonise.him.harmonise.*;
034: import org.openharmonise.him.window.messages.*;
035: import org.openharmonise.vfs.*;
036: import org.openharmonise.vfs.authentication.*;
037: import org.openharmonise.vfs.context.*;
038: import org.openharmonise.vfs.gui.*;
039: import org.openharmonise.vfs.servers.*;
040: import org.openharmonise.webdav.client.*;
041:
042: /**
043: * Action for changing a user's password.
044: *
045: * @author Matthew Large
046: * @version $Revision: 1.3 $
047: *
048: */
049: public class ActionChangeUserPassword extends AbstractHIMAction
050: implements HIMAction {
051:
052: /**
053: *
054: */
055: public ActionChangeUserPassword() {
056: super ();
057: this .setup();
058: }
059:
060: /**
061: * @param vfFile
062: */
063: public ActionChangeUserPassword(VirtualFile vfFile) {
064: super (vfFile);
065: }
066:
067: /**
068: * Configures this action.
069: *
070: */
071: private void setup() {
072: RuleGroup andGroup = new RuleGroup();
073: andGroup.setGroupType(RuleGroup.GROUPTYPE_AND);
074:
075: andGroup.addEnableRule(new PathRule("/webdav/Users"));
076: IsDirectoryRule dirRule = new IsDirectoryRule();
077: dirRule.setResultComparator(false);
078: andGroup.addEnableRule(dirRule);
079:
080: super .addEnableRule(andGroup);
081: }
082:
083: /* (non-Javadoc)
084: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
085: */
086: public void actionPerformed(ActionEvent arg0) {
087: VirtualFile vfPrincipal = super .getLastContextFile();
088: this .changePassword("Change " + vfPrincipal.getFileName()
089: + "'s password.", vfPrincipal);
090: }
091:
092: /* (non-Javadoc)
093: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getText()
094: */
095: public String getText() {
096: return "Change user's password";
097: }
098:
099: /* (non-Javadoc)
100: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getToolTip()
101: */
102: public String getToolTip() {
103: return "Change the user's login password";
104: }
105:
106: /* (non-Javadoc)
107: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getIcon()
108: */
109: public Icon getIcon() {
110: return IconManager.getInstance().getIcon("16-blank.gif");
111: }
112:
113: /* (non-Javadoc)
114: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getMnemonic()
115: */
116: public String getMnemonic() {
117: return "p";
118: }
119:
120: /* (non-Javadoc)
121: * @see com.simulacramedia.contentmanager.actions.CMAction#getDescription()
122: */
123: public String getDescription() {
124: return this .getToolTip();
125: }
126:
127: /* (non-Javadoc)
128: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorKeycode()
129: */
130: public int getAcceleratorKeycode() {
131: return 0;
132: }
133:
134: /* (non-Javadoc)
135: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorMask()
136: */
137: public int getAcceleratorMask() {
138: return 0;
139: }
140:
141: /* (non-Javadoc)
142: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#isEnabled(com.simulacramedia.contentmanager.context.ContextEvent)
143: */
144: public boolean isEnabled(ContextEvent ce) {
145: if (!this .m_bUserChecked) {
146: this .checkUser();
147: }
148: this .setEnabled(super .isEnabled(ce) && this .m_bShow);
149: return this .m_bShow;
150: }
151:
152: /**
153: * Changes a user's password.
154: *
155: * @param sMessage Message to go in dialog box
156: * @param vfPrincipal Virtual file for the principal that represents the user
157: * @return true if the method was successful
158: */
159: public boolean changePassword(String sMessage,
160: VirtualFile vfPrincipal) {
161: boolean bWorked = false;
162:
163: Server server = ServerList.getInstance().getHarmoniseServer();
164:
165: URI uri = server.getURI();
166:
167: String sURI = uri.getScheme() + "://" + uri.getHost() + ":"
168: + 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()
181: .getIcon("32-sim-logo.gif")).getImage());
182: ChangePasswordDialog dialog = new ChangePasswordDialog(
183: tempFrame);
184: dialog.setUsername(m_wdvfs.getAuthentication().getUsername());
185: dialog.setPassword(m_wdvfs.getAuthentication().getPassword());
186: if (sMessage != null && !sMessage.equals("")) {
187: dialog.setInformationText(sMessage);
188: }
189:
190: dialog.show();
191:
192: String sNewPassword = dialog.getNewPassword();
193: if (!sNewPassword.equals("")) {
194:
195: try {
196: int nRetn = -1;
197: StateHandler.getInstance().addWait(
198: "CHANGE_USER_PASSWORD");
199: try {
200: nRetn = UserConfigClient.setPassword(url, dialog
201: .getUsername(), dialog.getPassword(),
202: vfPrincipal.getFileName(), dialog
203: .getNewPassword());
204: } catch (Exception e) {
205: throw e;
206: } finally {
207: StateHandler.getInstance().removeWait(
208: "CHANGE_USER_PASSWORD");
209: }
210:
211: if (nRetn == UserConfigClient.CODE_AUTHENTICATION_FAIL) {
212: this
213: .changePassword(
214: "Your username/password information was incorrect",
215: vfPrincipal);
216: } else if (nRetn == UserConfigClient.CODE_INVALID_LENGTH) {
217: this .changePassword(
218: "The new password is not long enough",
219: vfPrincipal);
220: } else if (nRetn == UserConfigClient.CODE_NO_ALPHA_CHAR) {
221: this
222: .changePassword(
223: "The new password must contain at least one letter",
224: vfPrincipal);
225: } else if (nRetn == UserConfigClient.CODE_NO_CASE_MIX) {
226: this
227: .changePassword(
228: "The new password must contain mixed case letters",
229: vfPrincipal);
230: } else if (nRetn == UserConfigClient.CODE_NO_NUM_CHAR) {
231: this
232: .changePassword(
233: "The new password must contain at least one number",
234: vfPrincipal);
235: } else if (nRetn == UserConfigClient.CODE_SUCCESS) {
236: bWorked = true;
237: }
238: } catch (RemoteException e) {
239: e.printStackTrace();
240: } catch (ServiceException e) {
241: e.printStackTrace();
242: } catch (Exception e) {
243: e.printStackTrace();
244: }
245: } else {
246: MessageHandler.getInstance().fireMessageEvent(
247: "The user's password not changed.",
248: MessageHandler.TYPE_ERROR);
249: }
250:
251: return bWorked;
252: }
253:
254: }
|