public void InMemorySaveWithNullIdentityTestFixture()
        {
            ISecurityCacheProvider securityCache = SecurityCacheFactory.GetSecurityCacheProvider();
            IToken token = securityCache.SaveIdentity(null);

            if (token != null)
            {
                Assert.Fail();
            }
        }
        public void SaveIdentityWithDefaultExpiration()
        {
            ISecurityCacheProvider securityCache = SecurityCacheFactory.GetSecurityCacheProvider();

            Assert.IsNotNull(securityCache);

            IToken token = securityCache.SaveIdentity(identity);

            Assert.IsNotNull(token);
            Assert.IsNotNull(token.Value);
        }
Beispiel #3
0
        public void SavePrincipalWithDefaultExpiration()
        {
            ISecurityCacheProvider securityCache = SecurityCacheFactory.GetSecurityCacheProvider(defaultInstance);

            Assert.IsNotNull(securityCache);

            IToken token = securityCache.SavePrincipal(principal);

            Assert.IsNotNull(token);
            Assert.IsNotNull(token.Value);
        }
Beispiel #4
0
 /// <summary>
 ///     Prevents a default instance of the <see cref="SecurityManager"/> class from being created.
 /// </summary>
 /// <externalUnit cref="AuthorizationFactory"/>
 /// <externalUnit cref="SecurityCacheFactory"/>
 /// <revision revisor="dev06" date="10/6/2008" version="1.0.0.0">\
 ///     Member created
 /// </revision>
 private SecurityManager()
 {
     // Get the default security manager.
     // Initializes the Enterprise Library authorization and security
     // caching providers. The ASP.NET Membership and Profile providers
     // do not need to be initialized in this way
     // TODO: remove strings to settings file
     this.ruleProvider =
         AuthorizationFactory.GetAuthorizationProvider("RuleProvider");
     this.cache =
         SecurityCacheFactory.GetSecurityCacheProvider(
             "Caching Store Provider");
 }
Beispiel #5
0
        public void RetreiveProfileNotInCache()
        {
            ISecurityCacheProvider securityCache = SecurityCacheFactory.GetSecurityCacheProvider();

            Assert.IsNotNull(securityCache);

            IToken token = new GuidToken() as IToken;

            Assert.IsNotNull(token);

            object cachedProfile = securityCache.GetProfile(token);

            Assert.IsNull(cachedProfile);
        }
        public void RetreiveIdentityNotInCache()
        {
            ISecurityCacheProvider securityCache = SecurityCacheFactory.GetSecurityCacheProvider();

            Assert.IsNotNull(securityCache);

            IToken token = new GuidToken() as IToken;

            Assert.IsNotNull(token);

            IIdentity cachedIdentity = securityCache.GetIdentity(token);

            Assert.IsNull(cachedIdentity);
        }
Beispiel #7
0
        public void RetreivePrincipalNotInCache()
        {
            ISecurityCacheProvider securityCache = SecurityCacheFactory.GetSecurityCacheProvider();

            Assert.IsNotNull(securityCache);

            IToken token = new GuidToken() as IToken;

            Assert.IsNotNull(token);

            IPrincipal cachedPrincipal = securityCache.GetPrincipal(token);

            Assert.IsNull(cachedPrincipal);
        }
Beispiel #8
0
        public void SavePrincipalWithTokenFromPreviouslyCachedItem()
        {
            ISecurityCacheProvider securityCache = SecurityCacheFactory.GetSecurityCacheProvider(defaultInstance);

            Assert.IsNotNull(securityCache);

            IIdentity identity = new GenericIdentity("zman", "testauthtype");

            IToken token = securityCache.SaveIdentity(identity);

            Assert.IsNotNull(token);
            Assert.IsNotNull(token.Value);

            securityCache.SavePrincipal(principal, token);
        }
        public void RetreiveCachedIdentity()
        {
            ISecurityCacheProvider securityCache = SecurityCacheFactory.GetSecurityCacheProvider();

            Assert.IsNotNull(securityCache);

            IToken token = securityCache.SaveIdentity(identity);

            Assert.IsNotNull(token);
            Assert.IsNotNull(token.Value);

            IIdentity cachedIdentity = securityCache.GetIdentity(token);

            Assert.IsNotNull(cachedIdentity);
            Assert.AreEqual(cachedIdentity.Name, "zman");
        }
