Exemplo n.º 1
0
 public XafApplication Build()
 {
     try {
         var typesInfo = _buildTypesInfoSystem.Invoke(_moduleName);
         ReflectionHelper.AddResolvePath(_assemblyPath);
         var assembly     = ReflectionHelper.GetAssembly(Path.GetFileNameWithoutExtension(_moduleName), _assemblyPath);
         var assemblyInfo = typesInfo.FindAssemblyInfo(assembly);
         typesInfo.LoadTypes(assembly);
         var findTypeInfo        = typesInfo.FindTypeInfo(typeof(XafApplication));
         var findTypeDescendants = ReflectionHelper.FindTypeDescendants(assemblyInfo, findTypeInfo, false);
         var instance            = SecuritySystem.Instance;
         var info = XafTypesInfo.Instance;
         typesInfo.AssignAsInstance();
         var xafApplication = ((XafApplication)Enumerator.GetFirst(findTypeDescendants).CreateInstance(new object[0]));
         SecuritySystem.SetInstance(instance);
         SetConnectionString(xafApplication);
         if (!_withOutObjectSpaceProvider)
         {
             var objectSpaceProviders = ((IList <IObjectSpaceProvider>)xafApplication.GetFieldValue("objectSpaceProviders"));
             objectSpaceProviders.Add(new MyClass(xafApplication));
         }
         info.AssignAsInstance();
         return(xafApplication);
     } finally {
         ReflectionHelper.RemoveResolvePath(_assemblyPath);
     }
 }
 public override void Dispose()
 {
     if (SecuritySystem.Instance is IDisposable security)
     {
         security.Dispose();
     }
     SecuritySystem.SetInstance(null);
     base.Dispose();
 }
Exemplo n.º 3
0
        public static SecurityStrategyComplex GetSecurity(string userName)
        {
            AuthenticationStandard  authentication = new AuthenticationStandard();
            SecurityStrategyComplex security       = new SecurityStrategyComplex(typeof(PermissionPolicyUser), typeof(PermissionPolicyRole), authentication);
            //security.RegisterXPOAdapterProviders();
            string password = string.Empty;

            authentication.SetLogonParameters(new AuthenticationStandardLogonParameters(userName, password));
            SecuritySystem.SetInstance(security);
            return(security);
        }
Exemplo n.º 4
0
        protected override void OnLoggingOn(LogonEventArgs args)
        {
            MyLogonParameters parameters = (MyLogonParameters)args.LogonParameters;

            if (parameters.SecurityType == SecurityType.Complex)
            {
                ISecurity security = null;
                security = new SecurityComplex(typeof(User), typeof(Role), new AuthenticationStandard(typeof(User), parameters.GetType()));
                SecuritySystem.SetInstance(security);
                this.Security = security;
                ((MyLogonParameters)SecuritySystem.Instance.LogonParameters).UserName = parameters.UserName;
                ((MyLogonParameters)SecuritySystem.Instance.LogonParameters).Password = parameters.Password;
            }
            base.OnLoggingOn(args);
        }
Exemplo n.º 5
0
        static void Main()
        {
            XpoTypesInfoHelper.GetXpoTypeInfoSource();
            XafTypesInfo.Instance.RegisterEntity(typeof(Person));
            XafTypesInfo.Instance.RegisterEntity(typeof(PermissionPolicyUser));
            XafTypesInfo.Instance.RegisterEntity(typeof(PermissionPolicyRole));

            Console.WriteLine("Update database...");
            DataSet dataSet = new DataSet();

            Console.WriteLine("Database has been updated successfully.");

            XPObjectSpaceProvider directProvider    = new XPObjectSpaceProvider(new MemoryDataStoreProvider(dataSet));
            IObjectSpace          directObjectSpace = directProvider.CreateObjectSpace();

            UpdateDatabase(directObjectSpace);

            AuthenticationStandard  auth     = new AuthenticationStandard();
            SecurityStrategyComplex security = new SecurityStrategyComplex(typeof(PermissionPolicyUser), typeof(PermissionPolicyRole), auth);

            SecuritySystem.SetInstance(security);
            SecuredObjectSpaceProvider osProvider = new SecuredObjectSpaceProvider(security, new MemoryDataStoreProvider(dataSet));
            IObjectSpace securedObjectSpace       = osProvider.CreateObjectSpace();

            auth.SetLogonParameters(new AuthenticationStandardLogonParameters("User", ""));
            Console.WriteLine("Logging 'User' user...");
            security.Logon(directObjectSpace);
            Console.WriteLine("'User' is logged on.");
            Console.WriteLine("List of the 'Person' objects:");
            foreach (Person person in securedObjectSpace.GetObjects <Person>())
            {
                Console.WriteLine(person.FirstName);
            }

            auth.SetLogonParameters(new AuthenticationStandardLogonParameters("Admin", ""));
            Console.WriteLine("Logging 'Admin' user...");
            security.Logon(directObjectSpace);
            Console.WriteLine("Admin is logged on.");
            securedObjectSpace = osProvider.CreateObjectSpace();
            Console.WriteLine("List of the 'Person' objects:");
            foreach (Person person in securedObjectSpace.GetObjects <Person>())
            {
                Console.WriteLine(person.FirstName);
            }

            Console.WriteLine("Press enter to exit...");
            Console.ReadLine();
        }
Exemplo n.º 6
0
        private void SingleChoiceActionOnExecute(object sender, SingleChoiceActionExecuteEventArgs e)
        {
            if (e.SelectedChoiceActionItem.Id == "None")
            {
                Application.Security = new SecurityDummy();
                SecuritySystem.SetInstance(Application.Security);
//                var rootNavigationItems = ((IModelApplicationNavigationItems) Application.Model).NavigationItems;
//                var modelNavigationItems = rootNavigationItems.Items.GetItems<IModelNavigationItem>(item => item.Items);
//                var navigationItem = modelNavigationItems.First(item => item.Id=="Default");
//                navigationItem.Remove();
//                rootNavigationItems.StartupNavigationItem = modelNavigationItems.First(item => item.View == View.Model);
//                SessionSecurity = null;
//                Frame.GetController<ShowNavigationItemController>().RecreateNavigationItems();
//                Frame.GetController<LogoffController>().LogoffAction.DoExecute();
            }
        }
Exemplo n.º 7
0
 public virtual void TearDown()
 {
     SecuritySystem.SetInstance(null);
     modelApplication = null;
     CaptionHelper.Setup(null);
     testContext.Dispose();
     testContext = null;
     while (Application.OpenForms.Count != 0)
     {
         try {
             Application.OpenForms[0].Close();
         }
         catch {
         }
     }
 }
Exemplo n.º 8
0
        public IDataServerSecurity CreateAndLogonSecurity(IClientInfo clientInfo)
        {
            ApplicationServer.EnsureValueManager();
            string cacheKey = CreateCacheKey(clientInfo);
            var    result   = (IDataServerSecurity)cache.Get(cacheKey);

            if (result == null)
            {
                result = provider.CreateAndLogonSecurity(clientInfo);
                cache.Add(cacheKey, result, new CacheItemPolicy {
                    AbsoluteExpiration = DateTime.Now.AddHours(1)
                });
            }

            SecuritySystem.SetInstance(result);
            return(result);
        }
        private void SetupSecuredObjectSpaceProvider(string logonUserName)
        {
            AuthenticationStandard  authentication = new AuthenticationStandard();
            SecurityStrategyComplex security       = new SecurityStrategyComplex(typeof(UserType), typeof(RoleType), authentication);

            security.RegisterXPOAdapterProviders();
            securedObjectSpaceProvider = CreateSecuredObjectSpaceProvider(security);

            string userName = logonUserName;
            string password = string.Empty;

            authentication.SetLogonParameters(new AuthenticationStandardLogonParameters(userName, password));
            IObjectSpace loginObjectSpace = ((INonsecuredObjectSpaceProvider)securedObjectSpaceProvider).CreateNonsecuredObjectSpace();

            security.Logon(loginObjectSpace);

            SecuritySystem.SetInstance(security);
        }
Exemplo n.º 10
0
 public XafApplication Build()
 {
     try {
         var typesInfo = _buildTypesInfoSystem.Invoke(_moduleName);
         ReflectionHelper.AddResolvePath(_assemblyPath);
         var assembly     = ReflectionHelper.GetAssembly(Path.GetFileNameWithoutExtension(_moduleName), _assemblyPath);
         var assemblyInfo = typesInfo.FindAssemblyInfo(assembly);
         typesInfo.LoadTypes(assembly);
         var findTypeInfo        = typesInfo.FindTypeInfo(typeof(XafApplication));
         var findTypeDescendants = ReflectionHelper.FindTypeDescendants(assemblyInfo, findTypeInfo, false);
         var instance            = SecuritySystem.Instance;
         var xafApplication      = ((XafApplication)Enumerator.GetFirst(findTypeDescendants).CreateInstance(new object[0]));
         SecuritySystem.SetInstance(instance);
         if (ConfigurationManager.ConnectionStrings["ConnectionString"] != null)
         {
             ((ISupportFullConnectionString)xafApplication).ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
         }
         return(xafApplication);
     } finally {
         ReflectionHelper.RemoveResolvePath(_assemblyPath);
     }
 }