Exemplo n.º 1
0
        private bool AzManTestCheckAccess()
        {
            WindowsIdentity identity        = WindowsIdentity.GetCurrent();
            string          applicationName = "Application Test";

            string[]                  operations             = new string[] { this.txtOperation.Text };
            HybridDictionary          businessRuleParameters = new HybridDictionary();
            AzAuthorizationStoreClass store = new AzAuthorizationStoreClass();

            store.Initialize(0, AzManStorePath, null);
            IAzApplication   azApp     = store.OpenApplication(applicationName, null);
            IAzClientContext clientCtx = azApp.InitializeClientContextFromToken((UInt64)identity.Token, null);

            // costruisce il vettore dei valori e dei delle regole di business
            Object[] names        = new Object[0];
            Object[] values       = new Object[0];
            Object[] operationIds = new Object[operations.Length];
            for (Int32 index = 0; index < operations.Length; index++)
            {
                operationIds[index] = azApp.OpenOperation(operations[index], null).OperationID;
            }
            Object[] internalScopes = new Object[1];
            Object[] result         = (Object[])clientCtx.AccessCheck("AuditString", internalScopes, operationIds, names, values, null, null, null);
            foreach (Int32 accessAllowed in result)
            {
                if (accessAllowed != 0)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        private object[] GetTaskOperations(AzManAuthorizationProviderData data, IAzApplication azApp, string[] tasks)
        {
            string[]         scopes     = new string[] { data.Scope };
            StringCollection operations = new StringCollection();

            foreach (String task in tasks)
            {
                IAzScope scope = null;
                if ((scopes != null) && (scopes[0].Length > 0))
                {
                    scope = azApp.OpenScope(scopes[0], null);
                }

                IAzTask azTask = null;
                if (scope != null)
                {
                    azTask = scope.OpenTask(task, null);
                }
                else
                {
                    azTask = azApp.OpenTask(task, null);
                }

                Array ops = azTask.Operations as Array;
                Debug.Assert(ops != null);
                foreach (String op in ops)
                {
                    operations.Add(op);
                }
            }

            if (operations.Count == 0)
            {
                throw new ConfigurationException(SR.NoOperations);
            }

            object[] operationIds = new object[operations.Count];
            for (int index = 0; index < operations.Count; index++)
            {
                operationIds[index] = azApp.OpenOperation(operations[index], null).OperationID;
            }

            return(operationIds);
        }
        private object[] GetTaskOperations(IAzApplication azApp, string[] tasks)
        {
            string[]         scopes     = new string[] { this.scopeName };
            StringCollection operations = new StringCollection();

            foreach (String task in tasks)
            {
                IAzScope scope = null;
                if ((scopes != null) && (scopes[0].Length > 0))
                {
                    scope = azApp.OpenScope(scopes[0], null);
                }

                IAzTask azTask = null;
                if (scope != null)
                {
                    azTask = scope.OpenTask(task, null);
                }
                else
                {
                    azTask = azApp.OpenTask(task, null);
                }

                Array ops = azTask.Operations as Array;
                foreach (String op in ops)
                {
                    operations.Add(op);
                }
            }

            if (operations.Count == 0)
            {
                throw new ConfigurationErrorsException(Properties.Resources.NoOperations);
            }

            object[] operationIds = new object[operations.Count];
            for (int index = 0; index < operations.Count; index++)
            {
                operationIds[index] = azApp.OpenOperation(operations[index], null).OperationID;
            }

            return(operationIds);
        }
Exemplo n.º 4
0
        /// <devdoc>
        /// Checks access to specified a set of operations in a specified application in a specified scope.
        /// </devdoc>
        private bool CheckAccessOperations(AzManAuthorizationProviderData data, string auditIdentifier, IIdentity identity, string[] operations)
        {
            string[]       scopes = new string[] { data.Scope };
            IAzApplication azApp  = null;

            try
            {
                IAzClientContext clientCtx = GetClientContext(data, identity, data.Application, out azApp);
                Debug.Assert(azApp != null);

                object[] operationIds = new object[operations.Length];
                for (int index = 0; index < operations.Length; index++)
                {
                    operationIds[index] = azApp.OpenOperation(operations[index], null).OperationID;
                }

                object[] internalScopes = null;
                if (scopes != null)
                {
                    internalScopes    = new object[1];
                    internalScopes[0] = scopes[0];
                }

                object[] result = (object[])clientCtx.AccessCheck(auditIdentifier,
                                                                  internalScopes, operationIds, null, null, null, null, null);
                foreach (int accessAllowed in result)
                {
                    if (accessAllowed != 0)
                    {
                        return(false);
                    }
                }
            }
            catch (COMException comEx)
            {
                throw new SecurityException(comEx.Message, comEx);
            }
            return(true);
        }
        /// <devdoc>
        /// Checks access to specified a set of operations in a specified application in a specified scope.
        /// </devdoc>
        private bool CheckAccessOperations(string auditIdentifier, WindowsIdentity identity, string[] operations)
        {
            string[] scopes = new string[] { this.scopeName };

            IAzApplication azApp = null;

            try
            {
                IAzClientContext clientCtx    = GetClientContext(identity, this.applicationName, out azApp);
                object[]         operationIds = new object[operations.Length];
                for (int index = 0; index < operations.Length; index++)
                {
                    operationIds[index] = azApp.OpenOperation(operations[index], null).OperationID;
                }

                object[] internalScopes = null;
                if (scopes != null)
                {
                    internalScopes    = new object[1];
                    internalScopes[0] = scopes[0];
                }

                object[] result = (object[])clientCtx.AccessCheck(auditIdentifier,
                                                                  internalScopes, operationIds, null, null, null, null, null);
                foreach (int accessAllowed in result)
                {
                    if (accessAllowed != 0)
                    {
                        return(false);
                    }
                }
            }
            catch (COMException comEx)
            {
                throw new SecurityException(comEx.Message, comEx);
            }
            return(true);
        }
Exemplo n.º 6
0
        private void TestSuAzMan(string azManStorePath, int max)
        {
            WindowsIdentity       id    = WindowsIdentity.GetCurrent();
            IAzAuthorizationStore store = new AzAuthorizationStoreClass();

            store.Initialize(0, azManStorePath, null);
            int              rnd    = 0; // new Random().Next(max);
            IAzApplication   app    = store.OpenApplication("Application" + rnd.ToString(), null);
            IAzClientContext ctx    = app.InitializeClientContextFromToken((ulong)id.Token.ToInt64(), null);
            string           opName = "Operation" + rnd.ToString();
            IAzOperation     op     = app.OpenOperation(opName, null);

            object[] parameterNames = new object[1] {
                "chiave"
            };
            object[] parameterValues = new object[1] {
                "valore"
            };
            object[] oRes = (object[])ctx.AccessCheck("Test", null, new object[] { op.OperationID }, parameterNames, parameterValues, null, null, null);
            foreach (int accessAllowed in oRes)
            {
                if (accessAllowed != 0)
                {
                    break;
                }
            }
            store.CloseApplication("Application" + rnd.ToString(), 0);
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(op);
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(app);
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(store);
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(ctx);
            op    = null;
            ctx   = null;
            app   = null;
            store = null;
        }
		private object[] GetTaskOperations(IAzApplication azApp, string[] tasks)
		{
			string[] scopes = new string[] { this.scopeName };
			StringCollection operations = new StringCollection();
			foreach (String task in tasks)
			{
				IAzScope scope = null;
				if ((scopes != null) && (scopes[0].Length > 0))
				{
					scope = azApp.OpenScope(scopes[0], null);
				}

				IAzTask azTask = null;
				if (scope != null)
				{
					azTask = scope.OpenTask(task, null);
				}
				else
				{
					azTask = azApp.OpenTask(task, null);
				}

				Array ops = azTask.Operations as Array;
				foreach (String op in ops)
				{
					operations.Add(op);
				}
			}

			if (operations.Count == 0)
			{
				throw new ConfigurationErrorsException(Properties.Resources.NoOperations);
			}

			object[] operationIds = new object[operations.Count];
			for (int index = 0; index < operations.Count; index++)
			{
				operationIds[index] = azApp.OpenOperation(operations[index], null).OperationID;
			}

			return operationIds;
		}
Exemplo n.º 8
0
        private object[] GetTaskOperations(AzManAuthorizationProviderData data, IAzApplication azApp, string[] tasks)
        {
            string[] scopes = new string[] {data.Scope};
            StringCollection operations = new StringCollection();
            foreach (String task in tasks)
            {
                IAzScope scope = null;
                if ((scopes != null) && (scopes[0].Length > 0))
                {
                    scope = azApp.OpenScope(scopes[0], null);
                }

                IAzTask azTask = null;
                if (scope != null)
                {
                    azTask = scope.OpenTask(task, null);
                }
                else
                {
                    azTask = azApp.OpenTask(task, null);
                }

                Array ops = azTask.Operations as Array;
                Debug.Assert(ops != null);
                foreach (String op in ops)
                {
                    operations.Add(op);
                }
            }

            if (operations.Count == 0)
            {
                throw new ConfigurationException(SR.NoOperations);
            }

            object[] operationIds = new object[operations.Count];
            for (int index = 0; index < operations.Count; index++)
            {
                operationIds[index] = azApp.OpenOperation(operations[index], null).OperationID;
            }

            return operationIds;
        }