diff options
author | Shireesh Anjal <shireesh@gluster.com> | 2011-06-09 19:46:40 +0530 |
---|---|---|
committer | Shireesh Anjal <shireesh@gluster.com> | 2011-06-09 19:54:08 +0530 |
commit | 03deae0a3067483df28299d7690a10e182d1ef2f (patch) | |
tree | 9104e6ff0d2bd5642f65b1f2487bc3a6fb43dc37 | |
parent | 81e667e15bb51c6f998050c5dee231fb433845c9 (diff) |
SSL communication between console and gateway
31 files changed, 178 insertions, 259 deletions
diff --git a/src/com.gluster.storage.management.client/.classpath b/src/com.gluster.storage.management.client/.classpath index b8f71a37..d216a8fe 100644 --- a/src/com.gluster.storage.management.client/.classpath +++ b/src/com.gluster.storage.management.client/.classpath @@ -1,10 +1,11 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> + <classpathentry exported="true" kind="lib" path="keystore/"/> <classpathentry exported="true" kind="lib" path="lib/jersey-1.5/jersey-client-1.5.jar" sourcepath="/data/downloads/sun/jersey/sources/jersey-client-1.5-sources.jar"/> <classpathentry exported="true" kind="lib" path="lib/jersey-1.5/jersey-core-1.5.jar" sourcepath="/data/downloads/sun/jersey/sources/jersey-core-1.5-sources.jar"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> - <classpathentry kind="src" path="src"/> + <classpathentry excluding="keystore/" kind="src" path="src"/> <classpathentry combineaccessrules="false" kind="src" path="/com.gluster.storage.management.core"/> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/src/com.gluster.storage.management.client/META-INF/MANIFEST.MF b/src/com.gluster.storage.management.client/META-INF/MANIFEST.MF index 43ae7c3e..56cfe32e 100644 --- a/src/com.gluster.storage.management.client/META-INF/MANIFEST.MF +++ b/src/com.gluster.storage.management.client/META-INF/MANIFEST.MF @@ -11,4 +11,5 @@ Export-Package: com.gluster.storage.management.client, com.gluster.storage.management.client.constants Bundle-ClassPath: ., lib/jersey-1.5/jersey-client-1.5.jar, - lib/jersey-1.5/jersey-core-1.5.jar + lib/jersey-1.5/jersey-core-1.5.jar, + keystore/ diff --git a/src/com.gluster.storage.management.client/build.properties b/src/com.gluster.storage.management.client/build.properties index 271ce382..4dded7a7 100644 --- a/src/com.gluster.storage.management.client/build.properties +++ b/src/com.gluster.storage.management.client/build.properties @@ -2,7 +2,13 @@ source.. = src/ output.. = bin/ bin.includes = .,\ META-INF/,\ - lib/jersey-1.5/jersey-client-1.5.jar,\ - lib/jersey-1.5/jersey-core-1.5.jar -src.includes = lib/jersey-1.4/jersey-client-1.4.jar,\ - lib/jersey-1.4/jersey-core-1.4.jar + lib/,\ + keystore/ +src.includes = src/,\ + lib/,\ + keystore/,\ + build.properties,\ + .project,\ + .classpath,\ + .settings/,\ + META-INF/ diff --git a/src/com.gluster.storage.management.client/keystore/gmc-trusted.keystore b/src/com.gluster.storage.management.client/keystore/gmc-trusted.keystore Binary files differnew file mode 100644 index 00000000..5517b6e5 --- /dev/null +++ b/src/com.gluster.storage.management.client/keystore/gmc-trusted.keystore diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/AbstractClient.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/AbstractClient.java index 4aa029b8..e8df26cb 100644 --- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/AbstractClient.java +++ b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/AbstractClient.java @@ -1,10 +1,21 @@ package com.gluster.storage.management.client;
+import static com.gluster.storage.management.client.constants.ClientConstants.ALGORITHM_SUNX509;
+import static com.gluster.storage.management.client.constants.ClientConstants.KEYSTORE_TYPE_JKS;
+import static com.gluster.storage.management.client.constants.ClientConstants.PROTOCOL_TLS;
+import static com.gluster.storage.management.client.constants.ClientConstants.TRUSTED_KEYSTORE;
+import static com.gluster.storage.management.client.constants.ClientConstants.TRUSTED_KEYSTORE_ACCESS;
+
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.net.URI;
+import java.security.KeyStore;
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSession;
+import javax.net.ssl.TrustManagerFactory;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
@@ -15,6 +26,7 @@ import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.api.representation.Form;
+import com.sun.jersey.client.urlconnection.HTTPSProperties;
import com.sun.jersey.core.util.MultivaluedMapImpl;
public abstract class AbstractClient {
@@ -43,9 +55,55 @@ public abstract class AbstractClient { public AbstractClient(String securityToken, String clusterName) {
this.clusterName = clusterName;
setSecurityToken(securityToken);
- URI baseURI = new ClientUtil().getServerBaseURI();
+
+ SSLContext context = initializeSSLContext();
+ DefaultClientConfig config = createClientConfig(context);
+
// this must be after setting clusterName as sub-classes may refer to cluster name in the getResourcePath method
- resource = Client.create(new DefaultClientConfig()).resource(baseURI).path(getResourcePath());
+ resource = Client.create(config).resource(ClientUtil.getServerBaseURI()).path(getResourcePath());
+ }
+
+ private DefaultClientConfig createClientConfig(SSLContext context) {
+ DefaultClientConfig config = new DefaultClientConfig();
+ config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES,
+ new HTTPSProperties(createHostnameVerifier(), context));
+ return config;
+ }
+
+ private HostnameVerifier createHostnameVerifier() {
+ HostnameVerifier hostnameVerifier = new HostnameVerifier() {
+ @Override
+ public boolean verify(String arg0, SSLSession arg1) {
+ return true;
+ }
+ };
+ return hostnameVerifier;
+ }
+
+ private SSLContext initializeSSLContext() {
+ SSLContext context = null;
+ try {
+ context = SSLContext.getInstance(PROTOCOL_TLS);
+
+ KeyStore keyStore = KeyStore.getInstance(KEYSTORE_TYPE_JKS);
+ keyStore.load(loadResource(TRUSTED_KEYSTORE), TRUSTED_KEYSTORE_ACCESS.toCharArray());
+
+ KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(ALGORITHM_SUNX509);
+ keyManagerFactory.init(keyStore, TRUSTED_KEYSTORE_ACCESS.toCharArray());
+
+ TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(ALGORITHM_SUNX509);
+ trustManagerFactory.init(keyStore);
+
+ context.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
+ } catch (Exception e) {
+ throw new GlusterRuntimeException(
+ "Couldn't initialize SSL Context with Gluster Management Gateway! Error: " + e, e);
+ }
+ return context;
+ }
+
+ private InputStream loadResource(String resourcePath) {
+ return this.getClass().getClassLoader().getResourceAsStream(resourcePath);
}
/**
diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/constants/ClientConstants.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/constants/ClientConstants.java index 853cfe96..4726fc36 100644 --- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/constants/ClientConstants.java +++ b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/constants/ClientConstants.java @@ -25,8 +25,15 @@ package com.gluster.storage.management.client.constants; */ public class ClientConstants { public static final String SYS_PROP_SERVER_URL = "gluster.server.url"; - public static final String DEFAULT_SERVER_URL = "http://localhost:8080/glustermc/linux.gtk.x86_64"; - public static final String WEB_CONTEXT = "glustermc"; + public static final String DEFAULT_SERVER_URL = "https://localhost:8443/glustermg/linux.gtk.x86_64"; + public static final String CONTEXT_ROOT = "glustermg"; public static final String WEB_RESOURCE_BASE_PATH = "resources"; + + // SSL related + public static final String TRUSTED_KEYSTORE = "gmc-trusted.keystore"; + public static final String TRUSTED_KEYSTORE_ACCESS = "gluster"; + public static final String PROTOCOL_TLS = "TLS"; + public static final String ALGORITHM_SUNX509 = "SunX509"; + public static final String KEYSTORE_TYPE_JKS = "JKS"; } diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/utils/ClientUtil.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/utils/ClientUtil.java index 23d2f9fd..4f7ea64e 100644 --- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/utils/ClientUtil.java +++ b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/utils/ClientUtil.java @@ -8,13 +8,13 @@ import com.gluster.storage.management.client.constants.ClientConstants; public class ClientUtil { - public URI getServerBaseURI() { + public static URI getServerBaseURI() { return UriBuilder.fromUri(getBaseURL()).path(ClientConstants.WEB_RESOURCE_BASE_PATH).build(); } - private String getBaseURL() { + private static String getBaseURL() { // remove the platform path (e.g. /linux.gtk.x86_64) from the URL return System.getProperty(ClientConstants.SYS_PROP_SERVER_URL, ClientConstants.DEFAULT_SERVER_URL) - .replaceAll("glustermc\\/.*", "glustermc\\/"); + .replaceAll(ClientConstants.CONTEXT_ROOT + "\\/.*", ClientConstants.CONTEXT_ROOT + "\\/"); } } diff --git a/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/TestFileUtil.java b/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/TestFileUtil.java index 8902ae8f..699346f7 100644 --- a/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/TestFileUtil.java +++ b/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/TestFileUtil.java @@ -72,13 +72,4 @@ public class TestFileUtil { assertTrue("File contents expected [" + fileContent + "], actual [" + readContent + "]", readContent.equals(fileContent)); } - - /** - * Test method for {@link com.gluster.storage.management.core.utils.FileUtil#loadResource(java.lang.String)}. - */ - @Test - public final void testLoadResource() { - InputStream inputStream = fileUtil.loadResource("test/test.txt"); - Assert.assertNotNull(inputStream); - } } diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/FileUtil.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/FileUtil.java index 8c77fbab..d93ab2fb 100644 --- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/FileUtil.java +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/FileUtil.java @@ -30,7 +30,7 @@ import com.gluster.storage.management.core.constants.CoreConstants; import com.gluster.storage.management.core.exceptions.GlusterRuntimeException; public class FileUtil { - public String readFileAsString(File file) { + public static String readFileAsString(File file) { try { return new String(readFileAsByteArray(file), CoreConstants.ENCODING_UTF8); } catch (Exception e) { @@ -39,7 +39,7 @@ public class FileUtil { } } - public byte[] readFileAsByteArray(File file) throws FileNotFoundException, IOException { + public static byte[] readFileAsByteArray(File file) throws FileNotFoundException, IOException { FileInputStream fileInputStream = new FileInputStream(file); byte[] data = new byte[fileInputStream.available()]; fileInputStream.read(data); @@ -47,11 +47,7 @@ public class FileUtil { return data; } - public InputStream loadResource(String resourcePath) { - return this.getClass().getClassLoader().getResourceAsStream(resourcePath); - } - - public void createTextFile(String fileName, String contents) { + public static void createTextFile(String fileName, String contents) { try { FileWriter writer = new FileWriter(fileName); writer.write(contents); @@ -61,7 +57,7 @@ public class FileUtil { } } - public String getTempDirName() { + public static String getTempDirName() { return System.getProperty("java.io.tmpdir"); } @@ -72,7 +68,7 @@ public class FileUtil { * @return the new directory * @throws IOException if there is an error creating the temporary directory */ - public File createTempDir() + public static File createTempDir() { final File sysTempDir = new File(getTempDirName()); File newTempDir; @@ -111,7 +107,7 @@ public class FileUtil { * the file or dir to delete * @return true if all files are successfully deleted */ - public boolean recursiveDelete(File fileOrDir) + public static boolean recursiveDelete(File fileOrDir) { if(fileOrDir.isDirectory()) { diff --git a/src/com.gluster.storage.management.gui/plugin.xml b/src/com.gluster.storage.management.gui/plugin.xml index 89b2460b..f4c3c8f6 100644 --- a/src/com.gluster.storage.management.gui/plugin.xml +++ b/src/com.gluster.storage.management.gui/plugin.xml @@ -16,7 +16,7 @@ <perspective name="Gluster Perspective" class="com.gluster.storage.management.gui.Perspective" - id="com.gluster.storage.management.gui.perspective"> + id="com.gluster.storage.management.gui.Perspective"> </perspective> </extension> <extension @@ -30,15 +30,6 @@ restorable="true"> </view> <view - allowMultiple="false" - category="com.gluster.storage.management.gui.category" - class="com.gluster.storage.management.gui.views.DetailsView" - icon="icons/gluster_icon.png" - id="com.gluster.storage.management.gui.views.details.DetailsView" - name="Details" - restorable="true"> - </view> - <view category="org.eclipse.ui" class="org.eclipse.ui.ExtensionFactory:progressView" icon="icons/progress-bar.png" diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/Perspective.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/Perspective.java index 3f8702ce..6a4bb37b 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/Perspective.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/Perspective.java @@ -21,15 +21,12 @@ package com.gluster.storage.management.gui; import org.eclipse.ui.IPageLayout; import org.eclipse.ui.IPerspectiveFactory; -import com.gluster.storage.management.gui.views.DetailsView; -import com.gluster.storage.management.gui.views.NavigationView; - public class Perspective implements IPerspectiveFactory { /** * The ID of the perspective as specified in the extension. */ - public static final String ID = "com.gluster.storage.management.gui.perspective"; + public static final String ID = Perspective.class.getName(); public void createInitialLayout(IPageLayout layout) { layout.setEditorAreaVisible(false); diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/AddServerAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/AddServerAction.java index 230bff6a..4fd99cc7 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/AddServerAction.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/AddServerAction.java @@ -65,13 +65,13 @@ public class AddServerAction extends AbstractActionDelegate { } } - showStatusMessage(action.getDescription(), selectedServers, successServers, errMsg, partErrMsg); + showStatusMessage(action.getDescription(), selectedServers, successServers, partSuccessServers, errMsg, partErrMsg); } }); } private void showStatusMessage(String dialogTitle, Set<Server> selectedServers, Set<Server> successServers, - String errMsg, String partErrMsg) { + Set<Server> partSuccessServers, String errMsg, String partErrMsg) { if (successServers.size() == selectedServers.size()) { if (selectedServers.size() == 1) { showInfoDialog(dialogTitle, "Server [" + selectedServers.iterator().next() + "] added successfully!"); @@ -83,15 +83,13 @@ public class AddServerAction extends AbstractActionDelegate { } String finalMsg = ""; - if (successServers.size() == 0) { + if (successServers.size() == 0 && partSuccessServers.size() == 0) { finalMsg = "Server Addition Failed! Error(s):" + CoreConstants.NEWLINE + errMsg; } else { - finalMsg = "Following servers added successfully : " - + CoreConstants.NEWLINE - + successServers - + (partErrMsg.isEmpty() ? "" : CoreConstants.NEWLINE - + "Following servers were added to cluster, but with some errors: " + CoreConstants.NEWLINE - + partErrMsg) + finalMsg = (successServers.isEmpty() ? "" : "Following servers added successfully : " + + CoreConstants.NEWLINE + successServers + CoreConstants.NEWLINE) + + (partSuccessServers.isEmpty() ? "" : "Following servers were added to cluster, but with some errors: " + + CoreConstants.NEWLINE + partErrMsg + CoreConstants.NEWLINE) + (errMsg.isEmpty() ? "" : CoreConstants.NEWLINE + "Following errors occurred on other selected servers: " + CoreConstants.NEWLINE + errMsg); } diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/GUIHelper.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/GUIHelper.java index a38c6b38..9e2ec9e0 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/GUIHelper.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/GUIHelper.java @@ -366,12 +366,11 @@ public class GUIHelper { * Type of the selected object to look for * @return The selected object of given type if found, else null */ - @SuppressWarnings("rawtypes") - public Object getSelectedEntity(IWorkbenchSite site, Class expectedType) { + public <T> T getSelectedEntity(IWorkbenchSite site, Class<T> expectedType) { return getSelectedEntity(site.getWorkbenchWindow(), expectedType); } - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings({ "unchecked" }) public <T> T getSelectedEntity(IWorkbenchWindow window, Class<T> expectedType) { ISelection selection = window.getSelectionService().getSelection(NavigationView.ID); if (selection instanceof IStructuredSelection) { diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/DetailsView.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/DetailsView.java deleted file mode 100644 index efdb6457..00000000 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/DetailsView.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com> - * This file is part of Gluster Management Console. - * - * Gluster Management Console is free software; you can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Gluster Management Console is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License - * for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see - * <http://www.gnu.org/licenses/>. - *******************************************************************************/ -package com.gluster.storage.management.gui.views; - -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.TreeSelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.TabFolder; -import org.eclipse.swt.widgets.TabItem; -import org.eclipse.ui.ISelectionListener; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchPartSite; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.forms.widgets.FormToolkit; -import org.eclipse.ui.part.ViewPart; - -import com.gluster.storage.management.core.model.Entity; -import com.gluster.storage.management.gui.toolbar.GlusterToolbarManager; -import com.gluster.storage.management.gui.views.details.TabCreatorFactory; -import com.gluster.storage.management.gui.views.details.TabCreatorFactoryImpl; - -/** - * This view is displayed on the right hand side of the platform UI. It updates itself with appropriate tabs - * whenever selection changes on the navigation view (cluster tree) on the left hand side of the UI. - */ -public class DetailsView extends ViewPart implements ISelectionListener { - public static final String ID = DetailsView.class.getName(); - private final FormToolkit toolkit = new FormToolkit(Display.getCurrent()); - private TabFolder tabFolder; - private Entity entity; - private TabCreatorFactory tabCreatorFactory = new TabCreatorFactoryImpl(); - private GlusterToolbarManager toolbarManager; - private IWorkbenchPartSite site; - - public DetailsView() { - super(); - } - - @Override - public void createPartControl(final Composite parent) { - parent.addDisposeListener(new DisposeListener() { - public void widgetDisposed(DisposeEvent e) { - toolkit.dispose(); - } - }); - - tabFolder = new TabFolder(parent, SWT.TOP); - - // listen to selection event on the navigation tree view - IWorkbenchWindow window = getViewSite().getWorkbenchWindow(); - window.getSelectionService().addSelectionListener(this); - - // Create the toolbar manager - toolbarManager = new GlusterToolbarManager(window); - site = getSite(); - } - - @Override - public void setFocus() { - tabFolder.setFocus(); - } - - private void removeAllTabs() { - for (TabItem item : tabFolder.getItems()) { - item.getControl().dispose(); - item.dispose(); - } - } - - @Override - public void selectionChanged(IWorkbenchPart part, ISelection selection) { - if (part instanceof NavigationView && selection instanceof TreeSelection) { - Entity selectedEntity = (Entity) ((TreeSelection) selection).getFirstElement(); - - if (entity == selectedEntity || selectedEntity == null) { - // entity selection has not changed. do nothing. - return; - } - - entity = selectedEntity; - removeAllTabs(); - - // Create tabs for newly selected entity - tabCreatorFactory.getTabCreator(entity).createTabs(entity, tabFolder, toolkit, site); - - // update toolbar buttons visibility based on selected entity - toolbarManager.updateToolbar(entity); - } - } -} diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/DiscoveredServersView.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/DiscoveredServersView.java index 69c506f4..fe0b1f36 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/DiscoveredServersView.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/DiscoveredServersView.java @@ -22,12 +22,8 @@ package com.gluster.storage.management.gui.views; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; -import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TreeSelection; import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.ISelectionListener; -import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.part.ViewPart; import com.gluster.storage.management.core.model.Entity; @@ -39,7 +35,7 @@ import com.gluster.storage.management.gui.views.pages.ServersPage; /** * */ -public class DiscoveredServersView extends ViewPart implements IDoubleClickListener, ISelectionListener { +public class DiscoveredServersView extends ViewPart implements IDoubleClickListener { public static final String ID = DiscoveredServersView.class.getName(); private static final GUIHelper guiHelper = GUIHelper.getInstance(); private EntityGroup<Server> servers; @@ -53,6 +49,7 @@ public class DiscoveredServersView extends ViewPart implements IDoubleClickListe * * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) */ + @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void createPartControl(Composite parent) { if (servers == null) { @@ -64,7 +61,6 @@ public class DiscoveredServersView extends ViewPart implements IDoubleClickListe page = new ServersPage(parent, getSite(), servers); page.addDoubleClickListener(this); - getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(NavigationView.ID, this); } /* @@ -84,26 +80,4 @@ public class DiscoveredServersView extends ViewPart implements IDoubleClickListe clusterView.selectEntity((Entity) ((StructuredSelection) event.getSelection()).getFirstElement()); } } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, - * org.eclipse.jface.viewers.ISelection) - */ - @Override - public void selectionChanged(IWorkbenchPart part, ISelection selection) { - if (part instanceof NavigationView && selection instanceof TreeSelection) { - Entity selectedEntity = (Entity) ((TreeSelection) selection).getFirstElement(); - - if (servers == selectedEntity || selectedEntity == null || !(selectedEntity instanceof EntityGroup) - || ((EntityGroup) selectedEntity).getEntityType() != Server.class) { - // entity selection has not changed. do nothing. - return; - } - - servers = (EntityGroup<Server>) selectedEntity; - page.setInput(servers); - } - } } diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/GlusterServersView.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/GlusterServersView.java index fa9c2e7f..dfaf904a 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/GlusterServersView.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/GlusterServersView.java @@ -46,10 +46,11 @@ public class GlusterServersView extends ViewPart implements IDoubleClickListener /* (non-Javadoc) * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) */ + @SuppressWarnings("unchecked") @Override public void createPartControl(Composite parent) { if (servers == null) { - servers = (EntityGroup<GlusterServer>)guiHelper.getSelectedEntity(getSite(), EntityGroup.class); + servers = (EntityGroup<GlusterServer>) guiHelper.getSelectedEntity(getSite(), EntityGroup.class); } page = new GlusterServersPage(getSite(), parent, SWT.NONE, servers); diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/NavigationView.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/NavigationView.java index aede70c5..a5da2f62 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/NavigationView.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/NavigationView.java @@ -61,7 +61,7 @@ public class NavigationView extends ViewPart implements ISelectionListener { viewsManager = new GlusterViewsManager(getSite().getPage()); // listen to selection events to update views/toolbar accordingly - getSite().getPage().addSelectionListener(this); + getSite().getPage().addPostSelectionListener(this); } private void createNavigationTree(Composite parent) { diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/VolumesView.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/VolumesView.java index 4ccf5325..0a48d870 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/VolumesView.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/VolumesView.java @@ -22,26 +22,20 @@ package com.gluster.storage.management.gui.views; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; -import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TreeSelection; import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.ISelectionListener; -import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.part.ViewPart; import com.gluster.storage.management.core.model.Entity; import com.gluster.storage.management.core.model.EntityGroup; -import com.gluster.storage.management.core.model.Server; import com.gluster.storage.management.core.model.Volume; import com.gluster.storage.management.gui.utils.GUIHelper; -import com.gluster.storage.management.gui.views.pages.ServersPage; import com.gluster.storage.management.gui.views.pages.VolumesPage; /** * */ -public class VolumesView extends ViewPart implements IDoubleClickListener, ISelectionListener { +public class VolumesView extends ViewPart implements IDoubleClickListener { public static final String ID = VolumesView.class.getName(); private static final GUIHelper guiHelper = GUIHelper.getInstance(); private EntityGroup<Volume> volumes; @@ -52,6 +46,7 @@ public class VolumesView extends ViewPart implements IDoubleClickListener, ISele * * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) */ + @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void createPartControl(Composite parent) { if (volumes == null) { @@ -63,7 +58,6 @@ public class VolumesView extends ViewPart implements IDoubleClickListener, ISele page = new VolumesPage(parent, getSite(), volumes); page.addDoubleClickListener(this); - getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(NavigationView.ID, this); } /* @@ -83,26 +77,4 @@ public class VolumesView extends ViewPart implements IDoubleClickListener, ISele clusterView.selectEntity((Entity) ((StructuredSelection) event.getSelection()).getFirstElement()); } } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, - * org.eclipse.jface.viewers.ISelection) - */ - @Override - public void selectionChanged(IWorkbenchPart part, ISelection selection) { - if (part instanceof NavigationView && selection instanceof TreeSelection) { - Entity selectedEntity = (Entity) ((TreeSelection) selection).getFirstElement(); - - if (volumes == selectedEntity || selectedEntity == null || !(selectedEntity instanceof EntityGroup) - || ((EntityGroup) selectedEntity).getEntityType() != Volume.class) { - // entity selection has not changed. do nothing. - return; - } - - volumes = (EntityGroup<Volume>) selectedEntity; - page.setInput(volumes); - } - } } diff --git a/src/com.gluster.storage.management.server/.project b/src/com.gluster.storage.management.server/.project index 86d34a3b..259b3726 100644 --- a/src/com.gluster.storage.management.server/.project +++ b/src/com.gluster.storage.management.server/.project @@ -37,6 +37,5 @@ <nature>org.eclipse.wst.common.project.facet.core.nature</nature> <nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.wst.jsdt.core.jsNature</nature> - <nature>org.python.pydev.pythonNature</nature> </natures> </projectDescription> diff --git a/src/com.gluster.storage.management.server/.settings/org.eclipse.wst.common.component b/src/com.gluster.storage.management.server/.settings/org.eclipse.wst.common.component index e9b43da9..dbf56d1e 100644 --- a/src/com.gluster.storage.management.server/.settings/org.eclipse.wst.common.component +++ b/src/com.gluster.storage.management.server/.settings/org.eclipse.wst.common.component @@ -5,6 +5,6 @@ <wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/junit"/> <property name="java-output-path" value="/com.gluster.storage.management.server/build/classes"/> - <property name="context-root" value="glustermc"/> + <property name="context-root" value="glustermg"/> </wb-module> </project-modules> diff --git a/src/com.gluster.storage.management.server/WebContent/WEB-INF/web.xml b/src/com.gluster.storage.management.server/WebContent/WEB-INF/web.xml index 7c7d42d3..4aaa3c9b 100644 --- a/src/com.gluster.storage.management.server/WebContent/WEB-INF/web.xml +++ b/src/com.gluster.storage.management.server/WebContent/WEB-INF/web.xml @@ -3,7 +3,7 @@ xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> - <display-name>com.gluster.storage.management.server</display-name> + <display-name>glustermg</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> @@ -81,4 +81,14 @@ <filter-name>springSecurityFilterChain</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> + + <security-constraint> + <web-resource-collection> + <web-resource-name>Gluster Management Gateway</web-resource-name> + <url-pattern>/*</url-pattern> + </web-resource-collection> + <user-data-constraint> + <transport-guarantee>CONFIDENTIAL</transport-guarantee> + </user-data-constraint> +</security-constraint> </web-app> diff --git a/src/com.gluster.storage.management.server/WebContent/index.html b/src/com.gluster.storage.management.server/WebContent/index.html new file mode 100644 index 00000000..4c90162a --- /dev/null +++ b/src/com.gluster.storage.management.server/WebContent/index.html @@ -0,0 +1,8 @@ +<html> +<head> +<title>Gluster Management Console</title> +</head> +<body> +TODO: Identify the client's platform-browser and invoke appropriate JNLP URL. +</body> +</html> diff --git a/src/com.gluster.storage.management.server/WebContent/scripts/Globals.py b/src/com.gluster.storage.management.server/WebContent/scripts/Globals.py index 9ae53491..877c6c68 100644 --- a/src/com.gluster.storage.management.server/WebContent/scripts/Globals.py +++ b/src/com.gluster.storage.management.server/WebContent/scripts/Globals.py @@ -64,7 +64,7 @@ WEBDAV_DOCUMENT_ROOT_DIR = "/var/www/html" UPDATES_DIR = "/UPDATES" TRANSPORT_HOME_DIR = "/transport" GLUSTERFS_LOG_DIR = "/var/log/glusterfs" -LOG_DIR = "/var/log/glustermc" +LOG_DIR = "/var/log/glustermg" GLUSTER_UPDATES_FILE = "updates.xml" INSTALLER_STATUS_FILE = "/var/log/install-server-status.log" diff --git a/src/com.gluster.storage.management.server/WebContent/ssl/gmg-ssl.keystore b/src/com.gluster.storage.management.server/WebContent/ssl/gmg-ssl.keystore Binary files differnew file mode 100644 index 00000000..2efe19b0 --- /dev/null +++ b/src/com.gluster.storage.management.server/WebContent/ssl/gmg-ssl.keystore diff --git a/src/com.gluster.storage.management.server/build/glusterserver.ant b/src/com.gluster.storage.management.server/build/glusterserver.ant index 27c91b9d..e9b5b650 100644 --- a/src/com.gluster.storage.management.server/build/glusterserver.ant +++ b/src/com.gluster.storage.management.server/build/glusterserver.ant @@ -3,7 +3,7 @@ <echo message="buckminster.output=${buckminster.output}" /> <property name="WEB-INF" value="${basedir}/WebContent/WEB-INF" /> <property name="OUT" value="${buckminster.output}/glusterserver/" /> - <property name="WAR_FILE_NAME" value="glustermc.war" /> + <property name="WAR_FILE_NAME" value="glustermg.war" /> <property name="TEMP" value="${buckminster.output}/temp" /> <target name="help"> diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/data/ClusterInfo.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/data/ClusterInfo.java index 3b3401e3..1c3cd347 100644 --- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/data/ClusterInfo.java +++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/data/ClusterInfo.java @@ -18,6 +18,7 @@ *******************************************************************************/ package com.gluster.storage.management.server.data; +import java.util.ArrayList; import java.util.List; import javax.persistence.Entity; @@ -37,7 +38,7 @@ public class ClusterInfo { private String name; @OneToMany(mappedBy="cluster") - private List<ServerInfo> servers; + private List<ServerInfo> servers = new ArrayList<ServerInfo>(); public void setId(Integer id) { this.id = id; diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/filters/AuditFilter.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/filters/AuditFilter.java index b23d9c4f..daaf8f33 100644 --- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/filters/AuditFilter.java +++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/filters/AuditFilter.java @@ -5,13 +5,14 @@ package com.gluster.storage.management.server.filters; import com.sun.jersey.spi.container.ContainerRequest; import com.sun.jersey.spi.container.ContainerRequestFilter; +import com.sun.jersey.spi.container.ContainerResponse; import com.sun.jersey.spi.container.ContainerResponseFilter; import com.sun.jersey.spi.container.ResourceFilter; /** * Resource filter for maintaining audit trail of resource access */ -public class AuditFilter implements ResourceFilter, ContainerRequestFilter { +public class AuditFilter implements ResourceFilter, ContainerRequestFilter, ContainerResponseFilter { @Override public ContainerRequestFilter getRequestFilter() { @@ -20,12 +21,18 @@ public class AuditFilter implements ResourceFilter, ContainerRequestFilter { @Override public ContainerResponseFilter getResponseFilter() { - return null; + return this; } @Override public ContainerRequest filter(ContainerRequest req) { - System.out.println("Resource access [" + req.getMethod() + "][" + req.getPath() + "]"); + System.out.println("REQUEST: [" + req.getMethod() + "][" + req.getPath() + "]"); return req; } + + @Override + public ContainerResponse filter(ContainerRequest req, ContainerResponse response) { + System.out.println("RESPONSE: [" + req.getMethod() + "][" + req.getPath() + "]"); + return response; + } } diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/VolumesResource.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/VolumesResource.java index fe6de156..a2dfe2e3 100644 --- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/VolumesResource.java +++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/VolumesResource.java @@ -116,8 +116,6 @@ public class VolumesResource { @InjectParam private VolumeOptionsDefaults volumeOptionsDefaults; - private FileUtil fileUtil = new FileUtil(); - @GET @Produces(MediaType.TEXT_XML) public VolumeListResponse getAllVolumes(@PathParam(PATH_PARAM_CLUSTER_NAME) String clusterName) { @@ -452,7 +450,7 @@ public class VolumesResource { public void write(OutputStream output) throws IOException, WebApplicationException { try { File archiveFile = new File(downloadLogs(volume)); - output.write(fileUtil.readFileAsByteArray(archiveFile)); + output.write(FileUtil.readFileAsByteArray(archiveFile)); archiveFile.delete(); } catch (Exception e) { e.printStackTrace(); @@ -464,11 +462,11 @@ public class VolumesResource { private String downloadLogs(Volume volume) { // create temporary directory - File tempDir = fileUtil.createTempDir(); + File tempDir = FileUtil.createTempDir(); String tempDirPath = tempDir.getPath(); for (Brick brick : volume.getBricks()) { - String logDir = glusterUtil.getLogLocation(volume.getName(), brick.getBrickDirectory(), + String logDir = glusterUtil.getLogLocation(volume.getName(), brick.getQualifiedName(), brick.getServerName()); String logFileName = glusterUtil.getLogFileNameForBrickDir(brick.getBrickDirectory()); String logFilePath = logDir + CoreConstants.FILE_SEPARATOR + logFileName; @@ -476,11 +474,11 @@ public class VolumesResource { serverUtil.getFileFromServer(brick.getServerName(), logFilePath, tempDirPath); } - String gzipPath = fileUtil.getTempDirName() + CoreConstants.FILE_SEPARATOR + volume.getName() + "-logs.tar.gz"; + String gzipPath = FileUtil.getTempDirName() + CoreConstants.FILE_SEPARATOR + volume.getName() + "-logs.tar.gz"; new ProcessUtil().executeCommand("tar", "czvf", gzipPath, "-C", tempDir.getParent(), tempDir.getName()); // delete the temp directory - fileUtil.recursiveDelete(tempDir); + FileUtil.recursiveDelete(tempDir); return gzipPath; } diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java index fe725d17..42b204cd 100644 --- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java +++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java @@ -468,18 +468,18 @@ System.out.println(brickDir); } public String getLogLocation(String volumeName, String brickName, String knownServer) { - ProcessResult result = sshUtil.executeRemote(knownServer, "gluster volume log locate " + volumeName + " " - + brickName); + String command = "gluster volume log locate " + volumeName + " " + brickName; + ProcessResult result = sshUtil.executeRemote(knownServer, command); if (!result.isSuccess()) { - throw new GlusterRuntimeException("Command [gluster volume info] failed with error: [" - + result.getExitValue() + "][" + result.getOutput() + "]"); + throw new GlusterRuntimeException("Command [" + command + "] failed with error: [" + result.getExitValue() + + "][" + result.getOutput() + "]"); } String output = result.getOutput(); if (output.startsWith(VOLUME_LOG_LOCATION_PFX)) { return output.substring(VOLUME_LOG_LOCATION_PFX.length()).trim(); } - throw new GlusterRuntimeException("Couldn't parse output of [volume log locate] command. [" + output + throw new GlusterRuntimeException("Couldn't parse output of command [" + command + "]. Output [" + output + "] doesn't start with prefix [" + VOLUME_LOG_LOCATION_PFX + "]"); } diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/SshUtil.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/SshUtil.java index a4728d21..4d3661f8 100644 --- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/SshUtil.java +++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/SshUtil.java @@ -314,7 +314,19 @@ public class SshUtil { } private ProcessResult executeRemoteWithPubKey(String serverName, String command) { - return executeCommand(getConnection(serverName), command); + try { + return executeCommand(getConnection(serverName), command); + } catch(GlusterRuntimeException e) { + Throwable cause = e.getCause(); + if(cause != null && cause instanceof IOException) { + // cached ssh connection might have gone bad. + // remove it and try with a new one + sshConnCache.remove(serverName); + return executeCommand(getConnection(serverName), command); + } else { + throw e; + } + } } /** diff --git a/src/com.gluster.storage.management.server/src/spring/gluster-server-security.xml b/src/com.gluster.storage.management.server/src/spring/gluster-server-security.xml index 0de97761..59714c87 100644 --- a/src/com.gluster.storage.management.server/src/spring/gluster-server-security.xml +++ b/src/com.gluster.storage.management.server/src/spring/gluster-server-security.xml @@ -11,16 +11,18 @@ "> <http auto-config="true" use-expressions="true"> - <intercept-url pattern="/resources/*" + <!-- intercept-url pattern="/resources/*" access="hasRole('ROLE_ADMIN') and fullyAuthenticated" /> - <intercept-url pattern="/*" access="permitAll" /> + <intercept-url pattern="/*" access="permitAll" /--> + <!-- SSL Protection --> - <!-- <intercept-url pattern="/resources/*" access="hasRole('ROLE_ADMIN') - and fullyAuthenticated" requires-channel="https"/> <intercept-url pattern="/*" - access="permitAll" requires-channel="any"/> --> - <port-mappings> - <port-mapping http="8080" https="8443" /> - </port-mappings> + <intercept-url pattern="/resources/*" access="hasRole('ROLE_ADMIN') + and fullyAuthenticated" + requires-channel="https" /> + <intercept-url pattern="/*" access="permitAll" requires-channel="any" /> + <port-mappings> + <port-mapping http="8080" https="8443" /> + </port-mappings> <!-- HTTP basic authentication --> <http-basic /> |