KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > ui > dialogs > properties > RootDSEPropertyPage


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.browser.ui.dialogs.properties;
22
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.Arrays JavaDoc;
26 import java.util.List JavaDoc;
27
28 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
29 import org.apache.directory.ldapstudio.browser.common.widgets.entryeditor.EntryEditorWidgetTableMetadata;
30 import org.apache.directory.ldapstudio.browser.core.internal.model.RootDSE;
31 import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
32 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
33 import org.apache.directory.ldapstudio.browser.core.model.IEntry;
34 import org.apache.directory.ldapstudio.browser.core.model.IRootDSE;
35 import org.apache.directory.ldapstudio.browser.core.model.IValue;
36
37 import org.eclipse.jface.viewers.ArrayContentProvider;
38 import org.eclipse.jface.viewers.IStructuredContentProvider;
39 import org.eclipse.jface.viewers.ITableLabelProvider;
40 import org.eclipse.jface.viewers.LabelProvider;
41 import org.eclipse.jface.viewers.ListViewer;
42 import org.eclipse.jface.viewers.TableViewer;
43 import org.eclipse.jface.viewers.Viewer;
44 import org.eclipse.jface.viewers.ViewerSorter;
45 import org.eclipse.swt.SWT;
46 import org.eclipse.swt.graphics.Image;
47 import org.eclipse.swt.layout.GridData;
48 import org.eclipse.swt.layout.GridLayout;
49 import org.eclipse.swt.layout.RowData;
50 import org.eclipse.swt.layout.RowLayout;
51 import org.eclipse.swt.widgets.Composite;
52 import org.eclipse.swt.widgets.Control;
53 import org.eclipse.swt.widgets.Label;
54 import org.eclipse.swt.widgets.TabFolder;
55 import org.eclipse.swt.widgets.TabItem;
56 import org.eclipse.swt.widgets.Table;
57 import org.eclipse.swt.widgets.TableColumn;
58 import org.eclipse.swt.widgets.Text;
59 import org.eclipse.ui.IWorkbenchPropertyPage;
60 import org.eclipse.ui.dialogs.PropertyPage;
61
62
63 public class RootDSEPropertyPage extends PropertyPage implements IWorkbenchPropertyPage
64 {
65
66     private TabFolder tabFolder;
67
68     private TabItem commonsTab;
69
70     private TabItem controlsTab;
71
72     private TabItem extensionsTab;
73
74     private TabItem featuresTab;
75
76     private TabItem rawTab;
77
78
79     public RootDSEPropertyPage()
80     {
81         super();
82         super.noDefaultAndApplyButton();
83     }
84
85
86     protected Control createContents( Composite parent )
87     {
88
89         final IConnection connection = ConnectionPropertyPage.getConnection( getElement() );
90
91         this.tabFolder = new TabFolder( parent, SWT.TOP );
92         RowLayout mainLayout = new RowLayout();
93         mainLayout.fill = true;
94         mainLayout.marginWidth = 0;
95         mainLayout.marginHeight = 0;
96         this.tabFolder.setLayout( mainLayout );
97
98         Composite composite = new Composite( this.tabFolder, SWT.NONE );
99         GridLayout gl = new GridLayout( 2, false );
100         composite.setLayout( gl );
101         BaseWidgetUtils.createLabel( composite, "Directory Type:", 1 );
102         Text typeText = BaseWidgetUtils.createLabeledText( composite, "-", 1 );
103         if ( connection != null && connection.getRootDSE() != null )
104         {
105             // Try to detect LDAP server from RootDSE
106
//
107
IRootDSE rootDSE = connection.getRootDSE();
108             String JavaDoc type = detectOpenLDAP( rootDSE );
109             if ( type == null )
110             {
111                 type = detectSiemensDirX( rootDSE );
112                 if ( type == null )
113                 {
114                     type = detectActiveDirectory( rootDSE );
115                     if ( type == null )
116                     {
117                         type = detectByVendorName( rootDSE );
118                     }
119                 }
120             }
121
122             if ( type != null )
123             {
124                 typeText.setText( type );
125             }
126         }
127         addInfo( connection, composite, "vendorName", "Vendor Name:" );
128         addInfo( connection, composite, "vendorVersion", "Vendor Version:" );
129         addInfo( connection, composite, "supportedLDAPVersion", "Supported LDAP Versions:" );
130         addInfo( connection, composite, "supportedSASLMechanisms", "Supported SASL Mechanisms:" );
131
132         this.commonsTab = new TabItem( this.tabFolder, SWT.NONE );
133         this.commonsTab.setText( "Info" );
134         this.commonsTab.setControl( composite );
135
136         // naming contexts
137
// alt servers
138
// schema DN
139
// ldap version
140

141         Composite controlsComposite = new Composite( this.tabFolder, SWT.NONE );
142         controlsComposite.setLayoutData( new RowData( 10, 10 ) );
143         GridLayout controlsLayout = new GridLayout();
144         controlsComposite.setLayout( controlsLayout );
145         ListViewer controlsViewer = new ListViewer( controlsComposite );
146         controlsViewer.getList().setLayoutData( new GridData( GridData.FILL_BOTH ) );
147         controlsViewer.setContentProvider( new ArrayContentProvider() );
148         controlsViewer.setLabelProvider( new LabelProvider() );
149         if ( connection != null && connection.getRootDSE() != null )
150         {
151             controlsViewer.setInput( ( ( RootDSE ) connection.getRootDSE() ).getSupportedControls() );
152         }
153         this.controlsTab = new TabItem( this.tabFolder, SWT.NONE );
154         this.controlsTab.setText( "Controls" );
155         this.controlsTab.setControl( controlsComposite );
156
157         Composite extensionComposite = new Composite( this.tabFolder, SWT.NONE );
158         extensionComposite.setLayoutData( new RowData( 10, 10 ) );
159         GridLayout extensionLayout = new GridLayout();
160         extensionComposite.setLayout( extensionLayout );
161         ListViewer extensionViewer = new ListViewer( extensionComposite );
162         extensionViewer.getList().setLayoutData( new GridData( GridData.FILL_BOTH ) );
163         extensionViewer.setContentProvider( new ArrayContentProvider() );
164         extensionViewer.setLabelProvider( new LabelProvider() );
165         if ( connection != null && connection.getRootDSE() != null )
166         {
167             extensionViewer.setInput( ( ( RootDSE ) connection.getRootDSE() ).getSupportedExtensions() );
168         }
169         this.extensionsTab = new TabItem( this.tabFolder, SWT.NONE );
170         this.extensionsTab.setText( "Extensions" );
171         this.extensionsTab.setControl( extensionComposite );
172
173         Composite featureComposite = new Composite( this.tabFolder, SWT.NONE );
174         featureComposite.setLayoutData( new RowData( 10, 10 ) );
175         GridLayout featureLayout = new GridLayout();
176         featureComposite.setLayout( featureLayout );
177         ListViewer featureViewer = new ListViewer( featureComposite );
178         featureViewer.getList().setLayoutData( new GridData( GridData.FILL_BOTH ) );
179         featureViewer.setContentProvider( new ArrayContentProvider() );
180         featureViewer.setLabelProvider( new LabelProvider() );
181         if ( connection != null && connection.getRootDSE() != null )
182         {
183             featureViewer.setInput( ( ( RootDSE ) connection.getRootDSE() ).getSupportedFeatures() );
184         }
185         this.featuresTab = new TabItem( this.tabFolder, SWT.NONE );
186         this.featuresTab.setText( "Features" );
187         this.featuresTab.setControl( featureComposite );
188
189         Composite rawComposite = new Composite( this.tabFolder, SWT.NONE );
190         rawComposite.setLayoutData( new RowData( 10, 10 ) );
191         GridLayout rawLayout = new GridLayout();
192         rawComposite.setLayout( rawLayout );
193         Table table = new Table( rawComposite, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL
194             | SWT.FULL_SELECTION | SWT.HIDE_SELECTION );
195         GridData gridData = new GridData( GridData.FILL_BOTH );
196         table.setLayoutData( gridData );
197         table.setHeaderVisible( true );
198         table.setLinesVisible( true );
199         TableViewer viewer = new TableViewer( table );
200         for ( int i = 0; i < EntryEditorWidgetTableMetadata.COLUM_NAMES.length; i++ )
201         {
202             TableColumn column = new TableColumn( table, SWT.LEFT, i );
203             column.setText( EntryEditorWidgetTableMetadata.COLUM_NAMES[i] );
204             column.setWidth( 150 );
205             column.setResizable( true );
206         }
207         viewer.setColumnProperties( EntryEditorWidgetTableMetadata.COLUM_NAMES );
208         viewer.setSorter( new InnerViewerSorter() );
209         viewer.setContentProvider( new InnerContentProvider() );
210         viewer.setLabelProvider( new InnerLabelProvider() );
211         if ( connection != null )
212         {
213             IEntry entry = connection.getRootDSE();
214             viewer.setInput( entry );
215         }
216         this.rawTab = new TabItem( this.tabFolder, SWT.NONE );
217         this.rawTab.setText( "Raw" );
218         this.rawTab.setControl( rawComposite );
219
220         // setControl(composite);
221
return this.tabFolder;
222     }
223
224
225     /** Check various LDAP servers via vendorName attribute.
226      *
227      * @param rootDSE
228      */

229     private String JavaDoc detectByVendorName( IRootDSE rootDSE )
230     {
231
232         String JavaDoc result = null;
233
234         IAttribute vnAttribute = rootDSE.getAttribute( "vendorName" );
235         IAttribute vvAttribute = rootDSE.getAttribute( "vendorVersion" );
236
237         if ( vnAttribute != null && vnAttribute.getStringValues().length > 0 && vvAttribute != null
238             && vvAttribute.getStringValues().length > 0 )
239         {
240             if ( vnAttribute.getStringValues()[0].indexOf( "Apache Software Foundation" ) > -1 )
241             {
242                 result = "Apache Directory Server";
243             }
244             if ( vnAttribute.getStringValues()[0].indexOf( "Novell" ) > -1
245                 || vvAttribute.getStringValues()[0].indexOf( "eDirectory" ) > -1 )
246             {
247                 result = "Novell eDirectory";
248             }
249             if ( vnAttribute.getStringValues()[0].indexOf( "Sun" ) > -1
250                 || vvAttribute.getStringValues()[0].indexOf( "Sun" ) > -1 )
251             {
252                 result = "Sun Directory Server";
253             }
254             if ( vnAttribute.getStringValues()[0].indexOf( "Netscape" ) > -1
255                 || vvAttribute.getStringValues()[0].indexOf( "Netscape" ) > -1 )
256             {
257                 result = "Netscape Directory Server";
258             }
259             if ( vnAttribute.getStringValues()[0].indexOf( "International Business Machines" ) > -1
260                 && ( ( vvAttribute.getStringValues()[0].indexOf( "6.0" ) > -1 ) )
261                 || ( vvAttribute.getStringValues()[0].indexOf( "5.2" ) > -1 ) )
262             {
263                 result = "IBM Tivoli Directory Server";
264             }
265         }
266
267         return result;
268     }
269
270
271     /**
272      * Tries to detect a Microsoft Active Directory.
273      *
274      * @param rootDSE
275      * @return name of directory type, or null if no Active Directory server server was detected
276      */

277     private String JavaDoc detectActiveDirectory( IRootDSE rootDSE )
278     {
279
280         String JavaDoc result = null;
281
282         // check active directory
283
IAttribute rdncAttribute = rootDSE.getAttribute( "rootDomainNamingContext" );
284         if ( rdncAttribute != null )
285         {
286             IAttribute ffAttribute = rootDSE.getAttribute( "forestFunctionality" );
287             if ( ffAttribute != null )
288             {
289                 result = "Microsoft Active Directory 2003";
290             }
291             else
292             {
293                 result = "Microsoft Active Directory 2000";
294             }
295         }
296
297         return result;
298     }
299
300
301     /**
302      * Tries to detect a Siemens DirX server.
303      *
304      * @param rootDSE
305      * @return name of directory type, or null if no DirX server server was detected
306      */

307     private String JavaDoc detectSiemensDirX( IRootDSE rootDSE )
308     {
309
310         String JavaDoc result = null;
311
312         IAttribute ssseAttribute = rootDSE.getAttribute( "subSchemaSubentry" );
313         if ( ssseAttribute != null )
314         {
315             for ( int i = 0; i < ssseAttribute.getStringValues().length; i++ )
316             {
317                 if ( "cn=LDAPGlobalSchemaSubentry".equals( ssseAttribute.getStringValues()[i] ) )
318                 {
319                     result = "Siemens DirX";
320                 }
321             }
322         }
323
324         return result;
325     }
326
327
328     /**
329      * Tries to detect an OpenLDAP server
330      *
331      * @param rootDSE
332      * @return name (and sometimes version) of directory type, or null if no OpenLDAP server was detected
333      */

334     private String JavaDoc detectOpenLDAP( IRootDSE rootDSE )
335     {
336
337         String JavaDoc result = null;
338         boolean typeDetected = false;
339
340         // check OpenLDAP
341
IAttribute ocAttribute = rootDSE.getAttribute( "objectClass" );
342         if ( ocAttribute != null )
343         {
344             for ( int i = 0; i < ocAttribute.getStringValues().length; i++ )
345             {
346                 if ( "OpenLDAProotDSE".equals( ocAttribute.getStringValues()[i] ) )
347                 {
348                     IAttribute ccAttribute = rootDSE.getAttribute( "configContext" );
349                     if ( ccAttribute != null )
350                     {
351                         result = "OpenLDAP 2.3";
352                         typeDetected = true;
353                     }
354                     if ( !typeDetected )
355                     {
356                         IAttribute scAttribute = rootDSE.getAttribute( "supportedControl" );
357                         if ( scAttribute != null )
358                         {
359                             for ( int sci = 0; sci < scAttribute.getStringValues().length; sci++ )
360                             {
361                                 // if("1.2.840.113556.1.4.319".equals(scAttribute.getStringValues()[sci]))
362
// {
363
if ( "2.16.840.1.113730.3.4.18".equals( scAttribute.getStringValues()[sci] ) )
364                                 {
365                                     result = "OpenLDAP 2.2";
366                                     typeDetected = true;
367                                 }
368                             }
369                         }
370
371                     }
372                     if ( !typeDetected )
373                     {
374                         IAttribute seAttribute = rootDSE.getAttribute( "supportedExtension" );
375                         if ( seAttribute != null )
376                         {
377                             for ( int sei = 0; sei < seAttribute.getStringValues().length; sei++ )
378                             {
379                                 if ( "1.3.6.1.4.1.4203.1.11.3".equals( seAttribute.getStringValues()[sei] ) )
380                                 {
381                                     result = "OpenLDAP 2.1";
382                                     typeDetected = true;
383                                 }
384                             }
385                         }
386                     }
387                     if ( !typeDetected )
388                     {
389                         IAttribute sfAttribute = rootDSE.getAttribute( "supportedFeatures" );
390                         if ( sfAttribute != null )
391                         {
392                             for ( int sfi = 0; sfi < sfAttribute.getStringValues().length; sfi++ )
393                             {
394                                 if ( "1.3.6.1.4.1.4203.1.5.4".equals( sfAttribute.getStringValues()[sfi] ) )
395                                 {
396                                     result = "OpenLDAP 2.0";
397                                     typeDetected = true;
398                                 }
399                             }
400                         }
401                     }
402                     if ( !typeDetected )
403                     {
404                         result = "OpenLDAP";
405                         typeDetected = true;
406                     }
407                 }
408             }
409         }
410
411         return result;
412     }
413
414
415     private void addInfo( final IConnection connection, Composite composite, String JavaDoc attributeName, String JavaDoc labelName )
416     {
417         Label label = new Label( composite, SWT.NONE );
418         label.setText( labelName );
419         Text text = new Text( composite, SWT.NONE );
420         text.setEditable( false );
421         text.setBackground( composite.getBackground() );
422         try
423         {
424             String JavaDoc[] versions = connection.getRootDSE().getAttribute( attributeName ).getStringValues();
425             String JavaDoc version = Arrays.asList( versions ).toString();
426             text.setText( version.substring( 1, version.length() - 1 ) );
427         }
428         catch ( Exception JavaDoc e )
429         {
430             text.setText( "-" );
431         }
432     }
433
434     class InnerContentProvider implements IStructuredContentProvider
435     {
436         public Object JavaDoc[] getElements( Object JavaDoc inputElement )
437         {
438             if ( inputElement instanceof IEntry )
439             {
440                 IEntry entry = ( IEntry ) inputElement;
441                 if ( !entry.isAttributesInitialized() && entry.isDirectoryEntry() )
442                 {
443                     return new Object JavaDoc[]
444                         {};
445                 }
446                 else
447                 {
448                     IAttribute[] attributes = entry.getAttributes();
449                     List JavaDoc valueList = new ArrayList JavaDoc();
450                     for ( int i = 0; attributes != null && i < attributes.length; i++ )
451                     {
452                         IValue[] values = attributes[i].getValues();
453                         for ( int j = 0; j < values.length; j++ )
454                         {
455                             valueList.add( values[j] );
456                         }
457                     }
458                     return valueList.toArray();
459                 }
460             }
461             return new Object JavaDoc[0];
462         }
463
464
465         public void dispose()
466         {
467         }
468
469
470         public void inputChanged( Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput )
471         {
472         }
473     }
474
475     class InnerLabelProvider extends LabelProvider implements ITableLabelProvider
476     {
477         public String JavaDoc getColumnText( Object JavaDoc obj, int index )
478         {
479             if ( obj != null && obj instanceof IValue )
480             {
481                 IValue attributeValue = ( IValue ) obj;
482                 switch ( index )
483                 {
484                     case EntryEditorWidgetTableMetadata.KEY_COLUMN_INDEX:
485                         return attributeValue.getAttribute().getDescription();
486                     case EntryEditorWidgetTableMetadata.VALUE_COLUMN_INDEX:
487                         return attributeValue.getStringValue();
488                     default:
489                         return "";
490                 }
491             }
492             return "";
493         }
494
495
496         public Image getColumnImage( Object JavaDoc obj, int index )
497         {
498             return super.getImage( obj );
499         }
500     }
501
502     class InnerViewerSorter extends ViewerSorter
503     {
504
505     }
506
507 }
508
Popular Tags