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.serverconfig.security;
020:
021: import java.awt.*;
022: import java.awt.event.*;
023: import java.net.*;
024: import java.rmi.*;
025:
026: import javax.swing.*;
027: import javax.xml.rpc.*;
028:
029: import org.openharmonise.him.*;
030: import org.openharmonise.him.configuration.*;
031: import org.openharmonise.him.harmonise.*;
032: import org.openharmonise.him.serverconfig.*;
033: import org.openharmonise.vfs.servers.ServerList;
034:
035: /**
036: * Panel for configuring the security options of a Harmonise Information
037: * Server.
038: *
039: * @author Matthew Large
040: * @version $Revision: 1.1 $
041: *
042: */
043: public class SecurityServerConfigOptions extends
044: AbstractServerConfigOptions implements LayoutManager,
045: ActionListener, ApplyChangesListener, KeyListener {
046:
047: /**
048: * Description.
049: */
050: private JTextArea m_descriptionTextArea = null;
051:
052: /**
053: * Minimum password length option label.
054: */
055: private JLabel m_minPasswordLengthLabel = null;
056:
057: /**
058: * Minimum password length option text field.
059: */
060: private JTextField m_minPasswordLengthTextField = null;
061:
062: /**
063: * true if the minimum password length option has changed.
064: */
065: private boolean m_bminPasswordLengthChanged = false;
066:
067: /**
068: * Password change period option label.
069: */
070: private JLabel m_passwordChangePreriodLabel = null;
071:
072: /**
073: * Password change period option text field.
074: */
075: private JTextField m_passwordChangePreriodTextField = null;
076:
077: /**
078: * true if the password change period option has changed.
079: */
080: private boolean m_bpasswordChangePreriodChanged = false;
081:
082: /**
083: * Force alphabetical characters option label.
084: */
085: private JLabel m_forcePasswordAlphaLabel = null;
086:
087: /**
088: * Force alphabetical characters option drop down.
089: */
090: private JComboBox m_forcePasswordAlphaCombo = null;
091:
092: /**
093: * true if the force alphabetical characters option has changed.
094: */
095: private boolean m_bforcePasswordAlphaChanged = false;
096:
097: /**
098: * Force numerical characters option label.
099: */
100: private JLabel m_forcePasswordNumericLabel = null;
101:
102: /**
103: * Force numerical characters option drop down.
104: */
105: private JComboBox m_forcePasswordNumericCombo = null;
106:
107: /**
108: * true if the force numerical characters option has changed.
109: */
110: private boolean m_bforcePasswordNumericChanged = false;
111:
112: /**
113: * Force mixed case characters option label.
114: */
115: private JLabel m_forcePasswordMixedCaseLabel = null;
116:
117: /**
118: * Force mixed case characters option drop down.
119: */
120: private JComboBox m_forcePasswordMixedCaseCombo = null;
121:
122: /**
123: * true if the force mixed case characters option has changed.
124: */
125: private boolean m_bforcePasswordMixedCaseChanged = false;
126:
127: /**
128: * Retry limit option label.
129: */
130: private JLabel m_retryLimitLabel = null;
131:
132: /**
133: * Retry limit option text field.
134: */
135: private JTextField m_retryLimitTextField = null;
136:
137: /**
138: * true if the retry limit option has changed.
139: */
140: private boolean m_bretryLimitChanged = false;
141:
142: /**
143: * Password history check size option label.
144: */
145: private JLabel m_pwdHistCheckSizeLabel = null;
146:
147: /**
148: * Password history check size option text field.
149: */
150: private JTextField m_pwdHistCheckSizeTextField = null;
151:
152: /**
153: * true if the password history check size option has changed.
154: */
155: private boolean m_bpwdHistCheckSizeChanged = false;
156:
157: /**
158: * Username for the current user.
159: */
160: private String m_sUsername = null;
161:
162: /**
163: * Password for the current user.
164: */
165: private String m_sPassword = null;
166:
167: /**
168: * Constructs a new security configuration options panel.
169: *
170: */
171: public SecurityServerConfigOptions() {
172: super (null);
173: this .setup();
174: }
175:
176: /**
177: * Constructs a new security configuration options panel.
178: *
179: * @param dialog configuration dialog that this panel will be in.
180: */
181: public SecurityServerConfigOptions(ServerConfigDialog dialog) {
182: super (dialog);
183: dialog.addApplyChangesListener(this );
184: this .setup();
185: }
186:
187: /**
188: * Initialises this component.
189: *
190: */
191: private void setup() {
192: this .setLayout(this );
193:
194: this .m_sUsername = ServerList.getInstance()
195: .getHarmoniseServer().getVFS().getAuthentication()
196: .getUsername();
197: this .m_sPassword = ServerList.getInstance()
198: .getHarmoniseServer().getVFS().getAuthentication()
199: .getPassword();
200:
201: String fontName = "Dialog";
202: int fontSize = 11;
203: Font font = new Font(fontName, Font.PLAIN, fontSize);
204:
205: this .m_descriptionTextArea = new JTextArea(
206: "Use the list below to configure the password policy for the registered users of the Harmonise Server.");
207: this .m_descriptionTextArea.setEditable(false);
208: this .m_descriptionTextArea.setBorder(BorderFactory
209: .createEmptyBorder());
210: this .m_descriptionTextArea.setWrapStyleWord(true);
211: this .m_descriptionTextArea.setLineWrap(true);
212: this .m_descriptionTextArea.setOpaque(false);
213: this .add(m_descriptionTextArea);
214:
215: ConfigSettingsClient service = new ConfigSettingsClient();
216: URL url = null;
217: try {
218: URI uri = ServerList.getInstance().getHarmoniseServer()
219: .getURI();
220: String sURL = uri.getScheme() + "://" + uri.getHost() + ":"
221: + uri.getPort() + "/webdav/services/ConfigService";
222: url = new URL(sURL);
223:
224: } catch (MalformedURLException e) {
225: e.printStackTrace();
226: }
227:
228: String sValue = null;
229:
230: try {
231: ConfigProperty configProp = service.getProperty(url,
232: this .m_sUsername, this .m_sPassword,
233: "PWD_MIN_LENGTH");
234: sValue = configProp.getValue();
235: if (sValue == null) {
236: sValue = "100";
237: }
238: } catch (RemoteException e) {
239: e.printStackTrace();
240: } catch (ServiceException e) {
241: e.printStackTrace();
242: }
243:
244: m_minPasswordLengthLabel = new JLabel("Minimum password length");
245: this .m_minPasswordLengthLabel.setFont(font);
246: this .add(this .m_minPasswordLengthLabel);
247: m_minPasswordLengthTextField = new JTextField(sValue);
248: this .m_minPasswordLengthTextField.addKeyListener(this );
249: this .m_minPasswordLengthTextField.setFont(font);
250: this .add(this .m_minPasswordLengthTextField);
251:
252: try {
253: ConfigProperty configProp = service.getProperty(url,
254: this .m_sUsername, this .m_sPassword,
255: "PWD_CHANGE_PERIOD");
256: sValue = configProp.getValue();
257: if (sValue == null) {
258: sValue = "60";
259: }
260: } catch (RemoteException e) {
261: e.printStackTrace();
262: } catch (ServiceException e) {
263: e.printStackTrace();
264: }
265:
266: m_passwordChangePreriodLabel = new JLabel(
267: "Period before password change (days)");
268: this .m_passwordChangePreriodLabel.setFont(font);
269: this .add(this .m_passwordChangePreriodLabel);
270: m_passwordChangePreriodTextField = new JTextField(sValue);
271: this .m_passwordChangePreriodTextField.addKeyListener(this );
272: this .m_passwordChangePreriodTextField.setFont(font);
273: this .add(this .m_passwordChangePreriodTextField);
274:
275: try {
276: ConfigProperty configProp = service.getProperty(url,
277: this .m_sUsername, this .m_sPassword,
278: "PWD_FORCE_ALPHA_CHAR");
279: sValue = configProp.getValue();
280: if (sValue == null) {
281: sValue = "FALSE";
282: }
283: } catch (RemoteException e) {
284: e.printStackTrace();
285: } catch (ServiceException e) {
286: e.printStackTrace();
287: }
288:
289: this .m_forcePasswordAlphaLabel = new JLabel(
290: "Force alphabetic character?");
291: this .m_forcePasswordAlphaLabel.setFont(font);
292: this .add(m_forcePasswordAlphaLabel);
293:
294: this .m_forcePasswordAlphaCombo = new JComboBox(new String[] {
295: "TRUE", "FALSE" });
296: this .m_forcePasswordAlphaCombo.setFont(font);
297: this .m_forcePasswordAlphaCombo
298: .setActionCommand("PWD_FORCE_ALPHA_CHAR");
299: if (sValue.equalsIgnoreCase("TRUE")) {
300: this .m_forcePasswordAlphaCombo.setSelectedItem("TRUE");
301: } else {
302: this .m_forcePasswordAlphaCombo.setSelectedItem("FALSE");
303: }
304: this .add(m_forcePasswordAlphaCombo);
305: this .m_forcePasswordAlphaCombo.addActionListener(this );
306:
307: try {
308: ConfigProperty configProp = service.getProperty(url,
309: this .m_sUsername, this .m_sPassword,
310: "PWD_FORCE_NUM_CHAR");
311: sValue = configProp.getValue();
312: if (sValue == null) {
313: sValue = "FALSE";
314: }
315: } catch (RemoteException e) {
316: e.printStackTrace();
317: } catch (ServiceException e) {
318: e.printStackTrace();
319: }
320:
321: this .m_forcePasswordNumericLabel = new JLabel(
322: "Force number character?");
323: this .m_forcePasswordNumericLabel.setFont(font);
324: this .add(m_forcePasswordNumericLabel);
325:
326: this .m_forcePasswordNumericCombo = new JComboBox(new String[] {
327: "TRUE", "FALSE" });
328: this .m_forcePasswordNumericCombo.setFont(font);
329: this .m_forcePasswordNumericCombo
330: .setActionCommand("PWD_FORCE_NUM_CHAR");
331: if (sValue.equalsIgnoreCase("TRUE")) {
332: this .m_forcePasswordNumericCombo.setSelectedItem("TRUE");
333: } else {
334: this .m_forcePasswordNumericCombo.setSelectedItem("FALSE");
335: }
336: this .add(m_forcePasswordNumericCombo);
337: this .m_forcePasswordNumericCombo.addActionListener(this );
338:
339: try {
340: ConfigProperty configProp = service.getProperty(url,
341: this .m_sUsername, this .m_sPassword,
342: "PWD_FORCE_MIX_CASE");
343: sValue = configProp.getValue();
344: if (sValue == null) {
345: sValue = "FALSE";
346: }
347: } catch (RemoteException e) {
348: e.printStackTrace();
349: } catch (ServiceException e) {
350: e.printStackTrace();
351: }
352:
353: this .m_forcePasswordMixedCaseLabel = new JLabel(
354: "Force mixed case?");
355: this .m_forcePasswordMixedCaseLabel.setFont(font);
356: this .add(m_forcePasswordMixedCaseLabel);
357:
358: this .m_forcePasswordMixedCaseCombo = new JComboBox(
359: new String[] { "TRUE", "FALSE" });
360: this .m_forcePasswordMixedCaseCombo.setFont(font);
361: this .m_forcePasswordMixedCaseCombo
362: .setActionCommand("PWD_FORCE_MIX_CASE");
363: if (sValue.equalsIgnoreCase("TRUE")) {
364: this .m_forcePasswordMixedCaseCombo.setSelectedItem("TRUE");
365: } else {
366: this .m_forcePasswordMixedCaseCombo.setSelectedItem("FALSE");
367: }
368: this .add(m_forcePasswordMixedCaseCombo);
369: this .m_forcePasswordMixedCaseCombo.addActionListener(this );
370:
371: try {
372: ConfigProperty configProp = service.getProperty(url,
373: this .m_sUsername, this .m_sPassword,
374: "PWD_RETRY_LIMIT");
375: sValue = configProp.getValue();
376: if (sValue == null) {
377: sValue = "10";
378: }
379: } catch (RemoteException e) {
380: e.printStackTrace();
381: } catch (ServiceException e) {
382: e.printStackTrace();
383: }
384:
385: m_retryLimitLabel = new JLabel("Password retry limit");
386: this .m_retryLimitLabel.setFont(font);
387: this .add(this .m_retryLimitLabel);
388: m_retryLimitTextField = new JTextField(sValue);
389: this .m_retryLimitTextField.addKeyListener(this );
390: this .m_retryLimitTextField.setFont(font);
391: this .add(this .m_retryLimitTextField);
392:
393: try {
394: ConfigProperty configProp = service.getProperty(url,
395: this .m_sUsername, this .m_sPassword,
396: "PWD_HIST_CHECK_SIZE");
397: sValue = configProp.getValue();
398: if (sValue == null) {
399: sValue = "10";
400: }
401: } catch (RemoteException e) {
402: e.printStackTrace();
403: } catch (ServiceException e) {
404: e.printStackTrace();
405: }
406:
407: m_pwdHistCheckSizeLabel = new JLabel(
408: "Password history check size");
409: this .m_pwdHistCheckSizeLabel.setFont(font);
410: this .add(this .m_pwdHistCheckSizeLabel);
411: m_pwdHistCheckSizeTextField = new JTextField(sValue);
412: this .m_pwdHistCheckSizeTextField.addKeyListener(this );
413: this .m_pwdHistCheckSizeTextField.setFont(font);
414: this .add(this .m_pwdHistCheckSizeTextField);
415:
416: }
417:
418: /* (non-Javadoc)
419: * @see java.awt.Component#getPreferredSize()
420: */
421: public Dimension getPreferredSize() {
422: return new Dimension(this .getParent().getSize().width - 50, 100);
423: }
424:
425: /* (non-Javadoc)
426: * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
427: */
428: public void layoutContainer(Container arg0) {
429:
430: int nHeight = 20;
431:
432: this .m_descriptionTextArea.setSize(350, 30);
433: this .m_descriptionTextArea.setLocation(20, nHeight);
434: nHeight = nHeight + this .m_descriptionTextArea.getSize().height
435: + 20;
436:
437: this .m_minPasswordLengthLabel
438: .setSize(this .m_minPasswordLengthLabel
439: .getPreferredSize());
440: this .m_minPasswordLengthLabel.setLocation(20, nHeight);
441: this .m_minPasswordLengthTextField.setSize(100, 20);
442: this .m_minPasswordLengthTextField.setLocation(250, nHeight);
443: nHeight = nHeight
444: + this .m_minPasswordLengthLabel.getSize().height + 20;
445:
446: this .m_passwordChangePreriodLabel
447: .setSize(this .m_passwordChangePreriodLabel
448: .getPreferredSize());
449: this .m_passwordChangePreriodLabel.setLocation(20, nHeight);
450: this .m_passwordChangePreriodTextField.setSize(100, 20);
451: this .m_passwordChangePreriodTextField.setLocation(250, nHeight);
452: nHeight = nHeight
453: + this .m_passwordChangePreriodLabel.getSize().height
454: + 20;
455:
456: this .m_forcePasswordAlphaLabel
457: .setSize(this .m_forcePasswordAlphaLabel
458: .getPreferredSize());
459: this .m_forcePasswordAlphaLabel.setLocation(20, nHeight);
460: this .m_forcePasswordAlphaCombo.setSize(100, 20);
461: this .m_forcePasswordAlphaCombo.setLocation(250, nHeight);
462: nHeight = nHeight
463: + this .m_forcePasswordAlphaLabel.getSize().height + 20;
464:
465: this .m_forcePasswordNumericLabel
466: .setSize(this .m_forcePasswordNumericLabel
467: .getPreferredSize());
468: this .m_forcePasswordNumericLabel.setLocation(20, nHeight);
469: this .m_forcePasswordNumericCombo.setSize(100, 20);
470: this .m_forcePasswordNumericCombo.setLocation(250, nHeight);
471: nHeight = nHeight
472: + this .m_forcePasswordNumericLabel.getSize().height
473: + 20;
474:
475: this .m_forcePasswordMixedCaseLabel
476: .setSize(this .m_forcePasswordMixedCaseLabel
477: .getPreferredSize());
478: this .m_forcePasswordMixedCaseLabel.setLocation(20, nHeight);
479: this .m_forcePasswordMixedCaseCombo.setSize(100, 20);
480: this .m_forcePasswordMixedCaseCombo.setLocation(250, nHeight);
481: nHeight = nHeight
482: + this .m_forcePasswordMixedCaseLabel.getSize().height
483: + 20;
484:
485: this .m_retryLimitLabel.setSize(this .m_retryLimitLabel
486: .getPreferredSize());
487: this .m_retryLimitLabel.setLocation(20, nHeight);
488: this .m_retryLimitTextField.setSize(100, 20);
489: this .m_retryLimitTextField.setLocation(250, nHeight);
490: nHeight = nHeight + this .m_retryLimitLabel.getSize().height
491: + 20;
492:
493: this .m_pwdHistCheckSizeLabel
494: .setSize(this .m_pwdHistCheckSizeLabel
495: .getPreferredSize());
496: this .m_pwdHistCheckSizeLabel.setLocation(20, nHeight);
497: this .m_pwdHistCheckSizeTextField.setSize(100, 20);
498: this .m_pwdHistCheckSizeTextField.setLocation(250, nHeight);
499: }
500:
501: /* (non-Javadoc)
502: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
503: */
504: public Dimension minimumLayoutSize(Container arg0) {
505: return null;
506: }
507:
508: /* (non-Javadoc)
509: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
510: */
511: public Dimension preferredLayoutSize(Container arg0) {
512: return null;
513: }
514:
515: /* (non-Javadoc)
516: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
517: */
518: public void actionPerformed(ActionEvent ae) {
519: if (ae.getActionCommand().equals("PWD_FORCE_ALPHA_CHAR")) {
520: this .m_bforcePasswordAlphaChanged = true;
521: } else if (ae.getActionCommand().equals("PWD_FORCE_NUM_CHAR")) {
522: this .m_bforcePasswordNumericChanged = true;
523: } else if (ae.getActionCommand().equals("PWD_FORCE_MIX_CASE")) {
524: this .m_bforcePasswordMixedCaseChanged = true;
525: }
526: this .fireChangesMade();
527: }
528:
529: /* (non-Javadoc)
530: * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
531: */
532: public void keyReleased(KeyEvent ke) {
533: if (ke.getSource() == this .m_minPasswordLengthTextField) {
534: this .m_bminPasswordLengthChanged = true;
535: } else if (ke.getSource() == this .m_passwordChangePreriodTextField) {
536: this .m_bpasswordChangePreriodChanged = true;
537: } else if (ke.getSource() == this .m_retryLimitTextField) {
538: this .m_bretryLimitChanged = true;
539: } else if (ke.getSource() == this .m_pwdHistCheckSizeTextField) {
540: this .m_bpwdHistCheckSizeChanged = true;
541: }
542: this .fireChangesMade();
543: }
544:
545: /* (non-Javadoc)
546: * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#applyChanges()
547: */
548: public boolean applyChanges() {
549: boolean bOk = true;
550: ConfigSettingsClient service = new ConfigSettingsClient();
551: URL url = null;
552: try {
553: URI uri = ServerList.getInstance().getHarmoniseServer()
554: .getURI();
555: String sURL = uri.getScheme() + "://" + uri.getHost() + ":"
556: + uri.getPort() + "/webdav/services/ConfigService";
557: url = new URL(sURL);
558:
559: } catch (MalformedURLException e) {
560: e.printStackTrace();
561: }
562: try {
563: if (this .m_bminPasswordLengthChanged) {
564: service.setProperty(url, m_sUsername, m_sPassword,
565: new ConfigProperty("PWD_MIN_LENGTH",
566: this .m_minPasswordLengthTextField
567: .getText()));
568: this .m_bminPasswordLengthChanged = false;
569: }
570: if (this .m_bpasswordChangePreriodChanged) {
571: service.setProperty(url, m_sUsername, m_sPassword,
572: new ConfigProperty("PWD_CHANGE_PERIOD",
573: this .m_passwordChangePreriodTextField
574: .getText()));
575: this .m_bpasswordChangePreriodChanged = false;
576: }
577: if (this .m_bforcePasswordAlphaChanged) {
578: service.setProperty(url, m_sUsername, m_sPassword,
579: new ConfigProperty("PWD_FORCE_ALPHA_CHAR",
580: (String) this .m_forcePasswordAlphaCombo
581: .getSelectedItem()));
582: this .m_bforcePasswordAlphaChanged = false;
583: }
584: if (this .m_bforcePasswordNumericChanged) {
585: service
586: .setProperty(
587: url,
588: m_sUsername,
589: m_sPassword,
590: new ConfigProperty(
591: "PWD_FORCE_NUM_CHAR",
592: (String) this .m_forcePasswordNumericCombo
593: .getSelectedItem()));
594: this .m_bforcePasswordNumericChanged = false;
595: }
596: if (this .m_bforcePasswordMixedCaseChanged) {
597: service
598: .setProperty(
599: url,
600: m_sUsername,
601: m_sPassword,
602: new ConfigProperty(
603: "PWD_FORCE_MIX_CASE",
604: (String) this .m_forcePasswordMixedCaseCombo
605: .getSelectedItem()));
606: this .m_bforcePasswordMixedCaseChanged = false;
607: }
608: if (this .m_bretryLimitChanged) {
609: service.setProperty(url, m_sUsername, m_sPassword,
610: new ConfigProperty("PWD_RETRY_LIMIT",
611: this .m_retryLimitTextField.getText()));
612: this .m_bretryLimitChanged = false;
613: }
614: if (this .m_bpwdHistCheckSizeChanged) {
615: service.setProperty(url, m_sUsername, m_sPassword,
616: new ConfigProperty("PWD_HIST_CHECK_SIZE",
617: this .m_pwdHistCheckSizeTextField
618: .getText()));
619: this .m_bpwdHistCheckSizeChanged = false;
620: }
621: } catch (Exception e) {
622: e.printStackTrace();
623: bOk = false;
624: }
625: return bOk;
626: }
627:
628: /* (non-Javadoc)
629: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
630: */
631: public void removeLayoutComponent(Component arg0) {
632: }
633:
634: /* (non-Javadoc)
635: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
636: */
637: public void addLayoutComponent(String arg0, Component arg1) {
638: }
639:
640: /* (non-Javadoc)
641: * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
642: */
643: public void keyPressed(KeyEvent arg0) {
644: }
645:
646: /* (non-Javadoc)
647: * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
648: */
649: public void keyTyped(KeyEvent arg0) {
650: }
651:
652: /* (non-Javadoc)
653: * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#discardChanges()
654: */
655: public void discardChanges() {
656: }
657:
658: }
|