Re-added SecureBPMN implementation (changes to Activiti Designer 5.8.

This commit is contained in:
Achim D. Brucker 2015-05-30 16:11:41 +02:00
parent 444ca8cb38
commit b54e0d6705
1130 changed files with 254959 additions and 44 deletions

View File

@ -46,6 +46,10 @@ Export-Package:
Bundle-Activator: org.activiti.designer.eclipse.common.ActivitiPlugin
Import-Package: org.activiti.designer.eclipse.bpmn
Bundle-ClassPath: .,
xalan-2.7.1.jar,
serializer-2.7.1.jar,
xml-apis-1.3.04.jar,
com.sun.xacml-0.1.jar,
jdi.jar,
jdimodel.jar,
junit.jar

View File

@ -23,6 +23,18 @@ public final class ActivitiBPMNDiagramConstants {
public static final String BPMN_VALIDATOR_ID = "ActivitiDesignerBPMNValidator";
public static final String BPMN_VALIDATOR_NAME = "Activiti Designer BPMN Validator";
public static final String IMAGE_MARSHALLER_NAME = "Activiti Designer Image";
// <SecureBPMN>
// Adding Marshaller and Validator constants.
public static final String HTML_MARSHALLER_NAME = "SAP Research SCVM HTML";
public static final String ASLAN_MARSHALLER_NAME = "SAP Research SCVM ASLan";
public static final String XACML_MARSHALLER_NAME = "SAP Research SCVM Xacml";
public static final String XACML_VALIDATOR_ID = "SAPResearchSCVMXacmlValidator";
public static final String ASLAN_VALIDATOR_ID = "SAPResearchSCVMASLanValidator";
public static final String ASLAN_VALIDATOR_NAME = "SAP Research ASLan SCVM Validator";
// </SecureBPMN>
public static final String BPMN_MARSHALLER_VALIDATION_SKIP = "skip";
public static final String BPMN_MARSHALLER_VALIDATION_ATTEMPT = "attempt";

View File

@ -10,6 +10,10 @@ import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.ui.editor.DiagramEditor;
// <SecureBPMN>
import org.hamcrest.core.IsInstanceOf;
import org.eclipse.securebpmn2.SecurityFlow;
// <SecureBPMN>
/**
* Utility class to synchronize differences between the graphical representation and business model objects of a
@ -71,6 +75,9 @@ public class SequenceFlowSynchronizer {
}
private void setup() {
// <SecureBPMN>
if(this.graphicalRepresentation.getLink().getBusinessObjects().get(0) instanceof SecurityFlow)return;
// <SecureBPMN>
if(this.graphicalRepresentation == null) return;

View File

@ -19,6 +19,10 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Export-Package: org.activiti.designer.export.bpmn20.export
Bundle-ClassPath: .,
xalan-2.7.1.jar,
serializer-2.7.1.jar,
xml-apis-1.3.04.jar,
com.sun.xacml-0.1.jar,
jdi.jar,
jdimodel.jar,
junit.jar

View File

@ -32,9 +32,12 @@ public class UserTaskExport implements ActivitiNamespaceConstants {
public static void createUserTask(EObject object, XMLStreamWriter xtw) throws Exception {
UserTask userTask = (UserTask) object;
if ((userTask.getAssignee() != null && userTask.getAssignee().length() > 0)
|| (userTask.getCandidateUsers() != null && userTask.getCandidateUsers().size() > 0)
|| (userTask.getCandidateGroups() != null && userTask.getCandidateGroups().size() > 0)) {
|| (userTask.getCandidateGroups() != null && userTask.getCandidateGroups().size() > 0)
|| true // (SecureBPMN.getRoles() > 0)
) {
// start UserTask element
xtw.writeStartElement("userTask");
@ -61,14 +64,15 @@ public class UserTaskExport implements ActivitiNamespaceConstants {
candidateUsers += ", " + candidateUserIterator.next().getUser();
}
xtw.writeAttribute(ACTIVITI_EXTENSIONS_PREFIX, ACTIVITI_EXTENSIONS_NAMESPACE, "candidateUsers", candidateUsers);
} else {
} else if (userTask.getCandidateGroups() != null && userTask.getCandidateGroups().size() > 0){
Iterator<CandidateGroup> candidateGroupIterator = userTask.getCandidateGroups().iterator();
String candidateGroups = candidateGroupIterator.next().getGroup();
while (candidateGroupIterator.hasNext()) {
candidateGroups += ", " + candidateGroupIterator.next().getGroup();
}
xtw.writeAttribute(ACTIVITI_EXTENSIONS_PREFIX, ACTIVITI_EXTENSIONS_NAMESPACE, "candidateGroups", candidateGroups);
}
} else if (true) // SecureBPMN.roles
{}
if (userTask.getFormKey() != null && userTask.getFormKey().length() > 0) {
xtw.writeAttribute(ACTIVITI_EXTENSIONS_PREFIX, ACTIVITI_EXTENSIONS_NAMESPACE, "formKey", userTask.getFormKey());

View File

@ -16,6 +16,10 @@ Require-Bundle: org.eclipse.core.runtime,
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .,
xalan-2.7.1.jar,
serializer-2.7.1.jar,
xml-apis-1.3.04.jar,
com.sun.xacml-0.1.jar,
jdi.jar,
jdimodel.jar,
junit.jar

View File

@ -1,14 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<feature
id="org.activiti.designer.feature"
label="Activiti Eclipse BPMN 2.0 Designer"
label="Activiti Eclipse BPMN 2.0 Designer for SecureBPMN"
version="5.8.0"
provider-name="Activiti">
<description url="http://www.activiti.org">
This feature contains the Activiti Eclipse BPMN 2.0 designer plug-in which enables you to design and test BPMN 2.0 processes.
This feature contains the Activiti Eclipse BPMN 2.0 designer
plug-in which enables you to design and test SecureBPMN 2.0 processes. Please see
Achim D. Brucker. Integrating Security Aspects into Business Process Models. In it - Information
Technology, 55 (6), pages 239-246, 2013. Special Issue on "Security in Business Processes."
and Achim D. Brucker, Isabelle Hang, Gero Lückemeyer, and Raj Ruparel. SecureBPMN: Modeling
and Enforcing Access Control Requirements in Business Processes. In ACM symposium on access
control models and technologies (SACMAT). , pages 123-126, ACM Press, 2012. for details.
</description>
<copyright>
(c) 2011-2015 SAP SE
</copyright>
<license url="http://www.eclipse.org/legal/epl-v10.html">
Eclipse Public License -v 1.0
THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE (&quot;AGREEMENT&quot;). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT&apos;S ACCEPTANCE OF THIS AGREEMENT.
@ -55,15 +66,10 @@ All Recipient&apos;s rights under this Agreement shall terminate if it fails to
Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved.
This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.
</license>
<url>
<discovery label="Activiti suite website" url="http://activiti.org"/>
</url>
<includes
id="org.eclipse.graphiti.feature"
version="0.8.0"/>
<requires>
<import plugin="org.eclipse.ui"/>
<import plugin="org.eclipse.core.runtime" version="3.6.0.v20100505" match="greaterOrEqual"/>
@ -88,69 +94,98 @@ This Agreement is governed by the laws of the State of New York and the intellec
<import plugin="org.eclipse.ui.ide" version="3.6.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.emf.ecore"/>
<import plugin="org.eclipse.emf.ecore.xmi"/>
<import plugin="org.antlr.runtime" version="3.2.0" match="greaterOrEqual"/>
</requires>
<plugin
id="org.activiti.designer.gui"
download-size="0"
install-size="0"
version="5.8.0"
version="0.0.0"
unpack="false"/>
<plugin
id="org.activiti.designer.eclipse"
download-size="0"
install-size="0"
version="5.8.0"
version="0.0.0"
unpack="false"/>
<plugin
id="org.activiti.designer.model"
download-size="0"
install-size="0"
version="5.8.0"
version="0.0.0"
unpack="false"/>
<plugin
id="org.activiti.designer.integration"
download-size="0"
install-size="0"
version="5.8.0"
version="0.0.0"
unpack="false"/>
<plugin
id="org.activiti.designer.help"
download-size="0"
install-size="0"
version="5.8.0"
version="0.0.0"
unpack="false"/>
<plugin
id="org.activiti.designer.export.bpmn20"
download-size="0"
install-size="0"
version="5.8.0"
version="0.0.0"
unpack="false"/>
<plugin
id="org.activiti.designer.export.image"
download-size="0"
install-size="0"
version="5.8.0"
version="0.0.0"
unpack="false"/>
<plugin
id="org.activiti.designer.validation.bpmn20"
download-size="0"
install-size="0"
version="5.8.0"
version="0.0.0"
unpack="false"/>
<plugin
id="org.activiti.designer.util"
download-size="0"
install-size="0"
version="5.8.0"
version="0.0.0"
unpack="false"/>
<plugin
id="eu.aniketos.securebpmn.export.aslan"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
<plugin
id="eu.aniketos.securebpmn.export.html"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
<plugin
id="eu.aniketos.securebpmn"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
<plugin
id="eu.aniketos.securebpmn.validation.bpmn20"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
</feature>

View File

@ -25,6 +25,7 @@ Require-Bundle: org.eclipse.ui,
org.activiti.designer.integration,
org.eclipse.ui.ide,
org.activiti.designer.util
,eu.aniketos.securebpmn
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: org.activiti.designer,
@ -33,6 +34,10 @@ Export-Package: org.activiti.designer,
Bundle-Vendor: Eclipse Modeling Project
Bundle-Activator: org.activiti.designer.Activator
Bundle-ClassPath: .,
xalan-2.7.1.jar,
serializer-2.7.1.jar,
xml-apis-1.3.04.jar,
com.sun.xacml-0.1.jar,
jdi.jar,
jdimodel.jar,
junit.jar

Binary file not shown.

After

Width:  |  Height:  |  Size: 732 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -72,6 +72,20 @@
id="org.activiti.designer.multiInstanceTab"
label="Multi instance">
</propertyTab>
<!-- <SecureBPMN> -->
<propertyTab
afterTab="org.activiti.designer.mainConfigTab"
category="Activiti"
id="org.activiti.designer.securityTab"
label="Security">
</propertyTab>
<propertyTab
afterTab="org.activiti.designer.securityTab"
category="Activiti"
id="org.activiti.designer.needToKnowTab"
label="Need-to-know">
</propertyTab>
<!-- </SecureBPMN> -->
</propertyTabs>
</extension>
<extension
@ -114,6 +128,26 @@
id="org.activiti.designer.mainConfigTab.usertask"
tab="org.activiti.designer.mainConfigTab">
</propertySection>
<!-- <SecureBPMN> -->
<propertySection
class="org.activiti.designer.security.property.PropertyRbacSection"
filter="org.activiti.designer.security.property.PropertyRbacFilter"
id="org.activiti.designer.securityTab.usertask"
tab="org.activiti.designer.securityTab">
</propertySection>
<propertySection
class="org.activiti.designer.security.property.PropertySodBodSection"
filter="org.activiti.designer.security.property.PropertySodBodFilter"
id="org.activiti.designer.securityTab.sodbod"
tab="org.activiti.designer.securityTab">
</propertySection>
<propertySection
class="org.activiti.designer.security.property.PropertyNtkSection"
filter="org.activiti.designer.security.property.PropertyNtkFilter"
id="org.activiti.designer.securityTab.ntk"
tab="org.activiti.designer.needToKnowTab">
</propertySection>
<!-- </SecureBPMN> -->
<propertySection
class="org.activiti.designer.property.PropertyMailTaskSection"
filter="org.activiti.designer.property.PropertyMailTaskFilter"

View File

@ -59,6 +59,12 @@ public class ActivitiImageProvider extends AbstractImageProvider {
public static final String EDIT_ICON = PREFIX + "edit.icon"; //$NON-NLS-1$
public static final String NEW_ICON = PREFIX + "new.icon"; //$NON-NLS-1$
// <SecureBPMN>
//Security element icons
public static final String IMG_SECURITY_BOD = PREFIX + "security.bod"; //$NON-NLS-1$
public static final String IMG_SECURITY_SOD = PREFIX + "security.sod"; //$NON-NLS-1$
// </SecureBPMN>
@Override
protected void addAvailableImages() {
// register the path for each image identifier
@ -85,6 +91,11 @@ public class ActivitiImageProvider extends AbstractImageProvider {
addImageFilePath(IMG_ALFRESCO_LOGO, "icons/alfresco.png"); //$NON-NLS-1$
addImageFilePath(EDIT_ICON, "icons/edit.png"); //$NON-NLS-1$
addImageFilePath(NEW_ICON, "icons/new.png"); //$NON-NLS-1$
// <SecureBPMN>
//adding file path for security elements
addImageFilePath(IMG_SECURITY_BOD, "icons/type.security.bod.png"); //$NON-NLS-1$
addImageFilePath(IMG_SECURITY_SOD, "icons/type.security.sod.png"); //$NON-NLS-1$
// </SecureBPMN>
}
}

View File

@ -2,6 +2,9 @@ package org.activiti.designer.diagram;
import org.eclipse.graphiti.dt.AbstractDiagramTypeProvider;
import org.eclipse.graphiti.tb.IToolBehaviorProvider;
// <SecureBPMN>
import org.eclipse.graphiti.features.ConfigurableFeatureProviderWrapper;
// </SecureBPMN>
public class ActivitiBPMNDiagramTypeProvider extends AbstractDiagramTypeProvider {
@ -9,7 +12,14 @@ public class ActivitiBPMNDiagramTypeProvider extends AbstractDiagramTypeProvider
public ActivitiBPMNDiagramTypeProvider() {
super();
setFeatureProvider(new ActivitiBPMNFeatureProvider(this));
// <SecureBPMN>
setFeatureProvider(
// START SAP Research SCVM Extensions
// Support for making the Diagram read-only during attack trace visualization.
new ConfigurableFeatureProviderWrapper(
// END SAP Research SCVM Extensions
new ActivitiBPMNFeatureProvider(this)));
// </SecureBPMN>
}
@Override

View File

@ -113,6 +113,18 @@ import com.alfresco.designer.gui.features.CreateAlfrescoScriptTaskFeature;
import com.alfresco.designer.gui.features.CreateAlfrescoStartEventFeature;
import com.alfresco.designer.gui.features.CreateAlfrescoUserTaskFeature;
// <SecureBPMN>
import org.activiti.designer.security.features.AddSecurityBodFeature;
import org.activiti.designer.security.features.AddSecurityFlowFeature;
import org.activiti.designer.security.features.AddSecuritySodFeature;
import org.activiti.designer.security.features.CreateSecurityBodFeature;
import org.activiti.designer.security.features.CreateSecurityFlowFeature;
import org.activiti.designer.security.features.CreateSecuritySodFeature;
import org.eclipse.securebpmn2.BindingOfDuty;
import org.eclipse.securebpmn2.SecurityFlow;
import org.eclipse.securebpmn2.SeparationOfDuty;
// </SecureBPMN>
public class ActivitiBPMNFeatureProvider extends DefaultFeatureProvider {
public ActivitiBPMNFeatureProvider(IDiagramTypeProvider dtp) {
@ -132,6 +144,12 @@ public class ActivitiBPMNFeatureProvider extends DefaultFeatureProvider {
return new AddStartEventFeature(this);
}
}
// <SecureBPMN>
} else if (context.getNewObject() instanceof BindingOfDuty) {
return new AddSecurityBodFeature(this);
} else if (context.getNewObject() instanceof SeparationOfDuty) {
return new AddSecuritySodFeature(this);
// </SecureBPMN>
} else if (context.getNewObject() instanceof EndEvent) {
if(((EndEvent) context.getNewObject()).getEventDefinitions().size() > 0) {
return new AddErrorEndEventFeature(this);
@ -140,6 +158,10 @@ public class ActivitiBPMNFeatureProvider extends DefaultFeatureProvider {
}
} else if (context.getNewObject() instanceof SequenceFlow) {
return new AddSequenceFlowFeature(this);
// <SecureBPMN>
} else if (context.getNewObject() instanceof SecurityFlow) {
return new AddSecurityFlowFeature(this);
// </SecureBPMN>
} else if (context.getNewObject() instanceof UserTask) {
if(context.getNewObject() instanceof AlfrescoUserTask) {
return new AddAlfrescoUserTaskFeature(this);
@ -213,6 +235,10 @@ public class ActivitiBPMNFeatureProvider extends DefaultFeatureProvider {
new CreateEmbeddedSubProcessFeature(this),
new CreateCallActivityFeature(this),
new CreateAlfrescoScriptTaskFeature(this),
// <SecureBPMN>
new CreateSecurityBodFeature(this),
new CreateSecuritySodFeature(this),
// <SecureBPMN>
new CreateAlfrescoMailTaskFeature(this)};
}
@ -234,7 +260,10 @@ public class ActivitiBPMNFeatureProvider extends DefaultFeatureProvider {
@Override
public ICreateConnectionFeature[] getCreateConnectionFeatures() {
return new ICreateConnectionFeature[] { new CreateSequenceFlowFeature(this) };
// <SecureBPMN>
return new ICreateConnectionFeature[] { new CreateSequenceFlowFeature(this),
new CreateSecurityFlowFeature(this) };
// </SecureBPMN>
}
@Override

View File

@ -112,7 +112,28 @@ import com.alfresco.designer.gui.features.CreateAlfrescoScriptTaskFeature;
import com.alfresco.designer.gui.features.CreateAlfrescoStartEventFeature;
import com.alfresco.designer.gui.features.CreateAlfrescoUserTaskFeature;
public class ActivitiToolBehaviorProvider extends DefaultToolBehaviorProvider {
// <SecureBPMN>
import eu.aniketos.securebpmn.features.CheckServiceTaskFeature;
import eu.aniketos.securebpmn.features.ListProcessVariablesFeature;
import eu.aniketos.securebpmn.features.PerformNtkAnalysisFeature;
import eu.aniketos.securebpmn.features.ValidateAslanLocalFeature;
import eu.aniketos.securebpmn.features.ValidateAslanWebFeature;
import eu.aniketos.securebpmn.visualization.rbac.RbacVisualization;
import org.eclipse.securebpmn2.AuthorizationConstraint;
import org.eclipse.securebpmn2.SecurityFlow;
import org.eclipse.graphiti.features.FeatureCheckerAdapter;
import org.eclipse.graphiti.features.IFeatureChecker;
import org.eclipse.graphiti.features.IFeatureCheckerHolder;
import org.activiti.designer.security.features.CreateSecurityBodFeature;
import org.activiti.designer.security.features.CreateSecuritySodFeature;
import org.activiti.designer.security.features.DeleteSecurityFlowFeature;
// </SecureBPMN>
public class ActivitiToolBehaviorProvider extends DefaultToolBehaviorProvider
// <SecureBPMN>
implements IFeatureCheckerHolder
// </SecureBPMN>
{
private static final Map<Class< ? extends ICreateFeature>, PaletteEntry> toolMapping = new HashMap<Class< ? extends ICreateFeature>, PaletteEntry>();
@ -143,6 +164,10 @@ public class ActivitiToolBehaviorProvider extends DefaultToolBehaviorProvider {
toolMapping.put(CreateBusinessRuleTaskFeature.class, PaletteEntry.BUSINESSRULE_TASK);
toolMapping.put(CreateAlfrescoScriptTaskFeature.class, PaletteEntry.ALFRESCO_SCRIPT_TASK);
toolMapping.put(CreateAlfrescoMailTaskFeature.class, PaletteEntry.ALFRESCO_MAIL_TASK);
// <SecureBPMN>
toolMapping.put(CreateSecurityBodFeature.class, PaletteEntry.SECURITY_BOD);
toolMapping.put(CreateSecuritySodFeature.class, PaletteEntry.SECURITY_SOD);
// </SecureBPMN>
}
@Override
@ -179,7 +204,11 @@ public class ActivitiToolBehaviorProvider extends DefaultToolBehaviorProvider {
taskContext.setTargetContainer((ContainerShape) pe.eContainer());
taskContext.putProperty("org.activiti.designer.connectionContext", connectionContext);
if (bo instanceof StartEvent || bo instanceof Task || bo instanceof CallActivity || bo instanceof Gateway) {
if (bo instanceof StartEvent || bo instanceof Task || bo instanceof CallActivity || bo instanceof Gateway
// <SecureBPMN>
|| bo instanceof AuthorizationConstraint)
// </SecurePBMN>
{
CreateUserTaskFeature userTaskfeature = new CreateUserTaskFeature(getFeatureProvider());
ContextButtonEntry newUserTaskButton = new ContextButtonEntry(userTaskfeature, taskContext);
@ -226,7 +255,11 @@ public class ActivitiToolBehaviorProvider extends DefaultToolBehaviorProvider {
data.getDomainSpecificContextButtons().add(button);
}
if (bo instanceof StartEvent || bo instanceof Task || bo instanceof CallActivity || bo instanceof Gateway) {
if (bo instanceof StartEvent || bo instanceof Task || bo instanceof CallActivity || bo instanceof Gateway
// <SecureBPMN>
|| bo instanceof AuthorizationConstraint)
// </SecureBPMN>
{
ContextButtonEntry otherElementButton = new ContextButtonEntry(null, null);
otherElementButton.setText("new element"); //$NON-NLS-1$
@ -266,7 +299,13 @@ public class ActivitiToolBehaviorProvider extends DefaultToolBehaviorProvider {
"Create alfresco user task", "Create a new alfresco user task", ActivitiImageProvider.IMG_USERTASK);
addContextButton(otherElementButton, new CreateAlfrescoMailTaskFeature(getFeatureProvider()), taskContext,
"Create alfresco mail task", "Create a new alfresco mail task", ActivitiImageProvider.IMG_MAILTASK);
// <SecureBPMN>
addContextButton(otherElementButton, new CreateSecurityBodFeature(getFeatureProvider()), taskContext,
"Create binding of duty", "Create a new binding of duty", ActivitiImageProvider.IMG_SECURITY_BOD);
addContextButton(otherElementButton, new CreateSecuritySodFeature(getFeatureProvider()), taskContext,
"Create separation of duty", "Create a new separation of duty", ActivitiImageProvider.IMG_SECURITY_SOD);
// </SecureBPMN>
ContextButtonEntry editElementButton = new ContextButtonEntry(null, null);
editElementButton.setText("change element type"); //$NON-NLS-1$
editElementButton.setDescription("Change the element type to another type"); //$NON-NLS-1$
@ -369,11 +408,71 @@ public class ActivitiToolBehaviorProvider extends DefaultToolBehaviorProvider {
subMenuDelete.setText("Delete sequence flow"); //$NON-NLS-1$
subMenuDelete.setSubmenu(false);
menuList.add(subMenuDelete);
// <SecureBPMN>
} else if(bObject instanceof SecurityFlow){
ContextMenuEntry subMenuDelete = new ContextMenuEntry(new DeleteSecurityFlowFeature(getFeatureProvider()), context);
subMenuDelete.setText("Delete security flow"); //$NON-NLS-1$
subMenuDelete.setSubmenu(false);
menuList.add(subMenuDelete);
} else if (bObject instanceof ServiceTask) {
// Adding custom context menu entries.
ContextMenuEntry checkServiceTask = new ContextMenuEntry(new CheckServiceTaskFeature(getFeatureProvider()), context);
checkServiceTask.setText("Check ServiceTask"); //$NON-NLS-1$
checkServiceTask.setSubmenu(false);
menuList.add(checkServiceTask);
// </SecureBPMN>
}
}
}
}
}
// <SecureBPMN>
ContextMenuEntry subMenuSecureBPMN = new ContextMenuEntry(null, context);
subMenuSecureBPMN.setText("SecureBPMN Analyses"); //$NON-NLS-1$
subMenuSecureBPMN.setSubmenu(true);
/* adb: for the time being, provide only local analysis. First, the
* Web service options needs to be fixed (new formant) and, second, this
* selection should be made in the configuration pane ...
*
ContextMenuEntry subMenuSSoD = new ContextMenuEntry(null, context);
subMenuSSoD.setText("Static SoD Analysis"); //$NON-NLS-1$
subMenuSSoD.setSubmenu(true);
ContextMenuEntry validateSecurityViaBin = new ContextMenuEntry(new ValidateAslanLocalFeature(getFeatureProvider()), context);
validateSecurityViaBin.setText("local analysis"); //$NON-NLS-1$
validateSecurityViaBin.setSubmenu(false);
subMenuSSoD.add(validateSecurityViaBin);
ContextMenuEntry validateSecurityViaWS = new ContextMenuEntry(new ValidateAslanWebFeature(getFeatureProvider()), context);
validateSecurityViaWS.setText("via web service"); //$NON-NLS-1$
validateSecurityViaWS.setSubmenu(false);
subMenuSSoD.add(validateSecurityViaWS);
*/
ContextMenuEntry subMenuSSoD = new ContextMenuEntry(new ValidateAslanLocalFeature(getFeatureProvider()), context);
subMenuSSoD.setText("Anlyse static SoD"); //$NON-NLS-1$
subMenuSSoD.setSubmenu(false);
subMenuSecureBPMN.add(subMenuSSoD);
ContextMenuEntry subMenuNtK = new ContextMenuEntry(null, context);
subMenuNtK.setText("Need to Know Analysis"); //$NON-NLS-1$
subMenuNtK.setSubmenu(true);
ContextMenuEntry listProcessVars = new ContextMenuEntry(new ListProcessVariablesFeature(getFeatureProvider()), context);
listProcessVars.setText("List used process variables"); //$NON-NLS-1$
listProcessVars.setSubmenu(false);
subMenuNtK.add(listProcessVars);
ContextMenuEntry performNtkAnalysis = new ContextMenuEntry(new PerformNtkAnalysisFeature(getFeatureProvider()), context);
performNtkAnalysis.setText("Perform need-to-know analysis"); //$NON-NLS-1$
performNtkAnalysis.setSubmenu(false);
subMenuNtK.add(performNtkAnalysis);
subMenuSecureBPMN.add(subMenuNtK);
menuList.add(subMenuSecureBPMN);
// </SecureBPMN>
ContextMenuEntry subMenuExport = new ContextMenuEntry(new SaveBpmnModelFeature(getFeatureProvider()), context);
subMenuExport.setText("Export to BPMN 2.0 XML"); //$NON-NLS-1$
@ -405,7 +504,9 @@ public class ActivitiToolBehaviorProvider extends DefaultToolBehaviorProvider {
IPaletteCompartmentEntry boundaryEventCompartmentEntry = new PaletteCompartmentEntry("Boundary event", null);
IPaletteCompartmentEntry intermediateEventCompartmentEntry = new PaletteCompartmentEntry("Intermediate event", null);
IPaletteCompartmentEntry alfrescoCompartmentEntry = new PaletteCompartmentEntry("Alfresco", ActivitiImageProvider.IMG_ALFRESCO_LOGO);
// <SecureBPMN>
IPaletteCompartmentEntry securityCompartmentEntry = new PaletteCompartmentEntry("Security", null);
// </SecureBPMN>
for (int i = 0; i < superCompartments.length; i++) {
final IPaletteCompartmentEntry entry = superCompartments[i];
@ -420,6 +521,10 @@ public class ActivitiToolBehaviorProvider extends DefaultToolBehaviorProvider {
for (IToolEntry toolEntry : iPaletteCompartmentEntry.getToolEntries()) {
if ("sequenceflow".equalsIgnoreCase(toolEntry.getLabel())) {
connectionCompartmentEntry.getToolEntries().add(toolEntry);
// <SecureBPMN>
} else if ("securityflow".equalsIgnoreCase(toolEntry.getLabel())) {
connectionCompartmentEntry.getToolEntries().add(toolEntry);
// </SecureBPMN>
} else if ("startevent".equalsIgnoreCase(toolEntry.getLabel())) {
eventCompartmentEntry.getToolEntries().add(toolEntry);
} else if ("timerstartevent".equalsIgnoreCase(toolEntry.getLabel())) {
@ -466,6 +571,12 @@ public class ActivitiToolBehaviorProvider extends DefaultToolBehaviorProvider {
alfrescoCompartmentEntry.getToolEntries().add(toolEntry);
} else if ("alfrescomailtask".equalsIgnoreCase(toolEntry.getLabel())) {
alfrescoCompartmentEntry.getToolEntries().add(toolEntry);
// <SecureBPMN>
}else if ("separationofduty".equalsIgnoreCase(toolEntry.getLabel())) {
securityCompartmentEntry.getToolEntries().add(toolEntry);
} else if ("bindingofduty".equalsIgnoreCase(toolEntry.getLabel())) {
securityCompartmentEntry.getToolEntries().add(toolEntry);
// </SecureBPMN>
}
}
}
@ -492,6 +603,11 @@ public class ActivitiToolBehaviorProvider extends DefaultToolBehaviorProvider {
ret.add(alfrescoCompartmentEntry);
}
// <SecureBPMN>
if (securityCompartmentEntry.getToolEntries().size() > 0) {
ret.add(securityCompartmentEntry);
}
// </SecureBPMN>
final Map<String, List<CustomServiceTaskContext>> tasksInDrawers = new HashMap<String, List<CustomServiceTaskContext>>();
@ -691,4 +807,16 @@ public class ActivitiToolBehaviorProvider extends DefaultToolBehaviorProvider {
// Safe default assumption
return true;
}
// <SecureBPMN>
@Override
public IFeatureChecker getFeatureChecker() {
// TODO we can still create elements!
if (RbacVisualization.getInstance().isVisualizationRunning()) {
return new FeatureCheckerAdapter(false);
} else {
return new FeatureCheckerAdapter(true);
}
}
// </SecureBPMN>
}

View File

@ -15,6 +15,9 @@ import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
import org.eclipse.graphiti.mm.pictograms.Anchor;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
// <SecureBPMN>
import org.eclipse.securebpmn2.SecurityFlowNode;
// </SecureBPMN>
public class CreateSequenceFlowFeature extends AbstractCreateBPMNConnectionFeature {
@ -34,6 +37,10 @@ public class CreateSequenceFlowFeature extends AbstractCreateBPMNConnectionFeatu
} else if (source instanceof EndEvent) {
// prevent adding outgoing connections from EndEvents
return false;
// <SecureBPMN>
}else if(source instanceof SecurityFlowNode || target instanceof SecurityFlowNode){
return false;
// </SecureBPMN>
}
return true;
}

View File

@ -20,6 +20,10 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.ui.features.DefaultDeleteFeature;
// <SecureBPMN>
import org.eclipse.securebpmn2.AuthorizationConstraint;
import org.eclipse.securebpmn2.SecurityFlow;
// </SecureBPMN>
public class DeleteFlowElementFeature extends DefaultDeleteFeature {
@ -31,6 +35,11 @@ public class DeleteFlowElementFeature extends DefaultDeleteFeature {
if (bo instanceof Task || bo instanceof Gateway || bo instanceof Event || bo instanceof SubProcess || bo instanceof CallActivity) {
deleteSequenceFlows((FlowNode) bo);
}
// <SecureBPMN>
if(bo instanceof Activity || bo instanceof AuthorizationConstraint){
deleteSecurityFlows((FlowNode) bo);
}
// </SecureBPMN>
if (bo instanceof EObject) {
@ -71,6 +80,11 @@ public class DeleteFlowElementFeature extends DefaultDeleteFeature {
if(subFlowElement instanceof FlowNode) {
deleteSequenceFlows((FlowNode) subFlowElement);
}
// <SecureBPMN>
if(subFlowElement instanceof Activity || bo instanceof AuthorizationConstraint){
deleteSecurityFlows((FlowNode) bo);
}
// </SecureBPMN>
EcoreUtil.delete(subFlowElement, true);
}
subProcess.getFlowElements().clear();
@ -99,6 +113,28 @@ public class DeleteFlowElementFeature extends DefaultDeleteFeature {
EcoreUtil.delete(deleteObject, true);
}
}
// <SecureBPMN>
private void deleteSecurityFlows(FlowNode flowNode) {
List<SecurityFlow> toDeleteSecurityFlows = new ArrayList<SecurityFlow>();
for (SecurityFlow incomingSecurityFlow : flowNode.getIncomingSecurityFlow()) {
SecurityFlow toDeleteObject = (SecurityFlow) getFlowElement(incomingSecurityFlow);
if (toDeleteObject != null) {
toDeleteSecurityFlows.add(toDeleteObject);
}
}
for (SecurityFlow outgoingSecurityFlow : flowNode.getOutgoingSecurityFlow()) {
SecurityFlow toDeleteObject = (SecurityFlow) getFlowElement(outgoingSecurityFlow);
if (toDeleteObject != null) {
toDeleteSecurityFlows.add(toDeleteObject);
}
}
for (SecurityFlow deleteObject : toDeleteSecurityFlows) {
deletedConnectingFlows(deleteObject);
EcoreUtil.delete(deleteObject, true);
}
}
// </SecureBPMN>
private void deletedConnectingFlows(SequenceFlow sequenceFlow) {
for (EObject diagramObject : getDiagram().eResource().getContents()) {
@ -124,12 +160,40 @@ public class DeleteFlowElementFeature extends DefaultDeleteFeature {
}
}
}
// <SecureBPMN>
private void deletedConnectingFlows(SecurityFlow securityFlow) {
for (EObject diagramObject : getDiagram().eResource().getContents()) {
if(diagramObject instanceof Activity || diagramObject instanceof AuthorizationConstraint) {
SecurityFlow foundIncoming = null;
SecurityFlow foundOutgoing = null;
for(SecurityFlow flow : ((FlowNode) diagramObject).getIncomingSecurityFlow()) {
if(flow.getId().equals(securityFlow.getId())) {
foundIncoming = flow;
}
}
for(SecurityFlow flow : ((FlowNode) diagramObject).getOutgoingSecurityFlow()) {
if(flow.getId().equals(securityFlow.getId())) {
foundOutgoing = flow;
}
}
if(foundIncoming != null) {
((FlowNode) diagramObject).getIncomingSecurityFlow().remove(foundIncoming);
}
if(foundOutgoing != null) {
((FlowNode) diagramObject).getOutgoingSecurityFlow().remove(foundOutgoing);
}
}
}
}
// </SecureBPMN>
private EObject getFlowElement(FlowElement flowElement) {
for (EObject diagramObject : getDiagram().eResource().getContents()) {
if(diagramObject instanceof FlowElement == false) continue;
// <SecureBPMN>
System.out.println(((FlowElement) diagramObject).getName());
// </SecureBPMN>
if (((FlowElement) diagramObject).getId().equals(flowElement.getId())) {
return diagramObject;

View File

@ -17,6 +17,9 @@ import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.mm.pictograms.Shape;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.services.ILinkService;
// <SecureBPMN>
import org.eclipse.emf.ecore.EObject;
// </SecureBPMN>
public class DeleteSequenceFlowFeature extends AbstractCustomFeature {
@ -94,10 +97,17 @@ public class DeleteSequenceFlowFeature extends AbstractCustomFeature {
if(anchor instanceof ChopboxAnchor) {
Connection toDeletedConnection = null;
for (Connection connection : anchor.getOutgoingConnections()) {
// <SecureBPMN>
EObject bo =(EObject) getBusinessObjectForPictogramElement(connection);
if(bo instanceof SequenceFlow){
// </SecureBPMN>
SequenceFlow outFlow = (SequenceFlow) getBusinessObjectForPictogramElement(connection);
if(outFlow.getId().equals(sequenceFlow.getId())) {
toDeletedConnection = connection;
}
// <SecureBPMN>
}
// </SecureBPMN>
}
if(toDeletedConnection != null) {
anchor.getOutgoingConnections().remove(toDeletedConnection);
@ -111,10 +121,17 @@ public class DeleteSequenceFlowFeature extends AbstractCustomFeature {
if(anchor instanceof ChopboxAnchor) {
Connection toDeletedConnection = null;
for (Connection connection : anchor.getIncomingConnections()) {
// <SecureBPMN>
EObject bo =(EObject) getBusinessObjectForPictogramElement(connection);
if(bo instanceof SequenceFlow){
// </SecureBPMN>
SequenceFlow outFlow = (SequenceFlow) getBusinessObjectForPictogramElement(connection);
if(outFlow.getId().equals(sequenceFlow.getId())) {
toDeletedConnection = connection;
}
// <SecureBPMN>
}
// </SecureBPMN>
}
if(toDeletedConnection != null) {
anchor.getIncomingConnections().remove(toDeletedConnection);

View File

@ -5,6 +5,11 @@ import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
// <SecureBPMN>
import org.activiti.designer.util.preferences.Preferences;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FileFieldEditor;
// </SecureBPMN>
public class ActivitiPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
@ -13,11 +18,21 @@ public class ActivitiPreferencePage extends FieldEditorPreferencePage implements
}
public void createFieldEditors() {
// <SecureBPMN>
// Adding custom settings to the preference pane.
addField(new FileFieldEditor(Preferences.PATH_TO_SATMC_BINARY.getPreferenceId(),
"&Location of the SATMC binary", getFieldEditorParent()));
addField(new BooleanFieldEditor(Preferences.ALL_TASKS_AS_HUMANTASKS.getPreferenceId(), "&Analyze all Tasks as HumanTasks", getFieldEditorParent()));
// </SecureBPMN>
}
@Override
public void init(IWorkbench workbench) {
IPreferenceStore prefStore = ActivitiPlugin.getDefault().getPreferenceStore();
setPreferenceStore(prefStore);
// <SecureBPMN>
setDescription("Set general preferences of the Activiti Designer");
setTitle("Activiti Designer Preferences");
// </SecureBPMN>
}
}

View File

@ -0,0 +1,189 @@
/* Copyright 2012-2015 SAP SE
*
* Licensed 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.
*/
package org.activiti.designer.security.features;
import org.activiti.designer.ActivitiImageProvider;
import org.activiti.designer.util.eclipse.ActivitiUiUtil;
import org.activiti.designer.util.platform.OSEnum;
import org.activiti.designer.util.platform.OSUtil;
import org.activiti.designer.util.style.StyleUtil;
import org.eclipse.bpmn2.SubProcess;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.graphiti.features.IDirectEditingInfo;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.IAddContext;
import org.eclipse.graphiti.features.impl.AbstractAddShapeFeature;
import org.eclipse.graphiti.mm.algorithms.Ellipse;
import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
import org.eclipse.graphiti.mm.algorithms.Image;
import org.eclipse.graphiti.mm.algorithms.MultiText;
import org.eclipse.graphiti.mm.algorithms.Rectangle;
import org.eclipse.graphiti.mm.algorithms.RoundedRectangle;
import org.eclipse.graphiti.mm.algorithms.styles.Orientation;
import org.eclipse.graphiti.mm.pictograms.BoxRelativeAnchor;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.mm.pictograms.Shape;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.services.IGaService;
import org.eclipse.graphiti.services.IPeCreateService;
import org.eclipse.securebpmn2.AuthorizationConstraint;
/**
*
*/
public class AddSecurityBodFeature extends AbstractAddShapeFeature {
private static final int IMAGE_SIZE = 16;
public AddSecurityBodFeature(IFeatureProvider fp) {
super(fp);
}
@Override
public PictogramElement add(IAddContext context) {
final AuthorizationConstraint addedBod = (AuthorizationConstraint) context.getNewObject();
final ContainerShape parent = context.getTargetContainer();
// CONTAINER SHAPE WITH ROUNDED RECTANGLE
final IPeCreateService peCreateService = Graphiti.getPeCreateService();
final ContainerShape containerShape = peCreateService.createContainerShape(parent, true);
final IGaService gaService = Graphiti.getGaService();
int width = 0;
int height = 0;
GraphicsAlgorithm algorithm = null;
// check whether the context has a size (e.g. from a create feature)
// otherwise define a default size for the shape
width = context.getWidth() <= 0 ? 60 : context.getWidth();
height = context.getHeight() <= 0 ? 60 : context.getHeight();
RoundedRectangle roundedRectangle; // need to access it later
{
// create invisible outer rectangle expanded by
// the width needed for the anchor
final Rectangle invisibleRectangle = gaService.createInvisibleRectangle(containerShape);
gaService.setLocationAndSize(invisibleRectangle, context.getX(), context.getY(), width, height);
// create and set visible rectangle inside invisible rectangle
roundedRectangle = gaService.createRoundedRectangle(invisibleRectangle, 20, 20);
algorithm = roundedRectangle;
roundedRectangle.setParentGraphicsAlgorithm(invisibleRectangle);
roundedRectangle.setStyle(StyleUtil.getStyleForSecurityNode(getDiagram()));
gaService.setLocationAndSize(roundedRectangle, 0, 0, width, height);
//roundedRectangle.setForeground(Graphiti.getGaService().manageColor(getDiagram(), IColorConstant.LIGHT_BLUE));
// if addedClass has no resource we add it to the resource of
// the
// diagram
// in a real scenario the business model would have its own
// resource
if (addedBod.eResource() == null) {
Object parentObject = getBusinessObjectForPictogramElement(parent);
if (parentObject instanceof SubProcess) {
((SubProcess) parentObject).getFlowElements().add(addedBod);
} else {
getDiagram().eResource().getContents().add(addedBod);
}
}
// create link and wire it
link(containerShape, addedBod);
}
// SHAPE WITH TEXT
{
// create shape for text
final Shape shape = peCreateService.createShape(containerShape, false);
// create and set text graphics algorithm
final MultiText text = gaService.createDefaultMultiText(getDiagram(), shape, addedBod.getName());
text.setStyle(StyleUtil.getStyleForTask(getDiagram()));
text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
text.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
if (OSUtil.getOperatingSystem() == OSEnum.Mac) {
text.getFont().setSize(11);
}
gaService.setLocationAndSize(text, 0, 20, width, 30);
// create link and wire it
link(shape, addedBod);
// provide information to support direct-editing directly
// after object creation (must be activated additionally)
final IDirectEditingInfo directEditingInfo = getFeatureProvider().getDirectEditingInfo();
// set container shape for direct editing after object creation
directEditingInfo.setMainPictogramElement(containerShape);
// set shape and graphics algorithm where the editor for
// direct editing shall be opened after object creation
directEditingInfo.setPictogramElement(shape);
directEditingInfo.setGraphicsAlgorithm(text);
}
{
final Shape shape = peCreateService.createShape(containerShape, false);
final Image image = gaService.createImage(shape, getIcon(addedBod));
gaService.setLocationAndSize(image, 5, 5, IMAGE_SIZE, IMAGE_SIZE);
}
/*{
final Shape shape = peCreateService.createShape(containerShape, false);
final Image image = gaService.createImage(shape, "org.activiti.designer.alfresco.logo");
gaService.setLocationAndSize(image, 85, 3, IMAGE_SIZE, IMAGE_SIZE);
}*/
// add a chopbox anchor to the shape
peCreateService.createChopboxAnchor(containerShape);
// create an additional box relative anchor at middle-right
final BoxRelativeAnchor boxAnchor = peCreateService.createBoxRelativeAnchor(containerShape);
boxAnchor.setRelativeWidth(1.0);
boxAnchor.setRelativeHeight(0.51);
boxAnchor.setReferencedGraphicsAlgorithm(algorithm);
final Ellipse ellipse = ActivitiUiUtil.createInvisibleEllipse(boxAnchor, gaService);
gaService.setLocationAndSize(ellipse, 0, 0, 0, 0);
layoutPictogramElement(containerShape);
return containerShape;
}
@Override
public boolean canAdd(IAddContext context) {
if (context.getNewObject() instanceof AuthorizationConstraint) {
Object parentObject = getBusinessObjectForPictogramElement(context.getTargetContainer());
if (context.getTargetContainer() instanceof Diagram || parentObject instanceof SubProcess) {
return true;
}
}
return false;
}
protected String getIcon(EObject bo) {
return ActivitiImageProvider.IMG_SECURITY_BOD;
};
}

View File

@ -0,0 +1,292 @@
/* Copyright 2012-2015 SAP SE
*
* Licensed 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.
*/
package org.activiti.designer.security.features;
import java.util.Collection;
import java.util.List;
import org.activiti.designer.eclipse.bpmn.GraphicInfo;
import org.activiti.designer.util.style.StyleUtil;
import org.eclipse.bpmn2.EndEvent;
import org.eclipse.bpmn2.FlowNode;
import org.eclipse.bpmn2.Gateway;
import org.eclipse.bpmn2.SequenceFlow;
import org.eclipse.bpmn2.SubProcess;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.IAddConnectionContext;
import org.eclipse.graphiti.features.context.IAddContext;
import org.eclipse.graphiti.features.impl.AbstractAddFeature;
import org.eclipse.graphiti.mm.GraphicsAlgorithmContainer;
import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
import org.eclipse.graphiti.mm.algorithms.Polygon;
import org.eclipse.graphiti.mm.algorithms.Polyline;
import org.eclipse.graphiti.mm.algorithms.Text;
import org.eclipse.graphiti.mm.algorithms.styles.LineStyle;
import org.eclipse.graphiti.mm.algorithms.styles.Point;
import org.eclipse.graphiti.mm.algorithms.styles.StylesFactory;
import org.eclipse.graphiti.mm.pictograms.Anchor;
import org.eclipse.graphiti.mm.pictograms.ChopboxAnchor;
import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.mm.pictograms.PictogramLink;
import org.eclipse.graphiti.mm.pictograms.Shape;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.services.IGaService;
import org.eclipse.graphiti.services.IPeCreateService;
import org.eclipse.graphiti.util.IColorConstant;
import org.eclipse.securebpmn2.SecurityFlow;
/**
*
*/
public class AddSecurityFlowFeature extends AbstractAddFeature {
public AddSecurityFlowFeature(IFeatureProvider fp) {
super(fp);
}
@SuppressWarnings("unchecked")
public PictogramElement add(IAddContext context) {
IAddConnectionContext addConContext = (IAddConnectionContext) context;
SecurityFlow addedSecurityFlow = (SecurityFlow) context.getNewObject();
Anchor sourceAnchor = null;
Anchor targetAnchor = null;
if(addConContext.getSourceAnchor() == null) {
EList<Shape> shapeList = getDiagram().getChildren();
for (Shape shape : shapeList) {
FlowNode flowNode = (FlowNode) getBusinessObjectForPictogramElement(shape.getGraphicsAlgorithm().getPictogramElement());
if(flowNode == null || flowNode.getId() == null || addedSecurityFlow.getSourceRefNode() == null ||
addedSecurityFlow.getTargetRefNode() == null) continue;
if(flowNode.getId().equals(addedSecurityFlow.getSourceRefNode().getId())) {
EList<Anchor> anchorList = ((ContainerShape) shape).getAnchors();
for (Anchor anchor : anchorList) {
if(anchor instanceof ChopboxAnchor) {
sourceAnchor = anchor;
break;
}
}
}
if(flowNode.getId().equals(addedSecurityFlow.getTargetRefNode().getId())) {
EList<Anchor> anchorList = ((ContainerShape) shape).getAnchors();
for (Anchor anchor : anchorList) {
if(anchor instanceof ChopboxAnchor) {
targetAnchor = anchor;
break;
}
}
}
}
} else {
sourceAnchor = addConContext.getSourceAnchor();
targetAnchor = addConContext.getTargetAnchor();
}
if(sourceAnchor == null || targetAnchor == null) {
return null;
}
boolean inSubProcess = false;
Object parentObject = null;
ContainerShape parentShape = null;
if(sourceAnchor.eContainer() instanceof ContainerShape) {
parentShape = (ContainerShape) sourceAnchor.eContainer().eContainer();
parentObject = getBusinessObjectForPictogramElement(parentShape.getGraphicsAlgorithm().getPictogramElement());
if(parentObject != null && parentObject instanceof SubProcess == false) {
parentShape = (ContainerShape) targetAnchor.eContainer().eContainer();
parentObject = getBusinessObjectForPictogramElement(parentShape.getGraphicsAlgorithm().getPictogramElement());
}
}
if (parentObject != null && parentObject instanceof SubProcess) {
inSubProcess = true;
}
IPeCreateService peCreateService = Graphiti.getPeCreateService();
// CONNECTION WITH POLYLINE
FreeFormConnection connection = peCreateService.createFreeFormConnection(getDiagram());
connection.setStart(sourceAnchor);
connection.setEnd(targetAnchor);
sourceAnchor.getOutgoingConnections().add(connection);
targetAnchor.getIncomingConnections().add(connection);
GraphicsAlgorithm sourceGraphics = getPictogramElement(
addedSecurityFlow.getSourceRefNode()).getGraphicsAlgorithm();
GraphicsAlgorithm targetGraphics = getPictogramElement(
addedSecurityFlow.getTargetRefNode()).getGraphicsAlgorithm();
List<GraphicInfo> bendpointList = null;
if(addConContext.getProperty("org.activiti.designer.bendpoints") != null) {
bendpointList = (List<GraphicInfo>) addConContext.getProperty("org.activiti.designer.bendpoints");
}
if(bendpointList != null && bendpointList.size() >= 0) {
for (GraphicInfo graphicInfo : bendpointList) {
Point bendPoint = StylesFactory.eINSTANCE.createPoint();
if(inSubProcess == true) {
bendPoint.setX(parentShape.getGraphicsAlgorithm().getX() + graphicInfo.x);
bendPoint.setY(parentShape.getGraphicsAlgorithm().getY() + graphicInfo.y);
} else {
bendPoint.setX(graphicInfo.x);
bendPoint.setY(graphicInfo.y);
}
connection.getBendpoints().add(bendPoint);
}
} else {
/*if (addedSequenceFlow.getSourceRef() instanceof Gateway && addedSequenceFlow.getTargetRef() instanceof Gateway == false) {
if (((sourceGraphics.getY() + 10) < targetGraphics.getY()
|| (sourceGraphics.getY() - 10) > targetGraphics.getY()) &&
(sourceGraphics.getX() + (sourceGraphics.getWidth() / 2)) < targetGraphics.getX()) {
boolean subProcessWithBendPoint = false;
if(addedSequenceFlow.getTargetRef() instanceof SubProcess) {
int middleSub = targetGraphics.getY() + (targetGraphics.getHeight() / 2);
if((sourceGraphics.getY() + 20) < middleSub || (sourceGraphics.getY() - 20) > middleSub) {
subProcessWithBendPoint = true;
}
}
if(addedSequenceFlow.getTargetRef() instanceof SubProcess == false || subProcessWithBendPoint == true) {
Point bendPoint = StylesFactory.eINSTANCE.createPoint();
if(inSubProcess == true) {
bendPoint.setX(parentShape.getGraphicsAlgorithm().getX() + sourceGraphics.getX() + 20);
bendPoint.setY(parentShape.getGraphicsAlgorithm().getY() + targetGraphics.getY() + (targetGraphics.getHeight() / 2));
} else {
bendPoint.setX(sourceGraphics.getX() + 20);
bendPoint.setY(targetGraphics.getY() + (targetGraphics.getHeight() / 2));
}
connection.getBendpoints().add(bendPoint);
}
}
} else if (addedSequenceFlow.getTargetRef() instanceof Gateway) {
if (((sourceGraphics.getY() + 10) < targetGraphics.getY()
|| (sourceGraphics.getY() - 10) > targetGraphics.getY()) &&
(sourceGraphics.getX() + sourceGraphics.getWidth()) < targetGraphics.getX()) {
boolean subProcessWithBendPoint = false;
if(addedSequenceFlow.getSourceRef() instanceof SubProcess) {
int middleSub = sourceGraphics.getY() + (sourceGraphics.getHeight() / 2);
if((middleSub + 20) < targetGraphics.getY() || (middleSub - 20) > targetGraphics.getY()) {
subProcessWithBendPoint = true;
}
}
if(addedSequenceFlow.getSourceRef() instanceof SubProcess == false || subProcessWithBendPoint == true) {
Point bendPoint = StylesFactory.eINSTANCE.createPoint();
if(inSubProcess == true) {
bendPoint.setX(parentShape.getGraphicsAlgorithm().getX() + targetGraphics.getX() + 20);
bendPoint.setY(parentShape.getGraphicsAlgorithm().getY() + sourceGraphics.getY() + (sourceGraphics.getHeight() / 2));
} else {
bendPoint.setX(targetGraphics.getX() + 20);
bendPoint.setY(sourceGraphics.getY() + (sourceGraphics.getHeight() / 2));
}
connection.getBendpoints().add(bendPoint);
}
}
} else if (addedSequenceFlow.getTargetRef() instanceof EndEvent) {
int middleSource = sourceGraphics.getY() + (sourceGraphics.getHeight() / 2);
int middleTarget = targetGraphics.getY() + (targetGraphics.getHeight() / 2);
if (((middleSource + 10) < middleTarget &&
(sourceGraphics.getX() + sourceGraphics.getWidth()) < targetGraphics.getX()) ||
((middleSource - 10) > middleTarget &&
(sourceGraphics.getX() + sourceGraphics.getWidth()) < targetGraphics.getX())) {
Point bendPoint = StylesFactory.eINSTANCE.createPoint();
if(inSubProcess == true) {
bendPoint.setX(parentShape.getGraphicsAlgorithm().getX() + targetGraphics.getX() + (targetGraphics.getWidth() / 2));
bendPoint.setY(parentShape.getGraphicsAlgorithm().getY() + sourceGraphics.getY() + (sourceGraphics.getHeight() / 2));
} else {
bendPoint.setX(targetGraphics.getX() + (targetGraphics.getWidth() / 2));
bendPoint.setY(sourceGraphics.getY() + (sourceGraphics.getHeight() / 2));
}
connection.getBendpoints().add(bendPoint);
}
}*/
}
IGaService gaService = Graphiti.getGaService();
Polyline polyline = gaService.createPolyline(connection);
polyline.setLineStyle(LineStyle.SOLID);
polyline.setForeground(Graphiti.getGaService().manageColor(getDiagram(), IColorConstant.LIGHT_BLUE));
// create link and wire it
link(connection, addedSecurityFlow);
// add dynamic text decorator for the reference name
ConnectionDecorator textDecorator = peCreateService.createConnectionDecorator(connection, true, 0.5, true);
Text text = gaService.createDefaultText(getDiagram(), textDecorator);
text.setStyle(StyleUtil.getStyleForTask((getDiagram())));
gaService.setLocation(text, 10, 0);
// set reference name in the text decorator
SecurityFlow securityFlow = (SecurityFlow) context.getNewObject();
text.setValue(securityFlow.getName());
// add static graphical decorators (composition and navigable)
ConnectionDecorator cd = peCreateService.createConnectionDecorator(connection, false, 1.0, true);
createArrow(cd);
return connection;
}
public boolean canAdd(IAddContext context) {
// return true if given business object is an EReference
// note, that the context must be an instance of IAddConnectionContext
if (context instanceof IAddConnectionContext && context.getNewObject() instanceof SecurityFlow) {
return true;
}
return false;
}
private Polygon createArrow(GraphicsAlgorithmContainer gaContainer) {
int xy[] = new int[] { -10, -5, 0, 0, -10, 5, -8, 0 };
int beforeAfter[] = new int[] { 3, 3, 0, 0, 3, 3, 3, 3 };
Polygon polyline = Graphiti.getGaCreateService().createPolygon(gaContainer, xy, beforeAfter);
polyline.setStyle(StyleUtil.getStyleForPolygon(getDiagram()));
polyline.setForeground(Graphiti.getGaService().manageColor(getDiagram(), IColorConstant.LIGHT_BLUE));
return polyline;
}
private PictogramElement getPictogramElement(EObject businessObject) {
Collection<PictogramLink> pictogramLinks = getDiagram().getPictogramLinks();
for (PictogramLink pictogramLink : pictogramLinks) {
List<EObject> businessObjects = pictogramLink.getBusinessObjects();
for (EObject obj : businessObjects) {
if (EcoreUtil.equals((EObject) businessObject, obj)) {
PictogramElement pe = pictogramLink.getPictogramElement();
if (pe != null) {
return pe;
}
}
}
}
return null;
}
}

View File

@ -0,0 +1,189 @@
/* Copyright 2012-2015 SAP SE
*
* Licensed 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.
*/
package org.activiti.designer.security.features;
import org.activiti.designer.ActivitiImageProvider;
import org.activiti.designer.util.eclipse.ActivitiUiUtil;
import org.activiti.designer.util.platform.OSEnum;
import org.activiti.designer.util.platform.OSUtil;
import org.activiti.designer.util.style.StyleUtil;
import org.eclipse.bpmn2.SubProcess;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.graphiti.features.IDirectEditingInfo;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.IAddContext;
import org.eclipse.graphiti.features.impl.AbstractAddShapeFeature;
import org.eclipse.graphiti.mm.algorithms.Ellipse;
import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
import org.eclipse.graphiti.mm.algorithms.Image;
import org.eclipse.graphiti.mm.algorithms.MultiText;
import org.eclipse.graphiti.mm.algorithms.Rectangle;
import org.eclipse.graphiti.mm.algorithms.RoundedRectangle;
import org.eclipse.graphiti.mm.algorithms.styles.Orientation;
import org.eclipse.graphiti.mm.pictograms.BoxRelativeAnchor;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.mm.pictograms.Shape;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.services.IGaService;
import org.eclipse.graphiti.services.IPeCreateService;
import org.eclipse.securebpmn2.AuthorizationConstraint;
/**
*
*/
public class AddSecuritySodFeature extends AbstractAddShapeFeature {
private static final int IMAGE_SIZE_HIGHT = 16;
private static final int IMAGE_SIZE_WIDTH=50;
public AddSecuritySodFeature(IFeatureProvider fp) {
super(fp);
}
@Override
public PictogramElement add(IAddContext context) {
final AuthorizationConstraint addedSod = (AuthorizationConstraint) context.getNewObject();
final ContainerShape parent = context.getTargetContainer();
// CONTAINER SHAPE WITH ROUNDED RECTANGLE
final IPeCreateService peCreateService = Graphiti.getPeCreateService();
final ContainerShape containerShape = peCreateService.createContainerShape(parent, true);
final IGaService gaService = Graphiti.getGaService();
int width = 0;
int height = 0;
GraphicsAlgorithm algorithm = null;
// check whether the context has a size (e.g. from a create feature)
// otherwise define a default size for the shape
width = context.getWidth() <= 0 ? 60 : context.getWidth();
height = context.getHeight() <= 0 ? 60 : context.getHeight();
RoundedRectangle roundedRectangle; // need to access it later
{
// create invisible outer rectangle expanded by
// the width needed for the anchor
final Rectangle invisibleRectangle = gaService.createInvisibleRectangle(containerShape);
gaService.setLocationAndSize(invisibleRectangle, context.getX(), context.getY(), width, height);
// create and set visible rectangle inside invisible rectangle
roundedRectangle = gaService.createRoundedRectangle(invisibleRectangle, 20, 20);
algorithm = roundedRectangle;
roundedRectangle.setParentGraphicsAlgorithm(invisibleRectangle);
roundedRectangle.setStyle(StyleUtil.getStyleForSecurityNode(getDiagram()));
gaService.setLocationAndSize(roundedRectangle, 0, 0, width, height);
// if addedClass has no resource we add it to the resource of
// the
// diagram
// in a real scenario the business model would have its own
// resource
if (addedSod.eResource() == null) {
Object parentObject = getBusinessObjectForPictogramElement(parent);
if (parentObject instanceof SubProcess) {
((SubProcess) parentObject).getFlowElements().add(addedSod);
} else {
getDiagram().eResource().getContents().add(addedSod);
}
}
// create link and wire it
link(containerShape, addedSod);
}
// SHAPE WITH TEXT
{
// create shape for text
final Shape shape = peCreateService.createShape(containerShape, false);
// create and set text graphics algorithm
final MultiText text = gaService.createDefaultMultiText(getDiagram(), shape, addedSod.getName());
text.setStyle(StyleUtil.getStyleForTask(getDiagram()));
text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
text.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
if (OSUtil.getOperatingSystem() == OSEnum.Mac) {
text.getFont().setSize(11);
}
gaService.setLocationAndSize(text, 0, 20, width, 30);
// create link and wire it
link(shape, addedSod);
// provide information to support direct-editing directly
// after object creation (must be activated additionally)
final IDirectEditingInfo directEditingInfo = getFeatureProvider().getDirectEditingInfo();
// set container shape for direct editing after object creation
directEditingInfo.setMainPictogramElement(containerShape);
// set shape and graphics algorithm where the editor for
// direct editing shall be opened after object creation
directEditingInfo.setPictogramElement(shape);
directEditingInfo.setGraphicsAlgorithm(text);
}
{
final Shape shape = peCreateService.createShape(containerShape, false);
final Image image = gaService.createImage(shape, getIcon(addedSod));
gaService.setLocationAndSize(image, 5, 5, IMAGE_SIZE_WIDTH, IMAGE_SIZE_HIGHT);
}
/*{
final Shape shape = peCreateService.createShape(containerShape, false);
final Image image = gaService.createImage(shape, "org.activiti.designer.alfresco.logo");
gaService.setLocationAndSize(image, 85, 3, IMAGE_SIZE, IMAGE_SIZE);
}*/
// add a chopbox anchor to the shape
peCreateService.createChopboxAnchor(containerShape);
// create an additional box relative anchor at middle-right
final BoxRelativeAnchor boxAnchor = peCreateService.createBoxRelativeAnchor(containerShape);
boxAnchor.setRelativeWidth(1.0);
boxAnchor.setRelativeHeight(0.51);
boxAnchor.setReferencedGraphicsAlgorithm(algorithm);
final Ellipse ellipse = ActivitiUiUtil.createInvisibleEllipse(boxAnchor, gaService);
gaService.setLocationAndSize(ellipse, 0, 0, 0, 0);
layoutPictogramElement(containerShape);
return containerShape;
}
@Override
public boolean canAdd(IAddContext context) {
if (context.getNewObject() instanceof AuthorizationConstraint) {
Object parentObject = getBusinessObjectForPictogramElement(context.getTargetContainer());
if (context.getTargetContainer() instanceof Diagram || parentObject instanceof SubProcess) {
return true;
}
}
return false;
}
protected String getIcon(EObject bo) {
return ActivitiImageProvider.IMG_SECURITY_SOD;
};
}

View File

@ -0,0 +1,80 @@
/* Copyright 2012-2015 SAP SE
*
* Licensed 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.
*/
package org.activiti.designer.security.features;
import org.activiti.designer.features.AbstractCreateFastBPMNFeature;
import org.eclipse.bpmn2.SubProcess;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.ICreateContext;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.securebpmn2.BindingOfDuty;
import org.eclipse.securebpmn2.Securebpmn2Factory;
/**
*
*/
public class CreateSecurityBodFeature extends AbstractCreateFastBPMNFeature {
public static final String FEATURE_ID_KEY = "securityBod";
public CreateSecurityBodFeature(IFeatureProvider fp) {
super(fp, "BindingOfDuty", "Add Binding of Duty");
}
@Override
public boolean canCreate(ICreateContext context) {
Object parentObject = getBusinessObjectForPictogramElement(context.getTargetContainer());
return (context.getTargetContainer() instanceof Diagram || parentObject instanceof SubProcess);
}
@Override
public Object[] create(ICreateContext context) {
BindingOfDuty bod = Securebpmn2Factory.eINSTANCE.createBindingOfDuty();
bod.setId(getNextId());
bod.setName("bod");
bod.setDynamicEnforcement(false);
Object parentObject = getBusinessObjectForPictogramElement(context.getTargetContainer());
if (parentObject instanceof SubProcess) {
((SubProcess) parentObject).getFlowElements().add(bod);
} else {
getDiagram().eResource().getContents().add(bod);
}
addGraphicalContent(bod, context);
// activate direct editing after object creation
getFeatureProvider().getDirectEditingInfo().setActive(true);
return new Object[] { bod };
}
@Override
public String getCreateImageId() {
return "org.activiti.designer.security.bod";
}
@Override
protected String getFeatureIdKey() {
return FEATURE_ID_KEY;
}
@SuppressWarnings("rawtypes")
@Override
protected Class getFeatureClass() {
return Securebpmn2Factory.eINSTANCE.createBindingOfDuty().getClass();
}
}

View File

@ -0,0 +1,148 @@
/* Copyright 2012-2015 SAP SE
*
* Licensed 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.
*/
package org.activiti.designer.security.features;
import org.activiti.designer.ActivitiImageProvider;
import org.activiti.designer.features.AbstractCreateBPMNConnectionFeature;
import org.eclipse.bpmn2.Activity;
import org.eclipse.bpmn2.FlowNode;
import org.eclipse.bpmn2.SubProcess;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.ICreateConnectionContext;
import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
import org.eclipse.graphiti.mm.pictograms.Anchor;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.securebpmn2.Securebpmn2Factory;
import org.eclipse.securebpmn2.SecurityFlow;
import org.eclipse.securebpmn2.SecurityFlowNode;
/**
*
*/
public class CreateSecurityFlowFeature extends AbstractCreateBPMNConnectionFeature {
public static final String FEATURE_ID_KEY = "sf";
public CreateSecurityFlowFeature(IFeatureProvider fp) {
// provide name and description for the UI, e.g. the palette
super(fp, "SecurityFlow", "Create SecurityFlow"); //$NON-NLS-1$ //$NON-NLS-2$
}
public boolean canCreate(ICreateConnectionContext context) {
FlowNode source = getFlowNode(context.getSourceAnchor());
FlowNode target = getFlowNode(context.getTargetAnchor());
if (source != null && target != null && source != target) {
if(source instanceof SecurityFlowNode && target instanceof Activity) {
return true;
}
return false;
}
return false;
}
public boolean canStartConnection(ICreateConnectionContext context) {
// return true if source anchor isn't undefined
if (getFlowNode(context.getSourceAnchor()) != null) {
return true;
}
return false;
}
public Connection create(ICreateConnectionContext context) {
Connection newConnection = null;
FlowNode source = getFlowNode(context.getSourceAnchor());
FlowNode target = getFlowNode(context.getTargetAnchor());
if (source != null && target != null) {
// create new business object
SecurityFlow securityFlow = createSecurityFlow(source, target, context);
// add connection for business object
AddConnectionContext addContext = new AddConnectionContext(context.getSourceAnchor(),
context.getTargetAnchor());
addContext.setNewObject(securityFlow);
newConnection = (Connection) getFeatureProvider().addIfPossible(addContext);
}
return newConnection;
}
/**
* Returns the FlowNode belonging to the anchor, or null if not available.
*/
private FlowNode getFlowNode(Anchor anchor) {
if (anchor != null) {
Object obj = getBusinessObjectForPictogramElement(anchor.getParent());
if (obj instanceof FlowNode) {
return (FlowNode) obj;
}
}
return null;
}
private SecurityFlow createSecurityFlow(FlowNode source, FlowNode target, ICreateConnectionContext context) {
SecurityFlow securityFlow = Securebpmn2Factory.eINSTANCE.createSecurityFlow();
securityFlow.setId(getNextId());
securityFlow.setSourceRefNode(source);
securityFlow.setTargetRefNode(target);
securityFlow.setName(securityFlow.getId());
Object parentObject = null;
if(context.getSourcePictogramElement().eContainer() instanceof ContainerShape) {
ContainerShape parentShape = (ContainerShape) context.getSourcePictogramElement().eContainer();
parentObject = getBusinessObjectForPictogramElement(parentShape.getGraphicsAlgorithm().getPictogramElement());
if(parentObject != null && parentObject instanceof SubProcess == false) {
parentShape = (ContainerShape) context.getTargetPictogramElement().eContainer();
parentObject = getBusinessObjectForPictogramElement(parentShape.getGraphicsAlgorithm().getPictogramElement());
}
}
if (parentObject != null && parentObject instanceof SubProcess) {
((SubProcess) parentObject).getFlowElements().add(securityFlow);
} else {
getDiagram().eResource().getContents().add(securityFlow);
}
source.getOutgoingSecurityFlow().add(securityFlow);
target.getIncomingSecurityFlow().add(securityFlow);
return securityFlow;
}
@Override
public String getCreateImageId() {
return ActivitiImageProvider.IMG_EREFERENCE;
}
@Override
protected String getFeatureIdKey() {
return FEATURE_ID_KEY;
}
@SuppressWarnings("rawtypes")
@Override
protected Class getFeatureClass() {
return Securebpmn2Factory.eINSTANCE.createSecurityFlow().getClass();
}
}

View File

@ -0,0 +1,80 @@
/* Copyright 2012-2015 SAP SE
*
* Licensed 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.
*/
package org.activiti.designer.security.features;
import org.activiti.designer.features.AbstractCreateFastBPMNFeature;
import org.eclipse.bpmn2.SubProcess;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.ICreateContext;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.securebpmn2.Securebpmn2Factory;
import org.eclipse.securebpmn2.SeparationOfDuty;
/**
*
*/
public class CreateSecuritySodFeature extends AbstractCreateFastBPMNFeature {
public static final String FEATURE_ID_KEY = "securitySod";
public CreateSecuritySodFeature(IFeatureProvider fp) {
super(fp, "SeparationOfDuty", "Add Separation of Duty");
}
@Override
public boolean canCreate(ICreateContext context) {
Object parentObject = getBusinessObjectForPictogramElement(context.getTargetContainer());
return (context.getTargetContainer() instanceof Diagram || parentObject instanceof SubProcess);
}
@Override
public Object[] create(ICreateContext context) {
SeparationOfDuty sod = Securebpmn2Factory.eINSTANCE.createSeparationOfDuty();
sod.setId(getNextId());
sod.setName("sod");
sod.setDynamicEnforcement(false);
Object parentObject = getBusinessObjectForPictogramElement(context.getTargetContainer());
if (parentObject instanceof SubProcess) {
((SubProcess) parentObject).getFlowElements().add(sod);
} else {
getDiagram().eResource().getContents().add(sod);
}
addGraphicalContent(sod, context);
// activate direct editing after object creation
getFeatureProvider().getDirectEditingInfo().setActive(true);
return new Object[] { sod };
}
@Override
public String getCreateImageId() {
return "org.activiti.designer.security.sod";
}
@Override
protected String getFeatureIdKey() {
return FEATURE_ID_KEY;
}
@SuppressWarnings("rawtypes")
@Override
protected Class getFeatureClass() {
return Securebpmn2Factory.eINSTANCE.createSeparationOfDuty().getClass();
}
}

View File

@ -0,0 +1,155 @@
/* Copyright 2012-2015 SAP SE
*
* Licensed 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.
*/
package org.activiti.designer.security.features;
import java.util.List;
import org.eclipse.bpmn2.FlowElement;
import org.eclipse.bpmn2.SequenceFlow;
import org.eclipse.bpmn2.SubProcess;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.ICustomContext;
import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
import org.eclipse.graphiti.mm.pictograms.Anchor;
import org.eclipse.graphiti.mm.pictograms.ChopboxAnchor;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.mm.pictograms.Shape;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.services.ILinkService;
import org.eclipse.securebpmn2.SecurityFlow;
/**
*
*/
public class DeleteSecurityFlowFeature extends AbstractCustomFeature {
public DeleteSecurityFlowFeature(IFeatureProvider fp) {
super(fp);
}
@Override
public String getName() {
return "Delete security flow"; //$NON-NLS-1$
}
@Override
public String getDescription() {
return "Delete security flow"; //$NON-NLS-1$
}
@Override
public boolean canExecute(ICustomContext context) {
if(context.getPictogramElements() == null) return false;
for (PictogramElement pictogramElement : context.getPictogramElements()) {
if(pictogramElement.getLink() == null) continue;
Object boObject = getBusinessObjectForPictogramElement(pictogramElement);
if(boObject instanceof SecurityFlow == false) {
return false;
}
}
return true;
}
public void execute(ICustomContext context) {
if(context.getPictogramElements() == null) return;
ILinkService linkService = Graphiti.getLinkService();
for (final PictogramElement pictogramElement : context.getPictogramElements()) {
if(pictogramElement.getLink() == null) continue;
final Object boObject = getBusinessObjectForPictogramElement(pictogramElement);
if(boObject instanceof SecurityFlow == true) {
final SecurityFlow securityFlow = (SecurityFlow) boObject;
for(Shape shape : getDiagram().getChildren()) {
FlowElement flowElement = (FlowElement) getBusinessObjectForPictogramElement(shape.getGraphicsAlgorithm().getPictogramElement());
if(flowElement instanceof SubProcess) {
List<PictogramElement> pictoList = linkService.getPictogramElements(getDiagram(), flowElement);
if(pictoList != null && pictoList.size() > 0) {
ContainerShape parent = (ContainerShape) pictoList.get(0);
for(Shape subShape : parent.getChildren()) {
for(FlowElement subFlowElement : ((SubProcess) flowElement).getFlowElements()) {
removeAnchors(securityFlow, subFlowElement, subShape);
}
}
((SubProcess) flowElement).getFlowElements().remove(securityFlow);
}
} else {
removeAnchors(securityFlow, flowElement, shape);
}
}
getDiagram().getPictogramLinks().remove(pictogramElement.getLink());
getDiagram().getConnections().remove(pictogramElement);
if(securityFlow.getSourceRefNode() != null) {
securityFlow.getSourceRefNode().getOutgoingSecurityFlow().remove(securityFlow);
}
if(securityFlow.getTargetRefNode() != null) {
securityFlow.getTargetRefNode().getIncomingSecurityFlow().remove(securityFlow);
}
getDiagram().eResource().getContents().remove(securityFlow);
}
}
}
private void removeAnchors(SecurityFlow securityFlow, FlowElement flowElement, Shape shape) {
if(flowElement.getId().equals(securityFlow.getSourceRefNode().getId())) {
EList<Anchor> anchorList = shape.getAnchors();
for (Anchor anchor : anchorList) {
if(anchor instanceof ChopboxAnchor) {
Connection toDeletedConnection = null;
for (Connection connection : anchor.getOutgoingConnections()) {
EObject bo =(EObject) getBusinessObjectForPictogramElement(connection);
if(bo instanceof SecurityFlow) {
SecurityFlow outFlow = (SecurityFlow) getBusinessObjectForPictogramElement(connection);
if(outFlow.getId().equals(securityFlow.getId())) {
toDeletedConnection = connection;
}
}
}
if(toDeletedConnection != null) {
anchor.getOutgoingConnections().remove(toDeletedConnection);
}
}
}
}
if(flowElement.getId().equals(securityFlow.getTargetRefNode().getId())) {
EList<Anchor> anchorList = shape.getAnchors();
for (Anchor anchor : anchorList) {
if(anchor instanceof ChopboxAnchor) {
Connection toDeletedConnection = null;
for (Connection connection : anchor.getIncomingConnections()) {
EObject bo =(EObject) getBusinessObjectForPictogramElement(connection);
if(bo instanceof SecurityFlow) {
SecurityFlow outFlow = (SecurityFlow) getBusinessObjectForPictogramElement(connection);
if(outFlow.getId().equals(securityFlow.getId())) {
toDeletedConnection = connection;
}
}
}
if(toDeletedConnection != null) {
anchor.getIncomingConnections().remove(toDeletedConnection);
}
}
}
}
}
}

View File

@ -0,0 +1,51 @@
/* Copyright 2012-2015 SAP SE
*
* Licensed 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.
*/
package org.activiti.designer.security.property;
import org.activiti.designer.property.extension.util.ExtensionUtil;
import org.eclipse.bpmn2.AlfrescoUserTask;
import org.eclipse.bpmn2.ServiceTask;
import org.eclipse.bpmn2.UserTask;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.ui.platform.AbstractPropertySectionFilter;
/**
*
*/
public class PropertyNtkFilter extends AbstractPropertySectionFilter {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.graphiti.ui.platform.AbstractPropertySectionFilter#accept
* (org.eclipse.graphiti.mm.pictograms.PictogramElement)
*/
@Override
protected boolean accept(PictogramElement pe) {
EObject bo = Graphiti.getLinkService()
.getBusinessObjectForLinkedPictogramElement(pe);
if ((bo instanceof UserTask && bo instanceof AlfrescoUserTask == false)
|| (bo instanceof ServiceTask && !ExtensionUtil
.isCustomServiceTask(bo))) {
return true;
}
return false;
}
}

View File

@ -0,0 +1,804 @@
/* Copyright 2012-2015 SAP SE
*
* Licensed 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.
*/
package org.activiti.designer.security.property;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.activiti.designer.util.eclipse.ActivitiUiUtil;
import org.activiti.designer.util.property.ActivitiPropertySection;
import org.eclipse.bpmn2.Activity;
import org.eclipse.bpmn2.DataInput;
import org.eclipse.bpmn2.DataOutput;
import org.eclipse.bpmn2.ItemAwareElement;
import org.eclipse.bpmn2.ServiceTask;
import org.eclipse.bpmn2.Task;
import org.eclipse.bpmn2.UserTask;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.ui.editor.DiagramEditor;
import org.eclipse.securebpmn2.Action;
import org.eclipse.securebpmn2.ActivityAuthorizationConstraint;
import org.eclipse.securebpmn2.AtomicActivityAction;
import org.eclipse.securebpmn2.AtomicItemAwareElementAction;
import org.eclipse.securebpmn2.CompositeItemAwareElementAction;
import org.eclipse.securebpmn2.ItemAwareElementAction;
import org.eclipse.securebpmn2.NeedToKnow;
import org.eclipse.securebpmn2.Permission;
import org.eclipse.securebpmn2.Role;
import org.eclipse.securebpmn2.Securebpmn2Factory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
import eu.aniketos.securebpmn.ntk.NeedToKnowUtil;
import eu.aniketos.securebpmn.util.SecurityUtil;
/**
* Creates and controls the need-to-know tab in the properties view.
*
*
*/
public class PropertyNtkSection extends ActivitiPropertySection implements
ITabbedPropertyConstants {
private CCombo actionCombo;
private CCombo processVariableCombo;
private CCombo roleCombo;
private Table table;
private Composite buttonBox;
private Button addButton;
private Button removeButton;
private int checkCount = 0;
private SelectionListener selectionListener;
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#createControls
* (org.eclipse.swt.widgets.Composite,
* org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage)
*/
@Override
public void createControls(Composite parent,
TabbedPropertySheetPage tabbedPropertySheetPage) {
super.createControls(parent, tabbedPropertySheetPage);
// general vars
TabbedPropertySheetWidgetFactory factory = getWidgetFactory();
Composite composite = factory.createFlatFormComposite(parent);
FormData data;
// setup action combo box
actionCombo = factory.createCCombo(composite, SWT.NONE);
for (String actionName : NeedToKnowUtil
.getItemAwareElementActionNames()) {
actionCombo.add(actionName);
}
data = new FormData();
data.left = new FormAttachment(0, 120);
data.right = new FormAttachment(80, 0);
data.top = new FormAttachment(0, VSPACE);
actionCombo.setLayoutData(data);
// actionCombo.addFocusListener(listener);
// setup action label
CLabel actionLabel = factory.createCLabel(composite, "Action :"); //$NON-NLS-1$
data = new FormData();
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(actionCombo, -HSPACE);
data.top = new FormAttachment(actionCombo, 0, SWT.CENTER);
actionLabel.setLayoutData(data);
// setup process variable combo box
processVariableCombo = factory.createCCombo(composite, SWT.NONE);
data = new FormData();
data.left = new FormAttachment(0, 120);
data.right = new FormAttachment(80, 0);
data.top = new FormAttachment(actionCombo, VSPACE);
processVariableCombo.setLayoutData(data);
// processVariableCombo.addFocusListener(listener);
// setup process variable label
CLabel processVariableLabel = factory.createCLabel(composite,
"Process Variable :"); //$NON-NLS-1$
data = new FormData();
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(processVariableCombo, -HSPACE);
data.top = new FormAttachment(processVariableCombo, 0, SWT.CENTER);
processVariableLabel.setLayoutData(data);
// setup role combo box
roleCombo = factory.createCCombo(composite, SWT.NONE);
for (Role role : SecurityUtil.getRoles(getDiagram())) {
roleCombo.add(role.getName());
}
data = new FormData();
data.left = new FormAttachment(0, 120);
data.right = new FormAttachment(80, 0);
data.top = new FormAttachment(processVariableCombo, VSPACE);
roleCombo.setLayoutData(data);
// roleCombo.addFocusListener(listener);
// setup role label
CLabel roleLabel = factory.createCLabel(composite, "Role :"); //$NON-NLS-1$
data = new FormData();
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(roleCombo, -HSPACE);
data.top = new FormAttachment(roleCombo, 0, SWT.CENTER);
roleLabel.setLayoutData(data);
// setup table label
CLabel tableLabel = factory
.createCLabel(composite, "NtK Permissions :"); //$NON-NLS-1$
data = new FormData();
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(0, 100);
data.top = new FormAttachment(roleCombo, VSPACE);
tableLabel.setLayoutData(data);
// setup permission table part 1
data = new FormData(200, 140);
data.left = new FormAttachment(tableLabel, 10);
data.right = new FormAttachment(80, 0);
data.top = new FormAttachment(roleCombo, VSPACE);
table = new Table(composite, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL
| SWT.H_SCROLL);
table.setLayoutData(data);
table.setLinesVisible(true);
table.setHeaderVisible(true);
// setup table buttons
buttonBox = getButtonBoxControl(composite);
data = new FormData();
data.left = new FormAttachment(table, -HSPACE);
data.right = new FormAttachment(100, 0);
data.top = new FormAttachment(roleLabel, 0);
buttonBox.setLayoutData(data);
buttonBox.setVisible(true);
// buttonBox.addFocusListener(listener);
// setup permission table part 2
String[] titles = { " ", "Name", "Process Variable", "Action", "Roles" };
for (int i = 0; i < titles.length; i++) {
TableColumn column = new TableColumn(table, SWT.NONE);
column.setText(titles[i]);
column.setWidth(170);
}
table.getColumn(0).setWidth(30);
table.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
if (event.detail == SWT.CHECK) {
TableItem item = (TableItem) event.item;
if (item.getChecked() == true) {
checkCount++;
} else {
checkCount--;
}
}
selectionChanged();
}
});
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#refresh()
*/
@Override
public void refresh() {
// try to get the roles if combo is still empty
if (roleCombo.getItems().length == 0) {
for (Role role : SecurityUtil.getRoles(getDiagram())) {
roleCombo.add(role.getName());
}
}
// update task IO specifications
System.out.print("[SCVM-BPMN] updating task IO specifications...");
final Diagram diagram = getDiagram();
DiagramEditor diagramEditor = (DiagramEditor) getDiagramEditor();
TransactionalEditingDomain editingDomain = diagramEditor
.getEditingDomain();
ActivitiUiUtil.runModelChange(new Runnable() {
public void run() {
final List<Task> tasks = new ArrayList<Task>();
for (EObject obj : diagram.eResource().getContents()) {
if (obj instanceof Task) {
tasks.add((Task) obj);
}
}
for (Task t : tasks) {
NeedToKnowUtil.updateIOSpecification(t, diagram);
}
}
}, editingDomain, "Model Update");
System.out.println("done!");
// refresh process variable combo box
List<String> accessedProcessVariables = new ArrayList<String>();
;
PictogramElement pe = getSelectedPictogramElement();
if (pe != null) {
Object bo = Graphiti.getLinkService()
.getBusinessObjectForLinkedPictogramElement(pe);
if (bo instanceof UserTask) {
accessedProcessVariables = NeedToKnowUtil
.getAccessedProcessVariableNames((UserTask) bo);
updateTable((Activity) bo);
} else if (bo instanceof ServiceTask) {
accessedProcessVariables = NeedToKnowUtil
.getAccessedProcessVariableNames((ServiceTask) bo);
updateTable((Activity) bo);
}
} else {
return;
}
processVariableCombo.removeAll();
for (String processVariableName : accessedProcessVariables) {
processVariableCombo.add(processVariableName);
}
}
/**
* Creates the Composite holding the Buttons for adding and removing
* need-to-know Permissions.
*
* @param parent
* The parent Composite that the new Composite will be placed on.
* @return A Composite holding the add/remove Buttons
*/
private Composite getButtonBoxControl(Composite parent) {
if (buttonBox == null) {
buttonBox = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
buttonBox.setLayout(layout);
buttonBox.setBackground(Display.getDefault().getSystemColor(
SWT.COLOR_WHITE));
addButton = createPushButton(buttonBox, "Add");
removeButton = createPushButton(buttonBox, "Remove");
buttonBox.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent event) {
addButton = null;
removeButton = null;
buttonBox = null;
}
});
}
selectionChanged();
return buttonBox;
}
/**
* Enables the remove Button when at least one element in the table is
* selected and disables it when no elements are selected.
*/
private void selectionChanged() {
removeButton.setEnabled(checkCount > 0);
}
/**
* Helper method to create and set up a Button.
*
* @param parent
* The parent Composite the Button will be placed on.
* @param key
* The text that will be displayed on the Button.
* @return A newly created Button.
*/
private Button createPushButton(Composite parent, String key) {
Button button = new Button(parent, SWT.PUSH);
button.setText(key);
button.setFont(parent.getFont());
GridData data = new GridData(GridData.FILL_HORIZONTAL);
data.widthHint = 40;
button.setLayoutData(data);
button.addSelectionListener(getSelectionListener());
return button;
}
/**
* Returns the SelectionListener and creates one if no Listener is present.
*
* @return The SelectionListener for this class.
*/
private SelectionListener getSelectionListener() {
if (selectionListener == null) {
createSelectionListener();
}
return selectionListener;
}
/**
* Creates a SelectionListener that manages the Button functionality.
*/
private void createSelectionListener() {
selectionListener = new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
Widget widget = event.widget;
if (widget == addButton) {
addPressed();
} else if (widget == removeButton) {
removePressed();
} else if (widget == table) {
selectionChanged();
}
}
};
}
/**
* Contains the code that is executed when the "add" Button is pressed. In
* particular, it creates a new NeedToKnow Permission or updates the
* existing one.
*/
private void addPressed() {
if (actionCombo.getText() == "" || processVariableCombo.getText() == ""
|| roleCombo.getText() == "")
return;
PictogramElement pe = getSelectedPictogramElement();
if (pe != null) {
Object bo = Graphiti.getLinkService()
.getBusinessObjectForLinkedPictogramElement(pe);
if (bo instanceof Activity) {
DiagramEditor diagramEditor = (DiagramEditor) getDiagramEditor();
TransactionalEditingDomain editingDomain = diagramEditor
.getEditingDomain();
ActivitiUiUtil.runModelChange(new Runnable() {
public void run() {
Object bo = Graphiti.getLinkService()
.getBusinessObjectForLinkedPictogramElement(
getSelectedPictogramElement());
if (bo == null) {
return;
} else {
// check for existing NtK permissions
Activity activity = (Activity) bo;
NeedToKnow selectedNtk = null;
for (ActivityAuthorizationConstraint ac : activity
.getActivityAuthorizationConstraints()) {
if (selectedNtk != null)
break;
for (Permission p : ac.getPermissions()) {
if (selectedNtk != null)
break;
if (p instanceof NeedToKnow) {
NeedToKnow candidateNtk = (NeedToKnow) p;
for (Action a : p.getActions()) {
if (selectedNtk != null)
break;
if (a instanceof ItemAwareElementAction) {
ItemAwareElementAction iaea = (ItemAwareElementAction) a;
if (iaea.getActionName()
.equalsIgnoreCase(
actionCombo
.getText())) {
// action is the same
if (iaea instanceof AtomicItemAwareElementAction) {
// check directly
if (iaea.getItemAwareElement() == null)
continue;
if (actionCombo
.getText()
.equalsIgnoreCase(
"read")
&& iaea.getItemAwareElement() instanceof DataInput
&& iaea.getItemAwareElement()
.getId()
.equals(NeedToKnowUtil.ID_PREFIX_INPUT
+ processVariableCombo
.getText())) {
selectedNtk = candidateNtk;
break;
} else if (actionCombo
.getText()
.equalsIgnoreCase(
"write")
&& iaea.getItemAwareElement() instanceof DataOutput
&& iaea.getItemAwareElement()
.getId()
.equals(NeedToKnowUtil.ID_PREFIX_OUTPUT
+ processVariableCombo
.getText())) {
selectedNtk = candidateNtk;
break;
}
} else {
// check subactions
boolean containsRead = false;
boolean containsWrite = false;
for (ItemAwareElementAction inner_iaea : ((CompositeItemAwareElementAction) iaea)
.getItemAwareElementActions()) {
if (inner_iaea instanceof AtomicActivityAction) {
if (containsRead
&& containsWrite)
break;
if (inner_iaea
.getItemAwareElement() == null)
continue;
if (inner_iaea
.getItemAwareElement() instanceof DataInput
&& inner_iaea
.getItemAwareElement()
.getId()
.equals(NeedToKnowUtil.ID_PREFIX_INPUT
+ processVariableCombo
.getText())) {
containsRead = true;
}
if (inner_iaea
.getItemAwareElement() instanceof DataOutput
&& inner_iaea
.getItemAwareElement()
.getId()
.equals(NeedToKnowUtil.ID_PREFIX_OUTPUT
+ processVariableCombo
.getText())) {
containsWrite = true;
}
}
}
if (containsRead
&& containsWrite) {
selectedNtk = candidateNtk;
break;
}
}
}
}
}
}
}
}
if (selectedNtk == null) {
// combination not present, create
selectedNtk = Securebpmn2Factory.eINSTANCE
.createNeedToKnow();
selectedNtk.setId(UUID.randomUUID().toString());
selectedNtk.setPName("Perm-" + activity.getId()
+ "-" + processVariableCombo.getText()
+ "-" + actionCombo.getText());
Role targetRole = null;
for (Role role : SecurityUtil
.getRoles(getDiagram())) {
if (role.getName().equalsIgnoreCase(
roleCombo.getText())) {
targetRole = role;
break;
}
}
if (!getDiagram().eResource().getContents()
.contains(targetRole)
&& targetRole != null) {
getDiagram().eResource().getContents()
.add(targetRole);
}
selectedNtk.getRoles().add(targetRole);
getDiagram().eResource().getContents()
.add(selectedNtk);
ActivityAuthorizationConstraint activityAC = Securebpmn2Factory.eINSTANCE
.createActivityAuthorizationConstraint();
activityAC.setId(UUID.randomUUID().toString());
activityAC.getPermissions().add(selectedNtk);
activityAC.getActivities().add(activity);
getDiagram().eResource().getContents()
.add(activityAC);
if (actionCombo.getText().equals("read/write")) {
// create composite action
AtomicItemAwareElementAction readAction = Securebpmn2Factory.eINSTANCE
.createAtomicItemAwareElementAction();
readAction.setId(UUID.randomUUID()
.toString());
readAction.setActionName("read");
ItemAwareElement readElement = findItemAwareElement(
processVariableCombo.getText(),
false);
if (readElement != null) {
readAction
.setItemAwareElement(readElement);
} else {
System.err
.println("[SCVM-BPMN] ItemAwareElement for variable "
+ processVariableCombo
.getText()
+ "/read does not exist!");
}
getDiagram().eResource().getContents()
.add(readAction);
AtomicItemAwareElementAction writeAction = Securebpmn2Factory.eINSTANCE
.createAtomicItemAwareElementAction();
writeAction.setId(UUID.randomUUID()
.toString());
writeAction.setActionName("write");
ItemAwareElement writeElement = findItemAwareElement(
processVariableCombo.getText(),
true);
if (writeElement != null) {
writeAction
.setItemAwareElement(writeElement);
} else {
System.err
.println("[SCVM-BPMN] ItemAwareElement for variable "
+ processVariableCombo
.getText()
+ "/write does not exist!");
}
getDiagram().eResource().getContents()
.add(writeAction);
CompositeItemAwareElementAction rwAction = Securebpmn2Factory.eINSTANCE
.createCompositeItemAwareElementAction();
rwAction.setId(UUID.randomUUID().toString());
rwAction.setActionName("read/write");
rwAction.getItemAwareElementActions().add(
readAction);
rwAction.getItemAwareElementActions().add(
writeAction);
rwAction.getPermissions().add(selectedNtk);
getDiagram().eResource().getContents()
.add(rwAction);
} else {
// create atomic action
AtomicItemAwareElementAction iaeAction = Securebpmn2Factory.eINSTANCE
.createAtomicItemAwareElementAction();
iaeAction.setId(UUID.randomUUID()
.toString());
iaeAction.setActionName(actionCombo
.getText());
iaeAction.getPermissions().add(selectedNtk);
// add ItemAwareElement
ItemAwareElement iaElement = findItemAwareElement(
processVariableCombo.getText(),
actionCombo.getText()
.equals("read") ? false
: true);
if (iaElement != null) {
iaeAction
.setItemAwareElement(iaElement);
} else {
System.err
.println("[SCVM-BPMN] ItemAwareElement for variable "
+ processVariableCombo
.getText()
+ "/"
+ actionCombo.getText()
+ " does not exist!");
}
getDiagram().eResource().getContents()
.add(iaeAction);
}
} else {
// update existing ntk: add role
Role targetRole = null;
for (Role role : SecurityUtil
.getRoles(getDiagram())) {
if (role.getName().equalsIgnoreCase(
roleCombo.getText())) {
targetRole = role;
break;
}
}
if (!getDiagram().eResource().getContents()
.contains(targetRole)
&& targetRole != null) {
getDiagram().eResource().getContents()
.add(targetRole);
}
selectedNtk.getRoles().add(targetRole);
}
updateTable(activity);
}
}
}, editingDomain, "Adding NtK Permission");
}
}
}
/**
* Helper method for retrieving the ItemAwareElement, in particular the
* DataInput or DataOutput element, for a given process variable name and
* the type of access (read or write).
*
* @param processVariable
* The name of the process variable.
* @param isWriteable
* The type of access to the variable. true for write access,
* false for read access.
* @return The ItemAwareElement corresponding to the process variable
* access.
*/
private ItemAwareElement findItemAwareElement(String processVariable,
boolean isWriteable) {
for (EObject o : getDiagram().eResource().getContents()) {
if (o instanceof DataInput && !isWriteable) {
final DataInput in = (DataInput) o;
if (in.getId().equals(
NeedToKnowUtil.ID_PREFIX_INPUT + processVariable))
return in;
} else if (o instanceof DataOutput && isWriteable) {
final DataOutput out = (DataOutput) o;
if (out.getId().equals(
NeedToKnowUtil.ID_PREFIX_OUTPUT + processVariable))
return out;
}
}
return null;
}
/**
* Contains the code that is executed when the "remove" Button is pressed.
* In particular, it removes the NeedToKnow Permission from the Diagram.
*/
private void removePressed() {
PictogramElement pe = getSelectedPictogramElement();
if (pe != null) {
Object bo = Graphiti.getLinkService()
.getBusinessObjectForLinkedPictogramElement(pe);
if (bo instanceof Activity) {
DiagramEditor diagramEditor = (DiagramEditor) getDiagramEditor();
TransactionalEditingDomain editingDomain = diagramEditor
.getEditingDomain();
ActivitiUiUtil.runModelChange(new Runnable() {
public void run() {
Object bobj = Graphiti.getLinkService()
.getBusinessObjectForLinkedPictogramElement(
getSelectedPictogramElement());
if (bobj == null) {
return;
} else {
// remove the selected
// permission/activitiyAC/IAEAction
Activity activity = (Activity) bobj;
for (TableItem tItem : table.getItems()) {
List<ActivityAuthorizationConstraint> removeList = new ArrayList<ActivityAuthorizationConstraint>();
if (tItem.getChecked()) {
for (ActivityAuthorizationConstraint actAC : activity
.getActivityAuthorizationConstraints()) {
if (actAC.getPermissions().size() > 0) {
Permission p = actAC
.getPermissions().get(0);
if (p.getPName().equals(
tItem.getText(1))) {
for (Action a : p.getActions()) {
getDiagram().eResource()
.getContents()
.remove(a);
}
p.getActions().clear();
p.getRoles().clear();
p.getAuthorizationConstraints()
.clear();
getDiagram().eResource()
.getContents()
.remove(p);
removeList.add(actAC);
getDiagram().eResource()
.getContents()
.remove(actAC);
}
}
}
}
for (ActivityAuthorizationConstraint actAC : removeList) {
activity.getActivityAuthorizationConstraints()
.remove(actAC);
}
}
updateTable(activity);
}
}
}, editingDomain, "Removing NtK Permission");
}
}
}
/**
* Creates the table entries for a given activity.
*
* @param activity
* The activity for which the entries should be generated.
*/
private void updateTable(Activity activity) {
table.removeAll();
for (ActivityAuthorizationConstraint aac : activity
.getActivityAuthorizationConstraints()) {
if (aac.getPermissions().size() > 0
&& aac.getPermissions().get(0) instanceof NeedToKnow) {
Permission p = aac.getPermissions().get(0);
String[] nameParts = p.getPName().split("-");
TableItem ti = new TableItem(table, SWT.NONE);
String[] itemText = { "", p.getPName(), nameParts[2],
nameParts[3], "" };
for (Role r : p.getRoles()) {
if (itemText[4].length() == 0) {
itemText[4] += r.getName();
} else {
itemText[4] += ", " + r.getName();
}
}
ti.setText(itemText);
}
}
selectionChanged();
}
}

View File

@ -0,0 +1,43 @@
/* Copyright 2012-2015 SAP SE
*
* Licensed 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.
*/
package org.activiti.designer.security.property;
import org.eclipse.bpmn2.Activity;
import org.eclipse.bpmn2.AlfrescoMailTask;
import org.eclipse.bpmn2.AlfrescoScriptBase;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.ui.platform.AbstractPropertySectionFilter;
/**
*
*/
public class PropertyRbacFilter extends AbstractPropertySectionFilter {
@Override
protected boolean accept(PictogramElement pe) {
EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe);
if (bo instanceof Activity && bo instanceof AlfrescoScriptBase == false && bo instanceof AlfrescoMailTask == false ) {
return true;
}
return false;
}
}

View File

@ -0,0 +1,539 @@
/* Copyright 2012-2015 SAP SE
*
* Licensed 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.
*/
package org.activiti.designer.security.property;
import java.util.List;
import java.util.UUID;
import org.activiti.designer.util.eclipse.ActivitiUiUtil;
import org.activiti.designer.util.property.ActivitiPropertySection;
import org.eclipse.bpmn2.Activity;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.ui.editor.DiagramEditor;
import org.eclipse.securebpmn2.Action;
import org.eclipse.securebpmn2.ActivityAction;
import org.eclipse.securebpmn2.Permission;
import org.eclipse.securebpmn2.Role;
import org.eclipse.securebpmn2.Securebpmn2Factory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
import eu.aniketos.securebpmn.util.SecurityUtil;
/**
*
*/
public class PropertyRbacSection extends ActivitiPropertySection implements ITabbedPropertyConstants {
private CCombo actionCombo;
private CCombo roleCombo;
private String[] titles = {" ","PermissionId","Permission Name", "Action", "Roles"};
private SelectionListener selectionListener;
private Button addButton;
private Button removeButton;
private Table table;
private Composite buttonBox;
private int checkCount=0;
@Override
public void createControls(Composite parent, TabbedPropertySheetPage tabbedPropertySheetPage) {
super.createControls(parent, tabbedPropertySheetPage);
TabbedPropertySheetWidgetFactory factory = getWidgetFactory();
Composite composite = factory.createFlatFormComposite(parent);
FormData data;
actionCombo = factory.createCCombo(composite, SWT.NONE);
List<Action> actionList=SecurityUtil.getActivityActions();
for (int i = 0; i < actionList.size(); i++) {
actionCombo.add(actionList.get(i).getActionName());
}
data = new FormData();
data.left = new FormAttachment(0, 120);
data.right = new FormAttachment(80, 0);
data.top = new FormAttachment(0, VSPACE);
actionCombo.setLayoutData(data);
actionCombo.addFocusListener(listener);
CLabel actionLabel = factory.createCLabel(composite, "Action :"); //$NON-NLS-1$
data = new FormData();
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(actionCombo, -HSPACE);
data.top = new FormAttachment(actionCombo, 0, SWT.CENTER);
actionLabel.setLayoutData(data);
roleCombo = factory.createCCombo(composite, SWT.NONE);
data = new FormData();
data.left = new FormAttachment(0, 120);
data.right = new FormAttachment(80, 0);
data.top = new FormAttachment(actionCombo, VSPACE);
roleCombo.setLayoutData(data);
roleCombo.addFocusListener(listener);
CLabel roleLabel = factory.createCLabel(composite, "Role :"); //$NON-NLS-1$
data = new FormData();
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(roleCombo, -HSPACE);
data.top = new FormAttachment(roleCombo, 0, SWT.CENTER);
roleLabel.setLayoutData(data);
CLabel tableLabel = factory.createCLabel(composite, "Permissions :"); //$NON-NLS-1$
data = new FormData();
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(0, 100);
data.top = new FormAttachment(roleCombo, VSPACE);
tableLabel.setLayoutData(data);
data = new FormData(200,170);
data.left = new FormAttachment(tableLabel, 10);
data.right = new FormAttachment(80, 0);
data.top = new FormAttachment(roleCombo, VSPACE);
table = new Table (composite, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
table.setLayoutData(data);
//Layout layout=table.getLayout();
table.setLinesVisible (true);
table.setHeaderVisible (true);
/*GridData griddata = new GridData(SWT.FILL, SWT.FILL, true, true);
layout. = 100;
table.setLayoutData(griddata);
//table.setLayout(layout);
*
*/
buttonBox = getButtonBoxControl(composite);
data = new FormData();
data.left = new FormAttachment(table, -HSPACE);
data.right = new FormAttachment(100, 0);
data.top = new FormAttachment(roleLabel, 0);
buttonBox.setLayoutData(data);
buttonBox.setVisible(true);
buttonBox.addFocusListener(listener);
for (int i=0; i<titles.length; i++) {
TableColumn column = new TableColumn (table, SWT.NONE);
column.setText (titles [i]);
column.setWidth(170);
}
table.getColumn(0).setWidth(30);
table.getColumn(1).setWidth(0);
/*int count = 128;
for (int i=0; i<count; i++) {
TableItem item = new TableItem (table, SWT.NONE);
item.setText (0, "");
item.setText (1, "this stuff behaves the way I expect");
item.setText (2, "almost everywhere");
item.setText (3, "some.folder");
}*/
/*for (int i=0; i<titles.length; i++) {
table.getColumn (i).pack ();
} */
table.addListener (SWT.Selection, new Listener () {
public void handleEvent (Event event) {
String string = event.detail == SWT.CHECK ? "Checked" : "Selected";
// System.out.println (event.item + " " + string);
if(event.detail == SWT.CHECK){
TableItem item= (TableItem)event.item;
if(item.getChecked()==true){
checkCount++;
}
else{
checkCount--;
}
}
selectionChanged();
}
});
composite.pack ();
//composite.open ();
}
@Override
public void refresh() {
actionCombo.removeFocusListener(listener);
roleCombo.removeFocusListener(listener);
buttonBox.removeFocusListener(listener);
checkCount=0;
PictogramElement pe = getSelectedPictogramElement();
if (pe != null) {
Object bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe);
if (bo == null)
return;
Activity activity = (Activity) bo;
displayPermissions(activity);
actionCombo.addFocusListener(listener);
roleCombo.addFocusListener(listener);
buttonBox.addFocusListener(listener);
roleCombo.removeAll();
List<Role> roleList=SecurityUtil.getRoles(getDiagram());
for (int i = 0; i < roleList.size(); i++) {
roleCombo.add(roleList.get(i).getName());
}
}
}
private FocusListener listener = new FocusListener() {
public void focusGained(final FocusEvent e) {
}
public void focusLost(final FocusEvent e) {
PictogramElement pe = getSelectedPictogramElement();
if (pe != null) {
Object bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe);
if (bo instanceof Activity) {
DiagramEditor diagramEditor = (DiagramEditor) getDiagramEditor();
TransactionalEditingDomain editingDomain = diagramEditor.getEditingDomain();
ActivitiUiUtil.runModelChange(new Runnable() {
public void run() {
Object bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(getSelectedPictogramElement());
if (bo == null) {
return;
}
Activity activity=(Activity) bo;
displayPermissions(activity);
}
}, editingDomain, "Model Update");
}
}
}
};
/**
* Helper method to create a push button.
*
* @param parent
* the parent control
* @param key
* the resource name used to supply the button's label text
* @return Button
*/
private Button createPushButton(Composite parent, String key) {
Button button = new Button(parent, SWT.PUSH);
button.setText(key);
button.setFont(parent.getFont());
GridData data = new GridData(GridData.FILL_HORIZONTAL);
/* int widthHint = convertHorizontalDLUsToPixels(button,
IDialogConstants.BUTTON_WIDTH);
data.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT,
SWT.DEFAULT, true).x);*/
data.widthHint=40;
button.setLayoutData(data);
button.addSelectionListener(getSelectionListener());
return button;
}
/**
* Returns this field editor's selection listener. The listener is created
* if necessary.
*
* @return the selection listener
*/
private SelectionListener getSelectionListener() {
if (selectionListener == null) {
createSelectionListener();
}
return selectionListener;
}
/**
* Creates a selection listener.
*/
public void createSelectionListener() {
selectionListener = new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
Widget widget = event.widget;
if (widget == addButton) {
addPressed();
} else if (widget == removeButton) {
removePressed();
}
else if (widget == table) {
selectionChanged();
}
}
};
}
/**
* Creates the Add, Remove, Up, and Down button in the given button box.
*
* @param box
* the box for the buttons
*/
private void createButtons(Composite box) {
box.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
addButton = createPushButton(box, "Add");
removeButton = createPushButton(box, "Remove");
}
/**
* Notifies that the Add button has been pressed.
*/
private void addPressed() {
if(actionCombo.getText()=="" || roleCombo.getText()==""){
return;
}
PictogramElement pe = getSelectedPictogramElement();
if (pe != null) {
Object bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe);
if (bo instanceof Activity) {
DiagramEditor diagramEditor = (DiagramEditor) getDiagramEditor();
TransactionalEditingDomain editingDomain = diagramEditor.getEditingDomain();
ActivitiUiUtil.runModelChange(new Runnable() {
public void run() {
Object bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(getSelectedPictogramElement());
if (bo == null) {
return;
}
else{
//get the selected action
Activity activity= (Activity)bo;
List<ActivityAction> availableActions =activity.getActivityActions();
ActivityAction selectedAction=null;
if(availableActions.size()!=0){
for (ActivityAction temp : availableActions) {
if(temp.getActionName()!=null){
if(temp.getActionName().equals(actionCombo.getText())){
selectedAction=temp;
break;
}
}
}
}
//selected action not available
if(selectedAction==null){
selectedAction = Securebpmn2Factory.eINSTANCE.createAtomicActivityAction();
selectedAction.setId(UUID.randomUUID().toString());
selectedAction.setActionName(actionCombo.getText());
getDiagram().eResource().getContents().add(selectedAction);
activity.getActivityActions().add(selectedAction);
Permission newPermission=Securebpmn2Factory.eINSTANCE.createPermission();
newPermission.setId(UUID.randomUUID().toString());
newPermission.setPName("Perm-"+activity.getId()+"-"+actionCombo.getText());
getDiagram().eResource().getContents().add(newPermission);
selectedAction.getPermissions().add(newPermission);
Role selectedRole=getSelectedRole(roleCombo.getText());
if(getDiagram().eResource().getContents().contains(selectedRole)==false)
getDiagram().eResource().getContents().add(selectedRole);
newPermission.getRoles().add(selectedRole);
}
//selected action is available
else{
//get the associated permission
Permission availablePermission = selectedAction.getPermissions().get(0);
//get the roles to check if the role is already associated
List<Role> availableRoles=availablePermission.getRoles();
Role targetRole=null;
for (Role temp : availableRoles) {
if(temp.getName().equals(roleCombo.getText())){
targetRole=temp;
break;
}
}
if(targetRole==null){
// add role selected to the permission
Role selectedRole=getSelectedRole(roleCombo.getText());
if(getDiagram().eResource().getContents().contains(selectedRole)==false)
getDiagram().eResource().getContents().add(selectedRole);
availablePermission.getRoles().add(selectedRole);
}
}
displayPermissions(activity);
}
}
}, editingDomain, "Model Update");
}
}
}
/**
* Notifies that the Remove button has been pressed.
*/
private void removePressed() {
PictogramElement pe = getSelectedPictogramElement();
if (pe != null) {
Object bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe);
if (bo instanceof Activity) {
DiagramEditor diagramEditor = (DiagramEditor) getDiagramEditor();
TransactionalEditingDomain editingDomain = diagramEditor.getEditingDomain();
ActivitiUiUtil.runModelChange(new Runnable() {
public void run() {
Object bobj = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(getSelectedPictogramElement());
if (bobj == null) {
return;
}
else{
//get the selected action
Activity activity= (Activity)bobj;
List<ActivityAction> availableActions =activity.getActivityActions();
for(TableItem temp:table.getItems()){
if(temp.getChecked()){
for(ActivityAction aa:availableActions){
if(temp.getText(3).equals(aa.getActionName())){
aa.getPermissions().remove(0);
activity.getActivityActions().remove(aa);
break;
}
}
}
}
displayPermissions(activity);
}
}
}, editingDomain, "Model Update");
}
}
}
protected void selectionChanged() {
TableItem[] items = table.getSelection();
//int size = table.getItemCount();
//editButton.setEnabled(index >= 0);
removeButton.setEnabled(checkCount > 0);
// upButton.setEnabled(size > 1 && index > 0);
//downButton.setEnabled(size > 1 && index >= 0 && index < size - 1);
}
public Composite getButtonBoxControl(Composite parent) {
if (buttonBox == null) {
buttonBox = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
buttonBox.setLayout(layout);
createButtons(buttonBox);
buttonBox.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent event) {
addButton = null;
//editButton = null;
removeButton = null;
// upButton = null;
//downButton = null;
buttonBox = null;
}
});
} else {
//checkParent(buttonBox, parent);
}
selectionChanged();
return buttonBox;
}
private Role getSelectedRole(String roleName){
List<Role> roleList=SecurityUtil.getRoles(getDiagram());
Role role=null;
for (int i = 0; i < roleList.size(); i++) {
role=roleList.get(i);
if(role.getName().equals(roleName))
{
break;
}
}
return role;
}
private void displayPermissions(Activity activity){
table.removeAll();
Permission permission=null;
List<Role> roles=null;
List<ActivityAction> availableActions =activity.getActivityActions();
StringBuilder st=new StringBuilder();
for (ActivityAction temp : availableActions) {
if(temp!=null){
permission=temp.getPermissions().get(0);
roles=permission.getRoles();
for (int i = 0; i < roles.size(); i++) {
st.append(roles.get(i).getName());
if(i!=roles.size()-1)
{
st.append(",");
}
}
}
TableItem tableItem = new TableItem(table, SWT.NONE);
tableItem.setText(new String[] {"",permission.getId(),permission.getPName(),temp.getActionName(),st.toString()});
selectionChanged();
st.delete(0, st.length());
}
}
}

View File

@ -0,0 +1,45 @@
/* Copyright 2012-2015 SAP SE
*
* Licensed 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.
*/
package org.activiti.designer.security.property;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.ui.platform.AbstractPropertySectionFilter;
import org.eclipse.securebpmn2.BindingOfDuty;
import org.eclipse.securebpmn2.SeparationOfDuty;
/**
*
*/
public class PropertySodBodFilter extends AbstractPropertySectionFilter {
@Override
protected boolean accept(PictogramElement pe) {
EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe);
if (bo instanceof SeparationOfDuty || bo instanceof BindingOfDuty ) {
return true;
}
return false;
}
}

View File

@ -0,0 +1,714 @@
/* Copyright 2012-2015 SAP SE
*
* Licensed 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.
*/
//1. Populate the permissions of the associated task
//2. Checked ones are
package org.activiti.designer.security.property;
import java.util.ArrayList;
import java.util.List;
import org.activiti.designer.util.eclipse.ActivitiUiUtil;
import org.activiti.designer.util.property.ActivitiPropertySection;
import org.eclipse.bpmn2.Activity;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.validation.internal.modeled.model.validation.Constraint;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.ui.editor.DiagramEditor;
import org.eclipse.securebpmn2.ActivityAction;
import org.eclipse.securebpmn2.AuthorizationConstraint;
import org.eclipse.securebpmn2.BindingOfDuty;
import org.eclipse.securebpmn2.Permission;
import org.eclipse.securebpmn2.Role;
import org.eclipse.securebpmn2.SecurityFlow;
import org.eclipse.securebpmn2.SeparationOfDuty;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
/**
*
*/
public class PropertySodBodSection extends ActivitiPropertySection implements ITabbedPropertyConstants {
private Composite composite;
private String[] titles = {" ","Activity","PermissionId","Permission Name","Action", "Roles"};
private SelectionListener selectionListener;
private Button saveButton;
private Button selectAllButton;
private Button deSelectAllButton;
private Table table;
private Composite buttonBox;
private Text minUsersText;
private Text maxActionText;
private CLabel minUsersLabel;
private CLabel maxActionLabel;
private Text bodMaxUsersText;
private Text bodActionText;
private CLabel bodMaxUsersLabel;
private CLabel bodActionLabel;
private Composite checkButtonBox;
private Button enforcementTypeButton;
@Override
public void createControls(Composite parent, TabbedPropertySheetPage tabbedPropertySheetPage) {
super.createControls(parent, tabbedPropertySheetPage);
TabbedPropertySheetWidgetFactory factory = getWidgetFactory();
composite = factory.createFlatFormComposite(parent);
FormData data;
CLabel tableLabel = factory.createCLabel(composite, "Select Permissions :"); //$NON-NLS-1$
data = new FormData();
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(70, 0);
data.top = new FormAttachment(0, 0);
tableLabel.setLayoutData(data);
data = new FormData(180,170);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(70, 0);
data.top = new FormAttachment(tableLabel, -VSPACE);
table = new Table (composite, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
table.setLayoutData(data);
table.setLinesVisible (true);
table.setHeaderVisible (true);
buttonBox = getButtonBoxControl(composite);
data = new FormData();
data.left = new FormAttachment(table, -HSPACE);
data.right = new FormAttachment(100, 0);
data.top = new FormAttachment(tableLabel, -VSPACE);
buttonBox.setLayoutData(data);
buttonBox.setVisible(true);
buttonBox.addFocusListener(listener);
for (int i=0; i<titles.length; i++) {
TableColumn column = new TableColumn (table, SWT.NONE);
column.setText (titles [i]);
column.setWidth(170);
}
table.getColumn(0).setWidth(30);
table.getColumn(2).setWidth(0);
/*for (int i=0; i<titles.length; i++) {
table.getColumn (i).pack ();
} */
table.addListener (SWT.Selection, new Listener () {
public void handleEvent (Event event) {
String string = event.detail == SWT.CHECK ? "Checked" : "Selected";
// System.out.println (event.item + " " + string);
selectionChanged();
}
});
// static/dynamic enforcement control
checkButtonBox = new Composite(composite, SWT.NULL);
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
checkButtonBox.setLayout(layout);
checkButtonBox.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
enforcementTypeButton = factory.createButton(checkButtonBox, "Dynamic enforcement?", SWT.CHECK);
enforcementTypeButton.setToolTipText("Enable this checkbox to enforce the constraint dynamically.");
enforcementTypeButton.setVisible(true);
GridData gdata = new GridData(GridData.FILL_HORIZONTAL);
gdata.widthHint=40;
enforcementTypeButton.setLayoutData(gdata);
enforcementTypeButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
Widget widget = event.widget;
if (widget == enforcementTypeButton) {
enforcementTypeChanged();
}
}
});
checkButtonBox.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent event) {
enforcementTypeButton = null;
checkButtonBox = null;
}
});
data = new FormData();
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(80, 0);
data.top = new FormAttachment(table, VSPACE);
checkButtonBox.setLayoutData(data);
checkButtonBox.setVisible(true);
composite.pack ();
}
private void enforcementTypeChanged() {
if (enforcementTypeButton.getSelection()) {
// Dynamic enforcement model change
PictogramElement pe = getSelectedPictogramElement();
if (pe != null) {
Object bo = Graphiti.getLinkService()
.getBusinessObjectForLinkedPictogramElement(pe);
if (bo instanceof AuthorizationConstraint) {
DiagramEditor diagramEditor = (DiagramEditor) getDiagramEditor();
TransactionalEditingDomain editingDomain = diagramEditor
.getEditingDomain();
ActivitiUiUtil.runModelChange(new Runnable() {
public void run() {
Object bo = Graphiti
.getLinkService()
.getBusinessObjectForLinkedPictogramElement(
getSelectedPictogramElement());
if (bo == null) {
return;
} else {
AuthorizationConstraint ac = (AuthorizationConstraint) bo;
ac.setDynamicEnforcement(true);
}
}
}, editingDomain, "Constraint enforcement type update");
}
}
} else {
// Static enforcement model change
PictogramElement pe = getSelectedPictogramElement();
if (pe != null) {
Object bo = Graphiti.getLinkService()
.getBusinessObjectForLinkedPictogramElement(pe);
if (bo instanceof AuthorizationConstraint) {
DiagramEditor diagramEditor = (DiagramEditor) getDiagramEditor();
TransactionalEditingDomain editingDomain = diagramEditor
.getEditingDomain();
ActivitiUiUtil.runModelChange(new Runnable() {
public void run() {
Object bo = Graphiti
.getLinkService()
.getBusinessObjectForLinkedPictogramElement(
getSelectedPictogramElement());
if (bo == null) {
return;
} else {
AuthorizationConstraint ac = (AuthorizationConstraint) bo;
ac.setDynamicEnforcement(false);
}
}
}, editingDomain, "Constraint enforcement type update");
}
}
}
}
@Override
public void refresh() {
buttonBox.removeFocusListener(listener);
if(minUsersText != null) {
minUsersText.removeFocusListener(listener);
minUsersText.setVisible(false);
minUsersLabel.setVisible(false);
}
if(maxActionText != null) {
maxActionText.removeFocusListener(listener);
maxActionText.setVisible(false);
maxActionLabel.setVisible(false);
}
if(bodMaxUsersText != null) {
bodMaxUsersText.removeFocusListener(listener);
bodMaxUsersText.setVisible(false);
bodMaxUsersLabel.setVisible(false);
}
if(bodActionText != null) {
bodActionText.removeFocusListener(listener);
bodActionText.setVisible(false);
bodActionLabel.setVisible(false);
}
PictogramElement pe = getSelectedPictogramElement();
if (pe != null) {
Object bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe);
if (bo == null)
return;
AuthorizationConstraint constraint = (AuthorizationConstraint) bo;
displayPermissions(constraint);
if(minUsersText ==null){
minUsersText = createText(composite, getWidgetFactory(), checkButtonBox);
minUsersLabel=createLabel("Minimum Users Required :", composite, getWidgetFactory(), minUsersText);
minUsersText.setVisible(false);
minUsersLabel.setVisible(false);
}
if(maxActionText==null){
maxActionText = createText(composite, getWidgetFactory(), minUsersText);
maxActionLabel=createLabel("Maximum Actions Allowed per User:", composite, getWidgetFactory(), maxActionText);
maxActionText.setVisible(false);
maxActionLabel.setVisible(false);
}
if(bodMaxUsersText ==null){
bodMaxUsersText = createText(composite, getWidgetFactory(), checkButtonBox);
bodMaxUsersLabel=createLabel("Mamimum Users Allowed :", composite, getWidgetFactory(), bodMaxUsersText);
bodMaxUsersText.setVisible(false);
bodMaxUsersLabel.setVisible(false);
}
if(bodActionText==null){
bodActionText = createText(composite, getWidgetFactory(), bodMaxUsersText);
bodActionLabel=createLabel("Actions performed by same User:", composite, getWidgetFactory(), bodActionText);
bodActionText.setVisible(false);
bodActionLabel.setVisible(false);
}
if(bo instanceof SeparationOfDuty){
SeparationOfDuty sod=(SeparationOfDuty) bo;
minUsersText.setText("");
if(sod.getMinimumUsers()!=null)
minUsersText.setText(Integer.toString(sod.getMinimumUsers()));
maxActionText.setText("");
if(sod.getMaxUserActionsPermitted()!=null)
maxActionText.setText(Integer.toString(sod.getMaxUserActionsPermitted()));
minUsersText.setVisible(true);
minUsersLabel.setVisible(true);
maxActionText.setVisible(true);
maxActionLabel.setVisible(true);
}
else if(bo instanceof BindingOfDuty){
BindingOfDuty bod=(BindingOfDuty) bo;
bodMaxUsersText.setText("");
if(bod.getMaxUsers()!=null)
bodMaxUsersText.setText(Integer.toString(bod.getMaxUsers()));
bodActionText.setText("");
if(bod.getSameUserActionCount()!=null)
bodActionText.setText(Integer.toString(bod.getSameUserActionCount()));
bodMaxUsersText.setVisible(true);
bodMaxUsersLabel.setVisible(true);
bodActionText.setVisible(true);
bodActionLabel.setVisible(true);
}
else{
if(minUsersText!=null){
minUsersText.setVisible(false);
minUsersLabel.setVisible(false);
}
if(maxActionText!=null){
maxActionText.setVisible(false);
maxActionLabel.setVisible(false);
}
if(bodMaxUsersText!=null){
bodMaxUsersText.setVisible(false);
bodMaxUsersLabel.setVisible(false);
}
if(bodActionText!=null){
bodActionText.setVisible(false);
bodActionLabel.setVisible(false);
}
}
if(minUsersText != null) {
minUsersText.addFocusListener(listener);
}
if(maxActionText != null) {
maxActionText.addFocusListener(listener);
}
if(bodMaxUsersText != null) {
bodMaxUsersText.addFocusListener(listener);
}
if(bodActionText != null) {
bodActionText.addFocusListener(listener);
}
buttonBox.addFocusListener(listener);
// TODO update selection of enforcementTypeButton
enforcementTypeButton.setSelection(constraint.isDynamicEnforcement());
}
}
private FocusListener listener = new FocusListener() {
public void focusGained(final FocusEvent e) {
}
public void focusLost(final FocusEvent e) {
PictogramElement pe = getSelectedPictogramElement();
if (pe != null) {
Object bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe);
if (bo instanceof AuthorizationConstraint) {
DiagramEditor diagramEditor = (DiagramEditor) getDiagramEditor();
TransactionalEditingDomain editingDomain = diagramEditor.getEditingDomain();
ActivitiUiUtil.runModelChange(new Runnable() {
public void run() {
Object bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(getSelectedPictogramElement());
if (bo == null) {
return;
}
AuthorizationConstraint constraint = (AuthorizationConstraint) bo;
displayPermissions(constraint);
if(bo instanceof SeparationOfDuty){
SeparationOfDuty sod=(SeparationOfDuty) bo;
if(minUsersText!=null){
if(minUsersText.getText() != null && minUsersText.getText().length() > 0) {
Integer minUsersValue = null;
try {
minUsersValue = Integer.valueOf(minUsersText.getText());
} catch(Exception e) {}
sod.setMinimumUsers(minUsersValue);
}
}
if(maxActionText!=null){
if(maxActionText.getText() != null && maxActionText.getText().length() > 0) {
Integer maxActionValue = null;
try {
maxActionValue = Integer.valueOf(maxActionText.getText());
} catch(Exception e) {}
sod.setMaxUserActionsPermitted(maxActionValue);
}
}
}
else if(bo instanceof BindingOfDuty){
BindingOfDuty bod=(BindingOfDuty) bo;
if(bodMaxUsersText!=null){
if(bodMaxUsersText.getText() != null && bodMaxUsersText.getText().length() > 0) {
Integer bodMaxUsersValue = null;
try {
bodMaxUsersValue = Integer.valueOf(bodMaxUsersText.getText());
} catch(Exception e) {}
bod.setMaxUsers(bodMaxUsersValue);
}
}
if(bodActionText!=null){
if(bodActionText.getText() != null && bodActionText.getText().length() > 0) {
Integer bodActionValue = null;
try {
bodActionValue = Integer.valueOf(bodActionText.getText());
} catch(Exception e) {}
bod.setSameUserActionCount(bodActionValue);
}
}
}
}
}, editingDomain, "Model Update");
}
}
}
};
/**
* Helper method to create a push button.
*
* @param parent
* the parent control
* @param key
* the resource name used to supply the button's label text
* @return Button
*/
private Button createPushButton(Composite parent, String key) {
Button button = new Button(parent, SWT.PUSH);
button.setText(key);
button.setFont(parent.getFont());
GridData data = new GridData(GridData.FILL_HORIZONTAL);
data.widthHint=40;
button.setLayoutData(data);
button.addSelectionListener(getSelectionListener());
return button;
}
/**
* Returns this field editor's selection listener. The listener is created
* if necessary.
*
* @return the selection listener
*/
private SelectionListener getSelectionListener() {
if (selectionListener == null) {
createSelectionListener();
}
return selectionListener;
}
/**
* Creates a selection listener.
*/
public void createSelectionListener() {
selectionListener = new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
Widget widget = event.widget;
if (widget == saveButton) {
savePressed();
} else if (widget == deSelectAllButton) {
deSelectAllPressed();
}
else if (widget == selectAllButton) {
selectAllPressed();
}
else if (widget == table) {
selectionChanged();
}
}
};
}
/**
* Creates the Add, Remove, Up, and Down button in the given button box.
*
* @param box
* the box for the buttons
*/
private void createButtons(Composite box) {
box.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
saveButton = createPushButton(box, "Save");
selectAllButton = createPushButton(box, "Select All");
deSelectAllButton = createPushButton(box, "Deselect All");
}
/**
* Notifies that the Add button has been pressed.
*/
private void savePressed() {
PictogramElement pe = getSelectedPictogramElement();
if (pe != null) {
Object bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe);
if (bo instanceof AuthorizationConstraint) {
DiagramEditor diagramEditor = (DiagramEditor) getDiagramEditor();
TransactionalEditingDomain editingDomain = diagramEditor.getEditingDomain();
ActivitiUiUtil.runModelChange(new Runnable() {
public void run() {
Object bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(getSelectedPictogramElement());
if (bo == null) {
return;
}
else{
AuthorizationConstraint authorizationConstraint= (AuthorizationConstraint)bo;
//get all the permissions of the associated tasks
List<Permission> allPermissions=new ArrayList<Permission>();
List<Permission> toAddList=new ArrayList<Permission>();
List<Permission> toRemoveList=new ArrayList<Permission>();
List<Permission> currentPermissions=null;
Permission permission=null;
Activity activity=null;
List<SecurityFlow> flows=authorizationConstraint.getOutgoingSecurityFlow();
currentPermissions=authorizationConstraint.getPermissions();
for(SecurityFlow sf: flows){
activity=(Activity)sf.getTargetRefNode();
List<ActivityAction> availableActions =activity.getActivityActions();
for (ActivityAction temp : availableActions) {
if(temp!=null){
allPermissions.add(temp.getPermissions().get(0));
}
}
activity=null;
}
//iterate through the table and prepare two list toaddList toremoveList of permissions
TableItem[] items=table.getItems();
TableItem tempItem=null;
for(int i=0;i<items.length;i++){
tempItem=items[i];
permission=getPermission(tempItem.getText(2),allPermissions);
if(tempItem.getChecked()){
toAddList.add(permission);
}
else{
toRemoveList.add(permission);
}
}
//add the new permissions to the constraint
for(Permission toAdd: toAddList){
if(!currentPermissions.contains(toAdd)){
authorizationConstraint.getPermissions().add(toAdd);
}
}
// remove the permissions
for(Permission toRemove: toRemoveList){
if(currentPermissions.contains(toRemove)){
authorizationConstraint.getPermissions().remove(toRemove);
}
}
displayPermissions(authorizationConstraint);
}
}
}, editingDomain, "Model Update");
}
}
}
private void deSelectAllPressed() {
for(TableItem ti:table.getItems()){
ti.setChecked(false);
}
}
private void selectAllPressed() {
for(TableItem ti:table.getItems()){
ti.setChecked(true);
}
}
protected void selectionChanged() {
//TableItem[] items = table.getSelection();
//removeButton.setEnabled(items.length > 0);
}
public Composite getButtonBoxControl(Composite parent) {
if (buttonBox == null) {
buttonBox = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
buttonBox.setLayout(layout);
createButtons(buttonBox);
buttonBox.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent event) {
saveButton = null;
deSelectAllButton = null;
selectAllButton=null;
buttonBox = null;
}
});
} else {
//checkParent(buttonBox, parent);
}
selectionChanged();
return buttonBox;
}
private void displayPermissions(AuthorizationConstraint ac){
table.removeAll();
List<Permission> currentPermissions=null;
Permission permission=null;
Activity activity=null;
List<Role> roles=null;
currentPermissions=ac.getPermissions();
List<SecurityFlow> flows=ac.getOutgoingSecurityFlow();
for(SecurityFlow sf: flows){
activity=(Activity)sf.getTargetRefNode();
//List<Role> roles=null;
List<ActivityAction> availableActions =activity.getActivityActions();
StringBuilder st=new StringBuilder();
for (ActivityAction temp : availableActions) {
if(temp!=null){
permission=temp.getPermissions().get(0);
roles=permission.getRoles();
for (int i = 0; i < roles.size(); i++) {
st.append(roles.get(i).getName());
if(i!=roles.size()-1)
{
st.append(",");
}
}
}
TableItem tableItem = new TableItem(table, SWT.NONE);
if(currentPermissions.contains(permission))
tableItem.setChecked(true);
tableItem.setText(new String[] {"",activity.getName(),permission.getId(),permission.getPName(),temp.getActionName(),st.toString()});
selectionChanged();
st.delete(0, st.length());
roles=null;
permission=null;
}
activity=null;
}
}
private Permission getPermission(String id,List<Permission> permissions){
Permission perm=null;
for(Permission temp: permissions){
if(id.equals(temp.getId())){
perm=temp;
break;
}
}
return perm;
}
private Text createText(Composite parent, TabbedPropertySheetWidgetFactory factory, Control top) {
Text text = factory.createText(parent, ""); //$NON-NLS-1$
FormData data = new FormData();
data.left = new FormAttachment(0, 220);
data.right = new FormAttachment(70, 0);
if(top == null) {
data.top = new FormAttachment(0, VSPACE);
} else {
data.top = new FormAttachment(top, VSPACE);
}
text.setLayoutData(data);
text.addFocusListener(listener);
return text;
}
private CLabel createLabel(String text, Composite parent, TabbedPropertySheetWidgetFactory factory, Control control) {
CLabel label = factory.createCLabel(parent, text);
FormData data = new FormData();
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(control, -HSPACE);
data.top = new FormAttachment(control, 0, SWT.CENTER);
label.setLayoutData(data);
return label;
}
}

