Inheritance: IPermissionManager
        public bool IsFeatureInEveryoneGroup(long featureId)
        {
            PermissionManager permissionManager = new PermissionManager();
            SubjectManager subjectManager = new SubjectManager();

            return permissionManager.ExistsFeaturePermission(subjectManager.GetGroupByName("everyone").Id, featureId);
        }
        public bool SetFeaturePermission(long subjectId, long featureId, int value)
        {
            PermissionManager permissionManager = new PermissionManager();

            if (value == 2)
            {
                permissionManager.DeleteFeaturePermission(subjectId, featureId);

                return true;
            }
            else
            {
                FeaturePermission featurePermission = permissionManager.GetFeaturePermission(subjectId, featureId);

                if (featurePermission != null)
                {
                    featurePermission.PermissionType = (PermissionType)value;
                    permissionManager.UpdateFeaturePermission(featurePermission);

                    return true;
                }
                else
                {
                    permissionManager.CreateFeaturePermission(subjectId, featureId, (PermissionType)value);

                    return true;
                }
            }
        }
        public bool DeleteDataPermission(long subjectId, long entityId, long dataId, int rightType)
        {
            PermissionManager permissionManager = new PermissionManager();

            permissionManager.DeleteDataPermission(subjectId, entityId, dataId, (RightType)rightType);

            return true;
        }
        public void ConcealDataset(long entityId, long datasetId)
        {
            PermissionManager permissionManager = new PermissionManager();
            SubjectManager subjectManager = new SubjectManager();

            Group group = subjectManager.GetGroupByName("everyone");

            permissionManager.DeleteDataPermission(group.Id, entityId, datasetId, RightType.View);
        }
        public ActionResult Datasets_Select()
        {
            DatasetManager datasetManager = new DatasetManager();
            PermissionManager permissionManager = new PermissionManager();
            SubjectManager subjectManager = new SubjectManager();

            // DATA
            //var ids = datasetManager.GetDatasetLatestIds();
            List<DatasetVersion> data = datasetManager.GetDatasetLatestVersions(); // .GetDatasetLatestVersions(ids);

            List<DatasetGridRowModel> datasets = new List<DatasetGridRowModel>();
            data.ForEach(d => datasets.Add(DatasetGridRowModel.Convert(d, permissionManager.ExistsDataPermission(subjectManager.GetGroupByName("everyone").Id, 1, d.Id, RightType.View))));

            return View(new GridModel<DatasetGridRowModel> { Data = datasets });
        }
Exemple #6
0
        public ActionResult Create(UserCreateModel model)
        {
            if (ModelState.IsValid)
            {
                SubjectManager subjectManager = new SubjectManager();
                User user = subjectManager.CreateUser(model.Username, model.Password, model.FullName, model.Email, model.SecurityQuestion, model.SecurityAnswer, model.AuthenticatorList.Id);

                // Feature
                FeatureManager featureManager = new FeatureManager();
                Feature feature = featureManager.FeaturesRepo.Get(f => f.Name == "Search").FirstOrDefault();

                // Permissions
                PermissionManager permissionManager = new PermissionManager();
                permissionManager.CreateFeaturePermission(user.Id, feature.Id);

                return Json(new { success = true });
            }

            return PartialView("_CreatePartial", model);
        }
Exemple #7
0
        /// <summary>
        /// return true if user has edit rights
        /// </summary>
        /// <returns></returns>
        private bool hasUserEditRights(long entityId)
        {
            #region security permissions and authorisations check
            // set edit rigths
            PermissionManager permissionManager = new PermissionManager();
            SubjectManager subjectManager = new SubjectManager();
            Security.Services.Objects.TaskManager securityTaskManager = new Security.Services.Objects.TaskManager();

            bool hasAuthenticationRigths = false;

            User user = subjectManager.GetUserByName(GetUsernameOrDefault());
            long userid = -1;

            if (user != null)
            {
                userid = subjectManager.GetUserByName(GetUsernameOrDefault()).Id;

                hasAuthenticationRigths = permissionManager.HasUserDataAccess(userid, 1, entityId, RightType.Update);

                return (hasAuthenticationRigths);
            }
            else
            {
               return false;
            }

            #endregion
        }
Exemple #8
0
        //
        // GET: /DIM/Import/
        public ActionResult Index()
        {
            //xml metadata for import
            string metadataForImportPath = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DIM"), "MetadataIDIV_EXAMPLE.xml");

            XmlDocument metadataForImport = new XmlDocument();
            metadataForImport.Load(metadataForImportPath);

            // metadataStructure DI
            long metadataStructureId = 3;

            MetadataStructureManager metadataStructureManager = new MetadataStructureManager();
            string metadataStructrueName = metadataStructureManager.Repo.Get(metadataStructureId).Name;

            // loadMapping file
            string path_mappingFile = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DIM"), XmlMetadataImportHelper.GetMappingFileName(metadataStructureId, TransmissionType.mappingFileImport, metadataStructrueName));

            // XML mapper + mapping file
            XmlMapperManager xmlMapperManager = new XmlMapperManager(TransactionDirection.InternToExtern);
            xmlMapperManager.Load(path_mappingFile, "IDIV");

            // generate intern metadata
            XmlDocument metadataResult = xmlMapperManager.Generate(metadataForImport,1);

            // generate intern template
            XmlMetadataWriter xmlMetadatWriter = new XmlMetadataWriter(BExIS.Xml.Helpers.XmlNodeMode.xPath);
            XDocument metadataXml = xmlMetadatWriter.CreateMetadataXml(metadataStructureId);
            XmlDocument metadataXmlTemplate = XmlMetadataWriter.ToXmlDocument(metadataXml);

            XmlDocument completeMetadata = XmlMetadataImportHelper.FillInXmlAttributes(metadataResult, metadataXmlTemplate);

            // create Dataset

            //load datastructure
            DataStructureManager dsm = new DataStructureManager();
            ResearchPlanManager rpm = new ResearchPlanManager();
            MetadataStructureManager msm = new MetadataStructureManager();

            DatasetManager dm = new DatasetManager();
            Dataset dataset = dm.CreateEmptyDataset(dsm.UnStructuredDataStructureRepo.Get(1), rpm.Repo.Get(1), msm.Repo.Get(3));

            if (dm.IsDatasetCheckedOutFor(dataset.Id, GetUsernameOrDefault()) || dm.CheckOutDataset(dataset.Id, GetUsernameOrDefault()))
            {
                DatasetVersion workingCopy = dm.GetDatasetWorkingCopy(dataset.Id);
                workingCopy.Metadata = completeMetadata;

                string title = XmlDatasetHelper.GetInformation(workingCopy, NameAttributeValues.title);
                if (String.IsNullOrEmpty(title)) title = "No Title available.";

                dm.EditDatasetVersion(workingCopy, null, null, null);
                dm.CheckInDataset(dataset.Id, "Metadata was submited.", GetUsernameOrDefault());

                // add security
                if (GetUsernameOrDefault() != "DEFAULT")
                {
                    PermissionManager pm = new PermissionManager();
                    SubjectManager sm = new SubjectManager();

                    BExIS.Security.Entities.Subjects.User user = sm.GetUserByName(GetUsernameOrDefault());

                    foreach (RightType rightType in Enum.GetValues(typeof(RightType)).Cast<RightType>())
                    {
                        pm.CreateDataPermission(user.Id, 1, dataset.Id, rightType);
                    }
                }
            }

            return View();
        }
