Author: rob.stryker(a)jboss.com
Date: 2012-01-17 13:49:00 -0500 (Tue, 17 Jan 2012)
New Revision: 37907
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/.settings/.api_filters
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ServerWorkingCopyPropertyCommand.java
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/server/ServerSecureStorageTest.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/META-INF/MANIFEST.MF
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossServer.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/ServerUtil.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ServerPasswordSection.java
trunk/as/tests/org.jboss.ide.eclipse.as.test/META-INF/MANIFEST.MF
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/ASTestSuite.java
Log:
https://issues.jboss.org/browse/JBIDE-10490 - secure passwords for app servers (NOT
openshift)
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/META-INF/MANIFEST.MF 2012-01-17
18:25:01 UTC (rev 37906)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/META-INF/MANIFEST.MF 2012-01-17
18:49:00 UTC (rev 37907)
@@ -24,7 +24,8 @@
org.eclipse.core.commands;bundle-version="3.6.0",
org.eclipse.pde.core;bundle-version="3.7.0",
org.eclipse.jst.j2ee.web;bundle-version="1.1.500",
- org.jboss.ide.eclipse.as.management.core
+ org.jboss.ide.eclipse.as.management.core,
+ org.eclipse.equinox.security;bundle-version="1.1.1"
Bundle-ActivationPolicy: lazy
Export-Package: org.jboss.ide.eclipse.as.core,
org.jboss.ide.eclipse.as.core.extensions.descriptors,
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossServer.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossServer.java 2012-01-17
18:25:01 UTC (rev 37906)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossServer.java 2012-01-17
18:49:00 UTC (rev 37907)
@@ -28,14 +28,20 @@
import static org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants.WEB_PORT_DETECT;
import static
org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants.WEB_PORT_DETECT_XPATH;
+import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
+import java.net.URLEncoder;
import java.util.Date;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
+import org.eclipse.equinox.security.storage.EncodingUtils;
+import org.eclipse.equinox.security.storage.ISecurePreferences;
+import org.eclipse.equinox.security.storage.SecurePreferencesFactory;
+import org.eclipse.equinox.security.storage.StorageException;
import org.eclipse.jst.server.core.IWebModule;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
@@ -47,7 +53,6 @@
import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
import org.jboss.ide.eclipse.as.core.util.DeploymentPreferenceLoader;
-import org.jboss.ide.eclipse.as.core.util.ExpressionResolverUtil;
import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
import org.jboss.ide.eclipse.as.core.util.RuntimeUtils;
import org.jboss.ide.eclipse.as.core.util.ServerUtil;
@@ -67,7 +72,6 @@
setAttribute("auto-publish-time", 1); //$NON-NLS-1$
setAttribute("id", getAttribute("id", (String)"") + new
Date().getTime()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
setUsername("admin"); //$NON-NLS-1$
- setPassword("admin"); //$NON-NLS-1$
boolean defaultServerDeployment = isAS50() || isEAP(getServer());
setDeployLocationType(defaultServerDeployment ? IDeployableServer.DEPLOY_SERVER :
IDeployableServer.DEPLOY_METADATA);
}
@@ -248,12 +252,16 @@
}
public String getPassword() {
- return getAttribute(SERVER_PASSWORD, ""); //$NON-NLS-1$
+ String s = ServerUtil.getFromSecureStorage(getServer(), SERVER_PASSWORD);
+ if( s == null )
+ return getAttribute(SERVER_PASSWORD, "admin"); //$NON-NLS-1$
+ return s;
}
public void setPassword(String pass) {
- setAttribute(SERVER_PASSWORD, pass);
+ ServerUtil.storeInSecureStorage(getServer(), SERVER_PASSWORD, pass);
}
+
public boolean hasJMXProvider() {
DeployableServerBehavior beh = (DeployableServerBehavior)getServer().loadAdapter(
DeployableServerBehavior.class, new NullProgressMonitor());
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/ServerUtil.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/ServerUtil.java 2012-01-17
18:25:01 UTC (rev 37906)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/ServerUtil.java 2012-01-17
18:49:00 UTC (rev 37907)
@@ -11,6 +11,11 @@
package org.jboss.ide.eclipse.as.core.util;
import java.io.File;
+import java.io.IOError;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URL;
+import java.net.URLEncoder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
@@ -18,6 +23,10 @@
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
+import org.eclipse.equinox.security.storage.EncodingUtils;
+import org.eclipse.equinox.security.storage.ISecurePreferences;
+import org.eclipse.equinox.security.storage.SecurePreferencesFactory;
+import org.eclipse.equinox.security.storage.StorageException;
import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.server.core.IRuntime;
import org.eclipse.wst.server.core.IServer;
@@ -167,4 +176,53 @@
return new Path(checkedGetServerHome(jbs));
}
+
+ private static final String SECURE = "secure"; //$NON-NLS-1$
+ /**
+ * @since 2.3
+ */
+ public static String getFromSecureStorage(IServer server, String key) {
+ try {
+ ISecurePreferences node = getNode(server);
+ String val = node.get(key, null);
+ if (val == null) {
+ return null;
+ }
+ return new String(EncodingUtils.decodeBase64(val));
+ } catch(IOException e) {
+ return null;
+ } catch (StorageException e) {
+ return null;
+ }
+ }
+
+ /**
+ * @since 2.3
+ */
+ public static void storeInSecureStorage(IServer server, String key, String val ) {
+ try {
+ ISecurePreferences node = getNode(server);
+ if( val == null )
+ node.put(key, val, true);
+ else
+ node.put(key, EncodingUtils.encodeBase64(val.getBytes()), true /* encrypt
*/);
+ } catch (StorageException e) {
+ } catch (UnsupportedEncodingException e) {
+ }
+ }
+
+ private static ISecurePreferences getNode(IServer server) throws
UnsupportedEncodingException {
+ try {
+ IPath p = JBossServerCorePlugin.getServerStateLocation(server).append(SECURE);
+ if( !p.toFile().exists())
+ p.toFile().mkdirs();
+
+ URL url = p.toFile().toURI().toURL();
+ ISecurePreferences root = SecurePreferencesFactory.open(url, null);
+ return root;
+ } catch(IOException ioe ) {
+ return null;
+ }
+ }
+
}
Added: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/.settings/.api_filters
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/.settings/.api_filters
(rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ui/.settings/.api_filters 2012-01-17
18:49:00 UTC (rev 37907)
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"
standalone="no"?>
+<component id="org.jboss.ide.eclipse.as.ui" version="2">
+ <resource
path="jbossui/org/jboss/ide/eclipse/as/ui/editor/ServerPasswordSection.java"
type="org.jboss.ide.eclipse.as.ui.editor.ServerPasswordSection">
+ <filter id="338886760">
+ <message_arguments>
+ <message_argument
value="org.jboss.ide.eclipse.as.ui.editor.ServerPasswordSection.SetVarCommand"/>
+ <message_argument
value="org.jboss.ide.eclipse.as.ui_2.3.0"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource
path="jbossui/org/jboss/ide/eclipse/as/ui/editor/ServerPasswordSection.java"
type="org.jboss.ide.eclipse.as.ui.editor.ServerPasswordSection$SetPassCommand">
+ <filter id="338849923">
+ <message_arguments>
+ <message_argument
value="org.jboss.ide.eclipse.as.ui.editor.ServerPasswordSection.SetPassCommand"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource
path="jbossui/org/jboss/ide/eclipse/as/ui/editor/ServerPasswordSection.java"
type="org.jboss.ide.eclipse.as.ui.editor.ServerPasswordSection$SetUserCommand">
+ <filter id="338849923">
+ <message_arguments>
+ <message_argument
value="org.jboss.ide.eclipse.as.ui.editor.ServerPasswordSection.SetUserCommand"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource
path="jbossui/org/jboss/ide/eclipse/as/ui/editor/ServerPasswordSection.java"
type="org.jboss.ide.eclipse.as.ui.editor.ServerPasswordSection$SetVarCommand">
+ <filter comment="Visibility error" id="337686583">
+ <message_arguments>
+ <message_argument
value="org.jboss.ide.eclipse.as.ui.editor.ServerPasswordSection.SetVarCommand"/>
+ </message_arguments>
+ </filter>
+ </resource>
+</component>
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ServerPasswordSection.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ServerPasswordSection.java 2012-01-17
18:25:01 UTC (rev 37906)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ServerPasswordSection.java 2012-01-17
18:49:00 UTC (rev 37907)
@@ -21,6 +21,7 @@
*/
package org.jboss.ide.eclipse.as.ui.editor;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
@@ -52,6 +53,9 @@
private ModifyListener nameModifyListener, passModifyListener;
private Text nameText, passText;
private ServerAttributeHelper helper;
+
+ private String passwordString;
+
public void init(IEditorSite site, IEditorInput input) {
super.init(site, input);
helper = new ServerAttributeHelper(server.getOriginal(), server);
@@ -80,6 +84,7 @@
Label password = toolkit.createLabel(composite, Messages.swf_Password);
password.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
passText = toolkit.createText(composite, p);
+ passwordString = p;
d = new GridData(); d.grabExcessHorizontalSpace = true; d.widthHint = 100;
nameText.setLayoutData(d);
@@ -105,47 +110,37 @@
}
- public class SetUserCommand extends SetVarCommand {
+ public class SetUserCommand extends ServerWorkingCopyPropertyCommand {
public SetUserCommand(IServerWorkingCopy server) {
super(server, Messages.EditorChangeUsernameCommandName, nameText, nameText.getText(),
IJBossToolingConstants.SERVER_USERNAME, nameModifyListener);
}
}
- public class SetPassCommand extends SetVarCommand {
+ public class SetPassCommand extends ServerWorkingCopyPropertyCommand {
public SetPassCommand(IServerWorkingCopy server) {
super(server, Messages.EditorChangePasswordCommandName, passText, passText.getText(),
IJBossToolingConstants.SERVER_PASSWORD, passModifyListener);
}
- }
-
- public class SetVarCommand extends ServerCommand {
- private String oldVal;
- private String newVal;
- private String key;
- private Text text;
- private ModifyListener listener;
- public SetVarCommand(IServerWorkingCopy wc, String name,
- Text text, String newVal, String attributeKey,
- ModifyListener listener) {
- super(wc, name);
- this.text = text;
- this.key = attributeKey;
- this.newVal = newVal;
- this.listener = listener;
- this.oldVal = helper.getAttribute(attributeKey, ""); //$NON-NLS-1$
- }
-
public void execute() {
- helper.setAttribute(key, newVal);
+ passwordString = newVal;
}
public void undo() {
+ passwordString = oldVal;
text.removeModifyListener(listener);
- helper.setAttribute(key, oldVal);
text.setText(oldVal);
text.addModifyListener(listener);
}
}
+
+ /**
+ * Allow a section an opportunity to respond to a doSave request on the editor.
+ * @param monitor the progress monitor for the save operation.
+ */
+ public void doSave(IProgressMonitor monitor) {
+ monitor.worked(100);
+ }
+
}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ServerWorkingCopyPropertyCommand.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ServerWorkingCopyPropertyCommand.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ServerWorkingCopyPropertyCommand.java 2012-01-17
18:49:00 UTC (rev 37907)
@@ -0,0 +1,43 @@
+package org.jboss.ide.eclipse.as.ui.editor;
+
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+import org.eclipse.wst.server.ui.internal.command.ServerCommand;
+/**
+ * @since 2.3
+ */
+public class ServerWorkingCopyPropertyCommand extends ServerCommand {
+ protected String oldVal;
+ protected String newVal;
+ protected String key;
+ protected Text text;
+ protected ModifyListener listener;
+ protected IServerWorkingCopy wc;
+
+ public ServerWorkingCopyPropertyCommand(IServerWorkingCopy wc, String commandName,
+ Text text, String newVal, String attributeKey,
+ ModifyListener listener) {
+ super(wc, commandName);
+ this.wc = wc;
+ this.text = text;
+ this.key = attributeKey;
+ this.newVal = newVal;
+ this.listener = listener;
+ this.oldVal = wc.getAttribute(attributeKey, ""); //$NON-NLS-1$
+ }
+
+ public void execute() {
+ wc.setAttribute(key, newVal);
+ }
+
+ public void undo() {
+ if( listener != null )
+ text.removeModifyListener(listener);
+ wc.setAttribute(key, oldVal);
+ if( text != null && !text.isDisposed())
+ text.setText(oldVal);
+ if( listener != null )
+ text.addModifyListener(listener);
+ }
+}
\ No newline at end of file
Modified: trunk/as/tests/org.jboss.ide.eclipse.as.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/as/tests/org.jboss.ide.eclipse.as.test/META-INF/MANIFEST.MF 2012-01-17 18:25:01
UTC (rev 37906)
+++ trunk/as/tests/org.jboss.ide.eclipse.as.test/META-INF/MANIFEST.MF 2012-01-17 18:49:00
UTC (rev 37907)
@@ -42,7 +42,8 @@
org.jboss.ide.eclipse.as.wtp.ui,
org.eclipse.jst.jsf.core,
org.eclipse.jpt.jpa.core,
- org.jboss.ide.eclipse.as.management.core;bundle-version="1.0.0"
+ org.jboss.ide.eclipse.as.management.core;bundle-version="1.0.0",
+ org.eclipse.equinox.security;bundle-version="1.1.1"
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %Bundle-Vendor.0
Bundle-Localization: plugin
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/ASTestSuite.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/ASTestSuite.java 2012-01-17
18:25:01 UTC (rev 37906)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/ASTestSuite.java 2012-01-17
18:49:00 UTC (rev 37907)
@@ -42,6 +42,7 @@
import org.jboss.ide.eclipse.as.test.publishing.v2.SingleFileDeploymentTester;
import org.jboss.ide.eclipse.as.test.server.JBossServerAPITest;
import org.jboss.ide.eclipse.as.test.server.ServerBeanLoaderTest;
+import org.jboss.ide.eclipse.as.test.server.ServerSecureStorageTest;
import org.jboss.ide.eclipse.as.test.util.ArgsUtilTest;
import org.jboss.ide.eclipse.as.test.util.ExpressionResolverUtilTest;
@@ -53,6 +54,7 @@
suite.addTestSuite(ExpressionResolverUtilTest.class);
suite.addTestSuite(PreReqTest.class);
suite.addTestSuite(ServerBeanLoaderTest.class);
+ suite.addTestSuite(ServerSecureStorageTest.class);
suite.addTestSuite(RuntimeServerModelTest.class);
suite.addTestSuite(JEEClasspathContainerTest.class);
suite.addTestSuite(ProjectRuntimeTest.class);
Added:
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/server/ServerSecureStorageTest.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/server/ServerSecureStorageTest.java
(rev 0)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/server/ServerSecureStorageTest.java 2012-01-17
18:49:00 UTC (rev 37907)
@@ -0,0 +1,82 @@
+package org.jboss.ide.eclipse.as.test.server;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+import org.eclipse.wst.server.core.ServerCore;
+import org.jboss.ide.eclipse.as.core.server.internal.JBossServer;
+import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
+import org.jboss.ide.eclipse.as.core.util.ServerConverter;
+import org.jboss.ide.eclipse.as.core.util.ServerUtil;
+import org.jboss.ide.eclipse.as.test.util.ServerRuntimeUtils;
+import org.jboss.ide.eclipse.as.test.util.wtp.ProjectUtility;
+
+public class ServerSecureStorageTest extends TestCase {
+ public void tearDown() {
+ try {
+ ProjectUtility.deleteAllProjects();
+ ServerRuntimeUtils.deleteAllServers();
+ ServerRuntimeUtils.deleteAllRuntimes();
+ } catch(Exception e) {
+ }
+ }
+
+ public void testServerSecureStorage() throws CoreException {
+ IServer server = ServerRuntimeUtils.create60Server();
+ String val = ServerUtil.getFromSecureStorage(server, "TEST");
+ assertNull(val);
+ ServerUtil.storeInSecureStorage(server, "TEST", "VAL");
+ val = ServerUtil.getFromSecureStorage(server, "TEST");
+ assertEquals(val, "VAL");
+ }
+
+ public void testUserPass() throws CoreException {
+ IServer server = ServerRuntimeUtils.create60Server();
+ JBossServer jbs = ServerConverter.getJBossServer(server);
+ assertEquals(jbs.getUsername(), "admin");
+ assertEquals(jbs.getPassword(), "admin");
+
+ IServerWorkingCopy wc = server.createWorkingCopy();
+ wc.setAttribute(IJBossToolingConstants.SERVER_USERNAME, "newUser");
+ wc.setAttribute(IJBossToolingConstants.SERVER_PASSWORD, "newPass");
+ server = wc.save(false, null);
+
+ assertEquals(jbs.getUsername(), "newUser");
+ assertEquals(jbs.getPassword(), "newPass");
+
+ try {
+ jbs = ServerConverter.getJBossServer(server);
+ jbs.setUsername("failUser");
+ fail();
+ } catch( NullPointerException npe ) {
+ // expected... cannot set attributes when there is no working copy!
+ }
+
+ IServer server2 = ServerCore.findServer(server.getId());
+ jbs = ServerConverter.getJBossServer(server2);
+ assertEquals(jbs.getUsername(), "newUser");
+ assertEquals(jbs.getPassword(), "newPass");
+
+ // Note, the jbs is NOT from this new working copy
+ try {
+ wc = server2.createWorkingCopy();
+ jbs.setUsername("successUser");
+ fail();
+ } catch(NullPointerException npe ) {
+ // expected. The jbs must be created after the working copy
+ }
+
+ // Note, jbs must be made out of wc
+ wc = server2.createWorkingCopy();
+ jbs = ServerConverter.getJBossServer(wc);
+ jbs.setUsername("successUser");
+ jbs.setPassword("successPass");
+ server = wc.save(false, null);
+
+ jbs = ServerConverter.getJBossServer(server);
+ assertEquals(jbs.getUsername(), "successUser");
+ assertEquals(jbs.getPassword(), "successPass");
+ }
+}