public void AuthenticateUserCanLoadModulesAccordingToHisRoles()
        {
            IPrincipal cachedPrincipal = Thread.CurrentPrincipal;

            using (TestResourceFile resFile = new TestResourceFile(@"Services\FileCatalogReaderServiceFixtureWithRoles.xml"))
            {
                try
                {
                    GenericIdentity  identity  = new GenericIdentity("Me");
                    GenericPrincipal principal = new GenericPrincipal(identity, new string[] { "Users" });
                    Thread.CurrentPrincipal = principal;

                    SolutionProfileReader slnReader = new SolutionProfileReader(@"Services\FileCatalogReaderServiceFixtureWithRoles.xml");

                    SolutionProfileElement profile = slnReader.ReadProfile();

                    Assert.AreEqual(3, profile.Modules.Length, "The solution profile does not contains 3 modules.");
                    Assert.AreEqual("MyAssembly1.dll", profile.Modules[0].AssemblyFile, "The 1st module is not MyAssembly1.dll");
                    Assert.AreEqual("MyAssembly2.dll", profile.Modules[1].AssemblyFile, "The 2nd module is not MyAssembly2.dll");
                    Assert.AreEqual("MyAssembly4.dll", profile.Modules[2].AssemblyFile, "The 3rd module is not MyAssembly4.dll");
                }
                finally
                {
                    Thread.CurrentPrincipal = cachedPrincipal;
                }
            }
        }
        public void UnAuthenticatedUserCanLoadModulesWithoutRoles()
        {
            IPrincipal originalPrincipal = null;

            using (TestResourceFile resFile1 = new TestResourceFile(@"Services\FileCatalogReaderServiceFixtureWithRoles.xml"))
            {
                try
                {
                    originalPrincipal = Thread.CurrentPrincipal;
                    if (Thread.CurrentPrincipal.Identity.IsAuthenticated)
                    {
                        Thread.CurrentPrincipal = new GenericPrincipal(WindowsIdentity.GetCurrent(), null);
                    }
                    SolutionProfileReader slnReader =
                        new SolutionProfileReader(@"Services\FileCatalogReaderServiceFixtureWithRoles.xml");
                    SolutionProfileElement profile = slnReader.ReadProfile();

                    Assert.AreEqual(1, profile.Modules.Length, "The solution profile does not contains 1 module.");
                    Assert.AreEqual("MyAssembly1.dll", profile.Modules[0].AssemblyFile, "The 1st module is not MyAssembly1.dll");
                }
                finally
                {
                    Thread.CurrentPrincipal = originalPrincipal;
                }
            }
        }
Beispiel #3
0
        public IModuleInfo[] Parse(string xml)
        {
            SolutionProfileElement solution = XmlValidationHelper.DeserializeXml <SolutionProfileV2.SolutionProfileElement>(xml,
                                                                                                                            "SolutionProfileV2.xsd", Namespace);

            List <DependentModuleInfo> dmis = new List <DependentModuleInfo>();

            if (solution.Section != null)
            {
                foreach (SectionElement section in solution.Section)
                {
                    foreach (ModuleInfoElement moduleInfo in section.Modules)
                    {
                        DependentModuleInfo dmi = new DependentModuleInfo(moduleInfo.AssemblyFile);
                        SetModuleName(moduleInfo, dmi);
                        SetModuleRoles(moduleInfo, dmi);
                        SetSectionDependencies(solution.Section, section, dmi);
                        SetModuleDependencies(moduleInfo, dmi);
                        dmis.Add(dmi);
                    }
                }
            }

            return(dmis.ToArray());
        }
Beispiel #4
0
        /// <summary>
        /// Reads the solution profile form the specified file.
        /// </summary>
        /// <returns>An instance of <see cref="SolutionProfileElement"/>.</returns>
        public SolutionProfileElement ReadProfile()
        {
            SolutionProfileElement solution = new SolutionProfileElement();

            if (File.Exists(catalogFilePath))
            {
                try
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(SolutionProfileElement));
                    using (XmlReader reader = GetValidatingReader())
                    {
                        solution = (SolutionProfileElement)serializer.Deserialize(reader);
                        ProcessProfileRoles(solution);
                        return(solution);
                    }
                }
                catch (Exception ex)
                {
                    throw new SolutionProfileReaderException(String.Format(
                                                                 CultureInfo.CurrentCulture,
                                                                 Resources.ErrorReadingProfile,
                                                                 catalogFilePath), ex);
                }
            }
            else
            {
                ThrowIfCatalogPathNotDefault();
            }
            return(solution);
        }
