Commit cd3e2224 authored by Jonathan Shahen's avatar Jonathan Shahen

Ready to implement the Ranise reduction

parent a246143c
......@@ -2,3 +2,4 @@
target/
src/mohawk/converter/generated/*.java
src/mohawk/converter/generated/*.tokens
logs/
/* Taken from sharelatex's "Working Files/Mohawk Examples/old-simple-tests.txt"
*
* Converted simple_test1.txt into the new format
*/
*/
CanAssign {
// <Admin role, starting timeslot - end timeslot for admin role, role preconditions, [time slot rule gives role to user for, another time slot (optional)...],role to give to the user>
/* <Admin role,
* starting timeslot - end timeslot for admin role,
* role preconditions,
* [time slot rule gives role to user for, another time slot (optional)...],
* role to give to the user>
*/
<role0,t0-t0,TRUE,[t0],role1> //(1)
<role0,t0-t0,role1,[t0],role2> //(2)
}
......
Please direct all logs to go into this folder so that they do not accidently get added into the repo.
\ No newline at end of file
This diff is collapsed.
......@@ -36,7 +36,7 @@ import mohawk.converter.pieces.*;
public CanDisable canDisable = new CanDisable();
public Query query = new Query();
public ExpectedResult expectedResult;
public ExpectedResult expectedResult = ExpectedResult.UNKNOWN;
private void logmsg(String msg) {
......
package mohawk.converter.helper;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Logger;
import mohawk.converter.generated.MohawkTARBACParser;
import mohawk.converter.testing.BooleanErrorListener;
import mohawk.converter.testing.RegressionTests;
public class SpecHelper {
public final static Logger logger = Logger.getLogger("mohawk");
public String smvFilepath = "latestRBAC2SMV.smv";
public Boolean smvDeleteFile = false;
public String specFile = "";
public String specFileExt = ".spec";
public ArrayList<File> specFiles = new ArrayList<File>();
public boolean bulk = false;
public int mode = 3; // 1 for bmc, 2 for smc, 3 for both
public Long TIMEOUT_SECONDS = (long) 120; // Default 2 minutes
public BooleanErrorListener error = new BooleanErrorListener();
public void loadSpecFiles() throws IOException {
if (this.bulk == true) {
this.loadSpecFilesFromFolder(this.specFile);
} else {
this.addSpecFile(this.specFile);
}
}
public void loadSpecFilesFromFolder(String path) {
if (path == null || path == "") {
logger.severe("[ERROR] No SPEC Folder provided");
}
File folder = new File(path);
if (!folder.exists()) {
logger.severe("[ERROR] Spec Folder: '" + path + "' does not exists!");
}
if (!folder.isDirectory()) {
logger.severe("[ERROR] Spec Folder: '" + path + "' is not a folder and the 'bulk' option is present. "
+ "Try removing the '-bulk' option if you wish to use "
+ "a specific file, or change the option to point to a folder");
}
for (File f : folder.listFiles()) {
if (f.getName().endsWith(specFileExt)) {
logger.fine("Adding file to specFiles: " + f.getAbsolutePath());
specFiles.add(f);
}
}
}
public void addSpecFile(String path) throws IOException {
if (path == null || path.equals("")) {
logger.severe("[ERROR] No SPEC File provided");
}
File file2 = new File(path);
if (!file2.exists()) {
logger.severe("[ERROR] Spec File: '" + path + "' does not exists!");
}
if (!file2.isFile()) {
logger.severe("[ERROR] Spec File: '" + path + "' is not a file and the 'bulk' option was not set. "
+ "Try setting the '-bulk' option if you wish to search "
+ "through the folder, or change the option to point to a specific file");
}
logger.info("[FILE IO] Using SPEC File: " + file2.getCanonicalPath());
specFiles.add(file2);
}
public File getSmvFile(File specFile2) {
File nusmvFile = null;
if (smvDeleteFile) {
try {
nusmvFile = File.createTempFile("smvTempFile", ".smv");
} catch (IOException e) {
logger.severe("[ERROR] Unable to create a temporary SMV file in the current working directory: "
+ new File("").getAbsoluteFile());
}
return nusmvFile;
}
if (bulk) {
nusmvFile = new File(new File(smvFilepath).getAbsolutePath() + File.pathSeparator + specFile2.getName()
+ ".smv");
} else {
nusmvFile = new File(smvFilepath);
}
if (!nusmvFile.exists()) {
try {
nusmvFile.createNewFile();
} catch (IOException e) {
logger.severe("[ERROR] Unable to create a SMV file in the current working directory: "
+ new File("").getAbsoluteFile());
}
}
return nusmvFile;
}
public MohawkTARBACParser parseSpecFile(File specFile) throws IOException {
FileInputStream fis = new FileInputStream(specFile);
error.errorFound = false; // reset the error listener
MohawkTARBACParser parser = RegressionTests.runParser(fis, error);
if (error.errorFound) {
logger.warning("Unable to parse the file: " + specFile.getAbsolutePath());
}
return parser;
}
}
......@@ -14,6 +14,7 @@ import mohawk.converter.generated.MohawkTARBACLexer;
import mohawk.converter.generated.MohawkTARBACParser;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.BaseErrorListener;
import org.antlr.v4.runtime.CommonTokenStream;
import org.apache.commons.lang3.StringUtils;
import org.junit.Before;
......@@ -113,7 +114,7 @@ public class RegressionTests {
String str = "";
error.errorFound = false;
runParser(new ByteArrayInputStream(str.getBytes()));
runParser(new ByteArrayInputStream(str.getBytes()), error);
// Check for Parsing errors
assertTrue("The empty string passed the parser!", error.errorFound);
......@@ -122,10 +123,10 @@ public class RegressionTests {
private MohawkTARBACParser loadfile(String file) throws IOException {
FileInputStream fis = new FileInputStream(folderbase + file);
return runParser(fis);
return runParser(fis, error);
}
private MohawkTARBACParser runParser(InputStream is) throws IOException {
public static MohawkTARBACParser runParser(InputStream is, BaseErrorListener errorListener) throws IOException {
ANTLRInputStream input = new ANTLRInputStream(is);
MohawkTARBACLexer lexer = new MohawkTARBACLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
......@@ -134,17 +135,17 @@ public class RegressionTests {
System.out.println(tokens.getText());
parser.removeErrorListeners();
parser.addErrorListener(error);
parser.addErrorListener(errorListener);
parser.init();
System.out.println("Roles: " + parser.roles);
System.out.println("Timeslots: " + parser.timeslots);
System.out.println(parser.query);
System.out.println(parser.expectedResult);
System.out.println(parser.canAssign);
System.out.println(parser.canDisable);
System.out.println(parser.canEnable);
System.out.println(parser.canRevoke);
System.out.println(parser.query.toString());
System.out.println(parser.expectedResult.toString());
System.out.println(parser.canAssign.toString());
System.out.println(parser.canDisable.toString());
System.out.println(parser.canEnable.toString());
System.out.println(parser.canRevoke.toString());
return parser;
}
......
package mohawk.converter.to;
import java.io.File;
import mohawk.converter.generated.MohawkTARBACParser;
public interface ConvertTo {
public int convert(MohawkTARBACParser p, File f);
}
package mohawk.converter.to.mohawk;
import java.io.File;
import mohawk.converter.generated.MohawkTARBACParser;
import mohawk.converter.to.ConvertTo;
public class ConvertToMohawk implements ConvertTo {
@Override
public int convert(MohawkTARBACParser p, File f) {
// TODO Auto-generated method stub
return 0;
}
}
package mohawk.converter.to.ranise;
import java.io.File;
import mohawk.converter.generated.MohawkTARBACParser;
import mohawk.converter.to.ConvertTo;
public class ConvertToRanise implements ConvertTo {
@Override
public int convert(MohawkTARBACParser p, File f) {
// TODO Auto-generated method stub
return 0;
}
}
package mohawk.converter.to.uzun;
import java.io.File;
import mohawk.converter.generated.MohawkTARBACParser;
import mohawk.converter.to.ConvertTo;
public class ConvertToUzun implements ConvertTo {
@Override
public int convert(MohawkTARBACParser p, File f) {
// TODO Auto-generated method stub
return 0;
}
}
package mohawk.converter.to_mohawk;
public class ConvertToRBAC {
}
package mohawk.converter.to_ranise;
public class ConvertToRanise {
}
package mohawk.converter.to_uzun;
public class ConvertToUzun {
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment