Пример #1
0
        public LicenseData WithState(LicenseStateType state)
        {
            var clone = _data;

            clone.LicenseState = state;
            return(new LicenseData(clone));
        }
Пример #2
0
 public void LicenseUpdated(LicenseStateType previousState, LicenseStateType newState, DateTime eventTime)
 {
     try {
         var channel  = _channel.At(SITE, LICENSE, UPDATE);
         var resource = _apiUri.AsServerUri();
         Queue(eventTime, channel, resource, new[] { _apiUri.AsServerUri().ToString() }, new XDoc("deki-event")
               .Elem("channel", channel)
               .Elem("uri", _apiUri.AsServerUri().ToString())
               .Start("previous-license").Attr("state", previousState.ToString()).End()
               .Start("new-license").Attr("state", newState.ToString()).End()
               );
     } catch (Exception e) {
         _log.WarnExceptionMethodCall(e, "LicenseUpdated", "event couldn't be created");
     }
 }
Пример #3
0
        /// <summary>
        /// Get a user out of an authtoken from a request if it's valid.
        /// </summary>
        /// <returns></returns>
        private static UserBE UserFromAuthTokenInRequest(DreamContext context, bool impersonationOnly)
        {
            DreamMessage request   = context.Request;
            string       authToken = context.Uri.GetParam(DekiWikiService.AUTHTOKEN_URIPARAM, null);
            UserBE       user      = null;

            // Check if auth token is in a cookie
            if ((authToken == null) && request.HasCookies)
            {
                DreamCookie authCookie = DreamCookie.GetCookie(request.Cookies, DekiWikiService.AUTHTOKEN_COOKIENAME);
                if ((authCookie != null) && (!authCookie.Expired))
                {
                    authToken = authCookie.Value;
                }
            }

            // Check if auth token is in a header or passed in as query parameter
            authToken = authToken ?? request.Headers[DekiWikiService.AUTHTOKEN_HEADERNAME];

            // Extract user name from auth token if it's valid
            if (authToken != null)
            {
                user = ValidateAuthToken(authToken, impersonationOnly);

                // check whether licensestate prevents user from being authenticated
                var license = DekiContext.Current.LicenseManager;
                LicenseStateType licensestate = license.LicenseState;
                if ((licensestate == LicenseStateType.EXPIRED || licensestate == LicenseStateType.INVALID || licensestate == LicenseStateType.INACTIVE) &&
                    !PermissionsBL.IsUserAllowed(user, Permissions.ADMIN)
                    )
                {
                    if (DekiContext.Current.Instance.Log.IsWarnEnabled)
                    {
                        switch (licensestate)
                        {
                        case LicenseStateType.EXPIRED:
                            DekiContext.Current.Instance.Log.WarnFormat("UserFromAuthTokenInRequest: Expired license {0}, reverting non-admin user to anonymous", license.LicenseExpiration);
                            break;

                        case LicenseStateType.INVALID:
                            DekiContext.Current.Instance.Log.WarnFormat("UserFromAuthTokenInRequest: Invalid license, reverting non-admin user to anonymous");
                            break;

                        case LicenseStateType.INACTIVE:
                            DekiContext.Current.Instance.Log.WarnFormat("UserFromAuthTokenInRequest: Inactive license, reverting non-admin user to anonymous");
                            break;
                        }
                    }
                    user = null;
                }
                else
                {
                    DekiContext.Current.AuthToken = authToken;
                }
            }
            if (PermissionsBL.ValidateRequestApiKey())
            {
                uint userIdOverride = 0;
                if (uint.TryParse(context.GetParam(DekiWikiService.IMPERSONATE_USER_QUERYNAME, null), out userIdOverride))
                {
                    UserBE userOverride = UserBL.GetUserById(userIdOverride);
                    if (userOverride != null)
                    {
                        user = userOverride;
                        DekiContext.Current.Instance.Log.InfoFormat("APIKEY provided. Impersonating user id '{0}': {1}", user.ID, user.Name);
                    }
                }
            }
            return(user);
        }
 public void Verify(LicenseStateType previous, LicenseStateType @new, int times)
 {
     Assert.AreEqual(times, _called, "transition was called the wrong number of times");
     Assert.AreEqual(previous, _previous.LicenseState, "previous state was wrong");
     Assert.AreEqual(@new, _new.LicenseState, "new state was wrong");
 }
 public void Verify(LicenseStateType previous, LicenseStateType @new)
 {
     Verify(previous, @new, 1);
 }
Пример #6
0
 public void Verify(LicenseStateType previous, LicenseStateType @new, int times) {
     Assert.AreEqual(times, _called, "transition was called the wrong number of times");
     Assert.AreEqual(previous, _previous.LicenseState, "previous state was wrong");
     Assert.AreEqual(@new, _new.LicenseState, "new state was wrong");
 }
Пример #7
0
 public void Verify(LicenseStateType previous, LicenseStateType @new) {
     Verify(previous, @new, 1);
 }
Пример #8
0
 public void LicenseUpdated(LicenseStateType previousState, LicenseStateType newState, DateTime eventTime) {
     try {
         var channel = _channel.At(SITE, LICENSE, UPDATE);
         var resource = _apiUri.AsServerUri();
         Queue(eventTime, channel, resource, new[] { _apiUri.AsServerUri().ToString() }, new XDoc("deki-event")
             .Elem("channel", channel)
             .Elem("uri", _apiUri.AsServerUri().ToString())
             .Start("previous-license").Attr("state", previousState.ToString()).End()
             .Start("new-license").Attr("state", newState.ToString()).End()
         );
     } catch(Exception e) {
         _log.WarnExceptionMethodCall(e, "LicenseUpdated", "event couldn't be created");
     }
 }
