Commit eabb06b9 authored by Jonathan Shahen's avatar Jonathan Shahen

File is not used any more, removing it

parent 1735aaef
/**
* The MIT License
*
* Copyright (c) 2010 Karthick Jayaraman
*
* 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.
*/
/**
* RBAC2SMV - Tool for converting a RBAC specification
* to NuSMV specification
*/
package mohawk.rbac;
import java.io.*;
import java.util.*;
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.output.WriteNuSMV;
/**
* @author Karthick Jayaraman This is the main class that will serve as an entry point to the tool.
*
* STAND ALONE
*
*/
public class RBAC2SMV {
/**
* @param args
*
* Argument 0 - Rbac policy file. Argument 1 - Target NuSMV file.
* @throws IOException
* @throws TokenStreamException
*
*/
/*
* public static String getTokenType(int type) { /* int EOF = 1; int NULL_TREE_LOOKAHEAD = 3; int ID = 4; int LANGLE
* = 5; int RANGLE = 6; int COMMA = 7; int COND = 8; int WS = 9; int COMMENT = 10;
*/
/*
* switch(type) { case RBACLexerTokenTypes.EOF: return "EOF"; case RBACLexerTokenTypes.NULL_TREE_LOOKAHEAD: return
* "NULL"; case RBACLexerTokenTypes.ID: return "ID"; case RBACLexerTokenTypes.LANGLE: return "LANGLE"; case
* RBACLexerTokenTypes.RANGLE: return "RANGLE"; case RBACLexerTokenTypes.COMMA: return "COMMA"; case
* RBACLexerTokenTypes.COND: return "COND"; case RBACLexerTokenTypes.WS: return "WS"; case
* RBACLexerTokenTypes.COMMENT: return "COMMENT"; } return null; }
*/
public static void main(String[] args) throws Exception {
if (args.length < 2) {
System.out.println("Usage: java -cp ./mohawk.jar mohawk.RBAC2SMV <rbacspec> <smvfile>");
}
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];
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()));
/*
* Preparing NuSMV file.
*/
WriteNuSMV nusmv = new WriteNuSMV(nusmvfile, "smvtemplate");
if (rbac != null) {
nusmv.fillAttributes(rbac);
}
nusmv.writeFile();
System.out.println("NuSMV specification for " + rbacfile + " written to " + nusmvfile);
}
public 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;
}
public 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