public void AuthorizationFailedFires2WmiEvents()
        {
            AzManAuthorizationProvider instrumentedAzman          = new AzManAuthorizationProvider(data.StoreLocation, data.Application, data.AuditIdentifierPrefix, data.Scope);
            AuthorizationProviderInstrumentationListener listener = new AuthorizationProviderInstrumentationListener("foo", false, false, true);

            ReflectionInstrumentationBinder binder = new ReflectionInstrumentationBinder();

            binder.Bind(instrumentedAzman.GetInstrumentationEventProvider(), listener);

            using (WmiEventWatcher eventWatcher = new WmiEventWatcher(2))
            {
                bool res = instrumentedAzman.Authorize(cryptographyProviderCollection, unauthorizedTask);

                eventWatcher.WaitForEvents();

                Assert.AreEqual(2, eventWatcher.EventsReceived.Count);

                Assert.AreEqual("AuthorizationCheckPerformedEvent", eventWatcher.EventsReceived[0].ClassPath.ClassName);
                Assert.AreEqual("foo", eventWatcher.EventsReceived[0].Properties["InstanceName"].Value);
                Assert.AreEqual(cryptographyProviderCollection.Identity.Name, eventWatcher.EventsReceived[0].Properties["UserName"].Value);
                Assert.AreEqual(unauthorizedTask, eventWatcher.EventsReceived[0].Properties["TaskName"].Value);

                Assert.AreEqual("AuthorizationCheckFailedEvent", eventWatcher.EventsReceived[1].ClassPath.ClassName);
                Assert.AreEqual("foo", eventWatcher.EventsReceived[1].Properties["InstanceName"].Value);
                Assert.AreEqual(cryptographyProviderCollection.Identity.Name, eventWatcher.EventsReceived[1].Properties["UserName"].Value);
                Assert.AreEqual(unauthorizedTask, eventWatcher.EventsReceived[1].Properties["TaskName"].Value);
            }
        }
Beispiel #2
0
        private static void PerformsReplacementsInStoreLocation_Imp()
        {
            string location;

            location = @"msxml://ignored/testAzStore.xml";
            Assert.AreEqual(location, AzManAuthorizationProvider.GetStoreLocationPath(location));

            location = @"msxml://{currentPath}/testAzStore.xml";
            Assert.AreNotEqual(location, AzManAuthorizationProvider.GetStoreLocationPath(location));
            Assert.IsTrue(File.Exists((new Uri(AzManAuthorizationProvider.GetStoreLocationPath(location))).LocalPath));

            string currentDirectory = Environment.CurrentDirectory;

            try
            {
                Environment.CurrentDirectory = Environment.SystemDirectory;
                Assert.IsFalse(File.Exists((new Uri(AzManAuthorizationProvider.GetStoreLocationPath(location))).LocalPath));

                location = @"msxml://{baseDirectory}/testAzStore.xml";
                Assert.AreNotEqual(location, AzManAuthorizationProvider.GetStoreLocationPath(location));
                Assert.IsTrue(File.Exists((new Uri(AzManAuthorizationProvider.GetStoreLocationPath(location))).LocalPath));
            }
            finally
            {
                Environment.CurrentDirectory = currentDirectory;
            }
        }
