Commit 8c735bb6 authored by Jonathan Shahen's avatar Jonathan Shahen

Removing unused utilities

parent 1b4e5320
/**
* The MIT License
*
* Copyright (c) 2010 Karthick Jayaraman, 2014 Jonathan Shahen
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package mohawk.refine;
import java.io.File;
import java.util.logging.Logger;
import mohawk.global.pieces.mohawk.NuSMVMode;
import mohawk.rbac.RBACInstance;
import mohawk.rbac.RBACSpecReader;
/**
* @author Karthick Jayaraman, Jonathan Shahen
*
*/
public class AbsRefine {
public final static Logger logger = Logger.getLogger("mohawk");
public void refine(String specfile) {
refine(specfile, null);
}
public void refine(String specfile, NuSMVMode mode) {
File rbacfile = new File(specfile);
if (!rbacfile.exists()) {
System.out.println("The RBAC specification file " + rbacfile + " does not exists.");
return;
}
RBACSpecReader reader = new RBACSpecReader(specfile);
RBACInstance rbac = reader.getRBAC();
RolesAbsRefine absrefine = new RolesAbsRefine(rbac);
if (mode == null)
absrefine.setMode(NuSMVMode.SMC); // Set the SMC mode
else
absrefine.setMode(mode);
absrefine.absrefineloop();
}
}
/**
*
*/
package mohawk.util;
import java.io.*;
import java.util.logging.Logger;
import org.antlr.v4.runtime.*;
import mohawk.global.parser.mohawk.v1.MohawkLexer;
import mohawk.global.parser.mohawk.v1.MohawkParser;
import mohawk.output.WriteRBACSpec;
import mohawk.rbac.RBACInstance;
/**
* @author Karthick Jayaraman
*
* STAND ALONE
*
*/
public class RemoveCR {
public final static Logger logger = Logger.getLogger("mohawk");
/**
* @param args
*/
public static void main(String[] args) throws Exception {
File rbacfile = new File(args[0]);
if (!rbacfile.exists()) {
System.out.println("The RBAC specification file " + rbacfile + " does not exists.");
return;
}
String outputfile = args[1];
InputStream is = new FileInputStream(args[0]);
ANTLRInputStream input = new ANTLRInputStream(is);
MohawkLexer lexer = new MohawkLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
MohawkParser parser = new MohawkParser(tokens);
RBACInstance rbac = null;
parser.initRbac();
try {
parser.init();
rbac = new RBACInstance(parser.vRoles, parser.vUsers, parser.vAdmin, parser.mUA, parser.mCR, parser.mCA,
parser.vSpec);
} catch (RecognitionException e) {
e.printStackTrace();
}
rbac.getCR().clear();
WriteRBACSpec writer = new WriteRBACSpec("rbac.st");
try {
writer.Write2File(rbac, outputfile);
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
package mohawk.util;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;
import java.util.logging.Logger;
import mohawk.global.pieces.mohawk.*;
import mohawk.output.WriteRBACSpec;
import mohawk.rbac.RBACInstance;
import mohawk.rbac.RBACSpecReader;
/**
*
* @author Karthick Jayaraman
*
* STAND ALONE
*/
public class Replicate {
public final static Logger logger = Logger.getLogger("mohawk");
/**
* @param args
*/
public static void main(String[] args) {
if (args.length < 2) {
System.out.println("Usage: java -jar ./rbac2smv.jar Slicer rbacspec nusmvfile");
}
File rbacfile = new File(args[0]);
if (!rbacfile.exists()) {
System.out.println("The RBAC specification file " + rbacfile + " does not exists.");
return;
}
String nusmvfile = args[1];
int times = Integer.parseInt(args[2]);
RBACSpecReader rbacreader = new RBACSpecReader(args[0]);
RBACInstance rbac = rbacreader.getRBAC();
Replicator replica = new Replicator(rbac);
RBACInstance newrbac = replica.replicatePolicy(times);
WriteRBACSpec writer = new WriteRBACSpec("rbac.st");
try {
writer.Write2File(newrbac, nusmvfile);
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
class Replicator {
public Replicator(RBACInstance in_rbac) {
rbac = in_rbac;
}
public boolean isRole(String inRole) {
if (inRole.equalsIgnoreCase("Employee") || inRole.equalsIgnoreCase("Admin")) {
return false;
} else {
return true;
}
}
public Map<String, Vector<Integer>> modifyUA(Vector<String> newRoles) {
Map<String, Vector<Integer>> originalUA = rbac.getUA();
Map<String, Vector<Integer>> newUA = new HashMap<String, Vector<Integer>>();
for (String strKey : originalUA.keySet()) {
Vector<Integer> oldroleindices = originalUA.get(strKey);
Vector<Integer> newroleindices = new Vector<Integer>();
for (int i = 0; i < oldroleindices.size(); i++) {
int oldindex = oldroleindices.get(i);
int newindex = newRoles.indexOf(rbac.getRoles().get(oldindex));
newroleindices.add(newindex);
}
newUA.put(strKey, newroleindices);
}
return newUA;
}
public RBACInstance replicatePolicy(int times) {
Vector<String> vRoles = replicateRoles(times);
Map<String, Vector<CAEntry>> mCA = this.replicateCA(rbac.getCA(), vRoles, times);
Map<String, Vector<CREntry>> mCR = this.replicateCR(rbac.getCR(), times);
Vector<String> newSpec = new Vector<String>();
newSpec.add("user0");
newSpec.add("Branch1");
return new RBACInstance(vRoles, rbac.getUsers(), rbac.getAdmin(), modifyUA(vRoles), mCR, mCA, newSpec);
}
public int getRoleIndex(Vector<String> vRoles, String strRole) {
for (int i = 0; i < vRoles.size(); i++) {
if (vRoles.get(i).equalsIgnoreCase(strRole))
return i;
}
return -1;
}
public Vector<String> replicateRoles(int times) {
Vector<String> rvRoles = new Vector<String>();
Vector<String> inRoles = rbac.getRoles();
int index_to_add = 1;
while (index_to_add <= times) {
for (int i = 0; i < inRoles.size(); i++) {
String tmpRole = inRoles.get(i);
if (isRole(tmpRole)) {
tmpRole = tmpRole + index_to_add;
rvRoles.add(tmpRole);
}
}
index_to_add++;
}
rvRoles.add("Employee");
rvRoles.add("Admin");
return rvRoles;
}
public Map<String, Vector<CREntry>> replicateCR(Map<String, Vector<CREntry>> in_mCR, int times) {
Map<String, Vector<CREntry>> new_mCR = new HashMap<String, Vector<CREntry>>();
int index_to_add = 1;
while (index_to_add <= times) {
for (String strRole : in_mCR.keySet()) {
String newtargetrole;
if (this.isRole(strRole))
newtargetrole = strRole + index_to_add;
else
newtargetrole = strRole;
Vector<CREntry> new_vCR = new Vector<CREntry>();
CREntry newcr = new CREntry("Admin", newtargetrole);
new_vCR.add(newcr);
new_mCR.put(newtargetrole, new_vCR);
}
index_to_add++;
}
return new_mCR;
}
public Map<String, Vector<CAEntry>> replicateCA(Map<String, Vector<CAEntry>> in_mCA, Vector<String> newRoles,
int times) {
int index_to_add = 1;
Map<String, Vector<CAEntry>> new_mCA = new HashMap<String, Vector<CAEntry>>();
while (index_to_add <= times) {
for (String strRole : in_mCA.keySet()) {
Vector<CAEntry> in_vCA = in_mCA.get(strRole);
String newTargetRole = strRole + index_to_add;
Vector<CAEntry> new_vCA = new Vector<CAEntry>();
for (int i = 0; i < in_vCA.size(); i++) {
CAEntry oldcae = in_vCA.get(i);
PreCondition oldprecond = oldcae.getPreConditions();
PreCondition newprecond = new PreCondition();
for (int roleindex : oldprecond.keySet()) {
String tmpRole = rbac.getRoles().get(roleindex);
int newindex = this.getRoleIndex(newRoles, tmpRole + index_to_add);
newprecond.addConditional(newindex, oldprecond.getConditional(roleindex));
}
CAEntry newcae = new CAEntry("Admin", newprecond, newTargetRole);
new_vCA.add(newcae);
}
new_mCA.put(newTargetRole, new_vCA);
}
index_to_add++;
}
return new_mCA;
}
RBACInstance rbac;
}
/**
*
*/
package mohawk.util;
import java.io.File;
import java.util.*;
import mohawk.global.pieces.mohawk.CAEntry;
import mohawk.global.pieces.mohawk.CREntry;
import mohawk.rbac.RBACInstance;
import mohawk.rbac.RBACSpecReader;
import mohawk.slicer.RoleSlicer;
/**
* @author kjayaram
*
* STAND ALONE
*
*/
public class RoleAnalysis {
/**
* @param args
*/
public static void main(String[] args) {
// int oldroles, oldusers, oldcarules, oldcrrules; // NEVER USED
if (args.length < 2) {
System.out.println("Usage: java -jar ./rbac2smv.jar RoleAnalysis rbacspec nusmvfile");
}
File rbacfile = new File(args[0]);
if (!rbacfile.exists()) {
System.out.println("The RBAC specification file " + rbacfile + " does not exists.");
return;
}
RBACInstance rbac = null;
RBACSpecReader rbacreader = new RBACSpecReader(args[0]);
rbac = rbacreader.getRBAC();
// oldroles = rbac.getRoles().size(); // NEVER USED
// oldusers = rbac.getUsers().size(); // NEVER USED
// oldcarules = getCASize(rbac.getCA()); // NEVER USED
// oldcrrules = getCRSize(rbac.getCR()); // NEVER USED
Vector<CAEntry> AllDisjuncts = rbac.getCA().get(rbac.getSpec().get(1));
Map<String, Vector<CAEntry>> mCA = rbac.getCA();
/*
* Preparing Sliced Policy file.
*/
for (int i = 0; i < AllDisjuncts.size(); i++) {
Vector<CAEntry> slicedDisjuncts = new Vector<CAEntry>();
slicedDisjuncts.add(AllDisjuncts.get(i));
mCA.put(rbac.getSpec().get(1), slicedDisjuncts);
// mCA.remove(rbac.getSpec().get(1));
RBACInstance tmprbac = new RBACInstance(rbac.getRoles(), rbac.getUsers(), rbac.getAdmin(), rbac.getUA(),
rbac.getCR(), mCA, rbac.getSpec());
RoleSlicer roleslicer = new RoleSlicer(tmprbac);
try {
tmprbac = roleslicer.getSlicedPolicy();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("After slicing Disjunct " + i);
System.out.println("Roles : " + tmprbac.getRoles().size());
System.out.println("Users : " + tmprbac.getUsers().size());
System.out.println("CA : " + getCASize(tmprbac.getCA()));
System.out.println("CR : " + getCRSize(tmprbac.getCR()));
}
}
private static int getCASize(Map<String, Vector<CAEntry>> mCA) {
int size = 0;
Collection<Vector<CAEntry>> carules = mCA.values();
Iterator<Vector<CAEntry>> iterator = carules.iterator();
while (iterator.hasNext()) {
Vector<CAEntry> vCA = iterator.next();
size += vCA.size();
}
return size;
}
private static int getCRSize(Map<String, Vector<CREntry>> mCR) {
int size = 0;
Collection<Vector<CREntry>> carules = mCR.values();
Iterator<Vector<CREntry>> iterator = carules.iterator();
while (iterator.hasNext()) {
Vector<CREntry> vCR = iterator.next();
size += vCR.size();
}
return size;
}
}
/**
*
*/
package mohawk.util;
import java.io.*;
import java.util.*;
import java.util.logging.Logger;
import org.antlr.v4.runtime.*;
import mohawk.global.parser.mohawk.v1.MohawkLexer;
import mohawk.global.parser.mohawk.v1.MohawkParser;
import mohawk.global.pieces.mohawk.CAEntry;
import mohawk.global.pieces.mohawk.CREntry;
import mohawk.rbac.RBACInstance;
/**
* @author Karthick Jayaraman
*
*/
public class SizeOfRBAC {
public final static Logger logger = Logger.getLogger("mohawk");
/**
* @param args
* @throws FileNotFoundException
*/
public static void main(String[] args) throws Exception {
File rbacfile = new File(args[0]);
if (!rbacfile.exists()) {
System.out.println("The RBAC specification file " + rbacfile + " does not exists.");
return;
}
InputStream is = new FileInputStream(args[0]);
ANTLRInputStream input = new ANTLRInputStream(is);
MohawkLexer lexer = new MohawkLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
MohawkParser parser = new MohawkParser(tokens);
RBACInstance rbac = null;
parser.initRbac();
try {
parser.init();
rbac = new RBACInstance(parser.vRoles, parser.vUsers, parser.vAdmin, parser.mUA, parser.mCR, parser.mCA,
parser.vSpec);
} catch (RecognitionException e) {
e.printStackTrace();
}
System.out.println("No of roles : " + rbac.getRoles().size());
System.out.println("No of CA Rules : " + getCASize(rbac.getCA()));
System.out.println("No of CA Rules : " + getCRSize(rbac.getCR()));
}
private static int getCASize(Map<String, Vector<CAEntry>> mCA) {
int size = 0;
Collection<Vector<CAEntry>> carules = mCA.values();
Iterator<Vector<CAEntry>> iterator = carules.iterator();
while (iterator.hasNext()) {
Vector<CAEntry> vCA = iterator.next();
size += vCA.size();
}
return size;
}
private static int getCRSize(Map<String, Vector<CREntry>> mCR) {
int size = 0;
Collection<Vector<CREntry>> carules = mCR.values();
Iterator<Vector<CREntry>> iterator = carules.iterator();
while (iterator.hasNext()) {
Vector<CREntry> vCR = iterator.next();
size += vCR.size();
}
return size;
}
}
/**
*
*/
package mohawk.util;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;
import java.util.logging.Logger;
import mohawk.global.pieces.mohawk.CAEntry;
import mohawk.global.pieces.mohawk.CREntry;
import mohawk.output.WriteRBACSpec;
import mohawk.rbac.RBACInstance;
import mohawk.rbac.RBACSpecReader;
import mohawk.slicer.RoleSlicer;
import mohawk.slicer.SliceQueryRole;
/**
* @author kjayaram
*
*/
public class Slicer {
public final static Logger logger = Logger.getLogger("mohawk");
/**
* @param args
*/
public static void main(String[] args) {
int oldroles, oldusers, oldcarules, oldcrrules;
if (args.length < 2) {
System.out.println("Usage: java -jar ./rbac2smv.jar Slicer rbacspec nusmvfile");
}
File rbacfile = new File(args[0]);
if (!rbacfile.exists()) {
System.out.println("The RBAC specification file " + rbacfile + " does not exists.");
return;
}
String nusmvfile = args[1];
/*
* Reader reader = null; try { reader = new FileReader(rbacfile); } catch (FileNotFoundException e) {
* Auto-generated catch block e.printStackTrace(); }
*/
// RBACLexer lexer = new RBACLexer(reader);
// RBACParser parser = new RBACParser(lexer);
RBACInstance rbac = null;
RBACSpecReader rbacreader = new RBACSpecReader(args[0]);
rbac = rbacreader.getRBAC();
oldroles = rbac.getRoles().size();
oldusers = rbac.getUsers().size();
oldcarules = getCASize(rbac.getCA());
oldcrrules = getCRSize(rbac.getCR());
/*
* Preparing Sliced Policy file.
*/
RoleSlicer roleslicer = new RoleSlicer(rbac);
try {
rbac = roleslicer.getSlicedPolicy();
} catch (Exception e) {
e.printStackTrace();
}
if (args.length == 3) {
// if(args[2] == "QueryRole")
{
SliceQueryRole scRole = new SliceQueryRole(rbac);
try {
rbac = scRole.getSlicedPolicy();
} catch (Exception e) {
e.printStackTrace();
}
}
}
// FwdPruning fwdpruning = new FwdPruning(rbac);
// rbac = fwdpruning.getSlicedPolicy();
WriteRBACSpec writer = new WriteRBACSpec("rbac.st");
try {
writer.Write2File(rbac, nusmvfile);
} catch (IOException e1) {
e1.printStackTrace();
}
System.out.println("Sliced specification for " + rbacfile + " written to " + nusmvfile);
System.out.println("Results of slicing");
System.out.println("Roles old :" + oldroles + " new :" + rbac.getRoles().size());
System.out.println("Users old :" + oldusers + " new :" + rbac.getUsers().size());
System.out.println("CA Rules old :" + oldcarules + " new :" + getCASize(rbac.getCA()));
System.out.println("CR Rules old :" + oldcrrules + " new :" + getCRSize(rbac.getCR()));
}
private static int getCASize(Map<String, Vector<CAEntry>> mCA) {
int size = 0;
Collection<Vector<CAEntry>> carules = mCA.values();
Iterator<Vector<CAEntry>> iterator = carules.iterator();
while (iterator.hasNext()) {
Vector<CAEntry> vCA = iterator.next();
size += vCA.size();
}
return size;
}
private static int getCRSize(Map<String, Vector<CREntry>> mCR) {
int size = 0;
Collection<Vector<CREntry>> carules = mCR.values();
Iterator<Vector<CREntry>> iterator = carules.iterator();
while (iterator.hasNext()) {
Vector<CREntry> vCR = iterator.next();
size += vCR.size();
}
return size;
}
}
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