View File

@ -7,4 +7,8 @@ Bundle-Activator: org.activiti.designer.help.Activator
Require-Bundle: org.eclipse.core.runtime
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ClassPath: .
Bundle-ClassPath: .,
xalan-2.7.1.jar,
serializer-2.7.1.jar,
xml-apis-1.3.04.jar,
com.sun.xacml-0.1.jar

View File

@ -14,4 +14,8 @@ Export-Package: org.activiti.designer.integration;uses:="org.osgi.framework",
org.activiti.designer.integration.servicetask,
org.activiti.designer.integration.servicetask.annotation,
org.activiti.designer.integration.servicetask.validator
Bundle-ClassPath: .
Bundle-ClassPath: .,
xalan-2.7.1.jar,
serializer-2.7.1.jar,
xml-apis-1.3.04.jar,
com.sun.xacml-0.1.jar

View File

@ -1,5 +1,4 @@
source.. = src/main/java/
output.. = target/
bin.includes = META-INF/,\
.,\
plugin.xml
.

View File

@ -12,7 +12,9 @@ package org.activiti.designer.integration.palette;
*
*/
public enum PaletteEntry {
// <SecureBPMN>
SECURITY_BOD,SECURITY_SOD,
// </SecureBPMN>
ALL, START_EVENT, TIMER_START_EVENT, ALFRESCO_START_EVENT, END_EVENT, ERROR_END_EVENT, EXCLUSIVE_GATEWAY, INCLUSIVE_GATEWAY, MAIL_TASK, MANUAL_TASK,
RECEIVE_TASK, PARALLEL_GATEWAY, SCRIPT_TASK, SERVICE_TASK, CALL_ACTIVITY, SUBPROCESS,
USER_TASK, ALFRESCO_USER_TASK, BOUNDARY_TIMER, BUSINESSRULE_TASK, ALFRESCO_SCRIPT_TASK, ALFRESCO_MAIL_TASK;

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.activiti.designer.model.edit</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,19 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.activiti.designer.model.edit;singleton:=true
Bundle-Version: 1.0.0
Bundle-ClassPath: .
Bundle-Activator: org.eclipse.securebpmn2.provider.bpmn2EditPlugin$Implementation
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Export-Package: org.eclipse.bpmn2.di.provider,
org.eclipse.bpmn2.provider,
org.eclipse.dd.dc.provider,
org.eclipse.dd.di.provider,
org.eclipse.securebpmn2.provider
Require-Bundle: org.eclipse.core.runtime,
org.activiti.designer.model;visibility:=reexport,
org.eclipse.emf.edit;visibility:=reexport
Bundle-ActivationPolicy: lazy

View File

@ -0,0 +1,21 @@
# <copyright>
#
# Copyright (c) 2010 SAP AG.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Reiner Hille-Doering (SAP AG) - initial API and implementation and/or initial documentation
#
# </copyright>
bin.includes = .,\
icons/,\
META-INF/,\
plugin.xml,\
plugin.properties
jars.compile.order = .
source.. = src/
output.. = bin/

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Some files were not shown because too many files have changed in this diff Show More