de.uni.freiburg.iig.telematik.sewol.accesscontrol.parser.ACModelParsing Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of SEWOL Show documentation
Show all versions of SEWOL Show documentation
SEWOL provides support for the handling of workflow traces. Specifically it allows to specify the shape and content of process traces in terms of entries representing the execution of a specific workflow activity. SEWOL also allows to write these traces on disk as a log file with the help of a special file writer for process logs. Currently it supports plain text, Petrify, MXML and XES log file types. In order to specify security-related context information, SEWOL provides access control models such as access control lists (ACL) and role-based access control models (RBAC). All types of models can be conveniently edited with the help of appropriate dialogs.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package de.uni.freiburg.iig.telematik.sewol.accesscontrol.parser;
import de.invation.code.toval.debug.SimpleDebugger;
import de.invation.code.toval.file.FileUtils;
import de.invation.code.toval.graphic.dialog.MessageDialog;
import de.invation.code.toval.misc.soabase.SOABase;
import de.invation.code.toval.misc.wd.ProjectComponentException;
import de.invation.code.toval.properties.PropertyException;
import de.invation.code.toval.validate.ParameterException;
import de.invation.code.toval.validate.Validate;
import de.uni.freiburg.iig.telematik.sewol.accesscontrol.AbstractACModel;
import de.uni.freiburg.iig.telematik.sewol.accesscontrol.acl.ACLModel;
import de.uni.freiburg.iig.telematik.sewol.accesscontrol.properties.ACLModelProperties;
import de.uni.freiburg.iig.telematik.sewol.accesscontrol.properties.ACMValidationException;
import de.uni.freiburg.iig.telematik.sewol.accesscontrol.properties.ACModelProperties;
import de.uni.freiburg.iig.telematik.sewol.accesscontrol.properties.ACModelProperty;
import de.uni.freiburg.iig.telematik.sewol.accesscontrol.properties.ACModelType;
import de.uni.freiburg.iig.telematik.sewol.accesscontrol.properties.RBACModelProperties;
import de.uni.freiburg.iig.telematik.sewol.accesscontrol.rbac.RBACModel;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
*
* @author stocker
*/
public class ACModelParsing {
// public static void loadACModelsFromDirectory(String directory, Map availableContexts) throws ProjectComponentException{
// loadACModelsFromDirectory(directory, availableContexts, null);
// }
//
// public static Set loadACModelsFromDirectory(String directory, Map availableContexts, SimpleDebugger debugger) throws ProjectComponentException{
// Validate.notNull(availableContexts);
// Validate.noNullElements(availableContexts.values());
// if(debugger != null) debugger.message("Searching for access control models:");
// List acFiles = null;
// try {
// acFiles = FileUtils.getFileNamesInDirectory(directory, true);
// } catch (IOException e) {
// throw new ProjectComponentException("Cannot access access control model directory.", e);
// }
// Set result = new HashSet<>();
// for (String acFile : acFiles) {
// if(debugger != null) debugger.message("Loading access control model: " + acFile.substring(acFile.lastIndexOf('/') + 1) + "... ");
// try {
// AbstractACModel parsedModel = ACModelParsing.loadACModel(acFile, availableContexts);
// result.add(parsedModel);
// if(debugger != null) debugger.message("Done.");
// } catch (Exception e) {
// if(debugger != null) debugger.message("Error: " + e.getMessage());
// throw new ProjectComponentException("Cannot parse access control model.", e);
// }
// }
// if(debugger != null) debugger.newLine();
// return result;
// }
public static AbstractACModel loadACModel(String acFile, Map availableContexts, boolean validateModel) throws Exception {
ACModelProperties testProperties = new ACModelProperties();
try {
testProperties.load(acFile);
} catch (IOException e) {
throw new IOException("Cannot load properties file: " + acFile + ".");
}
String contextName = null;
try {
contextName = testProperties.getContextName();
} catch (Exception e) {
throw new Exception("Exception while extracting context name from AC model properties", e);
}
if (contextName == null) {
throw new PropertyException(ACModelProperty.CONTEXT_NAME, null, "Cannot extract context name from AC model properties");
}
if (!availableContexts.containsKey(contextName)) {
throw new PropertyException(ACModelProperty.CONTEXT_NAME, contextName, "No context with adequate name available.");
}
// Check if suitable context is available
if (!availableContexts.containsKey(contextName)) {
throw new Exception("Required SOABase \"" + contextName + "\" is not available");
}
SOABase context = availableContexts.get(contextName);
if (context == null) {
throw new Exception("Required SOABase \"" + contextName + "\" is NULL");
}
// Check ACModel type
AbstractACModel newModel = null;
if (testProperties.getType() == ACModelType.ACL) {
ACLModelProperties aclProperties = new ACLModelProperties();
aclProperties.load(acFile);
newModel = new ACLModel(aclProperties, context);
} else {
RBACModelProperties rbacProperties = new RBACModelProperties();
rbacProperties.load(acFile);
newModel = new RBACModel(rbacProperties, context);
}
if (validateModel) {
try {
newModel.checkValidity();
} catch (ACMValidationException e) {
throw new ParameterException("Parsed AC-model is not valid", e);
}
}
return newModel;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy