Esempio n. 1
0
        // Converts a Numeric Primitive value from a service attribute to a DynamoDBEntry that can
        // be converted to a DateTime.
        internal static DynamoDBEntry EpochSecondsToDateTime(DynamoDBEntry entry, string attributeName)
        {
            var primitive = entry.AsPrimitive();

            // only try to convert N types to epoch time
            if (primitive != null &&
                primitive.Type == DynamoDBEntryType.Numeric)
            {
                DateTime?dateTime = null;
                try
                {
                    var epochSeconds = primitive.AsInt();
                    dateTime = AWSSDKUtils.ConvertFromUnixEpochSeconds(epochSeconds);
                }
                catch (Exception e)
                {
                    var logger = Logger.GetLogger(typeof(Document));
                    logger.InfoFormat(
                        "Encountered error attempting to convert attribute '{0}' with value '{1}' to DateTime: {2}",
                        attributeName, entry, e);
                }

                if (dateTime.HasValue)
                {
                    entry = (Primitive)(dateTime.Value);
                }
            }

            return(entry);
        }
        public void Test()
        {
            var ttl  = "1574822917";
            var date = AWSSDKUtils.ConvertFromUnixEpochSeconds(int.Parse(ttl)).ToUniversalTime();

            date.Should().Equals(DateTime.Parse("2019-11-27T02:48:37.172Z"));
        }
 public static IdentityServer4.Models.PersistedGrant ToPersistedGrant(PersistedGrant grant)
 {
     return(new IdentityServer4.Models.PersistedGrant
     {
         Key = grant.Key,
         ClientId = grant.ClientId,
         SessionId = grant.SessionId,
         SubjectId = grant.SubjectId,
         Data = grant.Data,
         Type = grant.Type,
         Description = grant.Description,
         Expiration = grant.Expiration.HasValue ? new DateTime?(AWSSDKUtils.ConvertFromUnixEpochSeconds(grant.Expiration.Value)) : null,
         CreationTime = grant.CreationTime,
         ConsumedTime = grant.ConsumedTime
     });
 }
        /// <summary>
        /// Gets the persisted grant.
        /// </summary>
        /// <returns>The persisted grant.</returns>
        /// <param name="pgd">Pgd.</param>
        public static PersistedGrant GetPersistedGrant(this PersistedGrantDynamoDB pgd)
        {
            if (pgd == null)
            {
                return(null);
            }

            return(new PersistedGrant
            {
                Key = pgd.Key,
                ClientId = pgd.ClientId,
                SubjectId = pgd.SubjectId,
                Type = pgd.Type,
                CreationTime = AWSSDKUtils.ConvertFromUnixEpochSeconds(pgd.CreationTime),
                Expiration = AWSSDKUtils.ConvertFromUnixEpochSeconds(pgd.Expiration),
                Data = pgd.Data
            });
        }
        private void Test(NameValueCollection config)
        {
            using (var client = CreateClient())
            {
                store = new DynamoDBSessionStateStore("TestSessionProvider", config);
                timeoutField.SetValue(store, newTimeout);

                WaitUntilTableReady(client, TableStatus.ACTIVE);
                var table = Table.LoadTable(client, tableName);

                var creationTime = DateTime.Now;
                store.CreateUninitializedItem(null, sessionId, 10);
                var items = GetAllItems(table);
                Assert.Single(items);
                var testTtl   = config.AllKeys.Contains(DynamoDBSessionStateStore.CONFIG_TTL_ATTRIBUTE);
                var firstItem = items[0];
                Assert.Equal(testTtl, firstItem.ContainsKey(ttlAttributeName));
                if (testTtl)
                {
                    var epochSeconds = firstItem[ttlAttributeName].AsInt();
                    Assert.NotEqual(0, epochSeconds);
                    var expiresDateTime         = AWSSDKUtils.ConvertFromUnixEpochSeconds(epochSeconds);
                    var expectedExpiresDateTime = (creationTime + newTimeout).AddSeconds(ttlExpiredSessionsSeconds);
                    Assert.True((expiresDateTime - expectedExpiresDateTime) < TimeSpan.FromMinutes(1));
                }

                bool                locked;
                TimeSpan            lockAge;
                object              lockId;
                SessionStateActions actionFlags;
                store.GetItem(null, sessionId, out locked, out lockAge, out lockId, out actionFlags);

                Thread.Sleep(newTimeout);

                DynamoDBSessionStateStore.DeleteExpiredSessions(client, tableName);
                items = GetAllItems(table);
                Assert.Empty(items);
            }
        }
Esempio n. 6
0
 private static DateTimeOffset GetTimestampFromStringValue(string seconds) =>
 AWSSDKUtils.ConvertFromUnixEpochSeconds(int.Parse(seconds));