diff options
| author | Selvam <selvam@gluster.com> | 2011-04-08 11:39:32 +0530 |
|---|---|---|
| committer | Selvam <selvam@gluster.com> | 2011-04-12 14:17:49 +0530 |
| commit | 491325d013f1b1b5ac033eac4ff8b1d565e669e8 (patch) | |
| tree | 6e7b67daef46f9f7d99e4997dd6a2329ec2bf504 | |
| parent | d4ed073c4d386724e4d0376e296ca84f975c3ad4 (diff) | |
Volume property page - access control update
4 files changed, 107 insertions, 12 deletions
diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Volume.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Volume.java index baa3edb9..daa96cd4 100644 --- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Volume.java +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Volume.java @@ -49,7 +49,7 @@ public class Volume extends Entity { GLUSTERFS, NFS }; - private static final String OPTION_AUTH_ALLOW = "auth.allow:"; + private static final String OPTION_AUTH_ALLOW = "auth.allow"; private static final String[] VOLUME_TYPE_STR = new String[] { "Plain Distribute", "Distributed Mirror", "Distributed Stripe" }; diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterUtil.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterUtil.java index d1533f25..5ed83810 100644 --- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterUtil.java +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterUtil.java @@ -49,6 +49,7 @@ public class GlusterUtil { private static final String VOLUME_TRANSPORT_TYPE_PFX = "Transport-type:"; private static final String VOLUME_BRICKS_GROUP_PFX = "Bricks"; private static final String VOLUME_OPTIONS_RECONFIG_PFX = "Options Reconfigured"; + private static final String VOLUME_OPTION_AUTH_ALLOW = "auth.allow:"; private static final ProcessUtil processUtil = new ProcessUtil(); @@ -324,7 +325,7 @@ public class GlusterUtil { String volumeName = extractToken(line, VOLUME_NAME_PFX); if (volumeName != null) { if (volume != null) { - // add the previously read volume to volume list + volumes.add(volume); } diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/ValidationUtil.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/ValidationUtil.java new file mode 100644 index 00000000..76dc748e --- /dev/null +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/ValidationUtil.java @@ -0,0 +1,68 @@ +package com.gluster.storage.management.core.utils; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class ValidationUtil { + + // Access control may contains IP with wild card(*), hostname and/or multiple ip/hostnames + public static boolean isValidAccessControl(String ac) { + String access[] = ac.split(","); + boolean isValidAccessControl = true; + for (int i = 0; i < access.length && isValidAccessControl; i++) { + isValidAccessControl = (isValidIpWithWC(access[i]) || isValidHostName(access[i])); + } + return isValidAccessControl; + } + + public static boolean isValidIpWithWC(String ip) { + String ipAddress[] = ip.split("\\."); + boolean isValid = true; + + if (ip.equals("0.0.0.0") || ip.equals("255.255.255.255")) { // Invalidate the special ip's + isValid = false; + } + + for (int i = 0; i < ipAddress.length && isValid; i++) { + if (ipAddress[i].equals("*")) { + isValid = (i == ipAddress.length - 1) ? isValid : false; + } else { + isValid = isValidIpQuad(ipAddress[i]); + } + } + return isValid; + } + + public static boolean isValidIp(String ip) { + String ipAddress[] = ip.split("\\."); + boolean isValid = true; + + if (ip.equals("0.0.0.0") || ip.equals("255.255.255.255")) { // Invalidate the special ip's + isValid = false; + } + + for (int i = 0; i < ipAddress.length && isValid; i++) { + isValid = isValidIpQuad(ipAddress[i]); + } + return isValid; + } + + public static boolean isValidIpQuad(String ipQuad) { + Pattern pattern = Pattern.compile("([01]?\\d\\d?|2[0-4]\\d|25[0-5])"); + return pattern.matcher(ipQuad).matches(); + } + + public static boolean isValidHostName(String hostName) { + Pattern pattern = Pattern + .compile("^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\\-]*[A-Za-z0-9])$"); + return pattern.matcher(hostName).matches(); + } + + public static void main(String[] argv) { + String ip = "0.0.0.0"; + System.out.println("Is valid ip (" + ip + ")? " + isValidIp(ip)); + String hostName = "Selvam-sd.com"; + System.out.println(isValidHostName(hostName)); + } + +} diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/VolumeSummaryView.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/VolumeSummaryView.java index 798c2a40..291c494a 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/VolumeSummaryView.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/VolumeSummaryView.java @@ -1,5 +1,9 @@ package com.gluster.storage.management.gui.views; +import java.util.Map; + +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CLabel; import org.eclipse.swt.layout.FillLayout; @@ -17,13 +21,16 @@ import org.eclipse.ui.forms.widgets.ScrolledForm; import org.eclipse.ui.part.ViewPart; import com.gluster.storage.management.client.GlusterDataModelManager; +import com.gluster.storage.management.client.VolumesClient; import com.gluster.storage.management.core.model.DefaultClusterListener; import com.gluster.storage.management.core.model.Event; import com.gluster.storage.management.core.model.Event.EVENT_TYPE; +import com.gluster.storage.management.core.model.Status; import com.gluster.storage.management.core.model.Volume; import com.gluster.storage.management.core.model.Volume.NAS_PROTOCOL; import com.gluster.storage.management.core.model.Volume.VOLUME_TYPE; import com.gluster.storage.management.core.utils.NumberUtil; +import com.gluster.storage.management.core.utils.ValidationUtil; import com.gluster.storage.management.gui.IImageKeys; import com.gluster.storage.management.gui.toolbar.GlusterToolbarManager; import com.gluster.storage.management.gui.utils.GUIHelper; @@ -44,12 +51,12 @@ public class VolumeSummaryView extends ViewPart { } createSections(parent); - + // Refresh the navigation tree whenever there is a change to the data model volumeChangedListener = new DefaultClusterListener() { @Override public void volumeChanged(Volume volume, Event event) { - if(event.getEventType() == EVENT_TYPE.VOLUME_STATUS_CHANGED) { + if (event.getEventType() == EVENT_TYPE.VOLUME_STATUS_CHANGED) { updateVolumeStatusLabel(); new GlusterToolbarManager(getSite().getWorkbenchWindow()).updateToolbar(volume); } @@ -57,8 +64,10 @@ public class VolumeSummaryView extends ViewPart { }; GlusterDataModelManager.getInstance().addClusterListener(volumeChangedListener); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.eclipse.ui.part.WorkbenchPart#dispose() */ @Override @@ -131,12 +140,28 @@ public class VolumeSummaryView extends ViewPart { final Hyperlink changeLink = toolkit.createHyperlink(section, "change", SWT.NONE); changeLink.addHyperlinkListener(new HyperlinkAdapter() { + @SuppressWarnings("static-access") private void finishEdit() { - // TODO: Update value to back-end - // TODO: Validation of entered text - volume.setAccessControlList(accessControlText.getText()); - accessControlText.setEnabled(false); - changeLink.setText("change"); + + if (new ValidationUtil().isValidAccessControl(accessControlText.getText())) { + Status status = (new VolumesClient(GlusterDataModelManager.getInstance().getSecurityToken())) + .setVolumeOption(volume.getName(), "auth.allow", accessControlText.getText()); + if (status.isSuccess()) { + volume.setAccessControlList(accessControlText.getText()); + accessControlText.setEnabled(false); + changeLink.setText("change"); + MessageDialog.openInformation(Display.getDefault().getActiveShell(), "Access control", + status.getMessage()); + } else { + MessageDialog.openError(Display.getDefault().getActiveShell(), "Access control", + status.getMessage()); + } + + } else { + MessageDialog.openError(Display.getDefault().getActiveShell(), "Access control", + "Invalid IP / Host name "); + } + } private void startEdit() { @@ -167,7 +192,8 @@ public class VolumeSummaryView extends ViewPart { final Button nfsCheckBox = createCheckbox(nasProtocolsComposite, "NFS", volume.getNASProtocols().contains(NAS_PROTOCOL.NFS)); - createChangeLinkForNASProtocol(section, nfsCheckBox); + toolkit.createLabel(section, "", SWT.NONE); // dummy + // createChangeLinkForNASProtocol(section, nfsCheckBox); } private Button createCheckbox(Composite parent, String label, boolean selected) { |
