You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2018/08/19 16:55:27 UTC
[directory-studio] 01/02: DIRSTUDIO-1179: Fix connection passwords
keystore
This is an automated email from the ASF dual-hosted git repository.
seelmann pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-studio.git
commit a04da70202572fb071b28846fadf01df0b9325a8
Author: Stefan Seelmann <ma...@stefan-seelmann.de>
AuthorDate: Sun Aug 19 18:49:26 2018 +0200
DIRSTUDIO-1179: Fix connection passwords keystore
* Switch password keystore type to PKCS12
* Fix copy of keystore file, use JRE built-in function
* Add a test
---
.../connection/core/PasswordsKeyStoreManager.java | 10 ++-
.../PasswordsKeystorePreferencePage.java | 7 +-
.../test/integration/ui/PreferencesTest.java | 91 ++++++++++++++++++++++
.../integration/ui/bots/ConnectionsViewBot.java | 11 +++
...java => KeepConnectionsPasswordsDialogBot.java} | 36 +++------
...ava => PasswordsKeystorePreferencePageBot.java} | 36 ++++-----
.../test/integration/ui/bots/PreferencesBot.java | 9 +++
...sBot.java => SetupMasterPasswordDialogBot.java} | 36 +++------
...Bot.java => VerifyMasterPasswordDialogBot.java} | 36 +++------
9 files changed, 171 insertions(+), 101 deletions(-)
diff --git a/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/PasswordsKeyStoreManager.java b/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/PasswordsKeyStoreManager.java
index 6b948ab..7786af1 100644
--- a/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/PasswordsKeyStoreManager.java
+++ b/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/PasswordsKeyStoreManager.java
@@ -97,7 +97,7 @@ public class PasswordsKeyStoreManager
try
{
- keystore = KeyStore.getInstance( "JCEKS" ); //$NON-NLS-1$
+ keystore = KeyStore.getInstance( "PKCS12" ); //$NON-NLS-1$
// Getting the keystore file
File keystoreFile = getKeyStoreFile();
@@ -482,11 +482,17 @@ public class PasswordsKeyStoreManager
}
- public void reload( String masterPassword ) throws KeyStoreException
+ public void unload()
{
// Reseting the fields
this.keystore = null;
this.masterPassword = null;
+ }
+
+
+ public void reload( String masterPassword ) throws KeyStoreException
+ {
+ unload();
load( masterPassword );
}
diff --git a/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/preferences/PasswordsKeystorePreferencePage.java b/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/preferences/PasswordsKeystorePreferencePage.java
index ec6c3db..99223e9 100644
--- a/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/preferences/PasswordsKeystorePreferencePage.java
+++ b/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/preferences/PasswordsKeystorePreferencePage.java
@@ -23,6 +23,7 @@ package org.apache.directory.studio.connection.ui.preferences;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Files;
import java.security.KeyStoreException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -166,7 +167,7 @@ public class PasswordsKeystorePreferencePage extends PreferencePage implements I
try
{
// Copying the file
- FileUtils.copyFile( keystoreFile, getTemporaryKeystoreFile() );
+ Files.copy( keystoreFile.toPath(), getTemporaryKeystoreFile().toPath() );
}
catch ( IOException e )
{
@@ -344,8 +345,8 @@ public class PasswordsKeystorePreferencePage extends PreferencePage implements I
// Now, let's copy the temporary keystore as the global keystore
try
{
- FileUtils.copyFile( getTemporaryKeystoreFile(), ConnectionCorePlugin.getDefault()
- .getPasswordsKeyStoreManager().getKeyStoreFile() );
+ Files.copy( getTemporaryKeystoreFile().toPath(), ConnectionCorePlugin.getDefault()
+ .getPasswordsKeyStoreManager().getKeyStoreFile().toPath() );
}
catch ( IOException e )
{
diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/PreferencesTest.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/PreferencesTest.java
index 4817d19..f15e557 100644
--- a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/PreferencesTest.java
+++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/PreferencesTest.java
@@ -33,12 +33,21 @@ import java.util.Date;
import java.util.List;
import org.apache.directory.api.util.FileUtils;
+import org.apache.directory.server.annotations.CreateLdapServer;
+import org.apache.directory.server.annotations.CreateTransport;
import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
+import org.apache.directory.studio.connection.core.Connection;
import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
+import org.apache.directory.studio.connection.core.PasswordsKeyStoreManager;
import org.apache.directory.studio.test.integration.ui.bots.CertificateValidationPreferencePageBot;
import org.apache.directory.studio.test.integration.ui.bots.CertificateViewerDialogBot;
+import org.apache.directory.studio.test.integration.ui.bots.ConnectionsViewBot;
+import org.apache.directory.studio.test.integration.ui.bots.KeepConnectionsPasswordsDialogBot;
+import org.apache.directory.studio.test.integration.ui.bots.PasswordsKeystorePreferencePageBot;
import org.apache.directory.studio.test.integration.ui.bots.PreferencesBot;
+import org.apache.directory.studio.test.integration.ui.bots.SetupMasterPasswordDialogBot;
import org.apache.directory.studio.test.integration.ui.bots.StudioBot;
+import org.apache.directory.studio.test.integration.ui.bots.VerifyMasterPasswordDialogBot;
import org.apache.directory.studio.test.integration.ui.bots.utils.FrameworkRunnerWithScreenshotCaptureListener;
import org.eclipse.core.runtime.Platform;
import org.junit.After;
@@ -54,9 +63,12 @@ import org.junit.runner.RunWith;
* @version $Rev$, $Date$
*/
@RunWith(FrameworkRunnerWithScreenshotCaptureListener.class)
+@CreateLdapServer(transports =
+ { @CreateTransport(protocol = "LDAP") })
public class PreferencesTest extends AbstractLdapTestUnit
{
private StudioBot studioBot;
+ private ConnectionsViewBot connectionsViewBot;
@Before
@@ -64,12 +76,14 @@ public class PreferencesTest extends AbstractLdapTestUnit
{
studioBot = new StudioBot();
studioBot.resetLdapPerspective();
+ connectionsViewBot = studioBot.getConnectionView();
}
@After
public void tearDown() throws Exception
{
+ connectionsViewBot.deleteTestConnections();
}
@@ -171,4 +185,81 @@ public class PreferencesTest extends AbstractLdapTestUnit
preferencesBot.clickCancelButton();
}
+
+ /**
+ * Test for DIRSTUDIO-1179
+ * (java.io.IOException: Invalid secret key format after Java update).
+ */
+ @Test
+ public void testConnectionPasswordsKeystore() throws Exception
+ {
+ Connection connection = connectionsViewBot.createTestConnection( "BrowserTest", ldapServer.getPort() );
+ connectionsViewBot.closeSelectedConnections();
+
+ // the global password keystore manager
+ PasswordsKeyStoreManager passwordsKeyStoreManager = ConnectionCorePlugin.getDefault()
+ .getPasswordsKeyStoreManager();
+
+ URL url = Platform.getInstanceLocation().getURL();
+ File file = new File( url.getFile()
+ + ".metadata/.plugins/org.apache.directory.studio.connection.core/passwords.jks" );
+
+ // verify usage of password keystore is disabled
+ assertFalse( file.exists() );
+ PreferencesBot preferencesBot = studioBot.openPreferences();
+ PasswordsKeystorePreferencePageBot pageBot = preferencesBot.openPasswordsKeystorePage();
+ assertFalse( pageBot.isPasswordsKeystoreEnabled() );
+
+ // enable password keystore
+ SetupMasterPasswordDialogBot setupMasterPasswordDialogBot = pageBot.enablePasswordsKeystore();
+ setupMasterPasswordDialogBot.setMasterPassword( "secret12" );
+ setupMasterPasswordDialogBot.clickOkButton();
+
+ // verify usage of password keystore is enabled
+ assertTrue( pageBot.isPasswordsKeystoreEnabled() );
+
+ // apply
+ preferencesBot.clickOkButton();
+
+ // verify passwords keystore file exists and is loaded
+ assertTrue( file.exists() );
+ assertTrue( passwordsKeyStoreManager.isLoaded() );
+
+ // verify connection can be opened because keystore is already loaded
+ connectionsViewBot.selectConnection( connection.getName() );
+ connectionsViewBot.openSelectedConnection();
+ connectionsViewBot.closeSelectedConnections();
+
+ // unload the keystore
+ passwordsKeyStoreManager.unload();
+ assertFalse( passwordsKeyStoreManager.isLoaded() );
+
+ // verify master password prompt when opening the connection
+ connectionsViewBot.selectConnection( connection.getName() );
+ connectionsViewBot.openSelectedConnectionExpectingVerifyMasterPasswordDialog( "secret12" );
+ connectionsViewBot.closeSelectedConnections();
+
+ // disable password keystore, keep connection password
+ preferencesBot = studioBot.openPreferences();
+ pageBot = preferencesBot.openPasswordsKeystorePage();
+ assertTrue( pageBot.isPasswordsKeystoreEnabled() );
+ KeepConnectionsPasswordsDialogBot keepConnectionsPasswordsDialogBot = pageBot.disablePasswordsKeystore();
+ VerifyMasterPasswordDialogBot verifyMasterPasswordDialog = keepConnectionsPasswordsDialogBot.clickYesButtonExpectingVerifyMasterPasswordDialog();
+ verifyMasterPasswordDialog.enterMasterPassword( "secret12" );
+ verifyMasterPasswordDialog.clickOkButton();
+ assertFalse( pageBot.isPasswordsKeystoreEnabled() );
+
+ // apply
+ preferencesBot.clickOkButton();
+
+ // verify passwords keystore file was deleted
+ assertFalse( file.exists() );
+ assertFalse( passwordsKeyStoreManager.isLoaded() );
+
+ // verify connection can be opened and connections password was kept
+ connectionsViewBot.selectConnection( connection.getName() );
+ connectionsViewBot.openSelectedConnection();
+ connectionsViewBot.closeSelectedConnections();
+ }
+
}
diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/ConnectionsViewBot.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/ConnectionsViewBot.java
index 5f3e508..74983c2 100644
--- a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/ConnectionsViewBot.java
+++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/ConnectionsViewBot.java
@@ -86,6 +86,17 @@ public class ConnectionsViewBot
}
+ public void openSelectedConnectionExpectingVerifyMasterPasswordDialog( String masterPassword )
+ {
+ JobWatcher watcher = new JobWatcher( Messages.jobs__open_connections_name_1 );
+ getConnectionsTree().contextMenu( "Open Connection" ).click();
+ VerifyMasterPasswordDialogBot verifyMasterPasswordDialogBot = new VerifyMasterPasswordDialogBot();
+ verifyMasterPasswordDialogBot.enterMasterPassword( masterPassword );
+ verifyMasterPasswordDialogBot.clickOkButton();
+ watcher.waitUntilDone();
+ }
+
+
public void closeSelectedConnections()
{
JobWatcher watcher = new JobWatcher( Messages.jobs__close_connections_name_1 );
diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PreferencesBot.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/KeepConnectionsPasswordsDialogBot.java
similarity index 52%
copy from tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PreferencesBot.java
copy to tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/KeepConnectionsPasswordsDialogBot.java
index 910ab42..2e9d2e5 100644
--- a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PreferencesBot.java
+++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/KeepConnectionsPasswordsDialogBot.java
@@ -6,49 +6,33 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
- * under the License.
- *
+ * under the License.
+ *
*/
package org.apache.directory.studio.test.integration.ui.bots;
-import org.apache.directory.studio.test.integration.ui.bots.utils.TreeBot;
-
-public class PreferencesBot extends DialogBot
+public class KeepConnectionsPasswordsDialogBot extends DialogBot
{
- public PreferencesBot()
- {
- super( "Preferences" );
- }
-
-
- public CertificateValidationPreferencePageBot openCertificatValidationPage()
+ public KeepConnectionsPasswordsDialogBot()
{
- bot.tree().getTreeItem( "Apache Directory Studio" ).select().expand().getNode( "Connections" ).select()
- .expand().getNode( "Certificate Validation" ).select();
- return new CertificateValidationPreferencePageBot();
+ super( "Keep Connections Passwords?" );
}
- public boolean pageExists( String... path )
+ public VerifyMasterPasswordDialogBot clickYesButtonExpectingVerifyMasterPasswordDialog()
{
- TreeBot treeBot = new TreeBot( bot.tree() );
- return treeBot.exists( path );
+ clickButton( "Yes" );
+ return new VerifyMasterPasswordDialogBot();
}
-
- @Override
- public void clickOkButton()
- {
- super.clickButton( "Apply and Close" );
- }
}
diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PreferencesBot.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PasswordsKeystorePreferencePageBot.java
similarity index 56%
copy from tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PreferencesBot.java
copy to tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PasswordsKeystorePreferencePageBot.java
index 910ab42..9d7fcd2 100644
--- a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PreferencesBot.java
+++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PasswordsKeystorePreferencePageBot.java
@@ -6,49 +6,49 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
- * under the License.
- *
+ * under the License.
+ *
*/
package org.apache.directory.studio.test.integration.ui.bots;
-import org.apache.directory.studio.test.integration.ui.bots.utils.TreeBot;
-
-public class PreferencesBot extends DialogBot
+public class PasswordsKeystorePreferencePageBot extends DialogBot
{
- public PreferencesBot()
+ public PasswordsKeystorePreferencePageBot()
{
super( "Preferences" );
}
- public CertificateValidationPreferencePageBot openCertificatValidationPage()
+ public boolean isPasswordsKeystoreEnabled()
{
- bot.tree().getTreeItem( "Apache Directory Studio" ).select().expand().getNode( "Connections" ).select()
- .expand().getNode( "Certificate Validation" ).select();
- return new CertificateValidationPreferencePageBot();
+ activate();
+ return bot.checkBox().isChecked();
}
- public boolean pageExists( String... path )
+ public SetupMasterPasswordDialogBot enablePasswordsKeystore()
{
- TreeBot treeBot = new TreeBot( bot.tree() );
- return treeBot.exists( path );
+ activate();
+ bot.checkBox().click();
+ return new SetupMasterPasswordDialogBot();
}
- @Override
- public void clickOkButton()
+ public KeepConnectionsPasswordsDialogBot disablePasswordsKeystore()
{
- super.clickButton( "Apply and Close" );
+ activate();
+ bot.checkBox().click();
+ return new KeepConnectionsPasswordsDialogBot();
}
+
}
diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PreferencesBot.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PreferencesBot.java
index 910ab42..c65551a 100644
--- a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PreferencesBot.java
+++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PreferencesBot.java
@@ -51,4 +51,13 @@ public class PreferencesBot extends DialogBot
{
super.clickButton( "Apply and Close" );
}
+
+
+ public PasswordsKeystorePreferencePageBot openPasswordsKeystorePage()
+ {
+ bot.tree().getTreeItem( "Apache Directory Studio" ).select().expand().getNode( "Connections" ).select()
+ .expand().getNode( "Passwords Keystore" ).select();
+ return new PasswordsKeystorePreferencePageBot();
+ }
+
}
diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PreferencesBot.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/SetupMasterPasswordDialogBot.java
similarity index 52%
copy from tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PreferencesBot.java
copy to tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/SetupMasterPasswordDialogBot.java
index 910ab42..e30bcf1 100644
--- a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PreferencesBot.java
+++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/SetupMasterPasswordDialogBot.java
@@ -6,49 +6,33 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
- * under the License.
- *
+ * under the License.
+ *
*/
package org.apache.directory.studio.test.integration.ui.bots;
-import org.apache.directory.studio.test.integration.ui.bots.utils.TreeBot;
-
-public class PreferencesBot extends DialogBot
+public class SetupMasterPasswordDialogBot extends DialogBot
{
- public PreferencesBot()
- {
- super( "Preferences" );
- }
-
-
- public CertificateValidationPreferencePageBot openCertificatValidationPage()
+ public SetupMasterPasswordDialogBot()
{
- bot.tree().getTreeItem( "Apache Directory Studio" ).select().expand().getNode( "Connections" ).select()
- .expand().getNode( "Certificate Validation" ).select();
- return new CertificateValidationPreferencePageBot();
+ super( "Setup Master Password" );
}
- public boolean pageExists( String... path )
+ public void setMasterPassword( String masterPassword )
{
- TreeBot treeBot = new TreeBot( bot.tree() );
- return treeBot.exists( path );
+ bot.text( 0 ).setText( masterPassword );
+ bot.text( 1 ).setText( masterPassword );
}
-
- @Override
- public void clickOkButton()
- {
- super.clickButton( "Apply and Close" );
- }
}
diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PreferencesBot.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/VerifyMasterPasswordDialogBot.java
similarity index 52%
copy from tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PreferencesBot.java
copy to tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/VerifyMasterPasswordDialogBot.java
index 910ab42..80932bb 100644
--- a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PreferencesBot.java
+++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/VerifyMasterPasswordDialogBot.java
@@ -6,49 +6,33 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
- * under the License.
- *
+ * under the License.
+ *
*/
package org.apache.directory.studio.test.integration.ui.bots;
-import org.apache.directory.studio.test.integration.ui.bots.utils.TreeBot;
-
-public class PreferencesBot extends DialogBot
+public class VerifyMasterPasswordDialogBot extends DialogBot
{
- public PreferencesBot()
- {
- super( "Preferences" );
- }
-
-
- public CertificateValidationPreferencePageBot openCertificatValidationPage()
+ public VerifyMasterPasswordDialogBot()
{
- bot.tree().getTreeItem( "Apache Directory Studio" ).select().expand().getNode( "Connections" ).select()
- .expand().getNode( "Certificate Validation" ).select();
- return new CertificateValidationPreferencePageBot();
+ super( "Verify Master Password" );
}
- public boolean pageExists( String... path )
+ public void enterMasterPassword( String masterPassword )
{
- TreeBot treeBot = new TreeBot( bot.tree() );
- return treeBot.exists( path );
+ activate();
+ bot.text().setText( masterPassword );
}
-
- @Override
- public void clickOkButton()
- {
- super.clickButton( "Apply and Close" );
- }
}