1 20 21 package org.apache.directory.ldapstudio.browser.common.widgets.connection; 22 23 24 import java.util.ArrayList ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 28 import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants; 29 import org.apache.directory.ldapstudio.browser.common.jobs.RunnableContextJobAdapter; 30 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils; 31 import org.apache.directory.ldapstudio.browser.common.widgets.HistoryUtils; 32 import org.apache.directory.ldapstudio.browser.common.widgets.search.AliasesDereferencingWidget; 33 import org.apache.directory.ldapstudio.browser.common.widgets.search.LimitWidget; 34 import org.apache.directory.ldapstudio.browser.common.widgets.search.ReferralsHandlingWidget; 35 import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin; 36 import org.apache.directory.ldapstudio.browser.core.internal.model.Connection; 37 import org.apache.directory.ldapstudio.browser.core.jobs.CheckBindJob; 38 import org.apache.directory.ldapstudio.browser.core.jobs.CheckNetworkParameterJob; 39 import org.apache.directory.ldapstudio.browser.core.jobs.FetchBaseDNsJob; 40 import org.apache.directory.ldapstudio.browser.core.model.DN; 41 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 42 import org.apache.directory.ldapstudio.browser.core.model.NameException; 43 import org.eclipse.jface.dialogs.MessageDialog; 44 import org.eclipse.jface.operation.IRunnableContext; 45 import org.eclipse.swt.SWT; 46 import org.eclipse.swt.events.ModifyEvent; 47 import org.eclipse.swt.events.ModifyListener; 48 import org.eclipse.swt.events.SelectionEvent; 49 import org.eclipse.swt.events.SelectionListener; 50 import org.eclipse.swt.events.VerifyEvent; 51 import org.eclipse.swt.events.VerifyListener; 52 import org.eclipse.swt.layout.GridData; 53 import org.eclipse.swt.widgets.Button; 54 import org.eclipse.swt.widgets.Combo; 55 import org.eclipse.swt.widgets.Composite; 56 import org.eclipse.swt.widgets.Display; 57 import org.eclipse.swt.widgets.Group; 58 import org.eclipse.swt.widgets.Text; 59 60 61 70 public class ConnectionPageWrapper implements ModifyListener, SelectionListener 71 { 72 73 74 private Text nameText; 75 76 77 private Combo hostCombo; 78 79 80 private Text hostText; 81 82 83 private Combo portCombo; 84 85 86 private Text portText; 87 88 89 private Combo encryptionMethodCombo; 90 91 92 private Button checkConnectionButton; 93 94 95 private Button autoFetchBaseDnsButton; 96 97 98 private Button fetchBaseDnsButton; 99 100 101 private Combo baseDNCombo; 102 103 104 private LimitWidget limitWidget; 105 106 107 private AliasesDereferencingWidget aliasesDereferencingWidget; 108 109 110 private ReferralsHandlingWidget referralsHandlingWidget; 111 112 113 private Button openConnectionButton; 114 115 116 private Button anonymousAuthButton; 117 118 119 private Button simpleAuthButton; 120 121 122 private Combo simpleAuthBindPrincipalCombo; 123 124 125 private Text simpleAuthBindPrincipalText; 126 127 128 private Text simpleAuthBindPasswordText; 129 130 131 private Button saveSimpleAuthBindPasswordButton; 132 133 134 private Button checkSimpleAuthButton; 135 136 137 private List <ConnectionPageModifyListener> listenerList; 138 139 143 private boolean isConnectionOpened; 144 145 146 private IRunnableContext runnableContext; 147 148 149 155 public ConnectionPageWrapper( ConnectionPageModifyListener listener, IRunnableContext runnableContext ) 156 { 157 this.listenerList = new ArrayList <ConnectionPageModifyListener>( 5 ); 158 if ( listener != null ) 159 { 160 this.listenerList.add( listener ); 161 this.isConnectionOpened = listener.getRealConnection() != null && listener.getRealConnection().isOpened(); 162 } 163 else 164 { 165 this.isConnectionOpened = false; 166 } 167 this.runnableContext = runnableContext; 168 } 169 170 171 176 public void addConnectionPageModifyListener( ConnectionPageModifyListener listener ) 177 { 178 listenerList.add( listener ); 179 } 180 181 182 187 public String getName() 188 { 189 return nameText.getText(); 190 } 191 192 193 198 public String getHostName() 199 { 200 return hostCombo != null ? hostCombo.getText() : hostText.getText(); 201 } 202 203 204 209 public int getPort() 210 { 211 return Integer.parseInt( portCombo != null ? portCombo.getText() : portText.getText() ); 212 } 213 214 215 221 public int getEncyrptionMethod() 222 { 223 if ( encryptionMethodCombo != null ) 224 { 225 switch ( encryptionMethodCombo.getSelectionIndex() ) 226 { 227 case 1: 228 return IConnection.ENCYRPTION_LDAPS; 229 case 2: 230 return IConnection.ENCYRPTION_STARTTLS; 231 default: 232 return IConnection.ENCYRPTION_NONE; 233 } 234 } 235 return IConnection.ENCYRPTION_NONE; 236 } 237 238 239 245 public boolean isAutoFetchBaseDns() 246 { 247 return autoFetchBaseDnsButton.getSelection(); 248 } 249 250 251 256 public String getBaseDN() 257 { 258 return baseDNCombo.getText(); 259 } 260 261 262 267 public int getCountLimit() 268 { 269 return limitWidget.getCountLimit(); 270 } 271 272 273 278 public int getTimeLimit() 279 { 280 return limitWidget.getTimeLimit(); 281 } 282 283 284 289 public int getAliasesDereferencingMethod() 290 { 291 return aliasesDereferencingWidget.getAliasesDereferencingMethod(); 292 } 293 294 295 300 public int getReferralsHandlingMethod() 301 { 302 return referralsHandlingWidget.getReferralsHandlingMethod(); 303 } 304 305 306 311 public void setOpenConnectionOnFinish( boolean b ) 312 { 313 if ( openConnectionButton != null ) 314 { 315 openConnectionButton.setSelection( b ); 316 } 317 } 318 319 320 326 public boolean isOpenConnectionOnFinish() 327 { 328 return openConnectionButton.getSelection(); 329 } 330 331 332 338 public int getAuthenticationMethod() 339 { 340 if ( anonymousAuthButton.getSelection() ) 341 { 342 return IConnection.AUTH_ANONYMOUS; 343 } 344 else if ( simpleAuthButton.getSelection() ) 345 { 346 return IConnection.AUTH_SIMPLE; 347 } 348 349 return IConnection.AUTH_ANONYMOUS; 350 } 351 352 353 358 public String getSimpleAuthBindPrincipal() 359 { 360 return simpleAuthBindPrincipalCombo != null ? simpleAuthBindPrincipalCombo.getText() 361 : simpleAuthBindPrincipalText.getText(); 362 } 363 364 365 370 public String getSimpleAuthBindPassword() 371 { 372 return simpleAuthBindPasswordText.getText(); 373 } 374 375 376 381 public boolean isSaveSimpleAuthBindPassword() 382 { 383 return saveSimpleAuthBindPasswordButton.getSelection(); 384 } 385 386 387 397 public void addMainInput( String name, String host, int port, int encryptionMethod, Composite parent ) 398 { 399 400 Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); 401 402 Composite nameComposite = BaseWidgetUtils.createColumnContainer( composite, 2, 1 ); 403 BaseWidgetUtils.createLabel( nameComposite, "Connection name:", 1 ); 404 nameText = BaseWidgetUtils.createText( nameComposite, name, 1 ); 405 nameText.addModifyListener( this ); 406 407 BaseWidgetUtils.createSpacer( composite, 1 ); 408 409 Group group = BaseWidgetUtils.createGroup( composite, "Network Parameter", 1 ); 410 411 Composite groupComposite = BaseWidgetUtils.createColumnContainer( group, 3, 1 ); 412 BaseWidgetUtils.createLabel( groupComposite, "Hostname:", 1 ); 413 if ( isConnectionOpened ) 414 { 415 hostText = BaseWidgetUtils.createReadonlyText( groupComposite, host, 2 ); 416 } 417 else 418 { 419 String [] hostHistory = HistoryUtils.load( BrowserCommonConstants.DIALOGSETTING_KEY_HOST_HISTORY ); 420 hostCombo = BaseWidgetUtils.createCombo( groupComposite, hostHistory, -1, 2 ); 421 hostCombo.setText( host ); 422 hostCombo.addModifyListener( this ); 423 } 424 425 BaseWidgetUtils.createLabel( groupComposite, "Port:", 1 ); 426 if ( isConnectionOpened ) 427 { 428 portText = BaseWidgetUtils.createReadonlyText( groupComposite, Integer.toString( port ), 2 ); 429 } 430 else 431 { 432 String [] portHistory = HistoryUtils.load( BrowserCommonConstants.DIALOGSETTING_KEY_PORT_HISTORY ); 433 portCombo = BaseWidgetUtils.createCombo( groupComposite, portHistory, -1, 2 ); 434 portCombo.setText( Integer.toString( port ) ); 435 portCombo.addVerifyListener( new VerifyListener() 436 { 437 public void verifyText( VerifyEvent e ) 438 { 439 if ( !e.text.matches( "[0-9]*" ) ) 440 { 441 e.doit = false; 442 } 443 if ( portCombo.getText().length() > 4 && e.text.length() > 0 ) 444 { 445 e.doit = false; 446 } 447 } 448 } ); 449 portCombo.addModifyListener( this ); 450 } 451 452 String [] encMethods = new String [] 453 { "No encryption", "Use SSL encryption (ldaps://)", "Use StartTLS extension" }; 454 BaseWidgetUtils.createLabel( groupComposite, "Encryption method:", 1 ); 455 encryptionMethodCombo = BaseWidgetUtils.createReadonlyCombo( groupComposite, encMethods, encryptionMethod, 2 ); 456 encryptionMethodCombo.addSelectionListener( this ); 457 BaseWidgetUtils.createSpacer( groupComposite, 1 ); 458 BaseWidgetUtils 459 .createLabel( 460 groupComposite, 461 "Warning: The current version doesn't support certificate validation, \nbe aware of invalid certificates or man-in-the-middle attacks!", 462 2 ); 463 464 BaseWidgetUtils.createSpacer( groupComposite, 2 ); 465 checkConnectionButton = new Button( groupComposite, SWT.PUSH ); 466 GridData gd = new GridData(); 467 gd.horizontalAlignment = SWT.RIGHT; 468 gd.verticalAlignment = SWT.BOTTOM; 469 checkConnectionButton.setLayoutData( gd ); 470 checkConnectionButton.setText( "Check Network Parameter" ); 471 checkConnectionButton.setEnabled( !isConnectionOpened ); 472 checkConnectionButton.addSelectionListener( new SelectionListener() 473 { 474 public void widgetSelected( SelectionEvent e ) 475 { 476 IConnection connection = getTestConnection(); 477 CheckNetworkParameterJob job = new CheckNetworkParameterJob( connection ); 478 RunnableContextJobAdapter.execute( job, runnableContext ); 479 if ( job.getExternalResult().isOK() ) 480 { 481 MessageDialog.openInformation( Display.getDefault().getActiveShell(), "Check Network Parameter", 482 "The connection was established successfully." ); 483 } 484 } 485 486 487 public void widgetDefaultSelected( SelectionEvent e ) 488 { 489 } 490 } ); 491 492 setEnabled(); 493 } 494 495 496 503 public void addBaseDNInput( boolean autoFetchBaseDNs, String baseDN, Composite parent ) 504 { 505 506 Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); 507 508 Group group = BaseWidgetUtils.createGroup( composite, "Base DN", 1 ); 509 Composite groupComposite = BaseWidgetUtils.createColumnContainer( group, 3, 1 ); 510 GridData gd; 511 512 autoFetchBaseDnsButton = BaseWidgetUtils.createCheckbox( groupComposite, "Get base DNs from Root DSE", 2 ); 513 autoFetchBaseDnsButton.setSelection( autoFetchBaseDNs ); 514 autoFetchBaseDnsButton.addSelectionListener( this ); 515 516 fetchBaseDnsButton = new Button( groupComposite, SWT.PUSH ); 517 fetchBaseDnsButton.setText( "Fetch Base DNs" ); 518 fetchBaseDnsButton.setEnabled( true ); 519 gd = new GridData(); 520 gd.horizontalAlignment = SWT.RIGHT; 521 fetchBaseDnsButton.setLayoutData( gd ); 522 fetchBaseDnsButton.addSelectionListener( new SelectionListener() 523 { 524 525 public void widgetSelected( SelectionEvent e ) 526 { 527 IConnection connection = getTestConnection(); 528 529 FetchBaseDNsJob job = new FetchBaseDNsJob( connection ); 530 RunnableContextJobAdapter.execute( job, runnableContext ); 531 if ( job.getExternalResult().isOK() ) 532 { 533 if ( job.getBaseDNs().length > 0 ) 534 { 535 String [] baseDNs = job.getBaseDNs(); 536 baseDNCombo.setItems( baseDNs ); 537 baseDNCombo.select( 0 ); 538 539 String msg = "The server returned the following base DNs:"; 540 for ( int i = 0; i < baseDNs.length; i++ ) 541 { 542 msg += "\n - " + baseDNs[i]; 543 } 544 MessageDialog.openInformation( Display.getDefault().getActiveShell(), "Fetch Base DNs", msg ); 545 } 546 else 547 { 548 MessageDialog.openWarning( Display.getDefault().getActiveShell(), "Fetch Base DNs", 549 "No base DN returned from server. Please enter the base DN manually." ); 550 autoFetchBaseDnsButton.setSelection( false ); 551 } 552 } 553 } 554 555 556 public void widgetDefaultSelected( SelectionEvent e ) 557 { 558 } 559 } ); 560 561 BaseWidgetUtils.createLabel( groupComposite, "Base DN:", 1 ); 562 baseDNCombo = BaseWidgetUtils.createCombo( groupComposite, new String [] 563 { baseDN.toString() }, 0, 2 ); 564 baseDNCombo.setText( baseDN.toString() ); 565 baseDNCombo.addModifyListener( this ); 566 567 setEnabled(); 568 } 569 570 571 580 public void addLimitInput( int countLimit, int timeLimit, int aliasesDereferencingMethod, 581 int referralsHandlingMethod, Composite parent ) 582 { 583 584 Composite composite = BaseWidgetUtils.createColumnContainer( parent, 3, 1 ); 585 586 limitWidget = new LimitWidget( countLimit, timeLimit ); 587 limitWidget.createWidget( composite ); 588 589 aliasesDereferencingWidget = new AliasesDereferencingWidget( aliasesDereferencingMethod ); 590 aliasesDereferencingWidget.createWidget( composite ); 591 592 referralsHandlingWidget = new ReferralsHandlingWidget( referralsHandlingMethod ); 593 referralsHandlingWidget.createWidget( composite ); 594 595 setEnabled(); 596 } 597 598 599 605 public void addOpenConnectionInput( boolean openConnectionOnFinish, Composite parent ) 606 { 607 openConnectionButton = BaseWidgetUtils.createCheckbox( parent, "Open connection on finish", 1 ); 608 openConnectionButton.setSelection( openConnectionOnFinish ); 609 openConnectionButton.addSelectionListener( this ); 610 } 611 612 613 619 public void addAuthenticationMethodInput( int authMethod, Composite parent ) 620 { 621 622 Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); 623 624 Group group = BaseWidgetUtils.createGroup( composite, "Authentication Method", 1 ); 625 Composite groupComposite = BaseWidgetUtils.createColumnContainer( group, 1, 1 ); 626 627 anonymousAuthButton = BaseWidgetUtils.createRadiobutton( groupComposite, "Anonymous Authentication", 1 ); 628 anonymousAuthButton.setSelection( authMethod == IConnection.AUTH_ANONYMOUS ); 629 anonymousAuthButton.addSelectionListener( this ); 630 631 simpleAuthButton = BaseWidgetUtils.createRadiobutton( groupComposite, "Simple Authentication", 1 ); 632 simpleAuthButton.setSelection( authMethod == IConnection.AUTH_SIMPLE ); 633 simpleAuthButton.addSelectionListener( this ); 634 635 } 641 642 643 651 public void addSimpleAuthInput( boolean saveBindPassword, String bindPrincipal, String bindPassword, 652 Composite parent ) 653 { 654 655 Composite composite2 = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); 656 657 Group group = BaseWidgetUtils.createGroup( composite2, "Authentication Parameter", 1 ); 658 Composite composite = BaseWidgetUtils.createColumnContainer( group, 3, 1 ); 659 660 BaseWidgetUtils.createLabel( composite, "Bind DN or user:", 1 ); 661 if ( isConnectionOpened ) 662 { 663 simpleAuthBindPrincipalText = BaseWidgetUtils.createReadonlyText( composite, bindPrincipal, 2 ); 664 } 665 else 666 { 667 String [] dnHistory = HistoryUtils.load( BrowserCommonConstants.DIALOGSETTING_KEY_DN_HISTORY ); 668 simpleAuthBindPrincipalCombo = BaseWidgetUtils.createCombo( composite, dnHistory, -1, 2 ); 669 simpleAuthBindPrincipalCombo.setText( bindPrincipal ); 670 simpleAuthBindPrincipalCombo.addModifyListener( this ); 671 } 672 673 BaseWidgetUtils.createLabel( composite, "Bind password:", 1 ); 674 if ( isConnectionOpened ) 675 { 676 simpleAuthBindPasswordText = BaseWidgetUtils.createReadonlyPasswordText( composite, bindPassword, 2 ); 677 } 678 else 679 { 680 simpleAuthBindPasswordText = BaseWidgetUtils.createPasswordText( composite, bindPassword, 2 ); 681 } 682 simpleAuthBindPasswordText.addModifyListener( this ); 683 684 BaseWidgetUtils.createSpacer( composite, 1 ); 685 saveSimpleAuthBindPasswordButton = BaseWidgetUtils.createCheckbox( composite, "Save password", 1 ); 686 saveSimpleAuthBindPasswordButton.setSelection( saveBindPassword ); 687 saveSimpleAuthBindPasswordButton.addSelectionListener( this ); 688 689 checkSimpleAuthButton = new Button( composite, SWT.PUSH ); 690 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 691 gd.horizontalAlignment = SWT.RIGHT; 692 checkSimpleAuthButton.setLayoutData( gd ); 693 checkSimpleAuthButton.setText( "Check Authentication" ); 694 checkSimpleAuthButton.setEnabled( false ); 695 checkSimpleAuthButton.addSelectionListener( new SelectionListener() 696 { 697 public void widgetSelected( SelectionEvent e ) 698 { 699 IConnection connection = getTestConnection(); 700 CheckBindJob job = new CheckBindJob( connection ); 701 RunnableContextJobAdapter.execute( job, runnableContext ); 702 if ( job.getExternalResult().isOK() ) 703 { 704 MessageDialog.openInformation( Display.getDefault().getActiveShell(), "Check Authentication", 705 "The authentication was successful." ); 706 } 707 } 708 709 710 public void widgetDefaultSelected( SelectionEvent e ) 711 { 712 } 713 } ); 714 setEnabled(); 715 } 716 717 718 721 private void fireConnectionPageModified() 722 { 723 for ( Iterator <ConnectionPageModifyListener> it = listenerList.iterator(); it.hasNext(); ) 724 { 725 it.next().connectionPageModified(); 726 } 727 } 728 729 730 733 private void setEnabled() 734 { 735 736 if ( isConnectionOpened ) 737 { 738 if ( encryptionMethodCombo != null && checkConnectionButton != null ) 739 { 740 encryptionMethodCombo.setEnabled( false ); 741 checkConnectionButton.setEnabled( false ); 742 } 743 744 if ( baseDNCombo != null && autoFetchBaseDnsButton != null ) 745 { 746 autoFetchBaseDnsButton.setEnabled( false ); 747 baseDNCombo.setEnabled( false ); 748 fetchBaseDnsButton.setEnabled( false ); 749 } 750 751 if ( anonymousAuthButton != null && simpleAuthButton != null ) 752 { 753 anonymousAuthButton.setEnabled( false ); 754 simpleAuthButton.setEnabled( false ); 755 } 756 if ( saveSimpleAuthBindPasswordButton != null && saveSimpleAuthBindPasswordButton != null ) 757 { 758 saveSimpleAuthBindPasswordButton.setEnabled( false ); 759 checkSimpleAuthButton.setEnabled( false ); 760 } 761 } 762 else 763 { 764 if ( hostCombo != null && portCombo != null && checkConnectionButton != null ) 765 { 766 if ( !hostCombo.getText().equals( "" ) && !hostCombo.getText().equals( "" ) ) 767 { 768 checkConnectionButton.setEnabled( true ); 769 } 770 else 771 { 772 checkConnectionButton.setEnabled( false ); 773 } 774 } 775 776 if ( baseDNCombo != null && autoFetchBaseDnsButton != null ) 777 { 778 if ( autoFetchBaseDnsButton.getSelection() ) 779 { 780 baseDNCombo.setEnabled( false ); 781 } 782 else 783 { 784 baseDNCombo.setEnabled( true ); 785 } 786 } 787 if ( simpleAuthBindPrincipalCombo != null && simpleAuthBindPasswordText != null 788 && saveSimpleAuthBindPasswordButton != null ) 789 { 790 boolean simpleAuthSelected = simpleAuthButton == null || simpleAuthButton.getSelection(); 791 simpleAuthBindPrincipalCombo.setEnabled( simpleAuthSelected ); 792 simpleAuthBindPasswordText.setEnabled( saveSimpleAuthBindPasswordButton.getSelection() 793 && simpleAuthSelected ); 794 saveSimpleAuthBindPasswordButton.setEnabled( simpleAuthSelected ); 795 checkSimpleAuthButton.setEnabled( saveSimpleAuthBindPasswordButton.getSelection() 796 && !simpleAuthBindPrincipalCombo.getText().equals( "" ) 797 && !simpleAuthBindPasswordText.getText().equals( "" ) && simpleAuthSelected ); 798 } 799 } 800 } 801 802 803 806 private void validate() 807 { 808 String message = null; 809 String errorMessage = null; 810 811 boolean simpleAuthSelected = simpleAuthButton == null || simpleAuthButton.getSelection(); 812 813 if ( baseDNCombo != null && baseDNCombo.isVisible() ) 814 { 815 try 816 { 817 new DN( baseDNCombo.getText() ); 818 } 819 catch ( NameException e ) 820 { 821 message = "Please enter a valid base DN."; 822 } 823 } 824 if ( simpleAuthBindPasswordText != null && simpleAuthSelected && simpleAuthBindPasswordText.isVisible() ) 825 { 826 if ( saveSimpleAuthBindPasswordButton.getSelection() && "".equals( simpleAuthBindPasswordText.getText() ) ) 827 { 828 message = "Please enter a bind password."; 829 } 830 } 831 if ( simpleAuthBindPrincipalCombo != null && simpleAuthSelected && simpleAuthBindPrincipalCombo.isVisible() ) 832 { 833 if ( "".equals( simpleAuthBindPrincipalCombo.getText() ) ) 834 { 835 message = "Please enter a bind DN or user."; 836 } 837 else 838 { 839 } 841 } 842 if ( portCombo != null && portCombo.isVisible() ) 843 { 844 if ( "".equals( portCombo.getText() ) ) 845 { 846 message = "Please enter a port. The default LDAP port is 389."; 847 } 848 } 849 if ( hostCombo != null && hostCombo.isVisible() ) 850 { 851 if ( "".equals( hostCombo.getText() ) ) 852 { 853 message = "Please enter a hostname."; 854 } 855 } 856 if ( nameText != null && nameText.isVisible() ) 857 { 858 if ( "".equals( nameText.getText() ) ) 859 { 860 message = "Please enter a connection name."; 861 } 862 if ( BrowserCorePlugin.getDefault().getConnectionManager().getConnection( nameText.getText() ) != null 863 && BrowserCorePlugin.getDefault().getConnectionManager().getConnection( nameText.getText() ) != listenerList 864 .get( 0 ).getRealConnection() ) 865 { 866 errorMessage = "A connection named '" + nameText.getText() + "' already exists."; 867 } 868 } 869 870 for ( Iterator <ConnectionPageModifyListener> it = listenerList.iterator(); it.hasNext(); ) 871 { 872 ConnectionPageModifyListener listener = it.next(); 873 listener.setMessage( message ); 874 listener.setErrorMessage( errorMessage ); 875 } 876 } 877 878 879 882 public void modifyText( ModifyEvent e ) 883 { 884 setEnabled(); 885 validate(); 886 fireConnectionPageModified(); 887 } 888 889 890 893 public void widgetSelected( SelectionEvent e ) 894 { 895 setEnabled(); 896 validate(); 897 fireConnectionPageModified(); 898 } 899 900 901 904 public void widgetDefaultSelected( SelectionEvent e ) 905 { 906 setEnabled(); 907 validate(); 908 fireConnectionPageModified(); 909 } 910 911 912 918 public IConnection getTestConnection() 919 { 920 if ( getAuthenticationMethod() == IConnection.AUTH_ANONYMOUS ) 921 { 922 Connection conn; 923 try 924 { 925 conn = new Connection( null, getHostName(), getPort(), getEncyrptionMethod(), isAutoFetchBaseDns(), 926 new DN( getBaseDN() ), getCountLimit(), getTimeLimit(), getAliasesDereferencingMethod(), 927 getReferralsHandlingMethod(), IConnection.AUTH_ANONYMOUS, null, null ); 928 } 929 catch ( NameException e ) 930 { 931 conn = null; 932 } 933 return conn; 934 } 935 else if ( getAuthenticationMethod() == IConnection.AUTH_SIMPLE ) 936 { 937 Connection conn; 938 try 939 { 940 conn = new Connection( null, getHostName(), getPort(), getEncyrptionMethod(), isAutoFetchBaseDns(), 941 new DN( getBaseDN() ), getCountLimit(), getTimeLimit(), getAliasesDereferencingMethod(), 942 getReferralsHandlingMethod(), IConnection.AUTH_SIMPLE, getSimpleAuthBindPrincipal(), 943 getSimpleAuthBindPassword() ); 944 } 945 catch ( NameException e ) 946 { 947 conn = null; 948 } 949 return conn; 950 } 951 else 952 { 953 return null; 954 } 955 } 956 957 958 962 public void saveDialogSettings() 963 { 964 if ( !isConnectionOpened ) 965 { 966 if ( hostCombo != null ) 967 { 968 HistoryUtils.save( BrowserCommonConstants.DIALOGSETTING_KEY_HOST_HISTORY, hostCombo.getText() ); 969 } 970 if ( portCombo != null ) 971 { 972 HistoryUtils.save( BrowserCommonConstants.DIALOGSETTING_KEY_PORT_HISTORY, portCombo.getText() ); 973 } 974 if ( simpleAuthBindPrincipalCombo != null ) 975 { 976 HistoryUtils.save( BrowserCommonConstants.DIALOGSETTING_KEY_DN_HISTORY, simpleAuthBindPrincipalCombo 977 .getText() ); 978 } 979 } 980 } 981 982 } 983 | Popular Tags |