Beispiel #10
0
        public void RetreiveCachedProfile()
        {
            ISecurityCacheProvider securityCache = SecurityCacheFactory.GetSecurityCacheProvider(defaultInstance);

            Assert.IsNotNull(securityCache);

            IToken token = securityCache.SaveProfile(profile);

            Assert.IsNotNull(token);
            Assert.IsNotNull(token.Value);

            object cachedProfile = securityCache.GetProfile(token);

            Assert.IsNotNull(cachedProfile);
            Assert.AreEqual(cachedProfile.ToString(), "testprofile");
        }
Beispiel #11
0
        public void RetreiveCachedPrincipal()
        {
            ISecurityCacheProvider securityCache = SecurityCacheFactory.GetSecurityCacheProvider(defaultInstance);

            Assert.IsNotNull(securityCache);

            IToken token = securityCache.SavePrincipal(principal);

            Assert.IsNotNull(token);
            Assert.IsNotNull(token.Value);

            IPrincipal cachedPrincipal = securityCache.GetPrincipal(token);

            Assert.IsNotNull(cachedPrincipal);
            Assert.AreEqual(cachedPrincipal.Identity.Name, "zman");
        }
        public void ExplicitlyExpireIdentity()
        {
            ISecurityCacheProvider securityCache = SecurityCacheFactory.GetSecurityCacheProvider();

            Assert.IsNotNull(securityCache);

            IToken token = securityCache.SaveIdentity(identity);

            Assert.IsNotNull(token);
            Assert.IsNotNull(token.Value);

            securityCache.ExpireIdentity(token);

            IIdentity cachedIdentity = securityCache.GetIdentity(token);

            Assert.IsNull(cachedIdentity);
        }
Beispiel #13
0
        public void ExplicitlyExpirePrincipal()
        {
            ISecurityCacheProvider securityCache = SecurityCacheFactory.GetSecurityCacheProvider(defaultInstance);

            Assert.IsNotNull(securityCache);

            IToken token = securityCache.SavePrincipal(principal);

            Assert.IsNotNull(token);
            Assert.IsNotNull(token.Value);

            securityCache.ExpirePrincipal(token);

            IPrincipal cachedPrincipal = securityCache.GetPrincipal(token);

            Assert.IsNull(cachedPrincipal);
        }
Beispiel #14
0
        public void ExplicitlyExpireProfile()
        {
            ISecurityCacheProvider securityCache = SecurityCacheFactory.GetSecurityCacheProvider(defaultInstance);

            Assert.IsNotNull(securityCache);

            IToken token = securityCache.SaveProfile(profile);

            Assert.IsNotNull(token);
            Assert.IsNotNull(token.Value);

            securityCache.ExpireProfile(token);

            object tmpProfile = securityCache.GetProfile(token);

            Assert.IsNull(tmpProfile);
        }
Beispiel #15
0
        private void QuickStartForm_Load(object sender, System.EventArgs e)
        {
            // Initialize image to embedded logo
            this.logoPictureBox.Image = GetEmbeddedImage("SecurityQuickStart.logo.gif");

            // Initializes the Enterprise Library authorization and security caching providers
            // The ASP.NET Membership and Profile providers do not need to be initialized in this way
            this.ruleProvider = AuthorizationFactory.GetAuthorizationProvider("RuleProvider");
            this.cache        = SecurityCacheFactory.GetSecurityCacheProvider("Caching Store Provider");

            // Initialize forms displayed for user interaction
            this.addUserRoleForm = new AddUserRoleForm();
            this.userRoleForm    = new UserRoleForm();
            this.usersForm       = new UsersForm();
            this.credentialsForm = new CredentialsForm();
            this.roleAuthForm    = new RoleAuthorizationForm();
            this.profileForm     = new ProfileForm();
        }