Пример #9
0
 //--- Constructors ---
 public MindTouchLicenseTransitionException(LicenseStateType currentState, LicenseStateType proposedState) {
     CurrentState = currentState;
     ProposedState = proposedState;
 }
Пример #10
0
        private static void DetermineLicenseState(XDoc license, out LicenseStateType state, out DateTime expiration, out Permissions anonymousPermissions) {
            expiration = DateTime.MaxValue;
            state = LicenseStateType.INVALID;
            anonymousPermissions = PermissionSets.MINIMAL_ANONYMOUS_PERMISSIONS;

            // check if a valid license was passed in
            if((license == null) || license.IsEmpty) {
                return;
            }

            // check if the deki assembly is signed
            Assembly assembly = typeof(DekiWikiService).Assembly;
            if(ArrayUtil.IsNullOrEmpty(assembly.GetName().GetPublicKey())) {

                // no signature, default to community
                _log.Warn("Unable to validate signature of license since the MindTouch Core service was not signed by MindTouch. Reverting to community edition.");
                state = LicenseStateType.COMMUNITY;
                anonymousPermissions = PermissionSets.ALL;
                return;
            }

            // assembly is signed: validate xml signature
            RSACryptoServiceProvider rsa = RSAUtil.ProviderFrom(assembly);
            if((rsa == null) || !license.HasValidSignature(rsa)) {
                _log.Warn("License failed XML validation");
                state = LicenseStateType.INVALID;
                return;
            }

            // check license matched product key
            string productKey = license["licensee/product-key"].AsText;
            if((productKey != null) && !productKey.EqualsInvariantIgnoreCase(StringUtil.ComputeHashString(DekiService.MasterApiKey, Encoding.UTF8))) {
                _log.Warn("Invalid product-key in license");
                state = LicenseStateType.INVALID;
                return;
            }

            // determine license type
            switch(license["@type"].AsText ?? "inactive") {
            case "trial":
                state = LicenseStateType.TRIAL;
                break;
            case "inactive":
                state = LicenseStateType.INACTIVE;
                break;
            case "community":
                state = LicenseStateType.COMMUNITY;
                break;
            case "commercial":
                state = LicenseStateType.COMMERCIAL;
                break;
            default:
                _log.Warn("Unknown license type");
                state = LicenseStateType.INVALID;
                break;
            }

            // check expiration
            expiration = license["date.expiration"].AsDate ?? DateTime.MaxValue;
            if(state == LicenseStateType.COMMERCIAL) {

                // check if license is passed grace period
                if(expiration <= DateTime.UtcNow.AddDays(-GRACE_PERIOD)) {
                    state = LicenseStateType.EXPIRED;
                    return;
                }
            } else if(expiration <= DateTime.UtcNow) {
                state = LicenseStateType.EXPIRED;
                return;
            }

            // check version
            var licenseVersion = (license["version"].AsText ?? "*").Split('.');
            var assemblyVersion = typeof(LicenseBL).Assembly.GetName().Version;
            var appVersion = new[] { assemblyVersion.Major, assemblyVersion.Minor, assemblyVersion.Revision, assemblyVersion.Build };
            for(int i = 0; (i < licenseVersion.Length) && (i < appVersion.Length); ++i) {
                string pattern = licenseVersion[i];
                int value;
                if(!pattern.Equals("*") && (!int.TryParse(pattern, out value) || (value < appVersion[i]))) {
                    state = LicenseStateType.EXPIRED;
                    return;
                } 
            }

            // determine permissions for anonymous user
            anonymousPermissions = PermissionsBL.MaskFromString(DekiLicense.GetCapability(license, "anonymous-permissions")) | PermissionSets.MINIMAL_ANONYMOUS_PERMISSIONS;
        }
Пример #11
0
 //--- Constructors ---
 public LicenseData(XDoc currentLicense, LicenseStateType licenseState, DateTime licenseExpiration, Permissions anonymousPermissions) {
     this.CurrentLicense = currentLicense;
     this.LicenseState = licenseState;
     this.LicenseStateChecked = DateTime.UtcNow;
     this.LicenseExpiration = licenseExpiration;
     this.AnonymousPermissions = anonymousPermissions;
 }
Пример #12
0
 public static DekiResource LICENSE_TRANSITION_INVALID(LicenseStateType currentState, LicenseStateType proposedState) { return new DekiResource("System.API.Error.license_transition_invalid", currentState, proposedState); }
Пример #13
0
 public static DekiResource LICENSE_NO_NEW_USER_CREATION(LicenseStateType currentLicenseState) { return new DekiResource("System.API.Error.license_no_new_user_creation", currentLicenseState); }
Пример #14
0
 public LicenseData WithState(LicenseStateType state) {
     var clone = _data;
     clone.LicenseState = state;
     return new LicenseData(clone);
 }
Пример #15
0
 public MindTouchLicenseTransitionForbiddenLicenseTransitionException(LicenseStateType currentState, LicenseStateType proposedState)
     : base(DekiResources.LICENSE_TRANSITION_INVALID(currentState, proposedState)) {
 }
Пример #16
0
 public MindTouchLicenseNoNewUserForbiddenException(LicenseStateType currentLicenseState)
     : base(DekiResources.LICENSE_NO_NEW_USER_CREATION(currentLicenseState)) {
 }
Пример #17
0
 //--- Constructors ---
 public MindTouchNoNewUserLicenseException(LicenseStateType currentLicenseState) {
     CurrentLicenseState = currentLicenseState;
 }