Beispiel #3
0
 public void InvalidApplication()
 {
     data.Application = "INVALID";
     azman            = new AzManAuthorizationProvider();
     azman.Initialize(new TestAuthorizationProviderConfigurationView(data, Context));
     azman.Authorize(this.principal, authorizedTask);
 }
        public void AuthorizationFailedFires2WmiEvents()
        {
            AzManAuthorizationProvider instrumentedAzman = new AzManAuthorizationProvider(data.StoreLocation, data.Application, data.AuditIdentifierPrefix, data.Scope);
            AuthorizationProviderInstrumentationListener listener = new AuthorizationProviderInstrumentationListener("foo", false, false, true);

            ReflectionInstrumentationBinder binder = new ReflectionInstrumentationBinder();
            binder.Bind(instrumentedAzman.GetInstrumentationEventProvider(), listener);

            using (WmiEventWatcher eventWatcher = new WmiEventWatcher(2))
            {
                bool res = instrumentedAzman.Authorize(cryptographyProviderCollection, unauthorizedTask);

                eventWatcher.WaitForEvents();

                Assert.AreEqual(2, eventWatcher.EventsReceived.Count);

                Assert.AreEqual("AuthorizationCheckPerformedEvent", eventWatcher.EventsReceived[0].ClassPath.ClassName);
                Assert.AreEqual("foo", eventWatcher.EventsReceived[0].Properties["InstanceName"].Value);
                Assert.AreEqual(cryptographyProviderCollection.Identity.Name, eventWatcher.EventsReceived[0].Properties["UserName"].Value);
                Assert.AreEqual(unauthorizedTask, eventWatcher.EventsReceived[0].Properties["TaskName"].Value);

                Assert.AreEqual("AuthorizationCheckFailedEvent", eventWatcher.EventsReceived[1].ClassPath.ClassName);
                Assert.AreEqual("foo", eventWatcher.EventsReceived[1].Properties["InstanceName"].Value);
                Assert.AreEqual(cryptographyProviderCollection.Identity.Name, eventWatcher.EventsReceived[1].Properties["UserName"].Value);
                Assert.AreEqual(unauthorizedTask, eventWatcher.EventsReceived[1].Properties["TaskName"].Value);
            }
        }
Beispiel #5
0
 public void Setup()
 {
     data.Application           = "Enterprise Library Unit Test";
     data.AuditIdentifierPrefix = "myAuditId";
     data.Scope         = "";
     data.StoreLocation = @"msxml://{currentPath}/testAzStore.xml";
     azman = new AzManAuthorizationProvider();
     azman.Initialize(new TestAuthorizationProviderConfigurationView(data, Context));
 }
Beispiel #6
0
        public void AuthorizedScopeTask()
        {
            data.Scope = scope;
            azman      = new AzManAuthorizationProvider(data.StoreLocation, data.Application, data.AuditIdentifierPrefix, data.Scope, new NullAuthorizationProviderInstrumentationProvider());

            string task = "Manage Extranet";
            bool   res  = azman.Authorize(cryptographyProviderCollection, task);

            Assert.IsTrue(res);
        }
        public void UnauthorizedScopeTask()
        {
            string task = "Publish Extranet";

            data.Scope = scope;
            azman      = new AzManAuthorizationProvider(data.StoreLocation, data.Application, data.AuditIdentifierPrefix, data.Scope);
            bool res = azman.Authorize(cryptographyProviderCollection, task);

            Assert.IsFalse(res);
        }
Beispiel #8
0
        public void AuthorizedScopeTask()
        {
            azman = new AzManAuthorizationProvider();
            azman.Initialize(new TestAuthorizationProviderConfigurationView(data, Context));
            string task = "Manage Extranet";

            data.Scope = scope;
            bool res = azman.Authorize(this.principal, task);

            Assert.IsTrue(res);
        }
        public void AuthorizedScopeTask()
        {
            azman = new AzManAuthorizationProvider();
            azman.Initialize(new TestAuthorizationProviderConfigurationView(data, Context));
            string task = "Manage Extranet";

            data.Scope = scope;
            bool res = azman.Authorize(this.principal, task);

            Assert.IsTrue(res);
        }
 public void TestInitialize()
 {
     ReplaceSIDinConfigFile();
     cryptographyProviderCollection = new GenericPrincipal(
         WindowsIdentity.GetCurrent(),
         new string[] { "Guest" });
     data.Application = "Enterprise Library Unit Test";
     data.AuditIdentifierPrefix = "myAuditId";
     data.Scope = "";
     data.StoreLocation = @"msxml://{currentPath}/testAzStore.xml";
     azman = new AzManAuthorizationProvider(data.StoreLocation, data.Application, data.AuditIdentifierPrefix, data.Scope);
 }
