Beispiel #1
0
        private bool IsAuthorized(IPrincipal user, out IPrincipal authorizedUser)
        {
            bool isAuthorized = false;

            if (user != null &&
                user.Identity.IsAuthenticated &&
                user.Identity is System.Web.Security.FormsIdentity)
            {
                // we are authenticated, so let's check whether the cookie has the correct format
                WMUserPrincipal principal;
                try
                {
                    principal      = new WMUserPrincipal((FormsIdentity)user.Identity);
                    authorizedUser = principal;
                }
                catch (Exception)
                {
                    // this means we have a dodgy session cookie, so redirect
                    authorizedUser = WMUserPrincipal.AnonymousInstance;
                    return(false);
                }

                IWorkmateMembershipProvider provider = InstanceContainer.WorkmateMembershipProvider;
                if (principal.WMUserIdentity.LastRecordCheckUtc.AddSeconds(provider.LastRecordCheckWindowInSeconds) < DateTime.UtcNow)
                {
                    IUserBasic userBasic = provider.GetUserBasic(principal.WMUserIdentity.UserId, true);
                    if (userBasic != null)
                    {
                        this.UpdateAuthenticationCookie(userBasic);
                        isAuthorized = true;
                    }
                }
                else if (FormsAuthentication.SlidingExpiration)
                {// refresh the cookie if we have sliding expiration
                    // check whether we should update the last activity date
                    if (principal.WMUserIdentity.LastActivityUpdate.AddSeconds(provider.LastActivityUpdateWindowInSeconds) < DateTime.UtcNow)
                    {
                        // we have to update the lastactivity date...
                        IUserBasic userBasic = provider.GetUserBasic(principal.WMUserIdentity.UserId, true);
                        if (userBasic != null)
                        {
                            this.UpdateAuthenticationCookie(userBasic);
                            isAuthorized = true;
                        }
                    }
                    else
                    {
                        // refresh the cookie
                        this.RefreshAuthenticationCookie(principal.WMUserIdentity);
                        isAuthorized = true;
                    }
                }
            }
            else
            {
                authorizedUser = WMUserPrincipal.AnonymousInstance;
            }

            return(isAuthorized);
        }
Beispiel #2
0
 public static void Initialize(IApplicationContext applicationContext, ITicketManager ticketManager
                               , IWorkmateMembershipProvider workmateMembershipProvider, IWorkmateRoleProvider workmateRoleProvider
                               , IArticleManager articleManager, IRequestHelper requestHelper
                               , IArticleAttachmentManager articleAttachmentManager, IApplicationManager applicationManager
                               , IArticleGroupManager articleGroupManager, IArticleGroupThreadManager articleGroupThreadManager
                               , IApplicationDataCache applicationDataCache, IProfileImageManager profileImageManager
                               , ISystemProfileImageManager systemProfileImageManager, IEmailManager emailManager
                               , IEmailPublisher emailPublisher
                               , IOfficeManager officeManager, IDepartmentManager departmentManager
                               )
 {
     _ApplicationContext         = applicationContext;
     _TicketManager              = ticketManager;
     _WorkmateMembershipProvider = workmateMembershipProvider;
     _WorkmateRoleProvider       = workmateRoleProvider;
     _ArticleManager             = articleManager;
     _RequestHelper              = requestHelper;
     _ArticleAttachmentManager   = articleAttachmentManager;
     _ApplicationManager         = applicationManager;
     _ArticleGroupManager        = articleGroupManager;
     _ArticleGroupThreadManager  = articleGroupThreadManager;
     _ApplicationDataCache       = applicationDataCache;
     _ProfileImageManager        = profileImageManager;
     _SystemProfileImageManager  = systemProfileImageManager;
     _EmailManager      = emailManager;
     _EmailPublisher    = emailPublisher;
     _OfficeManager     = officeManager;
     _DepartmentManager = departmentManager;
 }
Beispiel #3
0
 public TicketManager(IApplicationSettings applicationSettings, IWorkmateMembershipProvider workmateMembershipProvider)
 {
     _ApplicationSettings        = applicationSettings;
     _WorkmateMembershipProvider = workmateMembershipProvider;
 }