Adding policy dynamic checks on skeleton and stub that has callback objects
authorrtrimana <rtrimana@uci.edu>
Thu, 17 Nov 2016 22:48:16 +0000 (14:48 -0800)
committerrtrimana <rtrimana@uci.edu>
Thu, 17 Nov 2016 22:48:16 +0000 (14:48 -0800)
iotjava/Makefile
iotjava/iotpolicy/IoTCompiler.java
iotjava/iotrmi/C++/sample/TestClass_Skeleton.hpp

index a63d357bca4bb07ae26659732a2b86bf45b45a1f..f1bb89a53fcdb8eec183cd76cf34317eb7f72b46 100644 (file)
@@ -32,9 +32,9 @@ PHONY += compile
 compile:
        cd $(BIN_DIR)/iotpolicy/output_files; cp *.java ./Java
        cd $(BIN_DIR)/iotpolicy/output_files; cp *.hpp ./Cplus
-#      cd $(BIN_DIR)/iotpolicy/output_files/Java; $(JAVAC) -cp .:..:../../../$(BIN_DIR) *.java
-#      cd $(BIN_DIR)/iotpolicy/output_files/Cplus; $(G++) ./*.hpp --std=c++11 -pthread -pg -I../../../../iotjava/iotrmi/C++/
-       cd $(BIN_DIR)/iotpolicy/output_files/Cplus; $(G++) ./Camera_CallbackSkeleton.hpp --std=c++11 -pthread -pg -I../../../../iotjava/iotrmi/C++/
+       cd $(BIN_DIR)/iotpolicy/output_files/Java; $(JAVAC) -cp .:..:../../../$(BIN_DIR) *.java
+       cd $(BIN_DIR)/iotpolicy/output_files/Cplus; $(G++) ./*.hpp --std=c++11 -pthread -pg -I../../../../iotjava/iotrmi/C++/
+#      cd $(BIN_DIR)/iotpolicy/output_files/Cplus; $(G++) ./CameraWithCaptureAndData_CallbackStub.hpp --std=c++11 -pthread -pg -I../../../../iotjava/iotrmi/C++/
 
 PHONY += clean
 clean:
@@ -62,7 +62,7 @@ rmi:
 #      $(G++) iotrmi/C++/sample/CallBack_Skeleton.cpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBack_Skeleton.out --std=c++11
        #$(G++) iotrmi/C++/sample/TestClass.cpp -o $(BIN_DIR)/iotrmi/C++/sample/TestClass.out --std=c++11
 #      $(G++) iotrmi/C++/sample/TestClass_Stub.cpp -o $(BIN_DIR)/iotrmi/C++/sample/TestClass_Stub.out --std=c++11 -pthread -pg
-#      $(G++) iotrmi/C++/sample/TestClass_Skeleton.cpp -o $(BIN_DIR)/iotrmi/C++/sample/TestClass_Skeleton.out --std=c++11 -pthread -pg
+       $(G++) iotrmi/C++/sample/TestClass_Skeleton.cpp -o $(BIN_DIR)/iotrmi/C++/sample/TestClass_Skeleton.out --std=c++11 -pthread -pg
        #$(G++) iotrmi/C++/sample/Test.cpp -o ../bin/iotrmi/C++/sample/Test.out --std=c++11 -lpthread
        #$(G++) iotrmi/C++/sample/Test2.cpp -o ../bin/iotrmi/C++/sample/Test2.out --std=c++11 -pthread -pg
 #      $(G++) iotrmi/C++/sample/StructC.cpp -o ../bin/iotrmi/C++/sample/StructC.out --std=c++11
index 619146e6bdbac8b8517dd60baff6850c471e0269..a43be1d16a4ff875f3f44255a5f327f92e15034a 100644 (file)
@@ -376,6 +376,30 @@ public class IoTCompiler {
                        println("private IoTRMIObject rmiObj;");
                        println("List<" + callbackType + "> listCallbackObj;");
                        println("private static int objIdCnt = 0;");
+                       // Generate permission stuff for callback stubs
+                       DeclarationHandler decHandler = mapIntDeclHand.get(callbackType);
+                       InterfaceDecl intDecl = (InterfaceDecl) decHandler.getInterfaceDecl(callbackType);
+                       Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(callbackType);
+                       for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
+                               String newCallbackIntface = intMeth.getKey();
+                               int newObjectId = mapNewIntfaceObjId.get(newCallbackIntface);
+                               println("private final static int object" + newObjectId + "Id = " + 
+                                       newObjectId + ";\t//" + newCallbackIntface);
+                               Set<String> methodIds = intMeth.getValue();
+                               print("private static Integer[] object" + newObjectId + "Permission = { ");
+                               int i = 0;
+                               for (String methodId : methodIds) {
+                                       int methodNumId = intDecl.getMethodNumId(methodId);
+                                       print(Integer.toString(methodNumId));
+                                       // Check if this is the last element (don't print a comma)
+                                       if (i != methodIds.size() - 1) {
+                                               print(", ");
+                                       }
+                                       i++;
+                               }
+                               println(" };");
+                               println("private List<Integer> set" + newObjectId + "Allowed;");
+                       }
                }
                println("\n");
        }
@@ -384,15 +408,21 @@ public class IoTCompiler {
        /**
         * HELPER: writeConstructorJavaStub() writes the constructor of the stub class
         */
