Commit fa6e3993 authored by Jonathan Shahen's avatar Jonathan Shahen

Formatting Changes to new formatter

parent 91969897
This diff is collapsed.
package mohawk;
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"),
SMVFILE("smvfile"),
SPECEXT("specext"),
BULK("bulk"),
NOSLICING("noslicing"),
SLICEQUERY("slicequery"),
MODE("mode"),
TIMEOUT("timeout"),
RUN("run"),
NUSMVPATH("nusmv"),
SKIPREFINE("skiprefine");
HELP("help"), AUTHORS("authors"), VERSION("version"), CHECKNUSMV("checknusmv"), LOGLEVEL("loglevel"), LOGFILE(
"logfile"), LOGFOLDER("logfolder"), NOHEADER("noheader"), RESULTSFILE("output"), MAXW("maxw"), LINESTR(
"linstr"), SPECFILE("input"), SMVFILE("smvfile"), SPECEXT("specext"), BULK("bulk"), NOSLICING(
"noslicing"), SLICEQUERY("slicequery"), MODE("mode"), TIMEOUT(
"timeout"), RUN("run"), NUSMVPATH("nusmv"), SKIPREFINE("skiprefine");
private String _str;
......@@ -35,11 +18,9 @@ public enum OptionString {
return _str;
}
/**
* Returns the commandline equivalent with the hyphen and a space following: AUTHORS -> "-authors "
/** Returns the commandline equivalent with the hyphen and a space following: AUTHORS -> "-authors "
*
* @return
*/
* @return */
public String c() {
return "-" + _str + " ";
}
......
......@@ -8,10 +8,7 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* @author kjayaram
*
*/
/** @author kjayaram */
public class RoleDepTree {
public RoleDepTree() {
......@@ -26,8 +23,7 @@ public class RoleDepTree {
Set<String> setRoles = mPriorityQueue.get(level);
if (setRoles == null)
setRoles = new HashSet<String>();
if (setRoles == null) setRoles = new HashSet<String>();
setRoles.add(strRole);
mPriorityQueue.put(level, setRoles);
......
......@@ -11,10 +11,7 @@ import java.util.logging.Logger;
import mohawk.rbac.RBACInstance;
import mohawk.rbac.RBACSpecReader;
/**
* @author kjayaram
*
*/
/** @author kjayaram */
public class CalculateDiameter {
public final static Logger logger = Logger.getLogger("mohawk");
......
......@@ -11,10 +11,7 @@ import java.util.logging.Logger;
import mohawk.global.pieces.mohawk.CAEntry;
import mohawk.rbac.RBACInstance;
/**
* @author kjayaram
*
*/
/** @author kjayaram */
public class CalculateRMax {
public final static Logger logger = Logger.getLogger("mohawk");
......@@ -104,8 +101,7 @@ public class CalculateRMax {
}
if (tmpCAE2.getPreConditions().keySet().contains(roleindex)) {
if (tmpCAE2.getPreConditions().getConditional(roleindex) == 1)
return true;
if (tmpCAE2.getPreConditions().getConditional(roleindex) == 1) return true;
}
return false;
......
......@@ -9,10 +9,7 @@ import java.util.logging.Logger;
import mohawk.global.pieces.mohawk.*;
import mohawk.rbac.RBACInstance;
/**
* @author kjayaram
*
*/
/** @author kjayaram */
public class CalculateRplus {
public final static Logger logger = Logger.getLogger("mohawk");
......@@ -63,10 +60,8 @@ public class CalculateRplus {
PreCondition precond = cae.getPreConditions();
for (int roleindex : precond.keySet()) {
if (precond.getConditional(roleindex) == 1)
tmpR_plus.add(roleindex);
else
tmpR_minus.add(roleindex);
if (precond.getConditional(roleindex) == 1) tmpR_plus.add(roleindex);
else tmpR_minus.add(roleindex);
}
}
}
......
......@@ -14,10 +14,7 @@ import mohawk.global.pieces.mohawk.CAEntry;
import mohawk.global.pieces.mohawk.PreCondition;
import mohawk.rbac.RBACInstance;
/**
* @author kjayaram
*
*/
/** @author kjayaram */
public class CalculateRplusOnly {
public final static Logger logger = Logger.getLogger("mohawk");
......@@ -49,8 +46,7 @@ public class CalculateRplusOnly {
String nxtRole = qRoleQueue.remove();
Vector<CAEntry> vCAE = rbac_instance.getCA().get(nxtRole);
if (vCAE == null)
continue;
if (vCAE == null) continue;
for (int i = 0; i < vCAE.size(); i++) {
......@@ -107,15 +103,13 @@ public class CalculateRplusOnly {
for (String strTgtRole : rbac_instance.getCA().keySet()) {
Vector<CAEntry> vCAE = rbac_instance.getCA().get(strTgtRole);
if (vCAE == null)
continue;
if (vCAE == null) continue;
for (int i = 0; i < vCAE.size(); i++) {
PreCondition precond = vCAE.get(i).getPreConditions();
if (precond.keySet().contains(iRoleIndex)) {
if (precond.getConditional(iRoleIndex) == 2)
sNegRoles.add(strRole);
if (precond.getConditional(iRoleIndex) == 2) sNegRoles.add(strRole);
}
}
}
......
......@@ -35,10 +35,7 @@ import mohawk.global.pieces.mohawk.CAEntry;
import mohawk.global.pieces.mohawk.PreCondition;
import mohawk.rbac.RBACInstance;
/**
* @author kjayaram
*
*/
/** @author kjayaram */
public class EstimateDia {
public final static Logger logger = Logger.getLogger("mohawk");
......@@ -65,10 +62,8 @@ public class EstimateDia {
PreCondition precond = cae.getPreConditions();
for (int roleindex : precond.keySet()) {
if (precond.getConditional(roleindex) == 1)
tmpR_plus.add(roleindex);
else
tmpR_minus.add(roleindex);
if (precond.getConditional(roleindex) == 1) tmpR_plus.add(roleindex);
else tmpR_minus.add(roleindex);
}
}
}
......@@ -97,10 +92,8 @@ public class EstimateDia {
PreCondition precond = cae.getPreConditions();
for (int roleindex : precond.keySet()) {
if (precond.getConditional(roleindex) == 1)
tmpR_plus.add(roleindex);
else
tmpR_minus.add(roleindex);
if (precond.getConditional(roleindex) == 1) tmpR_plus.add(roleindex);
else tmpR_minus.add(roleindex);
}
}
}
......@@ -192,8 +185,7 @@ public class EstimateDia {
Vector<CAEntry> vMatchingCA = rbac_instance.getCA().get(strRole);
if (vMatchingCA == null)
return;
if (vMatchingCA == null) return;
for (int i = 0; i < vMatchingCA.size(); i++) {
CAEntry cae = vMatchingCA.get(i);
......@@ -203,10 +195,8 @@ public class EstimateDia {
for (int roleindex : pcPreCond.keySet()) {
String strDepRole = rbac_instance.getRoles().get(roleindex);
if (pcPreCond.getConditional(roleindex) == 1)
vPosDeps.add(strDepRole);
else
vNegDeps.add(strDepRole);
if (pcPreCond.getConditional(roleindex) == 1) vPosDeps.add(strDepRole);
else vNegDeps.add(strDepRole);
}
}
}
......
......@@ -33,12 +33,9 @@ import java.io.IOException;
import mohawk.rbac.RBACPAT;
/**
* @author Karthick Jayaraman
*
* STAND ALONE
/** @author Karthick Jayaraman
*
*/
* STAND ALONE */
public class CnvRBACPAT {
public static void main(String args[]) throws IOException, Exception {
......
......@@ -24,34 +24,24 @@ import mohawk.rbac.RBACInstance;
public class WriteNuSMV {
/**
* Filename on disk that will contain the NuSMV spec
*/
/** Filename on disk that will contain the NuSMV spec */
private String filename;
/**
* Flag indicates whether the SMV specification has been initialized in the string.
*/
/** Flag indicates whether the SMV specification has been initialized in the string. */
private Boolean done;
/**
* SMV spec code
*/
/** SMV spec code */
private String smvcode;
/**
* Flag that indicates if you want to old format, pre 2.5.0
*/
/** Flag that indicates if you want to old format, pre 2.5.0 */
public Boolean olderVersion = false;
// RBAC Instance
private RBACInstance rbac;
/**
* This setting changes how the user transitions are computed
/** This setting changes how the user transitions are computed
* The result should be functionally the same, but organized differently
* WARNING: version 2 DOES NOT WORK and is incomplete, it must be finished up later
*/
* WARNING: version 2 DOES NOT WORK and is incomplete, it must be finished up later */
public Integer userTransistionVersion = 1;
private ST strTCodeTemplateV1;
......@@ -60,9 +50,7 @@ public class WriteNuSMV {
private String strTransTemplateV1;
// private String strTransTemplateV2;
/**
* Controls the output for this class
*/
/** Controls the output for this class */
public Level logLevel = Level.WARNING;
public boolean includeRuleComment = true;
......@@ -116,10 +104,8 @@ public class WriteNuSMV {
Map<String, Vector<CAEntry>> mCA = rbac.getCA();
if (mCA != null)
return mCA.get(strRole);
else
return null;
if (mCA != null) return mCA.get(strRole);
else return null;
// return rbac.getCA().get(strRole);
// return vFilCA;
......@@ -147,10 +133,8 @@ public class WriteNuSMV {
String strtemplate = null;
String line;
while ((line = br.readLine()) != null) {
if (strtemplate == null)
strtemplate = line;
else
strtemplate = strtemplate + "\n" + line;
if (strtemplate == null) strtemplate = line;
else strtemplate = strtemplate + "\n" + line;
}
// System.out.println(strtemplate);
......@@ -189,12 +173,12 @@ public class WriteNuSMV {
System.out.println("[START] Setting up CA-CR rules (Using version " + userTransistionVersion + ") ...");
/* TIMING */timing.startTimer(timingPrefix + " (Setting up CA-CR rules v" + userTransistionVersion + ")");
switch (userTransistionVersion) {
case 1:
setupUserTransitionsv1(strTCodeTemplateV1);
break;
case 2:
setupUserTransitionsv2(strTCodeTemplateV2);
break;
case 1 :
setupUserTransitionsv1(strTCodeTemplateV1);
break;
case 2 :
setupUserTransitionsv2(strTCodeTemplateV2);
break;
}
/* TIMING */timing.stopTimer(timingPrefix + " (Setting up CA-CR rules v" + userTransistionVersion + ")");
......@@ -394,12 +378,8 @@ public class WriteNuSMV {
strPreCond = getTrue();
}
String strTemp = "user = $user$ & " +
"admin = $admin$ & " +
"$admin$[$adminRoleIndex$] = $True$ & " +
strPreCond + " & " +
"role = " + iDestRoleIndex + " & " +
"act = ADD: " + getTrue() + ";";
String strTemp = "user = $user$ & " + "admin = $admin$ & " + "$admin$[$adminRoleIndex$] = $True$ & "
+ strPreCond + " & " + "role = " + iDestRoleIndex + " & " + "act = ADD: " + getTrue() + ";";
for (String vAdminUser : vAdminUsers) {
for (String vUser : vUsers) {
......@@ -459,12 +439,9 @@ public class WriteNuSMV {
strTTrans.add("user", shortenUser(vUser));
strTTrans.add("admin", shortenUser(vAdminUser));
if (adminRoleIndex == -1)
strTTrans.add("precondition", getTrue());
else if (adminRoleIndex == -2)
strTTrans.add("precondition", getFalse());
else
strTTrans.add("precondition", vAdminUser + "[" + adminRoleIndex + "]=" + getTrue());
if (adminRoleIndex == -1) strTTrans.add("precondition", getTrue());
else if (adminRoleIndex == -2) strTTrans.add("precondition", getFalse());
else strTTrans.add("precondition", vAdminUser + "[" + adminRoleIndex + "]=" + getTrue());
if (strTransition == null) {
strTransition = strTTrans.render();
......@@ -622,10 +599,8 @@ public class WriteNuSMV {
strTTrans.add("precondition", strPreCond);
if (strTransition == null)
strTransition = strTTrans.render();
else
strTransition = strTransition + "\n" + strTTrans.render();
if (strTransition == null) strTransition = strTTrans.render();
else strTransition = strTransition + "\n" + strTTrans.render();
}
if (includeRuleComment) {
......@@ -672,17 +647,12 @@ public class WriteNuSMV {
strTTrans.add("admin", shortenUser(vAdminUsers.get(i)));
}
if (adminRoleIndex == -1)
strTTrans.add("precondition", getTrue());
else if (adminRoleIndex == -2)
strTTrans.add("precondition", getFalse());
else
strTTrans.add("precondition", vAdminUsers.get(i) + "[" + adminRoleIndex + "]=" + getTrue());
if (strTransition == null)
strTransition = strTTrans.render();
else
strTransition = strTransition + "\n" + strTTrans.render();
if (adminRoleIndex == -1) strTTrans.add("precondition", getTrue());
else if (adminRoleIndex == -2) strTTrans.add("precondition", getFalse());
else strTTrans.add("precondition", vAdminUsers.get(i) + "[" + adminRoleIndex + "]=" + getTrue());
if (strTransition == null) strTransition = strTTrans.render();
else strTransition = strTransition + "\n" + strTTrans.render();
}
if (includeRuleComment) {
......
......@@ -12,9 +12,7 @@ import org.stringtemplate.v4.ST;
import mohawk.global.pieces.mohawk.*;
import mohawk.rbac.RBACInstance;
/**
* @author Karthick Jayaraman This class is for writing an a generated RBAC instance to file.
*/
/** @author Karthick Jayaraman This class is for writing an a generated RBAC instance to file. */
public class WriteRBACSpec {
// StringTemplate for RBAC instance
......@@ -40,10 +38,8 @@ public class WriteRBACSpec {
String strtemplate = null;
String line;
while ((line = br.readLine()) != null) {
if (strtemplate == null)
strtemplate = line;
else
strtemplate = strtemplate + "\n" + line;
if (strtemplate == null) strtemplate = line;
else strtemplate = strtemplate + "\n" + line;
}
return strtemplate;
......@@ -147,10 +143,8 @@ public class WriteRBACSpec {
for (int key : PreCnd.keySet()) {
String tmpRole;
if (PreCnd.getConditional(key) == 1)
tmpRole = rbacinstance.getRoles().get(key);// "role"+key;
else
tmpRole = "-" + rbacinstance.getRoles().get(key);// "-role"+key;
if (PreCnd.getConditional(key) == 1) tmpRole = rbacinstance.getRoles().get(key);// "role"+key;
else tmpRole = "-" + rbacinstance.getRoles().get(key);// "-role"+key;
if (strPreCnd == null) {
strPreCnd = new StringBuffer();
......
......@@ -12,11 +12,8 @@ import java.util.logging.Logger;
import mohawk.global.pieces.mohawk.CAEntry;
import mohawk.global.pieces.mohawk.CREntry;
/**
* This class represents an RBAC instance read from an input file. An object of this class is passed to WriteNuSMV to
* convert it to a NuSMV spec.
*
*/
/** This class represents an RBAC instance read from an input file. An object of this class is passed to WriteNuSMV to
* convert it to a NuSMV spec. */
public class RBACInstance {
public final static Logger logger = Logger.getLogger("mohawk");
......@@ -111,10 +108,9 @@ public class RBACInstance {
return vUsers;
}
/**
* Get the admin users
* @return
*/
/** Get the admin users
*
* @return */
public Vector<String> getAdmin() {
return vAdmin;
}
......@@ -163,10 +159,9 @@ public class RBACInstance {
return new Vector<String>(getTargetRolesSet());
}
/**
* Returns the role names of the target CA rules
* @return the keyset for mCA
*/
/** Returns the role names of the target CA rules
*
* @return the keyset for mCA */
public Set<String> getTargetRolesSet() {
return mCA.keySet();
}
......
......@@ -13,11 +13,9 @@ import mohawk.global.parser.mohawk.v1.MohawkLexer;
import mohawk.global.parser.mohawk.v1.MohawkParser;
import mohawk.global.pieces.mohawk.*;
/**
* @author Karthick Jayaraman
/** @author Karthick Jayaraman
*
* PART OF CnvRBACPAT (STANDALONE)
*/
* PART OF CnvRBACPAT (STANDALONE) */
public class RBACPAT {
private String filename;
......@@ -83,10 +81,8 @@ public class RBACPAT {
for (int key : prec.keySet()) {
String tmpRole = null;
if (prec.getConditional(key) == 1)
tmpRole = inrbac.getRoles().get(key);// "role"+key;
else
tmpRole = "-" + inrbac.getRoles().get(key);// "-role"+key
if (prec.getConditional(key) == 1) tmpRole = inrbac.getRoles().get(key);// "role"+key;
else tmpRole = "-" + inrbac.getRoles().get(key);// "-role"+key
if (strPreCnd == null) {
strPreCnd = new StringBuffer();
......@@ -115,10 +111,8 @@ public class RBACPAT {
canassign.add("conditions", strPreCnd);
canassign.add("target", targetrole);
if (canassignblock == null)
canassignblock = new StringBuffer();
else
canassignblock.append("\n");
if (canassignblock == null) canassignblock = new StringBuffer();
else canassignblock.append("\n");
canassignblock.append(canassign);
}
}
......@@ -144,8 +138,7 @@ public class RBACPAT {
// String strRole = vRoles.get(i);
for (int i = 0; i < vRoles.size(); i++) {
String strRole = vRoles.get(i);
if (!mCR.keySet().contains(strRole))
sIRRevokableRoles.add(strRole);
if (!mCR.keySet().contains(strRole)) sIRRevokableRoles.add(strRole);
}
for (String strRole : sIRRevokableRoles) {
......@@ -153,10 +146,8 @@ public class RBACPAT {
canrevoke.add("admin", "false");
canrevoke.add("target", strRole);
if (canrevokeblock == null)
canrevokeblock = new StringBuffer();
else
canrevokeblock.append("\n");
if (canrevokeblock == null) canrevokeblock = new StringBuffer();
else canrevokeblock.append("\n");
canrevokeblock.append(canrevoke);
}
......
......@@ -11,17 +11,13 @@ import org.antlr.v4.runtime.*;
import mohawk.global.parser.mohawk.v1.MohawkLexer;
import mohawk.global.parser.mohawk.v1.MohawkParser;
/**
* @author Karthick Jayaraman
*
*/
/** @author Karthick Jayaraman */
public class RBACSpecReader {
public final static Logger logger = Logger.getLogger("mohawk");
private RBACInstance rbac;
public RBACSpecReader() {
}
public RBACSpecReader() {}
public void RBACSpecReaderStr(String nusmvCode) throws IOException {
InputStream is = new FileInputStream(nusmvCode);
......
......@@ -30,11 +30,9 @@ import java.util.logging.Logger;
import mohawk.global.pieces.mohawk.*;
import mohawk.rbac.RBACInstance;
/**
* @author Karthick Jayaraman
/** @author Karthick Jayaraman
*
* NOT USED
*/
* NOT USED */
public class FwdPruning {
public final static Logger logger = Logger.getLogger("mohawk");
......@@ -72,8 +70,7 @@ public class FwdPruning {
int roleindex = vecUA.get(i);
String strRole = unsliced.getRoles().get(roleindex);
if (!unsliced.getCR().containsKey(strRole))
Roles_low.add(strRole);
if (!unsliced.getCR().containsKey(strRole)) Roles_low.add(strRole);
}
}
......@@ -104,11 +101,9 @@ public class FwdPruning {
String strRole = unsliced.getRoles().get(roleindex);
if (preconditions.getConditional(roleindex) == 1) {
if (!Roles_up.contains(strRole))
return false;
if (!Roles_up.contains(strRole)) return false;
} else {
if (Roles_low.contains(strRole))
return false;
if (Roles_low.contains(strRole)) return false;
}
}
......@@ -134,8 +129,7 @@ public class FwdPruning {
if (this.canApply(Roles_low, Roles_up, caentry.getPreConditions())) {
Roles_up.add(strTargetRole);
Vector<CAEntry> vecCAE = slicedCA.get(strTargetRole);
if (vecCAE == null)
vecCAE = new Vector<CAEntry>();
if (vecCAE == null) vecCAE = new Vector<CAEntry>();
vecCAE.add(caentry);
slicedCA.put(strTargetRole, vecCAE);
added = true;
......@@ -153,8 +147,7 @@ public class FwdPruning {
Roles_up = getRolesUp();
unslicedCA = unsliced.getCA();
if (slicedCA == null)
slicedCA = new HashMap<String, Vector<CAEntry>>();
if (slicedCA == null) slicedCA = new HashMap<String, Vector<CAEntry>>();
while (FwdPruneHelper())
;
......
......@@ -34,13 +34,12 @@ public class RemoveUnsetRoles {
mUA = new HashMap<String, Vector<Integer>>();
}
/**
* Slices away the Unset (not used in a single rule as the target for CA) Roles and replaces them with literals
/** Slices away the Unset (not used in a single rule as the target for CA) Roles and replaces them with literals
* IF the precondition requires a Unset Role then it is defaulted to FALSE (and thus can remove the whole rule)
* IF the precondition requires to NOt have a Unset Role then the role is substituted to TRUE
*
* @return whether an error occurred
* @throws Exception
*/
* @throws Exception */
public RBACInstance getOptimizedRBAC() throws Exception {
String timerKey = timingPrefix + "->RemoveUnsetRoles.slice()";
/* timing */timing.startTimer(timerKey);
......
......@@ -19,10 +19,7 @@ import mohawk.output.WriteRBACSpec;
import mohawk.rbac.RBACInstance;
import mohawk.singleton.MohawkSettings;
/**
* @author kjayaram
*
*/
/** @author kjayaram */
public class RolesAbsRefine {
public final static Logger logger = Logger.getLogger("mohawk");
......@@ -110,8 +107,8 @@ public class RolesAbsRefine {
if (mode == NuSMVMode.BMC) {
// CalculateDiameter diameter = new CalculateDiameter(); // NEVER USED
int bound = CalculateDiameter.GetDiameter(curInstance);
System.out.println(String.format("Estimate Diameter - No of Roles %d Diameter %d",
curInstance.getNumRoles(), bound));
System.out.println(
String.format("Estimate Diameter - No of Roles %d Diameter %d", curInstance.getNumRoles(), bound));
if (skipSMVFile) {
result = runNuSMV.BMC(bound, nusmv.getNuSMVCode());
......@@ -179,8 +176,7 @@ public class RolesAbsRefine {
Vector<CAEntry> vMatchingCA = unsliced.getCA().get(strRole);
if (vMatchingCA == null)
return;
if (vMatchingCA == null) return;
for (int i = 0; i < vMatchingCA.size(); i++) {
CAEntry cae = vMatchingCA.get(i);
......@@ -190,10 +186,8 @@ public class RolesAbsRefine {
for (int roleindex : pcPreCond.keySet()) {
String strDepRole = unsliced.getRoles().get(roleindex);
if (pcPreCond.getConditional(roleindex) == 1)
vPosDeps.add(strDepRole);
else
vNegDeps.add(strDepRole);
if (pcPreCond.getConditional(roleindex) == 1) vPosDeps.add(strDepRole);
else vNegDeps.add(strDepRole);
}
}
}
......@@ -265,13 +259,11 @@ public class RolesAbsRefine {
return ExecutionResult.GOAL_UNREACHABLE;
}
/**
* A quick function to see if this will get rid of the NuSMV error that is given when trying to use the SMV code
/** A quick function to see if this will get rid of the NuSMV error that is given when trying to use the SMV code
* generated by RBAC2SMV.java
*
* @author Jonathan Shahen
* @return
*/
* @return */
public RBACInstance refineOnly() {
refine();
......@@ -297,8 +289,7 @@ public class RolesAbsRefine {
if (sNextQueue != null) {
sFirstSetRoles.addAll(sNextQueue);
lastpriority++;
} else
break;
} else break;
}
nextsetroles = new Vector<String>();
......@@ -327,8 +318,7 @@ public class RolesAbsRefine {