KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > serverconfig > security > SecurityServerConfigOptions


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.serverconfig.security;
20
21 import java.awt.*;
22 import java.awt.event.*;
23 import java.net.*;
24 import java.rmi.*;
25
26 import javax.swing.*;
27 import javax.xml.rpc.*;
28
29 import org.openharmonise.him.*;
30 import org.openharmonise.him.configuration.*;
31 import org.openharmonise.him.harmonise.*;
32 import org.openharmonise.him.serverconfig.*;
33 import org.openharmonise.vfs.servers.ServerList;
34
35
36 /**
37  * Panel for configuring the security options of a Harmonise Information
38  * Server.
39  *
40  * @author Matthew Large
41  * @version $Revision: 1.1 $
42  *
43  */

44 public class SecurityServerConfigOptions
45     extends AbstractServerConfigOptions
46     implements LayoutManager, ActionListener, ApplyChangesListener, KeyListener {
47         
48         /**
49          * Description.
50          */

51         private JTextArea m_descriptionTextArea = null;
52         
53         /**
54          * Minimum password length option label.
55          */

56         private JLabel m_minPasswordLengthLabel = null;
57         
58         /**
59          * Minimum password length option text field.
60          */

61         private JTextField m_minPasswordLengthTextField = null;
62         
63         /**
64          * true if the minimum password length option has changed.
65          */

66         private boolean m_bminPasswordLengthChanged = false;
67         
68         /**
69          * Password change period option label.
70          */

71         private JLabel m_passwordChangePreriodLabel = null;
72         
73         /**
74          * Password change period option text field.
75          */

76         private JTextField m_passwordChangePreriodTextField = null;
77         
78         /**
79          * true if the password change period option has changed.
80          */

81         private boolean m_bpasswordChangePreriodChanged = false;
82         
83         /**
84          * Force alphabetical characters option label.
85          */

86         private JLabel m_forcePasswordAlphaLabel = null;
87         
88         /**
89          * Force alphabetical characters option drop down.
90          */

91         private JComboBox m_forcePasswordAlphaCombo = null;
92         
93         /**
94          * true if the force alphabetical characters option has changed.
95          */

96         private boolean m_bforcePasswordAlphaChanged = false;
97         
98         /**
99          * Force numerical characters option label.
100          */

101         private JLabel m_forcePasswordNumericLabel = null;
102         
103         /**
104          * Force numerical characters option drop down.
105          */

106         private JComboBox m_forcePasswordNumericCombo = null;
107         
108         /**
109          * true if the force numerical characters option has changed.
110          */

111         private boolean m_bforcePasswordNumericChanged = false;
112         
113         /**
114          * Force mixed case characters option label.
115          */

116         private JLabel m_forcePasswordMixedCaseLabel = null;
117         
118         /**
119          * Force mixed case characters option drop down.
120          */

121         private JComboBox m_forcePasswordMixedCaseCombo = null;
122         
123         /**
124          * true if the force mixed case characters option has changed.
125          */

126         private boolean m_bforcePasswordMixedCaseChanged = false;
127         
128         /**
129          * Retry limit option label.
130          */

131         private JLabel m_retryLimitLabel = null;
132         
133         /**
134          * Retry limit option text field.
135          */

136         private JTextField m_retryLimitTextField = null;
137         
138         /**
139          * true if the retry limit option has changed.
140          */

141         private boolean m_bretryLimitChanged = false;
142         
143         /**
144          * Password history check size option label.
145          */

146         private JLabel m_pwdHistCheckSizeLabel = null;
147         
148         /**
149          * Password history check size option text field.
150          */

151         private JTextField m_pwdHistCheckSizeTextField = null;
152         
153         /**
154          * true if the password history check size option has changed.
155          */

156         private boolean m_bpwdHistCheckSizeChanged = false;
157         
158         /**
159          * Username for the current user.
160          */

161         private String JavaDoc m_sUsername = null;
162         
163         /**
164          * Password for the current user.
165          */

166         private String JavaDoc m_sPassword = null;
167
168         /**
169          * Constructs a new security configuration options panel.
170          *
171          */

172         public SecurityServerConfigOptions() {
173             super(null);
174             this.setup();
175         }
176
177         /**
178          * Constructs a new security configuration options panel.
179          *
180          * @param dialog configuration dialog that this panel will be in.
181          */

182         public SecurityServerConfigOptions(ServerConfigDialog dialog) {
183             super(dialog);
184             dialog.addApplyChangesListener(this);
185             this.setup();
186         }
187         
188         /**
189          * Initialises this component.
190          *
191          */

192         private void setup() {
193             this.setLayout(this);
194             
195             this.m_sUsername = ServerList.getInstance().getHarmoniseServer().getVFS().getAuthentication().getUsername();
196             this.m_sPassword = ServerList.getInstance().getHarmoniseServer().getVFS().getAuthentication().getPassword();
197
198             String JavaDoc fontName = "Dialog";
199             int fontSize = 11;
200             Font font = new Font(fontName, Font.PLAIN, fontSize);
201             
202             this.m_descriptionTextArea = new JTextArea("Use the list below to configure the password policy for the registered users of the Harmonise Server.");
203             this.m_descriptionTextArea.setEditable(false);
204             this.m_descriptionTextArea.setBorder(BorderFactory.createEmptyBorder());
205             this.m_descriptionTextArea.setWrapStyleWord(true);
206             this.m_descriptionTextArea.setLineWrap(true);
207             this.m_descriptionTextArea.setOpaque(false);
208             this.add(m_descriptionTextArea);
209             
210             ConfigSettingsClient service = new ConfigSettingsClient();
211             URL url = null;
212             try {
213                 URI uri = ServerList.getInstance().getHarmoniseServer().getURI();
214                 String JavaDoc sURL = uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort() + "/webdav/services/ConfigService";
215                 url = new URL(sURL);
216                 
217             } catch (MalformedURLException e) {
218                 e.printStackTrace();
219             }
220         
221             String JavaDoc sValue = null;
222         
223             try {
224                 ConfigProperty configProp = service.getProperty(url, this.m_sUsername, this.m_sPassword, "PWD_MIN_LENGTH");
225                 sValue = configProp.getValue();
226                 if(sValue==null) {
227                     sValue = "100";
228                 }
229             } catch (RemoteException e) {
230                 e.printStackTrace();
231             } catch (ServiceException e) {
232                 e.printStackTrace();
233             }
234         
235             m_minPasswordLengthLabel = new JLabel("Minimum password length");
236             this.m_minPasswordLengthLabel.setFont(font);
237             this.add(this.m_minPasswordLengthLabel);
238             m_minPasswordLengthTextField = new JTextField(sValue);
239             this.m_minPasswordLengthTextField.addKeyListener(this);
240             this.m_minPasswordLengthTextField.setFont(font);
241             this.add(this.m_minPasswordLengthTextField);
242         
243             try {
244                 ConfigProperty configProp = service.getProperty(url, this.m_sUsername, this.m_sPassword, "PWD_CHANGE_PERIOD");
245                 sValue = configProp.getValue();
246                 if(sValue==null) {
247                     sValue = "60";
248                 }
249             } catch (RemoteException e) {
250                 e.printStackTrace();
251             } catch (ServiceException e) {
252                 e.printStackTrace();
253             }
254         
255             m_passwordChangePreriodLabel = new JLabel("Period before password change (days)");
256             this.m_passwordChangePreriodLabel.setFont(font);
257             this.add(this.m_passwordChangePreriodLabel);
258             m_passwordChangePreriodTextField = new JTextField(sValue);
259             this.m_passwordChangePreriodTextField.addKeyListener(this);
260             this.m_passwordChangePreriodTextField.setFont(font);
261             this.add(this.m_passwordChangePreriodTextField);
262         
263             try {
264                 ConfigProperty configProp = service.getProperty(url, this.m_sUsername, this.m_sPassword, "PWD_FORCE_ALPHA_CHAR");
265                 sValue = configProp.getValue();
266                 if(sValue==null) {
267                     sValue = "FALSE";
268                 }
269             } catch (RemoteException e) {
270                 e.printStackTrace();
271             } catch (ServiceException e) {
272                 e.printStackTrace();
273             }
274         
275             this.m_forcePasswordAlphaLabel = new JLabel("Force alphabetic character?");
276             this.m_forcePasswordAlphaLabel.setFont(font);
277             this.add(m_forcePasswordAlphaLabel);
278         
279             this.m_forcePasswordAlphaCombo = new JComboBox(new String JavaDoc[]{"TRUE", "FALSE"});
280             this.m_forcePasswordAlphaCombo.setFont(font);
281             this.m_forcePasswordAlphaCombo.setActionCommand("PWD_FORCE_ALPHA_CHAR");
282             if(sValue.equalsIgnoreCase("TRUE")) {
283                 this.m_forcePasswordAlphaCombo.setSelectedItem("TRUE");
284             } else {
285                 this.m_forcePasswordAlphaCombo.setSelectedItem("FALSE");
286             }
287             this.add(m_forcePasswordAlphaCombo);
288             this.m_forcePasswordAlphaCombo.addActionListener(this);
289         
290             try {
291                 ConfigProperty configProp = service.getProperty(url, this.m_sUsername, this.m_sPassword, "PWD_FORCE_NUM_CHAR");
292                 sValue = configProp.getValue();
293                 if(sValue==null) {
294                     sValue = "FALSE";
295                 }
296             } catch (RemoteException e) {
297                 e.printStackTrace();
298             } catch (ServiceException e) {
299                 e.printStackTrace();
300             }
301         
302             this.m_forcePasswordNumericLabel = new JLabel("Force number character?");
303             this.m_forcePasswordNumericLabel.setFont(font);
304             this.add(m_forcePasswordNumericLabel);
305         
306             this.m_forcePasswordNumericCombo = new JComboBox(new String JavaDoc[]{"TRUE", "FALSE"});
307             this.m_forcePasswordNumericCombo.setFont(font);
308             this.m_forcePasswordNumericCombo.setActionCommand("PWD_FORCE_NUM_CHAR");
309             if(sValue.equalsIgnoreCase("TRUE")) {
310                 this.m_forcePasswordNumericCombo.setSelectedItem("TRUE");
311             } else {
312                 this.m_forcePasswordNumericCombo.setSelectedItem("FALSE");
313             }
314             this.add(m_forcePasswordNumericCombo);
315             this.m_forcePasswordNumericCombo.addActionListener(this);
316         
317             try {
318                 ConfigProperty configProp = service.getProperty(url, this.m_sUsername, this.m_sPassword, "PWD_FORCE_MIX_CASE");
319                 sValue = configProp.getValue();
320                 if(sValue==null) {
321                     sValue = "FALSE";
322                 }
323             } catch (RemoteException e) {
324                 e.printStackTrace();
325             } catch (ServiceException e) {
326                 e.printStackTrace();
327             }
328         
329             this.m_forcePasswordMixedCaseLabel = new JLabel("Force mixed case?");
330             this.m_forcePasswordMixedCaseLabel.setFont(font);
331             this.add(m_forcePasswordMixedCaseLabel);
332         
333             this.m_forcePasswordMixedCaseCombo = new JComboBox(new String JavaDoc[]{"TRUE", "FALSE"});
334             this.m_forcePasswordMixedCaseCombo.setFont(font);
335             this.m_forcePasswordMixedCaseCombo.setActionCommand("PWD_FORCE_MIX_CASE");
336             if(sValue.equalsIgnoreCase("TRUE")) {
337                 this.m_forcePasswordMixedCaseCombo.setSelectedItem("TRUE");
338             } else {
339                 this.m_forcePasswordMixedCaseCombo.setSelectedItem("FALSE");
340             }
341             this.add(m_forcePasswordMixedCaseCombo);
342             this.m_forcePasswordMixedCaseCombo.addActionListener(this);
343         
344             try {
345                 ConfigProperty configProp = service.getProperty(url, this.m_sUsername, this.m_sPassword, "PWD_RETRY_LIMIT");
346                 sValue = configProp.getValue();
347                 if(sValue==null) {
348                     sValue = "10";
349                 }
350             } catch (RemoteException e) {
351                 e.printStackTrace();
352             } catch (ServiceException e) {
353                 e.printStackTrace();
354             }
355         
356             m_retryLimitLabel = new JLabel("Password retry limit");
357             this.m_retryLimitLabel.setFont(font);
358             this.add(this.m_retryLimitLabel);
359             m_retryLimitTextField = new JTextField(sValue);
360             this.m_retryLimitTextField.addKeyListener(this);
361             this.m_retryLimitTextField.setFont(font);
362             this.add(this.m_retryLimitTextField);
363             
364             try {
365                 ConfigProperty configProp = service.getProperty(url, this.m_sUsername, this.m_sPassword, "PWD_HIST_CHECK_SIZE");
366                 sValue = configProp.getValue();
367                 if(sValue==null) {
368                     sValue = "10";
369                 }
370             } catch (RemoteException e) {
371                 e.printStackTrace();
372             } catch (ServiceException e) {
373                 e.printStackTrace();
374             }
375         
376             m_pwdHistCheckSizeLabel = new JLabel("Password history check size");
377             this.m_pwdHistCheckSizeLabel.setFont(font);
378             this.add(this.m_pwdHistCheckSizeLabel);
379             m_pwdHistCheckSizeTextField = new JTextField(sValue);
380             this.m_pwdHistCheckSizeTextField.addKeyListener(this);
381             this.m_pwdHistCheckSizeTextField.setFont(font);
382             this.add(this.m_pwdHistCheckSizeTextField);
383         
384         }
385
386         /* (non-Javadoc)
387          * @see java.awt.Component#getPreferredSize()
388          */

389         public Dimension getPreferredSize() {
390             return new Dimension(this.getParent().getSize().width-50, 100);
391         }
392
393         /* (non-Javadoc)
394          * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
395          */

396         public void layoutContainer(Container arg0) {
397             
398             int nHeight = 20;
399             
400             this.m_descriptionTextArea.setSize(350, 30);
401             this.m_descriptionTextArea.setLocation(20, nHeight);
402             nHeight = nHeight + this.m_descriptionTextArea.getSize().height + 20;
403             
404             this.m_minPasswordLengthLabel.setSize(this.m_minPasswordLengthLabel.getPreferredSize());
405             this.m_minPasswordLengthLabel.setLocation(20, nHeight);
406             this.m_minPasswordLengthTextField.setSize(100, 20);
407             this.m_minPasswordLengthTextField.setLocation(250, nHeight);
408             nHeight = nHeight + this.m_minPasswordLengthLabel.getSize().height + 20;
409         
410             this.m_passwordChangePreriodLabel.setSize(this.m_passwordChangePreriodLabel.getPreferredSize());
411             this.m_passwordChangePreriodLabel.setLocation(20, nHeight);
412             this.m_passwordChangePreriodTextField.setSize(100, 20);
413             this.m_passwordChangePreriodTextField.setLocation(250, nHeight);
414             nHeight = nHeight + this.m_passwordChangePreriodLabel.getSize().height + 20;
415         
416             this.m_forcePasswordAlphaLabel.setSize(this.m_forcePasswordAlphaLabel.getPreferredSize());
417             this.m_forcePasswordAlphaLabel.setLocation(20, nHeight);
418             this.m_forcePasswordAlphaCombo.setSize(100, 20);
419             this.m_forcePasswordAlphaCombo.setLocation(250, nHeight);
420             nHeight = nHeight + this.m_forcePasswordAlphaLabel.getSize().height + 20;
421         
422             this.m_forcePasswordNumericLabel.setSize(this.m_forcePasswordNumericLabel.getPreferredSize());
423             this.m_forcePasswordNumericLabel.setLocation(20, nHeight);
424             this.m_forcePasswordNumericCombo.setSize(100, 20);
425             this.m_forcePasswordNumericCombo.setLocation(250, nHeight);
426             nHeight = nHeight + this.m_forcePasswordNumericLabel.getSize().height + 20;
427         
428             this.m_forcePasswordMixedCaseLabel.setSize(this.m_forcePasswordMixedCaseLabel.getPreferredSize());
429             this.m_forcePasswordMixedCaseLabel.setLocation(20, nHeight);
430             this.m_forcePasswordMixedCaseCombo.setSize(100, 20);
431             this.m_forcePasswordMixedCaseCombo.setLocation(250, nHeight);
432             nHeight = nHeight + this.m_forcePasswordMixedCaseLabel.getSize().height + 20;
433         
434             this.m_retryLimitLabel.setSize(this.m_retryLimitLabel.getPreferredSize());
435             this.m_retryLimitLabel.setLocation(20, nHeight);
436             this.m_retryLimitTextField.setSize(100, 20);
437             this.m_retryLimitTextField.setLocation(250, nHeight);
438             nHeight = nHeight + this.m_retryLimitLabel.getSize().height + 20;
439             
440             this.m_pwdHistCheckSizeLabel.setSize(this.m_pwdHistCheckSizeLabel.getPreferredSize());
441             this.m_pwdHistCheckSizeLabel.setLocation(20, nHeight);
442             this.m_pwdHistCheckSizeTextField.setSize(100, 20);
443             this.m_pwdHistCheckSizeTextField.setLocation(250, nHeight);
444         }
445
446         /* (non-Javadoc)
447          * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
448          */

449         public Dimension minimumLayoutSize(Container arg0) {
450             return null;
451         }
452
453         /* (non-Javadoc)
454          * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
455          */

456         public Dimension preferredLayoutSize(Container arg0) {
457             return null;
458         }
459
460         /* (non-Javadoc)
461          * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
462          */

463         public void actionPerformed(ActionEvent ae) {
464             if(ae.getActionCommand().equals("PWD_FORCE_ALPHA_CHAR")) {
465                 this.m_bforcePasswordAlphaChanged = true;
466             } else if(ae.getActionCommand().equals("PWD_FORCE_NUM_CHAR")) {
467                 this.m_bforcePasswordNumericChanged = true;
468             } else if(ae.getActionCommand().equals("PWD_FORCE_MIX_CASE")) {
469                 this.m_bforcePasswordMixedCaseChanged = true;
470             }
471             this.fireChangesMade();
472         }
473
474         /* (non-Javadoc)
475          * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
476          */

477         public void keyReleased(KeyEvent ke) {
478             if(ke.getSource()==this.m_minPasswordLengthTextField) {
479                 this.m_bminPasswordLengthChanged = true;
480             } else if(ke.getSource()==this.m_passwordChangePreriodTextField) {
481                 this.m_bpasswordChangePreriodChanged = true;
482             } else if(ke.getSource()==this.m_retryLimitTextField) {
483                 this.m_bretryLimitChanged = true;
484             } else if(ke.getSource()==this.m_pwdHistCheckSizeTextField) {
485                 this.m_bpwdHistCheckSizeChanged = true;
486             }
487             this.fireChangesMade();
488         }
489
490         /* (non-Javadoc)
491          * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#applyChanges()
492          */

493         public boolean applyChanges() {
494             boolean bOk = true;
495             ConfigSettingsClient service = new ConfigSettingsClient();
496             URL url = null;
497             try {
498                 URI uri = ServerList.getInstance().getHarmoniseServer().getURI();
499                 String JavaDoc sURL = uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort() + "/webdav/services/ConfigService";
500                 url = new URL(sURL);
501                 
502             } catch (MalformedURLException e) {
503                 e.printStackTrace();
504             }
505             try {
506                 if(this.m_bminPasswordLengthChanged) {
507                     service.setProperty(url, m_sUsername, m_sPassword, new ConfigProperty("PWD_MIN_LENGTH", this.m_minPasswordLengthTextField.getText()));
508                     this.m_bminPasswordLengthChanged=false;
509                 }
510                 if(this.m_bpasswordChangePreriodChanged) {
511                     service.setProperty(url, m_sUsername, m_sPassword, new ConfigProperty("PWD_CHANGE_PERIOD", this.m_passwordChangePreriodTextField.getText()));
512                     this.m_bpasswordChangePreriodChanged=false;
513                 }
514                 if(this.m_bforcePasswordAlphaChanged) {
515                     service.setProperty(url, m_sUsername, m_sPassword, new ConfigProperty("PWD_FORCE_ALPHA_CHAR", (String JavaDoc) this.m_forcePasswordAlphaCombo.getSelectedItem()));
516                     this.m_bforcePasswordAlphaChanged=false;
517                 }
518                 if(this.m_bforcePasswordNumericChanged) {
519                     service.setProperty(url, m_sUsername, m_sPassword, new ConfigProperty("PWD_FORCE_NUM_CHAR", (String JavaDoc) this.m_forcePasswordNumericCombo.getSelectedItem()));
520                     this.m_bforcePasswordNumericChanged=false;
521                 }
522                 if(this.m_bforcePasswordMixedCaseChanged) {
523                     service.setProperty(url, m_sUsername, m_sPassword, new ConfigProperty("PWD_FORCE_MIX_CASE", (String JavaDoc) this.m_forcePasswordMixedCaseCombo.getSelectedItem()));
524                     this.m_bforcePasswordMixedCaseChanged=false;
525                 }
526                 if(this.m_bretryLimitChanged) {
527                     service.setProperty(url, m_sUsername, m_sPassword, new ConfigProperty("PWD_RETRY_LIMIT", this.m_retryLimitTextField.getText()));
528                     this.m_bretryLimitChanged=false;
529                 }
530                 if(this.m_bpwdHistCheckSizeChanged) {
531                     service.setProperty(url, m_sUsername, m_sPassword, new ConfigProperty("PWD_HIST_CHECK_SIZE", this.m_pwdHistCheckSizeTextField.getText()));
532                     this.m_bpwdHistCheckSizeChanged=false;
533                 }
534             } catch (Exception JavaDoc e) {
535                 e.printStackTrace();
536                 bOk = false;
537             }
538             return bOk;
539         }
540
541         /* (non-Javadoc)
542          * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
543          */

544         public void removeLayoutComponent(Component arg0) {
545         }
546
547         /* (non-Javadoc)
548          * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
549          */

550         public void addLayoutComponent(String JavaDoc arg0, Component arg1) {
551         }
552
553         /* (non-Javadoc)
554          * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
555          */

556         public void keyPressed(KeyEvent arg0) {
557         }
558
559         /* (non-Javadoc)
560          * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
561          */

562         public void keyTyped(KeyEvent arg0) {
563         }
564
565         /* (non-Javadoc)
566          * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#discardChanges()
567          */

568         public void discardChanges() {
569         }
570
571     }
572
Popular Tags