Exemple #9
0
        /// <summary>
        /// return true if user has edit rights
        /// </summary>
        /// <returns></returns>
        private bool hasUserEditAccessRights(long entityId)
        {
            #region security permissions and authorisations check
            // set edit rigths
            PermissionManager permissionManager = new PermissionManager();
            SubjectManager subjectManager = new SubjectManager();
            Security.Services.Objects.TaskManager securityTaskManager = new Security.Services.Objects.TaskManager();

            bool hasAuthorizationRights = false;

            User user = subjectManager.GetUserByName(GetUsernameOrDefault());
            long userid = -1;

            if (user != null)
            {
                userid = subjectManager.GetUserByName(GetUsernameOrDefault()).Id;

                //User has Access to Features
                //Area DCM
                //Controller "Create Dataset"
                //Action "*"
                Task task = securityTaskManager.GetTask("DCM", "CreateDataset", "*");
                if (task != null)
                {
                    hasAuthorizationRights = permissionManager.HasSubjectFeatureAccess(userid, task.Feature.Id);
                }

                return (hasAuthorizationRights);
            }
            else
            {
                return false;
            }

            #endregion
        }
Exemple #10
0
        /// <summary>
        /// Lists all exisiting datasets alongside with their current status
        /// </summary>
        /// <returns></returns>
        public ActionResult List()
        {
            ViewBag.Title = PresentationModel.GetViewTitleForTenant("Maintain Datasets", this.Session.GetTenant());

            DatasetManager dm = new DatasetManager();
            PermissionManager permissionManager = new PermissionManager();
            SubjectManager subjectManager = new SubjectManager();

            User user = subjectManager.GetUserByName(HttpContext.User.Identity.Name);

            List<Dataset> datasets = dm.DatasetRepo.Query().OrderBy(p=>p.Id).ToList();

            List<long> datasetIds = new List<long>();
            if (user != null)
            {
                datasetIds.AddRange(permissionManager.GetAllDataIds(user.Id, 1, RightType.Delete));
            }

            ViewData["DatasetIds"] = datasetIds;

            return View(datasets);
        }
Exemple #11
0
        /// <summary>
        /// Purges a dataset, which means the dataset and all its versions will be physically removed from the database.
        /// </summary>
        /// <param name="id">the identifier of the dataset to be purged.</param>
        /// <remarks>This operation is not revocerable.</remarks>
        /// <returns></returns>
        public ActionResult Purge(long id)
        {
            ViewBag.Title = PresentationModel.GetViewTitleForTenant("Purge", this.Session.GetTenant());
            bool itsFine = false;
            DatasetManager dm = new DatasetManager();
            try
            {
                if (dm.PurgeDataset(id))
                {
                    itsFine = true;
                }
            }
            catch (Exception ex)
            {
                try // give it another try
                {
                    if (dm.PurgeDataset(id, true))
                    {
                        itsFine = true;
                    }
                }
                catch (Exception exx)
                {
                    ViewData.ModelState.AddModelError("", string.Format("Dataset {0} could not be purged. Details: {1}, see also: {2}", id, exx.Message, ex.Message));
                }
            }

            if (itsFine)
            {
                try
                {
                    PermissionManager pm = new PermissionManager();
                    pm.DeleteDataPermissionsByEntity(1, id);
                }
                catch
                {
                    ViewData.ModelState.AddModelError("", string.Format("Dataset {0} was purged, but its permissions were not altered. You need to remove them manually from the data permission management.", id));
                }
                try
                {
                    ISearchProvider provider = IoCFactory.Container.ResolveForSession<ISearchProvider>() as ISearchProvider;
                    provider?.UpdateSingleDatasetIndex(id, IndexingAction.DELETE);
                }
                catch
                {
                    ViewData.ModelState.AddModelError("", string.Format("Dataset {0} was purged, but it is still indexed for searching. You need to reindex the search via the managemnet console.", id));
                }
            }
            return View();
        }
Exemple #12
0
        public ActionResult Register(AccountRegisterModel model)
        {
            if (ModelState.IsValid)
            {
                SubjectManager subjectManager = new SubjectManager();

                User user = subjectManager.CreateUser(model.Username, model.Password, model.FullName, model.Email, model.SecurityQuestion, model.SecurityAnswer, model.AuthenticatorList.Id);
                LoggerFactory.LogData(user.Id.ToString(), typeof(User).Name, Vaiona.Entities.Logging.CrudState.Created);

                // Feature
                FeatureManager featureManager = new FeatureManager();
                Feature feature = featureManager.FeaturesRepo.Get(f => f.Name == "Search").FirstOrDefault();

                // Permissions
                PermissionManager permissionManager = new PermissionManager();
                permissionManager.CreateFeaturePermission(user.Id, feature.Id);

                FormsAuthentication.SetAuthCookie(model.Username, false);
                return Json(new { success = true });
            }

            return PartialView("_RegisterPartial", model);
        }