-       private void writeConstructorJavaStub(String intface, boolean callbackExist, Set<String> callbackClasses) {
+       private void writeConstructorJavaStub(String intface, String newStubClass, boolean callbackExist, Set<String> callbackClasses) {
 
-               println("public " + intface + "(int _port, String _address, int _rev, int[] _ports) throws Exception {");
+               println("public " + newStubClass + "(int _port, String _address, int _rev, int[] _ports) throws Exception {");
                println("address = _address;");
                println("ports = _ports;");
                println("rmiCall = new IoTRMICall(_port, _address, _rev);");
                if (callbackExist) {
                        Iterator it = callbackClasses.iterator();
                        String callbackType = (String) it.next();
+                       Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
+                       for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
+                               String newIntface = intMeth.getKey();
+                               int newObjectId = mapNewIntfaceObjId.get(newIntface);
+                               println("set" + newObjectId + "Allowed = Arrays.asList(object" + newObjectId +"Permission);");
+                       }
                        println("listCallbackObj = new ArrayList<" + callbackType + ">();");
                        println("___initCallBack();");
                }
@@ -400,6 +430,24 @@ public class IoTCompiler {
        }
 
 
+       /**
+        * HELPER: writeJavaMethodCallbackPermission() writes permission checks in stub for callbacks
+        */
+       private void writeJavaMethodCallbackPermission(String intface) {
+
+               println("int methodId = IoTRMIObject.getMethodId(method);");
+               // Get all the different stubs
+               Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
+               for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
+                       String newIntface = intMeth.getKey();
+                       int newObjectId = mapNewIntfaceObjId.get(newIntface);
+                       println("if (!set" + newObjectId + "Allowed.contains(methodId)) {");
+                       println("throw new Error(\"Callback object for " + intface + " is not allowed to access method: \" + methodId);");
+                       println("}");
+               }
+       }
+
+
        /**
         * HELPER: writeConstructorJavaStub() writes the constructor of the stub class
         */