Beispiel #16
0
        public void SaveProfileWithTokenFromPreviouslyCachedItem()
        {
            ISecurityCacheProvider securityCache = SecurityCacheFactory.GetSecurityCacheProvider(defaultInstance);

            Assert.IsNotNull(securityCache);

            IIdentity identity = new GenericIdentity("zman", "testauthtype");

            IToken token = securityCache.SaveIdentity(identity);

            Assert.IsNotNull(token);

            securityCache.SaveProfile(profile, token);
            Assert.IsNotNull(token);
            Assert.IsNotNull(token.Value);

            object tmpProfile = securityCache.GetProfile(token);

            Assert.IsNotNull(tmpProfile);
            Assert.AreEqual(tmpProfile.ToString(), "testprofile");
        }
        public void SaveIdentityWithTokenFromPreviousCachedItem()
        {
            ISecurityCacheProvider securityCache = SecurityCacheFactory.GetSecurityCacheProvider();

            Assert.IsNotNull(securityCache);

            string[]   roles     = new string[] { "admin", "manager" };
            IPrincipal principal = new GenericPrincipal(identity, roles);

            IToken token = securityCache.SavePrincipal(principal);

            Assert.IsNotNull(token);

            securityCache.SaveIdentity(identity, token);
            Assert.IsNotNull(token);
            Assert.IsNotNull(token.Value);

            IIdentity cachedIdentity = securityCache.GetIdentity(token);

            Assert.IsNotNull(cachedIdentity);
            Assert.AreEqual(cachedIdentity.Name, "zman");
        }
Beispiel #18
0
        public void RetrieveCachedPrincipalFiresWmiEvent()
        {
            SecurityCacheProvider securityCache = SecurityCacheFactory.GetSecurityCacheProvider() as SecurityCacheProvider;
            SecurityCacheProviderInstrumentationListener listener = new SecurityCacheProviderInstrumentationListener("foo", false, false, true);

            ReflectionInstrumentationBinder binder = new ReflectionInstrumentationBinder();

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

            using (WmiEventWatcher eventWatcher = new WmiEventWatcher(1))
            {
                IToken token   = new GuidToken();
                object profile = securityCache.GetPrincipal(token);
                eventWatcher.WaitForEvents();

                Assert.AreEqual(1, eventWatcher.EventsReceived.Count);
                Assert.AreEqual("SecurityCacheReadPerformedEvent", eventWatcher.EventsReceived[0].ClassPath.ClassName);
                Assert.AreEqual(SecurityEntityType.Principal.ToString(), eventWatcher.EventsReceived[0].Properties["EntityType"].Value);
                Assert.AreEqual("foo", eventWatcher.EventsReceived[0].Properties["InstanceName"].Value);
                Assert.AreEqual(token.Value, eventWatcher.EventsReceived[0].Properties["TokenUsed"].Value);
            }
        }
 public void CanCreateSecurityCacheProviderFromConfiguration()
 {
     ISecurityCacheProvider provider = SecurityCacheFactory.GetSecurityCacheProvider("provider1");
 }
        public void GetValidSecurityCache()
        {
            ISecurityCacheProvider securityCache = SecurityCacheFactory.GetSecurityCacheProvider();

            Assert.IsNotNull(securityCache);
        }
Beispiel #21
0
        public void GetNamedSecurityCache()
        {
            ISecurityCacheProvider securityCache = SecurityCacheFactory.GetSecurityCacheProvider(defaultInstance, context);

            Assert.IsNotNull(securityCache);
        }
 public void TryToCreateSecurityCacheProviderFromConfigurationWithNullName()
 {
     ISecurityCacheProvider provider = SecurityCacheFactory.GetSecurityCacheProvider(null);
 }
 public void TryToCreateSecurityCacheProviderFromConfigurationThatDoesNotExist()
 {
     ISecurityCacheProvider provider = SecurityCacheFactory.GetSecurityCacheProvider("provider3");
 }
Beispiel #24
0
        public void GetDefaultSecurityCache()
        {
            ISecurityCacheProvider securityCache = SecurityCacheFactory.GetSecurityCacheProvider(context);

            Assert.IsNotNull(securityCache);
        }