Exemple #13
0
 private void testSecuirty()
 {
     PermissionManager pManager = new PermissionManager();
     //var user = pManager.UsersRepo.Get(3); // Roman
     //var the = pManager.UsersRepo.Refresh(user.Id);
     //var the2 = pManager.UsersRepo.Reload(user);
 }
        public List<ListViewItem> LoadDatasetViewList()
        {
            PermissionManager pm = new PermissionManager();
            SubjectManager subjectManager = new SubjectManager();
            DatasetManager datasetManager = new DatasetManager();
            List<ListViewItem> temp = new List<ListViewItem>();

            //get all datasetsid where the current userer has access to
            long userid = -1;
            if (subjectManager.ExistsUsername(GetUsernameOrDefault()))
                userid = subjectManager.GetUserByName(GetUsernameOrDefault()).Id;

            if (userid != -1)
            {
                foreach (long id in pm.GetAllDataIds(userid, 1, RightType.Update))
                {
                    if (datasetManager.IsDatasetCheckedIn(id))
                    {
                        string title = XmlDatasetHelper.GetInformation(id, NameAttributeValues.title);
                        string description = XmlDatasetHelper.GetInformation(id, NameAttributeValues.description);

                        temp.Add(new ListViewItem(id, title, description));
                    }
                }
            }

            return temp.OrderBy(p => p.Title).ToList();
        }
        public bool SetFeaturePublicity(long featureId, bool value)
        {
            FeatureManager featureManager = new FeatureManager();
            PermissionManager permissionManager = new PermissionManager();
            SubjectManager subjectManager = new SubjectManager();

            Feature feature = featureManager.GetFeatureById(featureId);

            if (feature != null)
            {
                if (value)
                {
                    permissionManager.CreateFeaturePermission(subjectManager.GetGroupByName("everyone").Id, feature.Id);
                }
                else
                {
                    permissionManager.DeleteFeaturePermission(subjectManager.GetGroupByName("everyone").Id, feature.Id);
                }

                return true;
            }

            return false;
        }
        public ActionResult Subjects_Select(long id)
        {
            FeatureManager featureManager = new FeatureManager();

            // DATA
            Feature feature = featureManager.GetFeatureById(id);

            List<FeaturePermissionGridRowModel> featurePermissions = new List<FeaturePermissionGridRowModel>();

            if (feature != null)
            {
                PermissionManager permissionManager = new PermissionManager();
                SubjectManager subjectManager = new SubjectManager();

                IQueryable<Subject> data = subjectManager.GetAllSubjects();

                data.ToList().ForEach(s => featurePermissions.Add(FeaturePermissionGridRowModel.Convert(s, feature, permissionManager.GetFeaturePermissionType(s.Id, feature.Id), permissionManager.HasSubjectFeatureAccess(s.Id, feature.Id))));
            }

            return View(new GridModel<FeaturePermissionGridRowModel> { Data = featurePermissions });
        }
        /// <summary>
        /// Submit a Dataset based on the imformations
        /// in the CreateTaskManager
        /// </summary>
        public long SubmitDataset()
        {
            #region create dataset

            TaskManager = (CreateTaskmanager)Session["CreateDatasetTaskmanager"];

            if (TaskManager.Bus.ContainsKey(CreateTaskmanager.DATASTRUCTURE_ID)
                && TaskManager.Bus.ContainsKey(CreateTaskmanager.RESEARCHPLAN_ID)
                && TaskManager.Bus.ContainsKey(CreateTaskmanager.METADATASTRUCTURE_ID))
            {
                DatasetManager dm = new DatasetManager();
                long datasetId = 0;
                // for e new dataset
                if (!TaskManager.Bus.ContainsKey(CreateTaskmanager.ENTITY_ID))
                {
                    long datastructureId = Convert.ToInt64(TaskManager.Bus[CreateTaskmanager.DATASTRUCTURE_ID]);
                    long researchPlanId = Convert.ToInt64(TaskManager.Bus[CreateTaskmanager.RESEARCHPLAN_ID]);
                    long metadataStructureId = Convert.ToInt64(TaskManager.Bus[CreateTaskmanager.METADATASTRUCTURE_ID]);

                    DataStructureManager dsm = new DataStructureManager();

                    DataStructure dataStructure = dsm.StructuredDataStructureRepo.Get(datastructureId);
                    //if datastructure is not a structured one
                    if (dataStructure == null) dataStructure = dsm.UnStructuredDataStructureRepo.Get(datastructureId);

                    ResearchPlanManager rpm = new ResearchPlanManager();
                    ResearchPlan rp = rpm.Repo.Get(researchPlanId);

                    MetadataStructureManager msm = new MetadataStructureManager();
                    MetadataStructure metadataStructure = msm.Repo.Get(metadataStructureId);

                    var ds = dm.CreateEmptyDataset(dataStructure, rp, metadataStructure);
                    datasetId = ds.Id;

                    // add security
                    if (GetUsernameOrDefault() != "DEFAULT")
                    {
                        PermissionManager pm = new PermissionManager();
                        SubjectManager sm = new SubjectManager();

                        BExIS.Security.Entities.Subjects.User user = sm.GetUserByName(GetUsernameOrDefault());

                        foreach (RightType rightType in Enum.GetValues(typeof(RightType)).Cast<RightType>())
                        {
                            pm.CreateDataPermission(user.Id, 1, ds.Id, rightType);
                        }
                    }

                }
                else
                {
                    datasetId = Convert.ToInt64(TaskManager.Bus[CreateTaskmanager.ENTITY_ID]);
                }

                TaskManager = (CreateTaskmanager)Session["CreateDatasetTaskmanager"];

                if (dm.IsDatasetCheckedOutFor(datasetId, GetUsernameOrDefault()) || dm.CheckOutDataset(datasetId, GetUsernameOrDefault()))
                {
                    DatasetVersion workingCopy = dm.GetDatasetWorkingCopy(datasetId);

                    if (TaskManager.Bus.ContainsKey(CreateTaskmanager.METADATA_XML))
                    {
                        XDocument xMetadata = (XDocument)TaskManager.Bus[CreateTaskmanager.METADATA_XML];
                        workingCopy.Metadata = XmlMetadataWriter.ToXmlDocument(xMetadata);
                    }

                    string title = XmlDatasetHelper.GetInformation(workingCopy, NameAttributeValues.title);
                    if(String.IsNullOrEmpty(title)) title = "No Title available.";

                    TaskManager.AddToBus(CreateTaskmanager.ENTITY_TITLE, title );//workingCopy.Metadata.SelectNodes("Metadata/Description/Description/Title/Title")[0].InnerText);
                    TaskManager.AddToBus(CreateTaskmanager.ENTITY_ID, datasetId);

                    dm.EditDatasetVersion(workingCopy, null, null, null);
                    dm.CheckInDataset(datasetId, "Metadata was submited.", GetUsernameOrDefault());

                    //add to index
                    // ToDo check which SearchProvider it is, default luceneprovider
                    ISearchProvider provider = IoCFactory.Container.ResolveForSession<ISearchProvider>() as ISearchProvider;
                    provider?.UpdateSingleDatasetIndex(datasetId, IndexingAction.CREATE);

                    LoggerFactory.LogData(datasetId.ToString(), typeof(Dataset).Name, Vaiona.Entities.Logging.CrudState.Created);

                }

                return datasetId;
            }

            #endregion

            return -1;
        }
