diff options
author | Eike Stepper | 2013-11-04 11:00:40 +0000 |
---|---|---|
committer | Eike Stepper | 2013-11-04 11:01:32 +0000 |
commit | 0f604cea2cffafe922e559bd9c49ccb53719bbfa (patch) | |
tree | 85cfa49e462b537fdc087bab1827103e59a62230 /plugins | |
parent | d16124e1aeec375a03244bbd9891911f351e4db9 (diff) | |
download | cdo-0f604cea2cffafe922e559bd9c49ccb53719bbfa.tar.gz cdo-0f604cea2cffafe922e559bd9c49ccb53719bbfa.tar.xz cdo-0f604cea2cffafe922e559bd9c49ccb53719bbfa.zip |
[418452] [Security] Simplified security model editorbugs/418452
https://bugs.eclipse.org/bugs/show_bug.cgi?id=418452
Diffstat (limited to 'plugins')
9 files changed, 69 insertions, 49 deletions
diff --git a/plugins/org.eclipse.emf.cdo.security.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.security.ui/META-INF/MANIFEST.MF index 874d109622..a78bcf3203 100644 --- a/plugins/org.eclipse.emf.cdo.security.ui/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.emf.cdo.security.ui/META-INF/MANIFEST.MF @@ -7,8 +7,7 @@ Bundle-Name: %pluginName Bundle-Vendor: %providerName Bundle-ClassPath: . Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Export-Package: org.eclipse.emf.cdo.security.internal.ui.actions;version="4.3.0";x-internal:=true, - org.eclipse.emf.cdo.security.internal.ui.bundle;version="4.3.0";x-internal:=true, +Export-Package: org.eclipse.emf.cdo.security.internal.ui.bundle;version="4.3.0";x-internal:=true, org.eclipse.emf.cdo.security.internal.ui.dialogs;version="4.3.0";x-internal:=true, org.eclipse.emf.cdo.security.internal.ui.editor;version="4.3.0";x-internal:=true, org.eclipse.emf.cdo.security.internal.ui.handlers;version="4.3.0";x-internal:=true, diff --git a/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/security/internal/ui/editor/TableSection.java b/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/security/internal/ui/editor/TableSection.java index b622322504..3fc426c09f 100644 --- a/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/security/internal/ui/editor/TableSection.java +++ b/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/security/internal/ui/editor/TableSection.java @@ -14,7 +14,6 @@ import org.eclipse.emf.cdo.security.Directory; import org.eclipse.emf.cdo.security.Realm; import org.eclipse.emf.cdo.security.SecurityFactory; import org.eclipse.emf.cdo.security.SecurityPackage; -import org.eclipse.emf.cdo.security.internal.ui.actions.SelectionListenerAction; import org.eclipse.emf.cdo.security.internal.ui.messages.Messages; import org.eclipse.emf.cdo.security.internal.ui.util.ActionBarsHelper; import org.eclipse.emf.cdo.security.internal.ui.util.ObjectExistsConverter.ObjectWritableConverter; @@ -23,6 +22,7 @@ import org.eclipse.emf.cdo.security.internal.ui.util.TableLabelProvider; import org.eclipse.emf.cdo.ui.shared.SharedIcons; import org.eclipse.net4j.util.ui.UIUtil; +import org.eclipse.net4j.util.ui.actions.SelectionListenerAction; import org.eclipse.emf.common.command.Command; import org.eclipse.emf.common.notify.AdapterFactory; @@ -238,7 +238,7 @@ public abstract class TableSection<T extends EObject> extends AbstractSectionPar { Command dummy = createDeleteCommand(EcoreUtil.create(elementEClass)); - return new SelectionListenerAction(dummy.getLabel(), SharedIcons.getDescriptor("etool16/delete.gif")) //$NON-NLS-1$ + return new SelectionListenerAction<EObject>(dummy.getLabel(), SharedIcons.getDescriptor("etool16/delete.gif")) //$NON-NLS-1$ { @Override public void run() @@ -255,6 +255,12 @@ public abstract class TableSection<T extends EObject> extends AbstractSectionPar { return super.updateSelection(selection) && SecurityUIUtil.isEditable(getInput()); } + + @Override + protected Class<EObject> getType() + { + return EObject.class; + } }; } diff --git a/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/security/internal/ui/util/OneToManyBlock.java b/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/security/internal/ui/util/OneToManyBlock.java index f9c9395bb8..85d340e081 100644 --- a/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/security/internal/ui/util/OneToManyBlock.java +++ b/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/security/internal/ui/util/OneToManyBlock.java @@ -17,17 +17,19 @@ import org.eclipse.emf.cdo.security.Directory; import org.eclipse.emf.cdo.security.Realm; import org.eclipse.emf.cdo.security.SecurityItem; import org.eclipse.emf.cdo.security.SecurityPackage; -import org.eclipse.emf.cdo.security.internal.ui.actions.SelectionListenerAction; import org.eclipse.emf.cdo.security.internal.ui.messages.Messages; import org.eclipse.emf.cdo.security.internal.ui.util.ObjectExistsConverter.ObjectWritableConverter; import org.eclipse.emf.cdo.security.provider.SecurityEditPlugin; import org.eclipse.emf.cdo.ui.shared.SharedIcons; +import org.eclipse.net4j.util.ui.actions.SelectionListenerAction; + import org.eclipse.emf.common.command.Command; import org.eclipse.emf.common.command.IdentityCommand; import org.eclipse.emf.common.notify.AdapterFactory; import org.eclipse.emf.databinding.edit.EMFEditObservables; import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EReference; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.edit.command.AddCommand; @@ -331,8 +333,8 @@ public class OneToManyBlock }); } - final SelectionListenerAction removeAction = new SelectionListenerAction(Messages.OneToManyBlock_2, - SharedIcons.getDescriptor("etool16/delete.gif")) //$NON-NLS-1$ + final SelectionListenerAction<EObject> removeAction = new SelectionListenerAction<EObject>( + Messages.OneToManyBlock_2, SharedIcons.getDescriptor("etool16/delete.gif")) //$NON-NLS-1$ { @Override public void run() @@ -360,6 +362,12 @@ public class OneToManyBlock { return super.updateSelection(selection) && SecurityUIUtil.isEditable(input.getValue()); } + + @Override + protected Class<EObject> getType() + { + return EObject.class; + } }; removeButton.addSelectionListener(new SelectionAdapter() diff --git a/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/security/internal/ui/util/SecurityUIUtil.java b/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/security/internal/ui/util/SecurityUIUtil.java index a576b9063a..3e1d87e6b3 100644 --- a/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/security/internal/ui/util/SecurityUIUtil.java +++ b/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/security/internal/ui/util/SecurityUIUtil.java @@ -70,7 +70,6 @@ public final class SecurityUIUtil public static void applySupportedElementFilter(StructuredViewer viewer, EClass itemType) { ViewerFilter filter = getSupportedElementViewerFilter(itemType); - if (filter != null) { viewer.addFilter(filter); @@ -111,7 +110,6 @@ public final class SecurityUIUtil public static ViewerFilter getSupportedElementViewerFilter(EClass itemType) { IFilter filter = getSupportedElementFilter(itemType); - return filter == null ? null : getViewerFilter(filter); } @@ -167,6 +165,6 @@ public final class SecurityUIUtil public static boolean isEditable(Object object) { - return !(object instanceof EObject) || CDOUtil.isWritable((EObject)object); + return !(object instanceof EObject) || CDOUtil.isWritableObject((EObject)object); } } diff --git a/plugins/org.eclipse.emf.cdo/plugin.xml b/plugins/org.eclipse.emf.cdo/plugin.xml index 665bac6c45..f37d706bf2 100644 --- a/plugins/org.eclipse.emf.cdo/plugin.xml +++ b/plugins/org.eclipse.emf.cdo/plugin.xml @@ -49,7 +49,7 @@ id="org.eclipse.emf.cdo.view.properties" type="org.eclipse.emf.cdo.view.CDOView" namespace="org.eclipse.emf.cdo.view" - properties="open,viewID,branchName,branch,timeStamp,lastUpdateTime,readOnly,dirty,durable,sessionID,userID" + properties="open,viewID,branchName,branch,timeStamp,lastUpdateTime,readOnly,dirty,durable,sessionID,userID,userAuthenticated" class="org.eclipse.emf.internal.cdo.view.ViewProperties$Tester"/> <propertyTester id="org.eclipse.emf.cdo.object.properties" diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java index 21ed588f6c..5d6006878d 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java @@ -608,6 +608,32 @@ public final class CDOUtil } /** + * Queries whether an object is writable (is permitted to be modified in the + * current view context). + * + * @param eObject an object + * @return {@code false} if the {@code eObject} is managed by CDO and does not + * have {@linkplain CDOPermission#WRITE write permission}; + * {@code true}, otherwise + * + * @since 4.3 + */ + public static boolean isWritableObject(EObject eObject) + { + CDOObject cdoObject = CDOUtil.getCDOObject(eObject); + if (cdoObject != null) + { + CDOView view = cdoObject.cdoView(); + + // If the object is not in a view, then permissions aren't applicable + return view == null || !view.isReadOnly() && cdoObject.cdoPermission().isWritable(); + } + + // If there is no CDOObject, then this object is implicitly writable + return true; + } + + /** * @since 3.0 */ public static boolean isLegacyObject(EObject object) @@ -704,31 +730,4 @@ public final class CDOUtil return setAnnotation(modelElement, CDO_ANNOTATION_URI, DOCUMENTATION_KEY, value); } - /** - * Queries whether an object is writable (is permitted to be modified in the - * current view context). - * - * @param eObject an object - * @return {@code false} if the {@code eObject} is managed by CDO and does not - * have {@linkplain CDOPermission#WRITE write permission}; - * {@code true}, otherwise - * - * @since 4.3 - */ - public static boolean isWritable(EObject eObject) - { - CDOObject cdoObject = CDOUtil.getCDOObject(eObject); - - if (cdoObject != null) - { - CDOView view = cdoObject.cdoView(); - - // If the object is not in a view, then permissions aren't applicable - return view == null || !view.isReadOnly() && cdoObject.cdoPermission().isWritable(); - } - - // If there is no CDOObject, then this object is implicitly writable - return true; - } - } diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/SessionProperties.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/SessionProperties.java index 70f992815e..322e5c99f3 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/SessionProperties.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/SessionProperties.java @@ -254,8 +254,7 @@ public class SessionProperties extends Properties<CDOSession> implements CDOComm } }); - add(new Property<CDOSession>("userAuthenticated", "User Authenticated", - "Indication of whether this session is authenticated under a defined user account ID.") + add(new Property<CDOSession>("userAuthenticated") { @Override protected Object eval(CDOSession session) diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/ViewProperties.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/ViewProperties.java index 4451111bce..1a33e4309c 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/ViewProperties.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/ViewProperties.java @@ -13,6 +13,7 @@ package org.eclipse.emf.internal.cdo.view; import org.eclipse.emf.cdo.common.util.CDOCommonUtil; import org.eclipse.emf.cdo.view.CDOView; +import org.eclipse.net4j.util.StringUtil; import org.eclipse.net4j.util.properties.DefaultPropertyTester; import org.eclipse.net4j.util.properties.IProperties; import org.eclipse.net4j.util.properties.Properties; @@ -153,6 +154,15 @@ public class ViewProperties extends Properties<CDOView> return view.getSession().getUserID(); } }); + + add(new Property<CDOView>("userAuthenticated") + { + @Override + protected Object eval(CDOView view) + { + return !StringUtil.isEmpty(view.getSession().getUserID()); + } + }); } public static void main(String[] args) diff --git a/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/security/internal/ui/actions/SelectionListenerAction.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/SelectionListenerAction.java index b70e4c8e2a..dcf283ee43 100644 --- a/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/security/internal/ui/actions/SelectionListenerAction.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/actions/SelectionListenerAction.java @@ -8,9 +8,7 @@ * Contributors: * Christian W. Damus (CEA LIST) - initial API and implementation */ -package org.eclipse.emf.cdo.security.internal.ui.actions; - -import org.eclipse.emf.ecore.EObject; +package org.eclipse.net4j.util.ui.actions; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.IStructuredSelection; @@ -18,10 +16,11 @@ import org.eclipse.ui.actions.BaseSelectionListenerAction; /** * @author Christian W. Damus (CEA LIST) + * @since 3.4 */ -public class SelectionListenerAction extends BaseSelectionListenerAction +public abstract class SelectionListenerAction<T> extends BaseSelectionListenerAction { - private EObject selectedObject; + private T selectedObject; public SelectionListenerAction(String text) { @@ -38,22 +37,24 @@ public class SelectionListenerAction extends BaseSelectionListenerAction protected boolean updateSelection(IStructuredSelection selection) { boolean result = !selection.isEmpty(); - if (result) { Object first = selection.getFirstElement(); - result = first instanceof EObject; + Class<T> type = getType(); + result = type.isInstance(first); if (result) { - selectedObject = (EObject)first; + selectedObject = type.cast(first); } } return super.updateSelection(selection) && result; } - protected EObject getSelectedObject() + protected T getSelectedObject() { return selectedObject; } + + protected abstract Class<T> getType(); } |