directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r1221768 - in /directory/studio/trunk/plugins/connection.ui: ./ src/main/java/org/apache/directory/studio/connection/ui/widgets/
Date Wed, 21 Dec 2011 15:29:12 GMT
Author: pamarcelot
Date: Wed Dec 21 15:29:12 2011
New Revision: 1221768

URL: http://svn.apache.org/viewvc?rev=1221768&view=rev
Log:
Fix for DIRSTUDIO-755 (Implement the 'Add...' button in the 'Certificate Validation' preference
page).

Modified:
    directory/studio/trunk/plugins/connection.ui/pom.xml
    directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/CertificateListComposite.java
    directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages.properties
    directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages_de.properties
    directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages_fr.properties

Modified: directory/studio/trunk/plugins/connection.ui/pom.xml
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/connection.ui/pom.xml?rev=1221768&r1=1221767&r2=1221768&view=diff
==============================================================================
--- directory/studio/trunk/plugins/connection.ui/pom.xml (original)
+++ directory/studio/trunk/plugins/connection.ui/pom.xml Wed Dec 21 15:29:12 2011
@@ -113,6 +113,7 @@
             <Eclipse-LazyStart>true</Eclipse-LazyStart>
             <Bundle-Activator>org.apache.directory.studio.connection.ui.ConnectionUIPlugin</Bundle-Activator>
             <Require-Bundle>org.apache.commons.codec;bundle-version="${org.apache.commons.codec.version}",
+ org.apache.commons.io;bundle-version="${org.apache.commons.io.version}",
  org.apache.commons.lang;bundle-version="${org.apache.commons.lang.version}",
  org.apache.directory.shared.ldap.model;bundle-version="${org.apache.directory.shared.validversion}",
  org.apache.directory.studio.common.core,
@@ -158,12 +159,17 @@
     </dependency>
     <dependency>
       <groupId>org.apache.directory.studio</groupId>
-      <artifactId>org.apache.commons.lang</artifactId>
+      <artifactId>org.apache.commons.codec</artifactId>
       <scope>provided</scope>
     </dependency>
     <dependency>
       <groupId>org.apache.directory.studio</groupId>
-      <artifactId>org.apache.commons.codec</artifactId>
+      <artifactId>org.apache.commons.io</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.directory.studio</groupId>
+      <artifactId>org.apache.commons.lang</artifactId>
       <scope>provided</scope>
     </dependency>
     <dependency>

Modified: directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/CertificateListComposite.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/CertificateListComposite.java?rev=1221768&r1=1221767&r2=1221768&view=diff
==============================================================================
--- directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/CertificateListComposite.java
(original)
+++ directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/CertificateListComposite.java
Wed Dec 21 15:29:12 2011
@@ -20,15 +20,21 @@
 package org.apache.directory.studio.connection.ui.widgets;
 
 
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.security.cert.Certificate;
 import java.security.cert.CertificateException;
+import java.security.cert.CertificateFactory;
 import java.security.cert.X509Certificate;
 import java.util.Iterator;
 
+import org.apache.commons.io.FileUtils;
 import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
 import org.apache.directory.studio.connection.core.StudioKeyStoreManager;
 import org.apache.directory.studio.connection.ui.ConnectionUIConstants;
 import org.apache.directory.studio.connection.ui.ConnectionUIPlugin;
 import org.apache.directory.studio.connection.ui.dialogs.CertificateInfoDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.DoubleClickEvent;
 import org.eclipse.jface.viewers.IDoubleClickListener;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
@@ -36,8 +42,10 @@ import org.eclipse.jface.viewers.IStruct
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.LabelProvider;
 import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.viewers.TableViewer;
 import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.osgi.util.NLS;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