Exemple #18
0
        public ActionResult _CustomMyDatasetBinding()
        {
            DataTable model = new DataTable();

            ViewData["PageSize"] = 10;
            ViewData["CurrentPage"] = 1;

            #region header
            List<HeaderItem> headerItems = new List<HeaderItem>();

            HeaderItem headerItem = new HeaderItem()
            {
                Name = "ID",
                DisplayName = "ID",
                DataType = "Int64"
            };
            headerItems.Add(headerItem);

            ViewData["Id"] = headerItem;

            headerItem = new HeaderItem()
            {
                Name = "Title",
                DisplayName = "Title",
                DataType = "String"
            };
            headerItems.Add(headerItem);

            headerItem = new HeaderItem()
            {
                Name = "Description",
                DisplayName = "Description",
                DataType = "String"
            };
            headerItems.Add(headerItem);

            headerItem = new HeaderItem()
            {
                Name = "View",
                DisplayName = "View",
                DataType = "String"
            };
            headerItems.Add(headerItem);

            headerItem = new HeaderItem()
            {
                Name = "Update",
                DisplayName = "Update",
                DataType = "String"
            };
            headerItems.Add(headerItem);

            headerItem = new HeaderItem()
            {
                Name = "Delete",
                DisplayName = "Delete",
                DataType = "String"
            };
            headerItems.Add(headerItem);

            headerItem = new HeaderItem()
            {
                Name = "Download",
                DisplayName = "Download",
                DataType = "String"
            };
            headerItems.Add(headerItem);

            headerItem = new HeaderItem()
            {
                Name = "Grant",
                DisplayName = "Grant",
                DataType = "String"
            };
            headerItems.Add(headerItem);

            ViewData["DefaultHeaderList"] = headerItems;

            #endregion

            model = CreateDataTable(headerItems);

            DatasetManager datasetManager = new DatasetManager();
            PermissionManager permissionManager = new PermissionManager();
            SubjectManager subjectManager = new SubjectManager();

            List<long> gridCommands = datasetManager.GetDatasetLatestIds();
            gridCommands.Skip(Convert.ToInt16(ViewData["CurrentPage"])).Take(Convert.ToInt16(ViewData["PageSize"]));

            foreach (long datasetId in gridCommands)
            {
                //get permissions
                List<int> rights = permissionManager.GetAllRights(subjectManager.GetUserByName(GetUsernameOrDefault()).Id, 1, datasetId).ToList();

                if (rights.Count > 0)
                {
                    DataRow dataRow = model.NewRow();
                    Object[] rowArray = new Object[8];

                    if (datasetManager.IsDatasetCheckedIn(datasetId))
                    {
                        DatasetVersion dsv = datasetManager.GetDatasetLatestVersion(datasetId);

                        MetadataStructureManager msm = new MetadataStructureManager();
                        dsv.Dataset.MetadataStructure = msm.Repo.Get(dsv.Dataset.MetadataStructure.Id);

                        string title = XmlDatasetHelper.GetInformation(dsv, NameAttributeValues.title);
                        string description = XmlDatasetHelper.GetInformation(dsv, NameAttributeValues.description);

                        rowArray[0] = Convert.ToInt64(datasetId);
                        rowArray[1] = title;
                        rowArray[2] = description;
                    }
                    else
                    {
                        rowArray[0] = Convert.ToInt64(datasetId);
                        rowArray[1] = "";
                        rowArray[2] = "Dataset is just in processing.";
                    }

                    if (rights.Contains(1))
                    {
                        rowArray[3] = "✔";
                    }
                    else
                    {
                        rowArray[3] = "✘";
                    }
                    if (rights.Contains(2))
                    {
                        rowArray[4] = "✔";
                    }
                    else
                    {
                        rowArray[4] = "✘";
                    }
                    if (rights.Contains(3))
                    {
                        rowArray[5] = "✔";
                    }
                    else
                    {
                        rowArray[5] = "✘";
                    }
                    if (rights.Contains(4))
                    {
                        rowArray[6] = "✔";
                    }
                    else
                    {
                        rowArray[6] = "✘";
                    }
                    if (rights.Contains(5))
                    {
                        rowArray[7] = "✔";
                    }
                    else
                    {
                        rowArray[7] = "✘";
                    }

                    dataRow = model.NewRow();
                    dataRow.ItemArray = rowArray;
                    model.Rows.Add(dataRow);
                }
            }

            return View(new GridModel(model));
        }
