1 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 44 public class SecurityServerConfigOptions 45 extends AbstractServerConfigOptions 46 implements LayoutManager, ActionListener, ApplyChangesListener, KeyListener { 47 48 51 private JTextArea m_descriptionTextArea = null; 52 53 56 private JLabel m_minPasswordLengthLabel = null; 57 58 61 private JTextField m_minPasswordLengthTextField = null; 62 63 66 private boolean m_bminPasswordLengthChanged = false; 67 68 71 private JLabel m_passwordChangePreriodLabel = null; 72 73 76 private JTextField m_passwordChangePreriodTextField = null; 77 78 81 private boolean m_bpasswordChangePreriodChanged = false; 82 83 86 private JLabel m_forcePasswordAlphaLabel = null; 87 88 91 private JComboBox m_forcePasswordAlphaCombo = null; 92 93 96 private boolean m_bforcePasswordAlphaChanged = false; 97 98 101 private JLabel m_forcePasswordNumericLabel = null; 102 103 106 private JComboBox m_forcePasswordNumericCombo = null; 107 108 111 private boolean m_bforcePasswordNumericChanged = false; 112 113 116 private JLabel m_forcePasswordMixedCaseLabel = null; 117 118 121 private JComboBox m_forcePasswordMixedCaseCombo = null; 122 123 126 private boolean m_bforcePasswordMixedCaseChanged = false; 127 128 131 private JLabel m_retryLimitLabel = null; 132 133 136 private JTextField m_retryLimitTextField = null; 137 138 141 private boolean m_bretryLimitChanged = false; 142 143 146 private JLabel m_pwdHistCheckSizeLabel = null; 147 148 151 private JTextField m_pwdHistCheckSizeTextField = null; 152 153 156 private boolean m_bpwdHistCheckSizeChanged = false; 157 158 161 private String m_sUsername = null; 162 163 166 private String m_sPassword = null; 167 168 172 public SecurityServerConfigOptions() { 173 super(null); 174 this.setup(); 175 } 176 177 182 public SecurityServerConfigOptions(ServerConfigDialog dialog) { 183 super(dialog); 184 dialog.addApplyChangesListener(this); 185 this.setup(); 186 } 187 188 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 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 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 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 []{"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 []{"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 []{"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 389 public Dimension getPreferredSize() { 390 return new Dimension(this.getParent().getSize().width-50, 100); 391 } 392 393 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 449 public Dimension minimumLayoutSize(Container arg0) { 450 return null; 451 } 452 453 456 public Dimension preferredLayoutSize(Container arg0) { 457 return null; 458 } 459 460 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 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 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 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 ) 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 ) 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 ) 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 e) { 535 e.printStackTrace(); 536 bOk = false; 537 } 538 return bOk; 539 } 540 541 544 public void removeLayoutComponent(Component arg0) { 545 } 546 547 550 public void addLayoutComponent(String arg0, Component arg1) { 551 } 552 553 556 public void keyPressed(KeyEvent arg0) { 557 } 558 559 562 public void keyTyped(KeyEvent arg0) { 563 } 564 565 568 public void discardChanges() { 569 } 570 571 } 572 | Popular Tags |