public void AddPrincipalToCache(IJumbleblocksPrincipal principal)
        {
            var slidingExpiration = SecurityConfig.GetCacheSlidingExpiration();

            HttpContextBase.Cache.Add(principal.Identity.Name, principal, null, Cache.NoAbsoluteExpiration,
                                      slidingExpiration, CacheItemPriority.Normal, null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates article controller
        /// </summary>
        /// <param name="blogPostRepository">blogpost repository to use, leave null to use default mocked implementation</param>
        /// <param name="shouldBlogPostRepositoryAlwayReturnPost">if using default blogpost repository, if set to true then repository will always return BlogPost regardless of input. If however it is false posts titles are 0 to 19 and published date is current day</param>
        /// <param name="lookupRepository">repository to look things up, leave null for default mocked implementation</param>
        /// <param name="configurationReader">configuration reader to use, leave null for default mocked implementation</param>
        /// <param name="waneTransform">wane transform, leave null for default mocked implementaion</param>
        /// <param name="logger">Logger, leave null for default implementation</param>
        /// <param name="principal">principal used for security, leave null for default implementation</param>
        /// <returns></returns>
        public static BlogPostController CreateBlogPostController(IBlogPostRepository blogPostRepository = null, bool shouldBlogPostRepositoryAlwayReturnPost = true,
            ILookupRepository lookupRepository = null, IConfigurationReader configurationReader = null, IWaneTransform waneTransform = null, IJumbleblocksLogger logger = null,
            IJumbleblocksPrincipal principal = null)
        {
            if (blogPostRepository == null)
                blogPostRepository = CreateMockedBlogPostRepository(shouldBlogPostRepositoryAlwayReturnPost).Object;

            if (lookupRepository == null)
                lookupRepository = CreateMockedLookupRepository().Object;

            if (configurationReader == null)
                configurationReader = CreateMockedConfigurationReader().Object;

            if (waneTransform == null)
                waneTransform = CreateMockedWaneTransform().Object;

            if (logger == null)
                logger = new Mock<IJumbleblocksLogger>().Object;

            if (principal == null)
                principal = CreateMockedPrincipalAndAddBlogUserToLookUp(Mock.Get<ILookupRepository>(lookupRepository)).Object;

            var controller = new BlogPostController(blogPostRepository, lookupRepository, configurationReader, waneTransform, logger);
            controller.SetMockedControllerContext();
            controller.SetPrincipal(principal);

            return controller;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Adds principal to cache
 /// </summary>
 /// <param name="principal">principal to add to cache</param>
 public void AddPrincipalToCache(IJumbleblocksPrincipal principal)
 {
     if (principal != null)
     {
         var cacheItem = new CacheItem(principal.Identity.Name, principal);
         Cache.Add(cacheItem, _defaultCachePolicy);
     }
 }
        /// <summary>
        /// Sets the auth cookie with the user name
        /// </summary>
        /// <param name="principal">principal to get data from</param>
        public void SetAuth(IJumbleblocksPrincipal principal)
        {
            if (principal.Identity.IsAuthenticated)
            {
                var slidingExpiration = SecurityConfig.GetCookieSlidingExpiration();

                var ticket = new FormsAuthenticationTicket(1,
                                                           principal.Identity.Name,
                                                           DateTime.Now,
                                                           DateTime.Now.Add(slidingExpiration),
                                                           false,
                                                           String.Empty,
                                                           FormsAuthentication.FormsCookiePath);

                string encryptedTicket = FormsAuthentication.Encrypt(ticket);

                HttpContextBase.Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket));
            }
        }
 private void SetCurrentPrincipal(IJumbleblocksPrincipal principal)
 {
     FormsAuthentication.SetAuth(principal);
     HttpContextBase.User = principal;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Removes principal from cache
 /// </summary>
 /// <param name="principal">principal to remove</param>
 public void RemovePrincipalFromCache(IJumbleblocksPrincipal principal)
 {
     Cache.Remove(principal.Identity.Name);
 }
 public void RemovePrincipalFromCache(IJumbleblocksPrincipal principal)
 {
     HttpContextBase.Cache.Remove(principal.Identity.Name);
 }