Exemple #19
0
        private static void createSecuritySeedData()
        {
            #region Security

            // Authenticators
            AuthenticatorManager authenticatorManager = new AuthenticatorManager();

            Authenticator a1 = authenticatorManager.CreateAuthenticator("local", "BExIS.Security.Services.Authentication.BuiltInAuthenticationManager", "BExIS.Security.Services", "", AuthenticatorType.Internal);
            Authenticator a2 = authenticatorManager.CreateAuthenticator("ldap test server", "BExIS.Security.Services.Authentication.LdapAuthenticationManager", "BExIS.Security.Services", "ldapHost:ldap.forumsys.com;ldapPort:389;ldapBaseDn:dc=example,dc=com;ldapSecure:false;ldapAuthUid:uid;ldapProtocolVersion:3", AuthenticatorType.External);

            // Security Questions
            SecurityQuestionManager securityQuestionManager = new SecurityQuestionManager();

            SecurityQuestion sq1 = securityQuestionManager.CreateSecurityQuestion("What is the first name of the person you first kissed?");
            SecurityQuestion sq2 = securityQuestionManager.CreateSecurityQuestion("What was your favorite place to visit as a child?");
            SecurityQuestion sq3 = securityQuestionManager.CreateSecurityQuestion("What is the name of the place your wedding reception was held?");
            SecurityQuestion sq4 = securityQuestionManager.CreateSecurityQuestion("In what city or town did you meet your spouse/partner?");
            SecurityQuestion sq5 = securityQuestionManager.CreateSecurityQuestion("What was the make and model of your first car?");
            SecurityQuestion sq6 = securityQuestionManager.CreateSecurityQuestion("What was the name of your first teacher?");
            SecurityQuestion sq7 = securityQuestionManager.CreateSecurityQuestion("What is the name of your best friend from childhood?");
            SecurityQuestion sq8 = securityQuestionManager.CreateSecurityQuestion("What color was your first bycicle?");
            SecurityQuestion sq9 = securityQuestionManager.CreateSecurityQuestion("What was the first name of your manager at your first job?");
            SecurityQuestion sq10 = securityQuestionManager.CreateSecurityQuestion("What was the name of your first pet?");
            SecurityQuestion sq11 = securityQuestionManager.CreateSecurityQuestion("What was the name of your elementary/primary school?");

            // Entities
            EntityManager entityManager = new EntityManager();

            entityManager.CreateEntity("Dataset", "BExIS.Dlm.Entities.Data.Dataset", "BExIS.Dlm.Entities",true,true);

            // Subjects
            SubjectManager subjectManager = new SubjectManager();

            Group everyone = subjectManager.CreateGroup("everyone", "everyone group", true);

            Group g1 = subjectManager.CreateGroup("Admin", "Admin");

            User u1 = subjectManager.CreateUser("Administrator", "gWg2xG", "Admin", "*****@*****.**", sq1.Id, "Nothing", a1.Id);

            subjectManager.AddUserToGroup(u1.Id, g1.Id);

            // Tasks
            TaskManager taskManager = new TaskManager();

            taskManager.CreateTask("SAM", "Account", "*");
            taskManager.CreateTask("Site", "Nav", "*");
            taskManager.CreateTask("Shell", "Home", "*");
            taskManager.CreateTask("System", "Utils", "*");
            taskManager.CreateTask("DCM", "Help", "*");
            taskManager.CreateTask("DDM", "Help", "*");
            taskManager.CreateTask("DIM", "Help", "*");
            taskManager.CreateTask("RPM", "Help", "*");
            taskManager.CreateTask("SAM", "Help", "*");
            taskManager.CreateTask("Site", "ContactUs", "*");
            taskManager.CreateTask("Site", "Impressum", "*");
            taskManager.CreateTask("Site", "PrivacyPolicy", "*");
            taskManager.CreateTask("Site", "Terms", "*");

            //generic form for metadata
            taskManager.CreateTask("DCM", "Form", "*");

            // Features
            FeatureManager featureManager = new FeatureManager();
            Feature f1 = featureManager.CreateFeature("BExIS", "BExIS");
            Feature f9 = featureManager.CreateFeature("Search", "Search", f1.Id);

            #region Data Planning

            Feature f18 = featureManager.CreateFeature("Data Planning Management", "Data Planning Management", f1.Id);
            Feature f13 = featureManager.CreateFeature("Datastructure Management", "Datastructure Management", f18.Id);

            #endregion

            #region Data Dissemination

            Feature f16 = featureManager.CreateFeature("Data Dissemination", "Data Dissemination", f1.Id);

            #endregion

            #region Data Collection

            Feature f10 = featureManager.CreateFeature("Data Collection", "Data Collection", f1.Id);
            Feature f11 = featureManager.CreateFeature("Dataset Creation", "Dataset Creation", f10.Id);
            Feature f12 = featureManager.CreateFeature("Dataset Upload", "Dataset Upload", f10.Id);
            Feature f17 = featureManager.CreateFeature("Metadata Management", "Metadata Management", f10.Id);
            #endregion

            #region admin

            Feature f2 = featureManager.CreateFeature("Administration", "Administration", f1.Id);
            Feature f3 = featureManager.CreateFeature("Users Management", "Users Management", f2.Id);
            Feature f4 = featureManager.CreateFeature("Groups Management", "Groups Management", f2.Id);
            Feature f6 = featureManager.CreateFeature("Feature Permissions", "Feature Permissions", f2.Id);
            Feature f5 = featureManager.CreateFeature("Data Permissions", "Data Permissions", f2.Id);
            Feature f7 = featureManager.CreateFeature("Search Management", "Search Management", f2.Id);
            Feature f8 = featureManager.CreateFeature("Dataset Maintenance", "Dataset Maintenance", f2.Id);

            #endregion

            Task t1 = taskManager.CreateTask("SAM", "Users", "*");
            t1.Feature = f3;
            taskManager.UpdateTask(t1);
            Task t2 = taskManager.CreateTask("SAM", "Groups", "*");
            t2.Feature = f4;
            taskManager.UpdateTask(t2);
            Task t3 = taskManager.CreateTask("SAM", "DataPermissions", "*");
            t3.Feature = f5;
            taskManager.UpdateTask(t3);
            Task t4 = taskManager.CreateTask("SAM", "FeaturePermissions", "*");
            t4.Feature = f6;
            taskManager.UpdateTask(t4);
            Task t5 = taskManager.CreateTask("DDM", "Admin", "*");
            t5.Feature = f7;
            taskManager.UpdateTask(t5);

            Task t7 = taskManager.CreateTask("DDM", "Data", "*");
            t7.Feature = f9;
            taskManager.UpdateTask(t7);
            Task t8 = taskManager.CreateTask("DDM", "Home", "*");
            t8.Feature = f9;
            taskManager.UpdateTask(t8);
            Task t33 = taskManager.CreateTask("DDM", "CreateDataset", "*");
            t33.Feature = f9;
            taskManager.UpdateTask(t33);

            Task t9 = taskManager.CreateTask("DCM", "CreateDataset", "*");
            t9.Feature = f11;
            taskManager.UpdateTask(t9);
            Task t10 = taskManager.CreateTask("DCM", "CreateSelectDatasetSetup", "*");
            t10.Feature = f11;
            taskManager.UpdateTask(t10);
            Task t11 = taskManager.CreateTask("DCM", "CreateSetMetadataPackage", "*");
            t11.Feature = f11;
            taskManager.UpdateTask(t11);
            Task t12 = taskManager.CreateTask("DCM", "CreateSummary", "*");
            t12.Feature = f11;
            taskManager.UpdateTask(t12);

            Task t15 = taskManager.CreateTask("DCM", "Push", "*");
            t15.Feature = f12;
            taskManager.UpdateTask(t15);
            Task t16 = taskManager.CreateTask("DCM", "Submit", "*");
            t16.Feature = f12;
            taskManager.UpdateTask(t16);
            Task t17 = taskManager.CreateTask("DCM", "SubmitDefinePrimaryKey", "*");
            t17.Feature = f12;
            taskManager.UpdateTask(t17);
            Task t18 = taskManager.CreateTask("DCM", "SubmitGetFileInformation", "*");
            t18.Feature = f12;
            taskManager.UpdateTask(t18);
            Task t19 = taskManager.CreateTask("DCM", "SubmitSelectAFile", "*");
            t19.Feature = f12;
            taskManager.UpdateTask(t19);
            Task t20 = taskManager.CreateTask("DCM", "SubmitSpecifyDataset", "*");
            t20.Feature = f12;
            taskManager.UpdateTask(t20);
            Task t21 = taskManager.CreateTask("DCM", "SubmitSummary", "*");
            t21.Feature = f12;
            taskManager.UpdateTask(t21);
            Task t22 = taskManager.CreateTask("DCM", "SubmitValidation", "*");
            t22.Feature = f12;
            taskManager.UpdateTask(t22);

            Task t23 = taskManager.CreateTask("RPM", "Home", "*");
            t23.Feature = f18;
            taskManager.UpdateTask(t23);
            Task t24 = taskManager.CreateTask("RPM", "DataAttribute", "*");
            t24.Feature = f18;
            taskManager.UpdateTask(t24);
            Task t25 = taskManager.CreateTask("RPM", "Unit", "*");
            t25.Feature = f18;
            taskManager.UpdateTask(t25);

            Task t26 = taskManager.CreateTask("DIM", "Admin", "*");
            t26.Feature = f16;
            taskManager.UpdateTask(t26);

            Task t27 = taskManager.CreateTask("DCM", "ImportMetadataStructure", "*");
            t27.Feature = f17;
            taskManager.UpdateTask(t27);

            Task t28 = taskManager.CreateTask("DCM", "ImportMetadataStructureReadSource", "*");
            t28.Feature = f17;
            taskManager.UpdateTask(t28);

            Task t29 = taskManager.CreateTask("DCM", "ImportMetadataStructureSelectAFile", "*");
            t29.Feature = f17;
            taskManager.UpdateTask(t29);

            Task t30 = taskManager.CreateTask("DCM", "ImportMetadataStructureSetParameters", "*");
            t30.Feature = f17;
            taskManager.UpdateTask(t30);

            Task t31 = taskManager.CreateTask("DCM", "ImportMetadataStructureSummary", "*");
            t31.Feature = f17;
            taskManager.UpdateTask(t31);

            Task t32 = taskManager.CreateTask("SAM", "Dataset", "*");
            t32.Feature = f8;
            taskManager.UpdateTask(t32);

            Task t35 = taskManager.CreateTask("RPM", "DataStructureSearch", "*");
            t35.Feature = f13;
            taskManager.UpdateTask(t35);

            Task t36 = taskManager.CreateTask("RPM", "DataStructureEdit", "*");
            t36.Feature = f13;
            taskManager.UpdateTask(t36);

            Task t37 = taskManager.CreateTask("RPM", "DataStructureIO", "*");
            t37.Feature = f13;
            taskManager.UpdateTask(t37);

            Task t38 = taskManager.CreateTask("DCM", "ManageMetadataStructure", "*");
            t38.Feature = f17;
            taskManager.UpdateTask(t38);

            // Feature Permissions
            PermissionManager permissionManager = new PermissionManager();
            permissionManager.CreateFeaturePermission(g1.Id, f1.Id);
            //permissionManager.CreateFeaturePermission(everyone.Id, f9.Id);

            #endregion Security
        }
        public DataPermission CreateDataPermission(long subjectId, long entityId, long dataId, int rightType)
        {
            PermissionManager permissionManager = new PermissionManager();

            return permissionManager.CreateDataPermission(subjectId, entityId, dataId, (RightType)rightType);
        }