Beispiel #5
0
        /// <summary>
        /// Processes the solution profile comparing the roles the user has against
        /// the roles specified on the solution profile. The list of modules in the
        /// solution profile is modified eliminating the modules the user has not
        /// access to according his/her roles.
        /// </summary>
        /// <param name="profile">The solution profile specifying the modules and
        /// the roles needed to use that modules.</param>
        private static void ProcessProfileRoles(SolutionProfileElement profile)
        {
            IPrincipal principal = Thread.CurrentPrincipal;

            List <ModuleInfoElement> permittedModules = new List <ModuleInfoElement>();

            if (profile.Modules != null)
            {
                foreach (ModuleInfoElement modInfo in profile.Modules)
                {
                    if (modInfo.Roles != null)
                    {
                        if (principal.Identity.IsAuthenticated)
                        {
                            foreach (RoleElement role in modInfo.Roles)
                            {
                                if (principal.IsInRole(role.Allow))
                                {
                                    permittedModules.Add(modInfo);
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        permittedModules.Add(modInfo);
                    }
                }
                profile.Modules = permittedModules.ToArray();
            }
        }
 public void CanLoadProfileContainingModuleWithoutUpdateLocation()
 {
     using (TestResourceFile resFile = new TestResourceFile(@"Services\FileCatalogReaderServiceFixtureModuleWithoutUpdateLocation.xml"))
     {
         SolutionProfileReader slnReader =
             new SolutionProfileReader(@"Services\FileCatalogReaderServiceFixtureModuleWithoutUpdateLocation.xml");
         SolutionProfileElement profile = slnReader.ReadProfile();
     }
 }
        public void DoesNothingIfNoCatalogIsProvidedAndDefaultOneNotExists()
        {
            SolutionProfileReader  slnReader = new SolutionProfileReader();
            SolutionProfileElement profile   = slnReader.ReadProfile();

            //An empty solutionprofile is returned.
            Assert.IsNotNull(profile);
            Assert.IsNotNull(profile.Modules);
            Assert.AreEqual(0, profile.Modules.Length);
        }
 /// <summary>
 /// Processes the solution profile and returns the list of modules specified in it.
 /// </summary>
 /// <returns>An array of <see cref="Configuration.ModuleInfo"/> instances.</returns>
 public IModuleInfo[] EnumerateModules()
 {
     try
     {
         SolutionProfileReader  reader  = new SolutionProfileReader(catalogFilePath);
         SolutionProfileElement profile = reader.ReadProfile();
         return(CreateModuleInfos(profile));
     }
     catch (Exception ex)
     {
         throw new ModuleEnumeratorException(String.Format(CultureInfo.CurrentCulture,
                                                           Properties.Resources.ErrorEnumeratingModules,
                                                           this), ex);
     }
 }
 private static IModuleInfo[] CreateModuleInfos(SolutionProfileElement solutionProfile)
 {
     ModuleInfo[] mInfos = new ModuleInfo[solutionProfile.Modules.Length];
     for (int i = 0; i < solutionProfile.Modules.Length; i++)
     {
         ModuleInfoElement xsdModule = solutionProfile.Modules[i];
         ModuleInfo        mInfo     = new ModuleInfo(xsdModule.AssemblyFile);
         mInfo.SetUpdateLocation(xsdModule.UpdateLocation);
         if (xsdModule.Roles != null && xsdModule.Roles.Length > 0)
         {
             foreach (RoleElement role in xsdModule.Roles)
             {
                 mInfo.AddRoles(role.Allow);
             }
         }
         mInfos[i] = mInfo;
     }
     return(mInfos);
 }
        public IModuleInfo[] Parse(string xml)
        {
            SolutionProfileElement solution = XmlValidationHelper.DeserializeXml <SolutionProfileV1.SolutionProfileElement>(xml,
                                                                                                                            "SolutionProfileV1.xsd", Namespace);

            List <ModuleInfo> mis = new List <ModuleInfo>();

            if (solution.Modules != null)
            {
                foreach (ModuleInfoElement moduleInfo in solution.Modules)
                {
                    ModuleInfo mi = new ModuleInfo(moduleInfo.AssemblyFile);
                    SetModuleRoles(moduleInfo, mi);
                    mis.Add(mi);
                }
            }

            return(mis.ToArray());
        }