Beispiel #11
0
 public void TestInitialize()
 {
     ReplaceSIDinConfigFile();
     cryptographyProviderCollection = new GenericPrincipal(
         WindowsIdentity.GetCurrent(),
         new string[] { "Guest" });
     data.Application           = "Enterprise Library Unit Test";
     data.AuditIdentifierPrefix = "myAuditId";
     data.Scope         = "";
     data.StoreLocation = @"msxml://{currentPath}/testAzStore.xml";
     azman = new AzManAuthorizationProvider(data.StoreLocation, data.Application, data.AuditIdentifierPrefix, data.Scope);
 }
        public void CanCreateAzManAuthorizationProvider()
        {
            AzManAuthorizationProvider createdObject =
                (AzManAuthorizationProvider)EnterpriseLibraryContainer.Current.GetInstance <IAuthorizationProvider>("DefaultAzManProvider");

            Assert.IsNotNull(createdObject);
            Assert.AreEqual(@"Enterprise Library Unit Test", createdObject.ApplicationName);
            Assert.AreEqual("myAuditId", createdObject.AuditIdentifierPrefix);
            Assert.AreEqual("", createdObject.ScopeName);
            Assert.AreEqual(AzManAuthorizationProvider.GetStoreLocationPath(@"msxml://{currentPath}/testAzStore.xml"),
                            createdObject.StoreLocation);
        }
Beispiel #13
0
        /// <summary>
        /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
        /// Builds an <see cref="AzManAuthorizationProvider"/> based on an instance of <see cref="AzManAuthorizationProviderData"/>.
        /// </summary>
        /// <seealso cref="AuthorizationProviderCustomFactory"/>
        /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param>
        /// <param name="objectConfiguration">The configuration object that describes the object to build. Must be an instance of <see cref="AzManAuthorizationProviderData"/>.</param>
        /// <param name="configurationSource">The source for configuration objects.</param>
        /// <param name="reflectionCache">The cache to use retrieving reflection information.</param>
        /// <returns>A fully initialized instance of <see cref="AzManAuthorizationProvider"/>.</returns>
        public IAuthorizationProvider Assemble(IBuilderContext context, AuthorizationProviderData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            AzManAuthorizationProviderData castedObjectConfiguration
                = (AzManAuthorizationProviderData)objectConfiguration;

            IAuthorizationProvider createdObject
                = new AzManAuthorizationProvider(
                      castedObjectConfiguration.StoreLocation,
                      castedObjectConfiguration.Application,
                      castedObjectConfiguration.AuditIdentifierPrefix,
                      castedObjectConfiguration.Scope);

            return(createdObject);
        }
        public void AuthorizeFiresWmiEvent()
        {
            AzManAuthorizationProvider instrumentedAzman          = new AzManAuthorizationProvider(data.StoreLocation, data.Application, data.AuditIdentifierPrefix, data.Scope);
            AuthorizationProviderInstrumentationListener listener = new AuthorizationProviderInstrumentationListener("foo", false, false, true);

            ReflectionInstrumentationBinder binder = new ReflectionInstrumentationBinder();

            binder.Bind(instrumentedAzman.GetInstrumentationEventProvider(), listener);

            using (WmiEventWatcher eventWatcher = new WmiEventWatcher(1))
            {
                bool res = instrumentedAzman.Authorize(cryptographyProviderCollection, authorizedTask);

                eventWatcher.WaitForEvents();
                Thread.Sleep(500);

                Assert.AreEqual(1, eventWatcher.EventsReceived.Count);
                Assert.AreEqual("foo", eventWatcher.EventsReceived[0].Properties["InstanceName"].Value);
                Assert.AreEqual(cryptographyProviderCollection.Identity.Name, eventWatcher.EventsReceived[0].Properties["UserName"].Value);
                Assert.AreEqual(authorizedTask, eventWatcher.EventsReceived[0].Properties["TaskName"].Value);
            }
        }
 public void InvalidApplication()
 {
     data.Application = "INVALID";
     azman = new AzManAuthorizationProvider(data.StoreLocation, data.Application, data.AuditIdentifierPrefix, data.Scope, new NullAuthorizationProviderInstrumentationProvider());
     azman.Authorize(cryptographyProviderCollection, authorizedTask);
 }
		public void UnauthorizedScopeTask()
		{
			string task = "Publish Extranet";

			data.Scope = scope;
			azman = new AzManAuthorizationProvider(data.StoreLocation, data.Application, data.AuditIdentifierPrefix, data.Scope);
			bool res = azman.Authorize(cryptographyProviderCollection, task);

			Assert.IsFalse(res);
		}
        public void AuthorizeFiresWmiEvent()
        {
            AzManAuthorizationProvider instrumentedAzman = new AzManAuthorizationProvider(data.StoreLocation, data.Application, data.AuditIdentifierPrefix, data.Scope);
            AuthorizationProviderInstrumentationListener listener = new AuthorizationProviderInstrumentationListener("foo", false, false, true);

            ReflectionInstrumentationBinder binder = new ReflectionInstrumentationBinder();
            binder.Bind(instrumentedAzman.GetInstrumentationEventProvider(), listener);

            using (WmiEventWatcher eventWatcher = new WmiEventWatcher(1))
            {
                bool res = instrumentedAzman.Authorize(cryptographyProviderCollection, authorizedTask);

                eventWatcher.WaitForEvents();
				Thread.Sleep(500);

                Assert.AreEqual(1, eventWatcher.EventsReceived.Count);
                Assert.AreEqual("foo", eventWatcher.EventsReceived[0].Properties["InstanceName"].Value);
                Assert.AreEqual(cryptographyProviderCollection.Identity.Name, eventWatcher.EventsReceived[0].Properties["UserName"].Value);
                Assert.AreEqual(authorizedTask, eventWatcher.EventsReceived[0].Properties["TaskName"].Value);
            }
        }