Exemple #21
0
        public ActionResult ReloadMetadataEditor(bool locked = false, bool show = false)
        {
            ViewData["Locked"] = locked;
            ViewData["ShowOptional"] = show;

            ViewBag.Title = PresentationModel.GetViewTitleForTenant("Create Dataset", this.Session.GetTenant());
            TaskManager = (CreateTaskmanager)Session["CreateDatasetTaskmanager"];
            List<StepModelHelper> stepInfoModelHelpers = new List<StepModelHelper>();

            foreach (var stepInfo in TaskManager.StepInfos)
            {

                StepModelHelper stepModelHelper = GetStepModelhelper(stepInfo.Id);

                if (stepModelHelper.Model == null)
                {
                    if (stepModelHelper.Usage is MetadataPackageUsage)
                        stepModelHelper.Model = CreatePackageModel(stepInfo.Id, false);

                    if (stepModelHelper.Usage is MetadataNestedAttributeUsage)
                        stepModelHelper.Model = CreateCompoundModel(stepInfo.Id, false);

                    getChildModelsHelper(stepModelHelper);
                }

                stepInfoModelHelpers.Add(stepModelHelper);

            }

            MetadataEditorModel Model = new MetadataEditorModel();
            Model.StepModelHelpers = stepInfoModelHelpers;

            #region security permissions and authorisations check
            // set edit rigths
            PermissionManager permissionManager = new PermissionManager();
            SubjectManager subjectManager = new SubjectManager();
            Security.Services.Objects.TaskManager securityTaskManager = new Security.Services.Objects.TaskManager();

            bool hasAuthorizationRights = false;
            bool hasAuthenticationRigths = false;

            User user = subjectManager.GetUserByName(GetUsernameOrDefault());
            long userid = -1;
            long entityId = -1;

            if (TaskManager.Bus.ContainsKey(CreateTaskmanager.ENTITY_ID))
            {
                entityId = Convert.ToInt64(TaskManager.Bus[CreateTaskmanager.ENTITY_ID]);
                Model.EditRight = hasUserEditRights(entityId);
                Model.EditAccessRight = hasUserEditAccessRights(entityId);

            }
            else
            {
                Model.EditRight = false;
                Model.EditAccessRight = false;
            }

            Model.FromEditMode = true;

            if (TaskManager.Bus.ContainsKey(CreateTaskmanager.METADATASTRUCTURE_ID))
            {
                long metadataStructureId = Convert.ToInt64(TaskManager.Bus[CreateTaskmanager.METADATASTRUCTURE_ID]);
                Model.Import = IsImportAvavilable(metadataStructureId);
            }

            #endregion
            //set addtionaly functions
            Model.Actions = getAddtionalActions();

            return PartialView("MetadataEditor", Model);
        }
