private static void SetOkatoEntityPermissions(SPSite root)
        {
            var service = SPFarm.Local.Services.GetValue<BdcService>();
            var serviceContext = SPServiceContext.GetContext(root);
            var catalog = service.GetAdministrationMetadataCatalog(serviceContext);
            var entity = catalog.GetEntity("FLS.Sharepoint.FileSearchConnector.OkatoModel", "OkatoEntity");
            var model = catalog.GetModel("OkatoModel");
            var lobSystem = catalog.GetLobSystem("OkatoModel");
            var entityAccessControlList = entity.GetAccessControlList();
            var modelAccessControlList = model.GetAccessControlList();
            var lobSystemAccessControlList = lobSystem.GetAccessControlList();

            var accessControlEntry = new IndividualAccessControlEntry(
                @"i:0#.w|NT AUTHORITY\Network service",
                BdcRights.Edit | BdcRights.Execute | BdcRights.SelectableInClients | BdcRights.SetPermissions);
            entityAccessControlList.Add(accessControlEntry);
            modelAccessControlList.Add(accessControlEntry);
            lobSystemAccessControlList.Add(accessControlEntry);
            entity.SetAccessControlList(entityAccessControlList);
            model.SetAccessControlList(entityAccessControlList);
            lobSystem.SetAccessControlList(entityAccessControlList);
        }
 private static void SetBdcServiceAdministrator(SPSite root)
 {
     var service = SPFarm.Local.Services.GetValue<BdcService>();
     var catalog = service.GetAdministrationMetadataCatalog(SPServiceContext.GetContext(root));
     var accessControlList = catalog.GetAccessControlList();
     var accessControlEntry = new IndividualAccessControlEntry(@"i:0#.w|NT AUTHORITY\Network service", BdcRights.Execute | BdcRights.SetPermissions);
     accessControlList.Add(accessControlEntry);
     catalog.SetAccessControlList(accessControlList);
 }