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.editors;
020:
021: import java.net.*;
022: import java.rmi.*;
023:
024: import javax.swing.*;
025: import javax.xml.rpc.*;
026:
027: import org.openharmonise.him.*;
028: import org.openharmonise.him.authentication.gui.*;
029: import org.openharmonise.him.context.StateHandler;
030: import org.openharmonise.him.harmonise.*;
031: import org.openharmonise.him.window.messages.*;
032: import org.openharmonise.vfs.*;
033: import org.openharmonise.vfs.context.*;
034: import org.openharmonise.vfs.gui.*;
035: import org.openharmonise.vfs.servers.*;
036: import org.openharmonise.vfs.status.*;
037: import org.openharmonise.webdav.client.*;
038:
039: /**
040: * Handles editing of users.
041: *
042: * @author Matthew Large
043: * @version $Revision: 1.2 $
044: *
045: */
046: public class UserEditor extends BlankEditor implements Editor {
047:
048: /**
049: *
050: */
051: public UserEditor() {
052: super ();
053: }
054:
055: /* (non-Javadoc)
056: * @see com.simulacramedia.contentmanager.editors.Editor#open(java.lang.String, com.simulacramedia.vfs.AbstractVirtualFileSystem)
057: */
058: public PathStatusWrapper open(String sPath,
059: AbstractVirtualFileSystem vfs) {
060: VirtualFile vfPrincipal = vfs.getVirtualFile(sPath)
061: .getResource();
062: this .changePassword("Change " + vfPrincipal.getFileName()
063: + "'s password.", vfPrincipal);
064: return new PathStatusWrapper(null, new VFSStatus());
065: }
066:
067: /**
068: * Opens the change password dialog and deals with the results.
069: *
070: * @param sMessage Message for dialog
071: * @param vfPrincipal Virtual file for principal representing the user
072: * @return true if the method was successful
073: */
074: public boolean changePassword(String sMessage,
075: VirtualFile vfPrincipal) {
076: boolean bWorked = false;
077:
078: Server server = ServerList.getInstance().getHarmoniseServer();
079:
080: URI uri = server.getURI();
081:
082: String sURI = uri.getScheme() + "://" + uri.getHost() + ":"
083: + uri.getPort() + "/webdav/services/HarmoniseService";
084: URL url = null;
085: try {
086: url = new URL(sURI);
087: } catch (MalformedURLException e2) {
088: e2.printStackTrace();
089: System.exit(1);
090: }
091:
092: WebDAVFileSystem m_wdvfs = (WebDAVFileSystem) server.getVFS();
093:
094: JFrame tempFrame = new JFrame();
095: tempFrame.setIconImage(((ImageIcon) IconManager.getInstance()
096: .getIcon("32-sim-logo.gif")).getImage());
097: ChangePasswordDialog dialog = new ChangePasswordDialog(
098: tempFrame);
099: dialog.setUsername(m_wdvfs.getAuthentication().getUsername());
100: dialog.setPassword(m_wdvfs.getAuthentication().getPassword());
101: if (sMessage != null && !sMessage.equals("")) {
102: dialog.setInformationText(sMessage);
103: }
104:
105: dialog.show();
106:
107: String sNewPassword = dialog.getNewPassword();
108: if (!sNewPassword.equals("")) {
109:
110: try {
111: int nRetn = -1;
112: StateHandler.getInstance().addWait(
113: "CHANGE_USER_PASSWORD");
114: try {
115: nRetn = UserConfigClient.setPassword(url, dialog
116: .getUsername(), dialog.getPassword(),
117: vfPrincipal.getFileName(), dialog
118: .getNewPassword());
119: } catch (Exception e) {
120: throw e;
121: } finally {
122: StateHandler.getInstance().removeWait(
123: "CHANGE_USER_PASSWORD");
124: }
125:
126: if (nRetn == UserConfigClient.CODE_AUTHENTICATION_FAIL) {
127: this
128: .changePassword(
129: "Your username/password information was incorrect",
130: vfPrincipal);
131: } else if (nRetn == UserConfigClient.CODE_INVALID_LENGTH) {
132: this .changePassword(
133: "The new password is not long enough",
134: vfPrincipal);
135: } else if (nRetn == UserConfigClient.CODE_NO_ALPHA_CHAR) {
136: this
137: .changePassword(
138: "The new password must contain at least one letter",
139: vfPrincipal);
140: } else if (nRetn == UserConfigClient.CODE_NO_CASE_MIX) {
141: this
142: .changePassword(
143: "The new password must contain mixed case letters",
144: vfPrincipal);
145: } else if (nRetn == UserConfigClient.CODE_NO_NUM_CHAR) {
146: this
147: .changePassword(
148: "The new password must contain at least one number",
149: vfPrincipal);
150: } else if (nRetn == UserConfigClient.CODE_SUCCESS) {
151: MessageHandler.getInstance().fireMessageEvent(
152: "The password for "
153: + vfPrincipal.getFileName()
154: + " has been changed.",
155: MessageHandler.TYPE_CONFIRM);
156: bWorked = true;
157: }
158: } catch (RemoteException e) {
159: e.printStackTrace();
160: } catch (ServiceException e) {
161: e.printStackTrace();
162: } catch (Exception e) {
163: e.printStackTrace();
164: }
165: } else {
166: MessageHandler.getInstance().fireMessageEvent(
167: "The user's password not changed.",
168: MessageHandler.TYPE_ERROR);
169: }
170:
171: return bWorked;
172: }
173:
174: }
|