Exemple #22
0
        public List<ListViewItem> LoadDatasetVersionViewList( DataStructureType dataStructureType)
        {
            PermissionManager permissionManager = new PermissionManager();
                SubjectManager subjectManager = new SubjectManager();

                // add security
                ICollection<long> datasetIDs = permissionManager.GetAllDataIds(subjectManager.GetUserByName(GetUsernameOrDefault()).Id, 1, RightType.Update).ToList();

                DataStructureManager dataStructureManager = new DataStructureManager();
                DatasetManager dm = new DatasetManager();

                Dictionary<long, XmlDocument> dmtemp = new Dictionary<long, XmlDocument>();
                dmtemp = dm.GetDatasetLatestMetadataVersions();

                List<ListViewItem> temp = new List<ListViewItem>();

                if (dataStructureType.Equals(DataStructureType.Structured))
                {
                    List<StructuredDataStructure> list = dataStructureManager.StructuredDataStructureRepo.Get().ToList();

                    foreach (StructuredDataStructure sds in list)
                    {
                        sds.Materialize();

                        foreach (Dataset d in sds.Datasets)
                        {
                            if (dm.IsDatasetCheckedIn(d.Id))
                            {
                                if (datasetIDs.Contains(d.Id))
                                {
                                    temp.Add(new ListViewItem(d.Id,
                                        XmlDatasetHelper.GetInformation(dm.GetDatasetLatestVersion(d),
                                            NameAttributeValues.title)));
                                }
                            }
                        }
                    }

                }
                else
                {
                    List<UnStructuredDataStructure> list = dataStructureManager.UnStructuredDataStructureRepo.Get().ToList();

                    foreach (UnStructuredDataStructure sds in list)
                    {
                        foreach (Dataset d in sds.Datasets)
                        {
                            if (datasetIDs.Contains(d.Id))
                            {
                                if (dm.IsDatasetCheckedIn(d.Id))
                                {
                                    DatasetVersion datasetVersion = dm.GetDatasetLatestVersion(d);
                                    temp.Add(new ListViewItem(d.Id,
                                        XmlDatasetHelper.GetInformation(datasetVersion, NameAttributeValues.title)));
                                }
                            }
                        }
                    }
                }

               return temp.OrderBy(p => p.Title).ToList();
        }
Exemple #23
0
        // set feature permission of the group "bexisUser"
        public void SetFeaturePermissions(long groupId, string[] featureNames)
        {
            FeatureManager featureManager = new FeatureManager();
            PermissionManager permissionManager = new PermissionManager();

            // never set administration features (this parent Id)
            long parentId = featureManager.FeaturesRepo.Get().Where(f => f.Name.Equals("Administration")).FirstOrDefault().Id;

            for (int i = 0; i < featureNames.Length; i++)
            {
                long featureId = featureManager.FeaturesRepo.Get(f => featureNames[i].Equals(f.Name) && !f.Parent.Id.Equals(parentId)).FirstOrDefault().Id;
                permissionManager.CreateFeaturePermission(groupId, featureId);
            }
        }