@@ -413,6 +461,7 @@ public class IoTCompiler {
                println("rmiObj = new IoTRMIObject(ports[0]);");
                println("while (true) {");
                println("byte[] method = rmiObj.getMethodBytes();");
+               writeJavaMethodCallbackPermission(intface);
                println("int objId = IoTRMIObject.getObjectId(method);");
                println(intface + "_CallbackSkeleton skel = (" + intface + "_CallbackSkeleton) listCallbackObj.get(objId);");
                println("if (skel != null) {");
@@ -664,7 +713,7 @@ public class IoTCompiler {
                                // Write properties
                                writePropertiesJavaStub(intface, newIntface, callbackExist, callbackClasses);
                                // Write constructor
-                               writeConstructorJavaStub(newStubClass, callbackExist, callbackClasses);
+                               writeConstructorJavaStub(intface, newStubClass, callbackExist, callbackClasses);
                                // Write methods
                                writeMethodJavaStub(intMeth.getValue(), intDecl, callbackClasses);
                                println("}");
@@ -693,6 +742,30 @@ public class IoTCompiler {
                        println("private IoTRMIObject rmiObj;");
                        println("List<" + callbackType + "> listCallbackObj;");
                        println("private static int objIdCnt = 0;");
+                       // Generate permission stuff for callback stubs
+                       DeclarationHandler decHandler = mapIntDeclHand.get(callbackType);
+                       InterfaceDecl intDecl = (InterfaceDecl) decHandler.getInterfaceDecl(callbackType);
+                       Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(callbackType);
+                       for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
+                               String newCallbackIntface = intMeth.getKey();
+                               int newObjectId = mapNewIntfaceObjId.get(newCallbackIntface);
+                               println("private final static int object" + newObjectId + "Id = " + 
+                                       newObjectId + ";\t//" + newCallbackIntface);
+                               Set<String> methodIds = intMeth.getValue();
+                               print("private static Integer[] object" + newObjectId + "Permission = { ");
+                               int i = 0;
+                               for (String methodId : methodIds) {
+                                       int methodNumId = intDecl.getMethodNumId(methodId);
+                                       print(Integer.toString(methodNumId));
+                                       // Check if this is the last element (don't print a comma)
+                                       if (i != methodIds.size() - 1) {
+                                               print(", ");
+                                       }
+                                       i++;
+                               }
+                               println(" };");
+                               println("private List<Integer> set" + newObjectId + "Allowed;");
+                       }
                }
                println("\n");
        }
