Exemple #1
0
        private void RefreshCacheForToken(string token)
        {
            using (var context = LuckIndiaDBContext.GetContext())
            {
                var accessToken = context.AccessTokens
                                  .Include(x => x.User)
                                  // .Include(x => x.Application)
                                  .FirstOrDefault(x => x.Token == token);

                if (accessToken == null ||
                    !ExpirableValidator.IsActive(accessToken.StartDate, accessToken.EndDate))
                {
                    throw new InvalidAccessTokenException();
                }

                var accessTokenCache = new AccessTokenCacheModel
                {
                    AccessToken   = accessToken,
                    ApplicationId = accessToken.ApplicationId,
                    UserId        = accessToken.UserId
                };

                _cache.TryAdd(token, accessTokenCache);
            }
        }
        /// <summary>
        /// Validates that the given application token is active.
        /// </summary>
        /// <param name="token"></param>
        //public void ValidateApplicationToken(string token)
        //{
        //    this.Logger.AppendLine("Checking valid application token.");

        //    var applicationToken = this.ApplicationTokens.FirstOrDefault(x => x.Token == token);
        //    if (applicationToken == null || ExpirableValidator.IsExpired(applicationToken.EndDate))
        //    {
        //        throw new InvalidDataException("Invalid ApplicationToken.");
        //    }
        //}

        /// <summary>
        /// Validates that the given application token is active and it has the role of an authority.
        /// </summary>
        /// <param name="token"></param>
        //public void ValidateAuthorityApplicationToken(string token)
        //{
        //    this.Logger.AppendLine("Checking valid authority application token.");

        //    var applicationToken = this.ApplicationTokens.FirstOrDefault(x => x.Token == token);
        //    if (applicationToken == null || ExpirableValidator.IsExpired(applicationToken.EndDate))
        //    {
        //        throw new InvalidDataException("Invalid authority application.");
        //    }

        //    if (!applicationToken.Application.ApplicationRoles.Any(x => x.RoleId == (int)ApplicationRoleValue.AuthenticationAuthority))
        //    {
        //        throw new InvalidDataException("Invalid authority application.");
        //    }
        //}

        /// <summary>
        /// Validates that the given user token is active.
        /// </summary>
        /// <param name="token"></param>
        //public void ValidateUserToken(string token)
        //{
        //    this.Logger.AppendLine("Checking valid UserToken.");

        //    var userToken = this.UserTokens.FirstOrDefault(x => x.Token == token);
        //    if (userToken == null || ExpirableValidator.IsExpired(userToken.EndDate))
        //    {
        //        throw new InvalidDataException("Invalid UserToken.");
        //    }
        //}

        /// <summary>
        /// Validates that the given accessToken is active.
        /// </summary>
        /// <param name="token"></param>
        public void ValidateAccessToken(string token)
        {
            this.Logger.AppendLine("Checking valid access token.");

            var accessToken = this.AccessTokens.FirstOrDefault(x => x.Token == token);

            if (accessToken == null || ExpirableValidator.IsExpired(accessToken.EndDate))
            {
                throw new InvalidAccessTokenException();
            }
        }
Exemple #3
0
        /// <summary>
        /// Validates that the given user token is active.
        /// </summary>
        /// <param name="token"></param>
        public void ValidateUserToken(string token)
        {
            this.Logger.AppendLine("Checking valid UserToken.");

            var userToken = this.UserTokens.FirstOrDefault(x => x.Token == token);

            if (userToken == null || ExpirableValidator.IsExpired(userToken.EndDate))
            {
                throw new InvalidDataException("Invalid UserToken.");
            }
        }
Exemple #4
0
        /// <summary>
        /// Validates that the given application token is active and it has the role of an authority.
        /// </summary>
        /// <param name="token"></param>
        public void ValidateAuthorityApplicationToken(string token)
        {
            this.Logger.AppendLine("Checking valid authority application token.");

            var applicationToken = this.ApplicationTokens.FirstOrDefault(x => x.Token == token);

            if (applicationToken == null || ExpirableValidator.IsExpired(applicationToken.EndDate))
            {
                throw new InvalidDataException("Invalid authority application.");
            }

            if (!applicationToken.Application.ApplicationRoles.Any(x => x.RoleId == (int)ApplicationRoleValue.AuthenticationAuthority))
            {
                throw new InvalidDataException("Invalid authority application.");
            }
        }