Exemple #24
0
        public long createDataset(string dataSetID, XmlDocument metadataXml, long metadataStructureId, DataStructure dataStructure, string researchPlanName)
        {
            Dataset dataset = new Dataset();

            DatasetManager datasetManager = new DatasetManager();
            DataStructureManager dataStructureManager = new DataStructureManager();
            ResearchPlanManager researchPlanManager = new ResearchPlanManager();
            MetadataStructureManager metadataStructureManager = new MetadataStructureManager();
            PermissionManager permissionManager = new PermissionManager();
            SubjectManager subjectManager = new SubjectManager();

            // get existing researchPlan
            ResearchPlan researchPlan = researchPlanManager.Repo.Get(r => researchPlanName.Equals(r.Title)).FirstOrDefault();

            // get existing metadataStructure (created manualy by using edited Bexis1_XSD)
            MetadataStructure metadataStructure = metadataStructureManager.Repo.Get(metadataStructureId);

            // update verwendet, da bei unstructured structures im dataset constructor dataset(dataStructure) nullexception
            dataset = datasetManager.CreateEmptyDataset(dataStructure, researchPlan, metadataStructure);
            long datasetId = dataset.Id;

            // dataPermission
            List<string> usersWithDataPerm = new List<string>();

            // create dataPermission for originalDatasetManager
            string originalDatasetManager = metadataXml.SelectSingleNode("Metadata/general/general/originalDatasetManager/originalDatasetManager").InnerText;
            User userODM = subjectManager.UsersRepo.Get(u => originalDatasetManager.Equals(u.FullName)).FirstOrDefault();
            permissionManager.CreateDataPermission(userODM.Id, 1, dataset.Id, RightType.Create);
            permissionManager.CreateDataPermission(userODM.Id, 1, dataset.Id, RightType.View);
            permissionManager.CreateDataPermission(userODM.Id, 1, dataset.Id, RightType.Update);
            permissionManager.CreateDataPermission(userODM.Id, 1, dataset.Id, RightType.Download);
            usersWithDataPerm.Add(originalDatasetManager);

            // create dataPermissions for metadataAuthor
            string metadataAuthor = metadataXml.SelectSingleNode("Metadata/general/general/metadataCreator/metadataCreator").InnerText;
            if (!usersWithDataPerm.Contains(metadataAuthor))
            {
                User userMA = subjectManager.UsersRepo.Get(u => metadataAuthor.Equals(u.FullName)).FirstOrDefault();
                permissionManager.CreateDataPermission(userMA.Id, 1, dataset.Id, RightType.Create);
                permissionManager.CreateDataPermission(userMA.Id, 1, dataset.Id, RightType.View);
                permissionManager.CreateDataPermission(userMA.Id, 1, dataset.Id, RightType.Update);
                permissionManager.CreateDataPermission(userMA.Id, 1, dataset.Id, RightType.Download);
                usersWithDataPerm.Add(metadataAuthor);
            }

            // create dataPermissions for designatedDatasetManager
            string designatedDatasetManager = metadataXml.SelectSingleNode("Metadata/general/general/designatedDatasetManager/contactType/designatedDatasetManagerName/designatedDatasetManagerName").InnerText;
            if (!usersWithDataPerm.Contains(designatedDatasetManager))
            {
                User userDDM = subjectManager.UsersRepo.Get(u => designatedDatasetManager.Equals(u.FullName)).FirstOrDefault();
                permissionManager.CreateDataPermission(userDDM.Id, 1, dataset.Id, RightType.Create);
                permissionManager.CreateDataPermission(userDDM.Id, 1, dataset.Id, RightType.View);
                permissionManager.CreateDataPermission(userDDM.Id, 1, dataset.Id, RightType.Update);
                permissionManager.CreateDataPermission(userDDM.Id, 1, dataset.Id, RightType.Download);
                usersWithDataPerm.Add(designatedDatasetManager);
            }

            // create dataPermissions for owners
            XmlNodeList ownerNodes = metadataXml.SelectNodes("Metadata/general/general/owners/ownerType/owner/owner");
            foreach (XmlNode ownerNode in ownerNodes)
            {
                string owner = ownerNode.InnerText;
                if (!usersWithDataPerm.Contains(owner))
                {
                    User userO = subjectManager.UsersRepo.Get(u => owner.Equals(u.FullName)).FirstOrDefault();
                    if (userO != null)
                    {
                        permissionManager.CreateDataPermission(userO.Id, 1, dataset.Id, RightType.Create);
                        permissionManager.CreateDataPermission(userO.Id, 1, dataset.Id, RightType.View);
                        permissionManager.CreateDataPermission(userO.Id, 1, dataset.Id, RightType.Update);
                        permissionManager.CreateDataPermission(userO.Id, 1, dataset.Id, RightType.Download);
                        usersWithDataPerm.Add(owner);
                    }
                }
            }

            // integrate metadataXml to dataset
            // checkOut
            if (datasetManager.IsDatasetCheckedOutFor(datasetId, userODM.Name) || datasetManager.CheckOutDataset(datasetId, userODM.Name))
            {
                DatasetVersion workingCopy = datasetManager.GetDatasetWorkingCopy(datasetId); // get dataset
                workingCopy.Metadata = metadataXml; // set metadata to dataset
                datasetManager.EditDatasetVersion(workingCopy, null, null, null); // edit dataset
                datasetManager.CheckInDataset(datasetId, "Metadata was submited.", userODM.Name); // check in
            }

            return dataset.Id;
        }
Exemple #25
0
        public string TransferDataPermission()
        {
            SubjectManager subjectManager = new SubjectManager();
            var securityMigration = new SecurityMigration();
            Dictionary<int, int> DataSetIDs = new Dictionary<int, int>();
            var groups = subjectManager.GetAllGroups();
            string DatasetMappingPath = Path.Combine(AppConfiguration.DataPath, "DatasetMapping.txt");
            //Key is last datasetId and value is the new one
            Dictionary<int, int> DatasetsMapping = File.ReadAllLines(DatasetMappingPath).AsEnumerable().Select(item => new { oldId = int.Parse(item.Split('\t')[0]), newId = int.Parse(item.Split('\t')[1]) }).ToDictionary(c => c.oldId, c => c.newId);
            DatasetManager dm = new DatasetManager();

            PermissionManager permissionManager = new PermissionManager();
            List<SecurityMigration.Right> rights = securityMigration.GetBexisRights(DataBase, DatasetsMapping);
            foreach (var group in groups)
            {
                var groupRights = rights.Where(item => item.RoleName == group.Name || item.RoleName == "_" + group.Name);

                foreach (var right in groupRights)
                {
                    int newDataSetId = DatasetsMapping.FirstOrDefault(item => item.Key == right.DataSetId).Value;

                    //each entity wich exists in this list has view and download feature
                    permissionManager.CreateDataPermission(group.Id, 1, newDataSetId, RightType.View);
                    permissionManager.CreateDataPermission(group.Id, 1, newDataSetId, RightType.Download);

                    if (right.CanEdit)
                        permissionManager.CreateDataPermission(group.Id, 1, newDataSetId, RightType.Update);

                }
            }
            foreach (var DatasetMapping in DatasetsMapping)
            {
                //extract grant user from the last version and add it to new ver
                if (dm.GetDataset(DatasetMapping.Value) == null)
                    continue;
                DatasetVersion dsv = dm.GetDatasetLatestVersion(DatasetMapping.Value);
                string grantUserEmailAddress = dsv.Metadata.SelectSingleNode("Metadata/general/general/designatedDatasetManager/contactType/email/email").InnerText;
                if (!string.IsNullOrEmpty(grantUserEmailAddress))
                {
                    var grantUser = subjectManager.GetUserByEmail(grantUserEmailAddress);
                    permissionManager.CreateDataPermission(grantUser.Id, 1, DatasetMapping.Value, RightType.Grant);
                }
            }
            return "All of permissions transfered successfully.";
        }
        public ActionResult Subjects_Select(long dataId, long entityId)
        {
            EntityManager entityManager = new EntityManager();
            PermissionManager permissionManager = new PermissionManager();
            SubjectManager subjectManager = new SubjectManager();

            List<DataPermissionGridRowModel> subjects = new List<DataPermissionGridRowModel>();

            IQueryable<Subject> data = subjectManager.GetAllSubjects();
            data.ToList().ForEach(s => subjects.Add(DataPermissionGridRowModel.Convert(dataId, entityManager.GetEntityById(entityId), s, permissionManager.GetAllRights(s.Id, entityId, dataId).ToList())));

            return View(new GridModel<DataPermissionGridRowModel> { Data = subjects });
        }