@@ -46,6 +54,7 @@ import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.FileDialog;
 
 
 /**
@@ -56,7 +65,6 @@ import org.eclipse.swt.widgets.Composite
  */
 public class CertificateListComposite extends Composite
 {
-
     private StudioKeyStoreManager keyStoreManager;
     private Composite container;
     private TableViewer tableViewer;
@@ -129,7 +137,6 @@ public class CertificateListComposite ex
         viewButton.setEnabled( false );
         viewButton.addSelectionListener( new SelectionAdapter()
         {
-            @Override
             public void widgetSelected( SelectionEvent e )
             {
                 IStructuredSelection selection = ( IStructuredSelection ) tableViewer.getSelection();
@@ -141,22 +148,53 @@ public class CertificateListComposite ex
 
         addButton = BaseWidgetUtils.createButton( buttonContainer, Messages
             .getString( "CertificateListComposite.AddButton" ), 1 ); //$NON-NLS-1$
-        addButton.setEnabled( false );
-        // TODO: implement add action
+        addButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                // Asking the user for the certificate file
+                FileDialog dialog = new FileDialog( getShell(), SWT.OPEN );
+                dialog.setText( Messages.getString( "CertificateListComposite.LoadCertificate"
) ); //$NON-NLS-1$
+                String returnedFileName = dialog.open();
+
+                if ( returnedFileName != null )
+                {
+                    try
+                    {
+                        // Reading the certificate
+                        X509Certificate certificate = generateCertificate( FileUtils.readFileToByteArray(
new File(
+                            returnedFileName ) ) );
+
+                        // Adding the certificate
+                        keyStoreManager.addCertificate( certificate );
+
+                        // Refreshing the table viewer
+                        tableViewer.refresh();
+                        tableViewer.setSelection( new StructuredSelection( certificate )
);
+                    }
+                    catch ( Exception ex )
+                    {
+                        MessageDialog.openError( addButton.getShell(),
+                            Messages.getString( "CertificateListComposite.ErrorDialogTitle"
), //$NON-NLS-1$
+                            NLS.bind( Messages.getString( "CertificateListComposite.ErrorDialogMessage"
),
+                                ex.getMessage() ) );
+                    }
+                }
+            };
+        } );
 
         removeButton = BaseWidgetUtils.createButton( buttonContainer, Messages
             .getString( "CertificateListComposite.RemoveButton" ), 1 ); //$NON-NLS-1$
         removeButton.setEnabled( false );
         removeButton.addSelectionListener( new SelectionAdapter()
         {
-            @Override
             public void widgetSelected( SelectionEvent e )
             {
                 IStructuredSelection selection = ( IStructuredSelection ) tableViewer.getSelection();
-                Iterator<X509Certificate> iterator = selection.iterator();
+                Iterator<?> iterator = selection.iterator();
                 while ( iterator.hasNext() )
                 {
-                    X509Certificate certificate = iterator.next();
+                    X509Certificate certificate = ( X509Certificate ) iterator.next();
                     try
                     {
                         keyStoreManager.removeCertificate( certificate );
@@ -172,6 +210,19 @@ public class CertificateListComposite ex
     }
 
 
+    private static X509Certificate generateCertificate( byte[] data ) throws CertificateException
+    {
+        CertificateFactory cf = CertificateFactory.getInstance( "X.509" ); //$NON-NLS-1$
+        Certificate certificate = cf.generateCertificate( new ByteArrayInputStream( data
) );
+        if ( certificate instanceof X509Certificate )
+        {
+            return ( X509Certificate ) certificate;
+        }
+
+        return null;
+    }
+
+
     /**
      * Sets the input for this composite.
      * 
@@ -203,6 +254,7 @@ public class CertificateListComposite ex
                     throw new RuntimeException( e );
                 }
             }
+
             return null;
         }
 
@@ -226,7 +278,6 @@ public class CertificateListComposite ex
 
     class KeyStoreLabelProvider extends LabelProvider
     {
-        @Override
         public String getText( Object element )
         {
             if ( element instanceof X509Certificate )
@@ -243,11 +294,11 @@ public class CertificateListComposite ex
                     return Messages.getString( "CertificateListComposite.UntitledCertificate"
); //$NON-NLS-1$
                 }
             }
+
             return super.getText( element );
         }
 
 
-        @Override
         public Image getImage( Object element )
         {
             if ( element instanceof X509Certificate )
@@ -255,7 +306,6 @@ public class CertificateListComposite ex
                 return ConnectionUIPlugin.getDefault().getImage( ConnectionUIConstants.IMG_CERTIFICATE
);
             }
 
-            // TODO Auto-generated method stub
             return super.getImage( element );
         }
     }

Modified: directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages.properties?rev=1221768&r1=1221767&r2=1221768&view=diff
==============================================================================
--- directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages.properties
(original)
+++ directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages.properties
Wed Dec 21 15:29:12 2011
@@ -104,6 +104,9 @@ CertificateListComposite.AddButton    		
 CertificateListComposite.RemoveButton 			= Remove
 CertificateListComposite.ViewButton   			= View...
 CertificateListComposite.UntitledCertificate	= <Untitled>
+CertificateListComposite.LoadCertificate        = Load Certificate
+CertificateListComposite.ErrorDialogTitle       = Error
+CertificateListComposite.ErrorDialogMessage     = An error occurred while adding the certificate:
{0}
 
 NetworkParameterPage.CheckNetworkParameter        = Check Network Parameter
 NetworkParameterPage.ConnectionEstablished        = The connection was established successfully.

Modified: directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages_de.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages_de.properties?rev=1221768&r1=1221767&r2=1221768&view=diff
==============================================================================
--- directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages_de.properties
(original)
+++ directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages_de.properties
Wed Dec 21 15:29:12 2011
@@ -103,6 +103,9 @@ CertificateListComposite.AddButton    		
 CertificateListComposite.RemoveButton 			= Entfernen
 CertificateListComposite.ViewButton   			= Anzeigen...
 CertificateListComposite.UntitledCertificate	= <Unbetitelt>
+CertificateInfoComposite.LoadCertificate        = Zertifikat laden
+CertificateInfoComposite.ErrorDialogTitle       = Fehler
+CertificateInfoComposite.ErrorDialogMessage     = TODO:An error occurred while adding the
certificate: {0}
 
 NetworkParameterPage.CheckNetworkParameter        = Netzwerkparameter \u00FCberpr\u00FCfen
 NetworkParameterPage.ConnectionEstablished        = Die Verbindung wurde erfolgreich aufgebaut.

Modified: directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages_fr.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages_fr.properties?rev=1221768&r1=1221767&r2=1221768&view=diff
==============================================================================
--- directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages_fr.properties
(original)
+++ directory/studio/trunk/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/messages_fr.properties
Wed Dec 21 15:29:12 2011
@@ -102,6 +102,9 @@ CertificateListComposite.AddButton    		
 CertificateListComposite.RemoveButton 			= Supprimer
 CertificateListComposite.ViewButton   			= Afficher...
 CertificateListComposite.UntitledCertificate	= <Sans titre>
+CertificateListComposite.LoadCertificate        = Charger un certificat
+CertificateListComposite.ErrorDialogTitle       = Erreur
+CertificateListComposite.ErrorDialogMessage     = Une erreur est survenue lors de l'ajout
du certificat : {0}
 
 NetworkParameterPage.CheckNetworkParameter        = V\u00E9rifier les param\u00E8tres r\u00E9seau
 NetworkParameterPage.ConnectionEstablished        = La connexion a \u00E9t\u00E9 \u00E9tablie
avec succ\u00E8s



Mime
View raw message