@@ -701,15 +774,21 @@ public class IoTCompiler {
        /**
         * HELPER: writeConstructorJavaCallbackStub() writes the constructor of the callback stub class
         */
-       private void writeConstructorJavaCallbackStub(String intface, boolean callbackExist, Set<String> callbackClasses) {
+       private void writeConstructorJavaCallbackStub(String intface, String newStubClass, boolean callbackExist, Set<String> callbackClasses) {
 
                // TODO: If we want callback in callback, then we need to add address and port initializations
-               println("public " + intface + "(IoTRMICall _rmiCall, int _objectId) throws Exception {");
+               println("public " + newStubClass + "(IoTRMICall _rmiCall, int _objectId) throws Exception {");
                println("objectId = _objectId;");
                println("rmiCall = _rmiCall;");
                if (callbackExist) {
                        Iterator it = callbackClasses.iterator();
                        String callbackType = (String) it.next();
+                       Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
+                       for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
+                               String newIntface = intMeth.getKey();
+                               int newObjectId = mapNewIntfaceObjId.get(newIntface);
+                               println("set" + newObjectId + "Allowed = Arrays.asList(object" + newObjectId +"Permission);");
+                       }
                        println("listCallbackObj = new ArrayList<" + callbackType + ">();");
                        println("___initCallBack();");
                        println("// TODO: Add address and port initialization here if we want callback in callback!");
@@ -755,7 +834,7 @@ public class IoTCompiler {
                                // Write properties
                                writePropertiesJavaCallbackStub(intface, newIntface, callbackExist, callbackClasses);
                                // Write constructor
-                               writeConstructorJavaCallbackStub(newStubClass, callbackExist, callbackClasses);
+                               writeConstructorJavaCallbackStub(intface, newStubClass, callbackExist, callbackClasses);
                                // Write methods
                                // TODO: perhaps need to generate callback for callback
                                writeMethodJavaStub(intMeth.getValue(), intDecl, callbackClasses);
@@ -770,7 +849,7 @@ public class IoTCompiler {
        /**
         * HELPER: writePropertiesJavaSkeleton() writes the properties of the skeleton class
         */
-       private void writePropertiesJavaSkeleton(String intface, boolean callbackExist) {
+       private void writePropertiesJavaSkeleton(String intface, boolean callbackExist, InterfaceDecl intDecl) {
 
                println("private " + intface + " mainObj;");
                //println("private int ports;");
@@ -787,6 +866,20 @@ public class IoTCompiler {
                        int newObjectId = mapNewIntfaceObjId.get(newIntface);
                        println("private final static int object" + newObjectId + "Id = " + 
                                newObjectId + ";\t//" + newIntface);
+                       Set<String> methodIds = intMeth.getValue();
+                       print("private static Integer[] object" + newObjectId + "Permission = { ");
+                       int i = 0;
+                       for (String methodId : methodIds) {
+                               int methodNumId = intDecl.getMethodNumId(methodId);
+                               print(Integer.toString(methodNumId));
+                               // Check if this is the last element (don't print a comma)
+                               if (i != methodIds.size() - 1) {
+                                       print(", ");
+                               }
+                               i++;
+                       }
+                       println(" };");
+                       println("private List<Integer> set" + newObjectId + "Allowed;");
                }
                println("\n");
        }
@@ -800,7 +893,13 @@ public class IoTCompiler {
                println("public " + newSkelClass + "(" + intface + " _mainObj, int _port) throws Exception {");
                println("mainObj = _mainObj;");
                println("rmiObj = new IoTRMIObject(_port);");
-               //println("set0Allowed = Arrays.asList(object0Permission);");
+               // Generate permission control initialization
+               Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
+               for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
+                       String newIntface = intMeth.getKey();
+                       int newObjectId = mapNewIntfaceObjId.get(newIntface);
+                       println("set" + newObjectId + "Allowed = Arrays.asList(object" + newObjectId +"Permission);");
+               }
                println("___waitRequestInvokeMethod();");
                println("}\n");
        }
@@ -1029,10 +1128,32 @@ public class IoTCompiler {
        }
 
 
+       /**
+        * HELPER: writeJavaMethodPermission() writes permission checks in skeleton
+        */
+       private void writeJavaMethodPermission(String intface) {
+
+               // Get all the different stubs
+               Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
+               for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
+                       String newIntface = intMeth.getKey();
+                       int newObjectId = mapNewIntfaceObjId.get(newIntface);
+                       println("if (_objectId == object" + newObjectId + "Id) {");
+                       println("if (!set" + newObjectId + "Allowed.contains(methodId)) {");
+                       println("throw new Error(\"Object with object Id: \" + _objectId + \"  is not allowed to access method: \" + methodId);");
+                       println("}");
+                       println("else {");
+                       println("throw new Error(\"Object Id: \" + _objectId + \" not recognized!\");");
+                       println("}");
+                       println("}");
+               }
+       }
+
+
        /**
         * HELPER: writeJavaWaitRequestInvokeMethod() writes the main loop of the skeleton class
         */
-       private void writeJavaWaitRequestInvokeMethod(Collection<String> methods, InterfaceDecl intDecl, boolean callbackExist) {
+       private void writeJavaWaitRequestInvokeMethod(Collection<String> methods, InterfaceDecl intDecl, boolean callbackExist, String intface) {
 
                // Use this set to handle two same methodIds
                Set<String> uniqueMethodIds = new HashSet<String>();
@@ -1042,7 +1163,8 @@ public class IoTCompiler {
                println("rmiObj.getMethodBytes();");
                println("int _objectId = rmiObj.getObjectId();");
                println("int methodId = rmiObj.getMethodId();");
-               // TODO: code the permission check here!
+               // Generate permission check
+               writeJavaMethodPermission(intface);
                println("switch (methodId) {");
                // Print methods and method Ids
                for (String method : methods) {
@@ -1097,7 +1219,7 @@ public class IoTCompiler {
                        println("");
                        println("public class " + newSkelClass  + " implements " + intface + " {\n");
                        // Write properties
-                       writePropertiesJavaSkeleton(intface, callbackExist);
+                       writePropertiesJavaSkeleton(intface, callbackExist, intDecl);
                        // Write constructor
                        writeConstructorJavaSkeleton(newSkelClass, intface);
                        // Write methods
@@ -1105,7 +1227,7 @@ public class IoTCompiler {
                        // Write method helper
                        writeMethodHelperJavaSkeleton(methods, intDecl, callbackClasses);
                        // Write waitRequestInvokeMethod() - main loop
-                       writeJavaWaitRequestInvokeMethod(methods, intDecl, callbackExist);
+                       writeJavaWaitRequestInvokeMethod(methods, intDecl, callbackExist, intface);
                        println("}");
                        pw.close();
                        System.out.println("IoTCompiler: Generated skeleton class " + newSkelClass + ".java...");
@@ -1647,6 +1769,14 @@ public class IoTCompiler {
                        println("IoTRMIObject *rmiObj;");
                        println("vector<" + callbackType + "*> vecCallbackObj;");
                        println("static int objIdCnt;");
+                       // Generate permission stuff for callback stubs
+                       Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(callbackType);
+                       for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
+                               String newCallbackIntface = intMeth.getKey();
+                               int newObjectId = mapNewIntfaceObjId.get(newCallbackIntface);
+                               println("const static int object" + newObjectId + "Id = " + newObjectId + ";");
+                               println("const static set<int> set" + newObjectId + "Allowed;");
+                       }
                }
                println("\n");
        }
@@ -1703,7 +1833,26 @@ public class IoTCompiler {
 
 
        /**
-        * HELPER: writeInitCallbackCplusStub() writes the constructor of the stub class
+        * HELPER: writeCplusMethodCallbackPermission() writes permission checks in stub for callbacks
+        */
+       private void writeCplusMethodCallbackPermission(String intface) {
+
+               println("int methodId = IoTRMIObject::getMethodId(method);");
+               // Get all the different stubs
+               Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
+               for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
+                       String newIntface = intMeth.getKey();
+                       int newObjectId = mapNewIntfaceObjId.get(newIntface);
+                       println("if (set" + newObjectId + "Allowed.find(methodId) == set" + newObjectId + "Allowed.end()) {");
+                       println("cerr << \"Callback object for " + intface + " is not allowed to access method: \" << methodId;");
+                       println("exit(-1);");
+                       println("}");
+               }
+       }
+
+
+       /**
+        * HELPER: writeInitCallbackCplusStub() writes the initialization of callback
         */
        private void writeInitCallbackCplusStub(String intface, InterfaceDecl intDecl) {
 
@@ -1712,7 +1861,7 @@ public class IoTCompiler {
                println("rmiObj = new IoTRMIObject(ports[0], &bResult);");
                println("while (true) {");
                println("char* method = rmiObj->getMethodBytes();");
-               println("int methodId = IoTRMIObject::getMethodId(method);");
+               writeCplusMethodCallbackPermission(intface);
                println("int objId = IoTRMIObject::getObjectId(method);");
                println("if (objId < vecCallbackObj.size()) {   // Check if still within range");
                println(intface + "_CallbackSkeleton* skel = dynamic_cast<" + intface + 
@@ -1729,7 +1878,7 @@ public class IoTCompiler {
 
 
        /**
-        * HELPER: writeInitCallbackSendInfoCplusStub() writes the constructor of the stub class
+        * HELPER: writeInitCallbackSendInfoCplusStub() writes the initialization of callback
         */
        private void writeInitCallbackSendInfoCplusStub(InterfaceDecl intDecl) {
 
@@ -1789,6 +1938,8 @@ public class IoTCompiler {
                                // Write methods
                                writeMethodCplusStub(methods, intDecl, callbackClasses);
                                print("}"); println(";");
+                               if (callbackExist)
+                                       writePermissionInitializationCplus(intface, newStubClass, intDecl);
                                println("#endif");
                                pw.close();
                                System.out.println("IoTCompiler: Generated stub class " + newStubClass + ".hpp...");
@@ -1816,6 +1967,13 @@ public class IoTCompiler {
                        // TODO: Need to initialize address and ports if we want to have callback-in-callback
                        println("string address;");
                        println("vector<int> ports;\n");
+                       Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(callbackType);
+                       for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
+                               String newCallbackIntface = intMeth.getKey();
+                               int newObjectId = mapNewIntfaceObjId.get(newCallbackIntface);
+                               println("const static int object" + newObjectId + "Id = " + newObjectId + ";");
+                               println("const static set<int> set" + newObjectId + "Allowed;");
+                       }
                }
                println("\n");
        }
@@ -1880,7 +2038,9 @@ public class IoTCompiler {
                                writeDeconstructorCplusStub(newStubClass, callbackExist, callbackClasses);
                                // Write methods
                                writeMethodCplusStub(methods, intDecl, callbackClasses);
-                               print("}"); println(";");
+                               println("};");
+                               if (callbackExist)
+                                       writePermissionInitializationCplus(intface, newStubClass, intDecl);
                                println("#endif");
                                pw.close();
                                System.out.println("IoTCompiler: Generated callback stub class " + newIntface + ".hpp...");
@@ -1895,7 +2055,6 @@ public class IoTCompiler {
        private void writePropertiesCplusSkeleton(String intface, boolean callbackExist, Set<String> callbackClasses) {
 
                println(intface + " *mainObj;");
-               //println("private int ports;");
                // Callback
                if (callbackExist) {
                        Iterator it = callbackClasses.iterator();
@@ -1912,13 +2071,40 @@ public class IoTCompiler {
                for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
                        String newIntface = intMeth.getKey();
                        int newObjectId = mapNewIntfaceObjId.get(newIntface);
-//                     println("const static int object" + newObjectId + "Id = " + 
-//                             newObjectId + ";\t//" + newIntface);
+                       println("const static int object" + newObjectId + "Id = " + newObjectId + ";");
+                       println("const static set<int> set" + newObjectId + "Allowed;");
                }
                println("\n");
        }
 
 
+       /**
+        * HELPER: writePermissionInitializationCplus() writes the initialization of permission set
+        */
+       private void writePermissionInitializationCplus(String intface, String newSkelClass, InterfaceDecl intDecl) {
+
+               // Keep track of object Ids of all stubs registered to this interface
+               Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
+               for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
+                       String newIntface = intMeth.getKey();
+                       int newObjectId = mapNewIntfaceObjId.get(newIntface);
+                       print("const set<int> " + newSkelClass + "::set" + newObjectId + "Allowed {");
+                       Set<String> methodIds = intMeth.getValue();
+                       int i = 0;
+                       for (String methodId : methodIds) {
+                               int methodNumId = intDecl.getMethodNumId(methodId);
+                               print(Integer.toString(methodNumId));
+                               // Check if this is the last element (don't print a comma)
+                               if (i != methodIds.size() - 1) {
+                                       print(", ");
+                               }
+                               i++;
+                       }
+                       println(" };");
+               }       
+       }
+
+
        /**
         * HELPER: writeConstructorCplusSkeleton() writes the constructor of the skeleton class
         */
@@ -2215,10 +2401,34 @@ public class IoTCompiler {
        }
 
 
+       /**
+        * HELPER: writeCplusMethodPermission() writes permission checks in skeleton
+        */
+       private void writeCplusMethodPermission(String intface) {
+
+               // Get all the different stubs
+               Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
+               for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
+                       String newIntface = intMeth.getKey();
+                       int newObjectId = mapNewIntfaceObjId.get(newIntface);
+                       println("if (_objectId == object" + newObjectId + "Id) {");
+                       println("if (set" + newObjectId + "Allowed.find(methodId) == set" + newObjectId + "Allowed.end()) {");
+                       println("cerr << \"Object with object Id: \" << _objectId << \"  is not allowed to access method: \" << methodId << endl;");
+                       println("exit(-1);");
+                       println("}");
+                       println("else {");
+                       println("cerr << \"Object Id: \" << _objectId << \" not recognized!\" << endl;");
+                       println("exit(-1);");
+                       println("}");
+                       println("}");
+               }
+       }
+
+
        /**
         * HELPER: writeCplusWaitRequestInvokeMethod() writes the main loop of the skeleton class
         */
-       private void writeCplusWaitRequestInvokeMethod(Collection<String> methods, InterfaceDecl intDecl, boolean callbackExist) {
+       private void writeCplusWaitRequestInvokeMethod(Collection<String> methods, InterfaceDecl intDecl, boolean callbackExist, String intface) {
 
                // Use this set to handle two same methodIds
                Set<String> uniqueMethodIds = new HashSet<String>();
@@ -2228,7 +2438,8 @@ public class IoTCompiler {
                println("rmiObj->getMethodBytes();");
                println("int _objectId = rmiObj->getObjectId();");
                println("int methodId = rmiObj->getMethodId();");
-               // TODO: code the permission check here!
+               // Generate permission check
+               writeCplusMethodPermission(intface);
                println("switch (methodId) {");
                // Print methods and method Ids
                for (String method : methods) {
@@ -2301,8 +2512,9 @@ public class IoTCompiler {
                        // Write method helper
                        writeMethodHelperCplusSkeleton(methods, intDecl, callbackClasses);
                        // Write waitRequestInvokeMethod() - main loop
-                       writeCplusWaitRequestInvokeMethod(methods, intDecl, callbackExist);
+                       writeCplusWaitRequestInvokeMethod(methods, intDecl, callbackExist, intface);
                        println("};");
+                       writePermissionInitializationCplus(intface, newSkelClass, intDecl);
                        println("#endif");
                        pw.close();
                        System.out.println("IoTCompiler: Generated skeleton class " + newSkelClass + ".hpp...");
@@ -2757,6 +2969,7 @@ public class IoTCompiler {
                importClasses.add("java.io.IOException");
                importClasses.add("java.util.List");
                importClasses.add("java.util.ArrayList");
+               importClasses.add("java.util.Arrays");
                importClasses.add("iotrmi.Java.IoTRMICall");
                importClasses.add("iotrmi.Java.IoTRMIObject");
 
@@ -2770,6 +2983,7 @@ public class IoTCompiler {
                List<String> importClasses = new ArrayList<String>();
                // Add the standard list first
                importClasses.add("<vector>");
+               importClasses.add("<set>");
                importClasses.add("\"IoTRMICall.hpp\"");
                importClasses.add("\"IoTRMIObject.hpp\"");
 
index 9ea8bab47648fa0dd3667c3a7b3e415f2c51be18..c42f31a1fdfc4eabd1393a8a992b4c0cef2c8a8f 100644 (file)
@@ -52,7 +52,7 @@ class TestClass_Skeleton : public TestClassInterface {
                TestClassInterface                      *tc;
                IoTRMIObject                            *rmiObj;
                // Permission setup
-               const static int                        object0Id;
+               const static int                        object0Id = 0;
                //const static int                      object0Permission[];
                const static set<int>           set0Allowed;
                
@@ -64,7 +64,7 @@ class TestClass_Skeleton : public TestClassInterface {
 
 
 // Permission setup
-const int TestClass_Skeleton::object0Id = 0;
+//const int TestClass_Skeleton::object0Id = 0;
 //const int TestClass_Skeleton::object0Permission[] = {0, 1, 2, 3, 4, 5};
 const set<int> TestClass_Skeleton::set0Allowed {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};