Beispiel #18
0
 public void ConstructWithNullAuthorizationProviderThrows()
 {
     azman = new AzManAuthorizationProvider(data.StoreLocation, data.Application, data.AuditIdentifierPrefix, data.Scope, null);
 }
Beispiel #19
0
 public void InvalidApplication()
 {
     data.Application = "INVALID";
     azman = new AzManAuthorizationProvider();
     azman.Initialize(new TestAuthorizationProviderConfigurationView(data, Context));
     azman.Authorize(this.principal, authorizedTask);
 }
Beispiel #20
0
 public void Setup()
 {
     data.Application = "Enterprise Library Unit Test";
     data.AuditIdentifierPrefix = "myAuditId";
     data.Scope = "";
     data.StoreLocation = @"msxml://{currentPath}/testAzStore.xml";
     azman = new AzManAuthorizationProvider();
     azman.Initialize(new TestAuthorizationProviderConfigurationView(data, Context));
 }
 public void ConstructWithNullAuthorizationProviderThrows()
 {
     azman = new AzManAuthorizationProvider(data.StoreLocation, data.Application, data.AuditIdentifierPrefix, data.Scope, null);
 }
        public void AuthorizedScopeTask()
        {
            data.Scope = scope;
            azman = new AzManAuthorizationProvider(data.StoreLocation, data.Application, data.AuditIdentifierPrefix, data.Scope, new NullAuthorizationProviderInstrumentationProvider());

            string task = "Manage Extranet";
            bool res = azman.Authorize(cryptographyProviderCollection, task);

            Assert.IsTrue(res);
        }
Beispiel #23
0
 public void InvalidApplication()
 {
     data.Application = "INVALID";
     azman            = new AzManAuthorizationProvider(data.StoreLocation, data.Application, data.AuditIdentifierPrefix, data.Scope, new NullAuthorizationProviderInstrumentationProvider());
     azman.Authorize(cryptographyProviderCollection, authorizedTask);
 }