Commit f4b68aa2 authored by Jonathan Shahen's avatar Jonathan Shahen

Implemented ShortNames option: the converted file will shorten the names of...

Implemented ShortNames option: the converted file will shorten the names of all the rolenames so it is easier to read, and is a much smaller file size
parent 62e92f98
Pipeline #7960 skipped
......@@ -171,29 +171,19 @@ public class ConverterInstance {
logger.info("[CONVERTING] ...Done Converting to TRole");
}
// if (cmd.hasOption(OptionString.TO_TRULE.toString()) || cmd.hasOption(OptionString.TO_ALL.toString())) {
// logger.info("[CONVERTING] Converting to TRule... " + specFile.getName());
// /* Timing */timing.startTimer("convertToTRule (" + i + ")");
//
// ConvertToTRule toTRule = new ConvertToTRule(timing);
// toTRule.convert(m, specFile, true);
//
// if (toTRule.lastError == null) {
// logger.info("[SUCCESS] Successfully converted to TRule Input Format");
// } else {
// logger.warning("[FAILURE] Failed to convert to TRule Input Format; Error code "
// + toTRule.lastError);
// }
//
// /* Timing */timing.stopTimer("convertToTRule (" + i + ")");
// logger.info("[CONVERTING] ...Done Converting to TRule");
// }
if (cmd.hasOption(OptionString.TO_MOHAWK.toString()) || cmd.hasOption(OptionString.TO_ALL.toString())) {
logger.info("[CONVERTING] Converting to Mohawk... " + specFile.getName());
/* Timing */timing.startTimer("convertToMohawk (" + i + ")");
ConvertToMohawk toMohawk = new ConvertToMohawk(timing);
if (cmd.hasOption(OptionString.SHORT_ROLENAMES.toString())) {
logger.fine("[OPTION] Short Rolenames: Enabled");
toMohawk.shortRolenames = true;
} else {
logger.fine("[OPTION] Short Rolenames: Disabled");
}
toMohawk.convert(m, specFile, true);
if (toMohawk.lastError == null) {
......@@ -315,6 +305,9 @@ public class ConverterInstance {
options.addOption(OptionString.BULK.toString(), false,
"Use the folder that rbacspec points to and run against all *.spec");
options.addOption(OptionString.SHORT_ROLENAMES.toString(), false,
"Converted file will have short names (only works for to_mohawk)");
options.addOption(OptionString.TO_ASAPTIME_NSA.toString(), false,
"Convert input SPEC file to ASAPTime NSA format");
options.addOption(OptionString.TO_ASAPTIME_SA.toString(), false,
......
......@@ -2,10 +2,16 @@ package mohawk.converter;
public enum OptionString {
HELP("help"), AUTHORS("authors"), VERSION("version"), CHECKNUSMV("checknusmv"), LOGLEVEL("loglevel"), LOGFILE(
"logfile"), LOGFOLDER("logfolder"), NOHEADER("noheader"), RESULTSFILE("output"), MAXW("maxw"), LINESTR(
"linstr"), SPECFILE("input"), SPECEXT("specext"), BULK("bulk"), TO_ASAPTIME_NSA("to_asaptime_nsa"), TO_ASAPTIME_SA(
"to_asaptime_sa"), TO_TROLE("to_trole"), TO_TRULE("to_trule"), TO_MOHAWK("to_mohawk"), TO_MOHAWK_T(
"to_mohawk_t"), TO_ALL("to_all");
"logfile"),
LOGFOLDER("logfolder"), NOHEADER("noheader"), RESULTSFILE("output"), MAXW("maxw"), LINESTR(
"linstr"),
SPECFILE("input"), SPECEXT("specext"), BULK("bulk"), TO_ASAPTIME_NSA(
"to_asaptime_nsa"),
TO_ASAPTIME_SA("to_asaptime_sa"), TO_TROLE("to_trole"), TO_TRULE(
"to_trule"),
TO_MOHAWK("to_mohawk"), TO_MOHAWK_T("to_mohawk_t"), TO_ALL(
"to_all"),
SHORT_ROLENAMES("shortnames");
private String _str;
......
......@@ -27,6 +27,7 @@ import mohawk.global.timing.MohawkTiming;
public class ConvertToMohawk extends ConvertTo {
public static final Logger logger = Logger.getLogger("mohawk");
public boolean shortRolenames = false;
public ConvertToMohawk(MohawkTiming timing) {
super(timing);
......@@ -89,15 +90,26 @@ public class ConvertToMohawk extends ConvertTo {
/* Timing */timing.stopTimer(tPrefix + "_removeTemporality");
if (logger.isLoggable(Level.FINE)) {
logger.fine("[STEPWISE] Rules Before CA and CR Conversion: " + workableRules);
logger.fine("[STEPWISE] Rules After CA and CR Conversion: " + workableRules);
}
if (shortRolenames) {
logger.info("Creating Short Rolenames");
roleHelperTemporality.setupSortedRoles();
}
// Convert Rules into Reduced Mohawk CA and CR Rules (5)
/* Timing */timing.startTimer(tPrefix + "_convertRules");
for (Object r : reducedRules) {
if (r instanceof MohawkCA_Rule) {
if (shortRolenames) {
((MohawkCA_Rule) r).shortRolenames(roleHelperTemporality);
}
newCARules.add((MohawkCA_Rule) r);
} else if (r instanceof MohawkCR_Rule) {
if (shortRolenames) {
((MohawkCR_Rule) r).shortRolenames(roleHelperTemporality);
}
newCRRules.add((MohawkCR_Rule) r);
} else {
throw new IllegalArgumentException("Can only convert Can Assign and Can Revoke Rules in Mohawk");
......@@ -105,7 +117,7 @@ public class ConvertToMohawk extends ConvertTo {
}
/* Timing */timing.stopTimer(tPrefix + "_convertRules");
boolean queryFound = query.finalize(roleHelperTemporality);
boolean queryFound = query.finalize(roleHelperTemporality, shortRolenames);
if (queryFound == false) { throw new Exception("The query could not find the Goal Role!"); }
// Stats and logging
numberOfRules = newCARules.size() + newCRRules.size();
......@@ -113,12 +125,20 @@ public class ConvertToMohawk extends ConvertTo {
/* Timing */timing.startTimer(tPrefix + "_template");
String template = ConvertTo.readFile(this.getClass().getResource("mohawkTemplate.st"));
ST st = new ST(template);
st.add("roles", roleHelperTemporality.getArray());
st.add("users", new String[] { "AdminUser", "User" });
st.add("specuser", "User");
if (shortRolenames) {
st.add("roles", roleHelperTemporality.getArrayShortNames());
st.add("adminuser", "AU");
st.add("adminrole", "A");
st.add("users", new String[] { "AU", "User" });
st.add("specuser", "User");// Can't use 'U'
} else {
st.add("roles", roleHelperTemporality.getArray());
st.add("adminuser", "AdminUser");
st.add("adminrole", "AdminRole");
st.add("users", new String[] { "AdminUser", "User" });
st.add("specuser", "User");
}
st.add("specrole", query.specRole);
st.add("adminuser", "AdminUser");
st.add("adminrole", "AdminRole");
st.add("canrevoke", newCRRules);
st.add("canassign", newCARules);
convertedStr = st.render();
......
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