Exemplo n.º 1
0
        public async Task <bool> CreateManyConsentHandleAsync(IList <FlattenedConsentHandle> flatteneds,
                                                              CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                MyMappings.Init();
                if (flatteneds == null)
                {
                    throw new ArgumentNullException("flattened");
                }
                if (flatteneds.Count == 0)
                {
                    throw new ArgumentException("flattened is empty");
                }

                var session = CassandraSession;
                cancellationToken.ThrowIfCancellationRequested();

                var batch = new BatchStatement();
                var query = from item in flatteneds
                            select new FlattenedConsentRecord(item);
                var boundStatements = await BuildBoundStatements_ForCreate(query.ToList());

                batch.AddRange(boundStatements);

                await session.ExecuteAsync(batch).ConfigureAwait(false);

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public async Task <IEnumerable <global::IdentityServer3.Core.Models.Consent> > FindConsentsByClientIdAsync(
            string clientId,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                MyMappings.Init();
                var     session = CassandraSession;
                IMapper mapper  = new Mapper(session);
                cancellationToken.ThrowIfCancellationRequested();
                var record =
                    await
                    mapper.FetchAsync <FlattenedConsentHandle>(
                        "SELECT * FROM consent_by_clientid WHERE clientid = ?", clientId);

                List <Consent> finalResult = new List <Consent>();
                foreach (var item in record)
                {
                    var consent = await item.MakeConsentAsync();

                    finalResult.Add(consent);
                }
                return(finalResult);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        public async Task <global::IdentityServer3.Core.Models.AuthorizationCode> FindAuthorizationCodeByKey(
            string key,
            IClientStore clientStore,
            IScopeStore scopeStore,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                MyMappings.Init();
                var     session = CassandraSession;
                IMapper mapper  = new Mapper(session);
                cancellationToken.ThrowIfCancellationRequested();
                var record =
                    await
                    mapper.SingleAsync <FlattenedAuthorizationCodeHandle>(
                        "SELECT * FROM authorizationcodehandle_by_key WHERE key = ?", key);

                IAuthorizationCodeHandle ch = record;
                var result = await ch.MakeAuthorizationCodeAsync(clientStore, scopeStore);

                return(result);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Exemplo n.º 4
0
        public async Task <bool> DeleteAuthorizationCodeByKey(string key,
                                                              CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                MyMappings.Init();
                var     session = CassandraSession;
                IMapper mapper  = new Mapper(session);
                cancellationToken.ThrowIfCancellationRequested();
                var record_find =
                    await
                    mapper.SingleAsync <FlattenedAuthorizationCodeHandle>(
                        "SELECT * FROM authorizationcodehandle_by_key WHERE key = ?", key);

                // now that we gots ourselves the record, we have the primary key

                cancellationToken.ThrowIfCancellationRequested();

                var batch           = new BatchStatement();
                var boundStatements = await BuildBoundStatements_ForAuthorizationCodeHandleDelete(record_find.ClientId, key);

                batch.AddRange(boundStatements);

                await session.ExecuteAsync(batch).ConfigureAwait(false);

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Exemplo n.º 5
0
        public async Task <IEnumerable <ITokenMetadata> > FindAuthorizationCodeMetadataBySubject(string subject,
                                                                                                 IClientStore clientStore,
                                                                                                 IScopeStore scopeStore,
                                                                                                 CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                MyMappings.Init();
                var     session = CassandraSession;
                IMapper mapper  = new Mapper(session);
                cancellationToken.ThrowIfCancellationRequested();
                var record =
                    await
                    mapper.FetchAsync <FlattenedAuthorizationCodeHandle>(
                        "SELECT * FROM AuthorizationCodehandle_by_clientid WHERE subjectid = ?", subject);

                List <global::IdentityServer3.Core.Models.AuthorizationCode> authCodes = new List <global::IdentityServer3.Core.Models.AuthorizationCode>();
                foreach (var rec in record)
                {
                    var authCode = await rec.MakeAuthorizationCodeAsync(clientStore, scopeStore);

                    authCodes.Add(authCode);
                }

                return(authCodes);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
        public async Task <Store.Core.Models.IPage <Scope> > PageScopesAsync(int pageSize, byte[] pagingState,
                                                                             CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                MyMappings.Init();
                cancellationToken.ThrowIfCancellationRequested();

                var           session = CassandraSession;
                IMapper       mapper  = new Mapper(session);
                IPage <Scope> page;
                if (pagingState == null)
                {
                    page = await mapper.FetchPageAsync <Scope>(
                        Cql.New(SelectScopeQuery).WithOptions(opt =>
                                                              opt.SetPageSize(pageSize)));
                }
                else
                {
                    page = await mapper.FetchPageAsync <Scope>(
                        Cql.New(SelectScopeQuery).WithOptions(opt =>
                                                              opt.SetPageSize(pageSize).SetPagingState(pagingState)));
                }

                // var result = CreatePageProxy(page);
                var result = new PageProxy <Scope>(page);

                return(result);
            }
            catch (Exception e)
            {
                // only here to catch during a debug unit test.
                throw;
            }
        }
Exemplo n.º 7
0
        public async Task <bool> CreateManyAuthorizationCodeHandleAsync(
            IList <FlattenedAuthorizationCodeHandle> flattenedAuthorizationCodeHandles,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                MyMappings.Init();
                if (flattenedAuthorizationCodeHandles == null)
                {
                    throw new ArgumentNullException("flattenedAuthorizationCodeHandles");
                }
                if (flattenedAuthorizationCodeHandles.Count == 0)
                {
                    throw new ArgumentException("flattenedAuthorizationCodeHandles is empty");
                }

                var session = CassandraSession;
                cancellationToken.ThrowIfCancellationRequested();


                var batch           = new BatchStatement();
                var boundStatements = await BuildBoundStatements_ForCreate(flattenedAuthorizationCodeHandles);

                batch.AddRange(boundStatements);

                await session.ExecuteAsync(batch).ConfigureAwait(false);

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
        public async Task <IEnumerable <global::IdentityServer3.Core.Models.Scope> > FindScopesAsync(
            bool publicOnly = true,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                MyMappings.Init();
                cancellationToken.ThrowIfCancellationRequested();

                var query = string.Format("SELECT * FROM scopes_by_id WHERE ShowInDiscoveryDocument = {0}",
                                          publicOnly ? "true" : "false");
                var     session            = CassandraSession;
                IMapper mapper             = new Mapper(session);
                var     scopeMappedRecords = (await mapper.FetchAsync <ScopeMappedRecord>(query)).ToList();

                foreach (var scopeMappedRecord in scopeMappedRecords)
                {
                    scopeMappedRecord.Claims =
                        JsonConvert.DeserializeObject <List <ScopeClaim> >(scopeMappedRecord.ClaimsDocument);
                }
                var queryFinal = from item in scopeMappedRecords
                                 select(Scope) item;

                return(queryFinal);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Exemplo n.º 9
0
        public async Task <IEnumerable <ITokenMetadata> > FindRefreshTokenMetadataBySubject(string subject,
                                                                                            IClientStore clientStore,
                                                                                            CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                MyMappings.Init();
                var     session = CassandraSession;
                IMapper mapper  = new Mapper(session);
                cancellationToken.ThrowIfCancellationRequested();
                var record =
                    await
                    mapper.FetchAsync <FlattenedRefreshTokenHandle>(
                        "SELECT * FROM refreshtokenhandle_by_clientid WHERE subjectid = ?", subject);

                List <ITokenMetadata> listTokenMetadatas = new List <ITokenMetadata>();
                foreach (var item in record)
                {
                    var tmd = await item.MakeRefreshTokenAsync(clientStore);

                    listTokenMetadatas.Add(tmd);
                }

                return(listTokenMetadatas);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Exemplo n.º 10
0
 public async Task <bool> CreateConsentHandleAsync(FlattenedConsentHandle flat,
                                                   CancellationToken cancellationToken = default(CancellationToken))
 {
     try
     {
         MyMappings.Init();
         var list = new List <FlattenedConsentHandle> {
             flat
         };
         return(await CreateManyConsentHandleAsync(list, cancellationToken));
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Exemplo n.º 11
0
 public async Task <bool> CreateAuthorizationCodeHandleAsync(FlattenedAuthorizationCodeHandle tokenHandle,
                                                             CancellationToken cancellationToken = default(CancellationToken))
 {
     try
     {
         MyMappings.Init();
         var list = new List <FlattenedAuthorizationCodeHandle> {
             tokenHandle
         };
         return(await CreateManyAuthorizationCodeHandleAsync(list, cancellationToken));
     }
     catch (Exception e)
     {
         return(false);
     }
 }
        public async Task <global::IdentityServer3.Core.Models.Scope> FindScopeByIdAsync(Guid id,
                                                                                         CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                MyMappings.Init();
                var     session = CassandraSession;
                IMapper mapper  = new Mapper(session);
                cancellationToken.ThrowIfCancellationRequested();
                var record = await mapper.SingleAsync <ScopeMappedRecord>("SELECT * FROM scopes_by_id WHERE id = ?", id);

                record.Claims = JsonConvert.DeserializeObject <List <ScopeClaim> >(record.ClaimsDocument);
                return(record);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Exemplo n.º 13
0
        public async Task <bool> DeleteConsentBySubjectAndClientIdAsync(
            string subject, string clientId,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                MyMappings.Init();
                var     session = CassandraSession;
                IMapper mapper  = new Mapper(session);
                cancellationToken.ThrowIfCancellationRequested();
                await
                mapper.DeleteAsync <FlattenedConsentHandle>("WHERE clientid = ? AND subject = ?", clientId, subject);

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Exemplo n.º 14
0
        public async Task <global::IdentityServer3.Core.Models.Consent> FindConsentByIdAsync(Guid id,
                                                                                             CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                MyMappings.Init();
                var     session = CassandraSession;
                IMapper mapper  = new Mapper(session);
                cancellationToken.ThrowIfCancellationRequested();
                var record =
                    await mapper.SingleAsync <FlattenedConsentHandle>("SELECT * FROM consent_by_id WHERE id = ?", id);

                var result = await record.MakeConsentAsync();

                return(result);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Exemplo n.º 15
0
        public async Task <bool> DeleteAuthorizationCodesByClientIdAndSubjectId(string client, string subject,
                                                                                CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                MyMappings.Init();
                var     session = CassandraSession;
                IMapper mapper  = new Mapper(session);
                cancellationToken.ThrowIfCancellationRequested();
                // first find all the keys that are associated with this client and subject
                var record_find =
                    await
                    mapper.FetchAsync <FlattenedAuthorizationCodeHandle>(
                        "SELECT * FROM AuthorizationCodehandle_by_clientid WHERE ClientId = ? AND subjectId = ?",
                        client, subject);

                cancellationToken.ThrowIfCancellationRequested();

                // now that we gots ourselves the record, we have the primary key
                // we can now build a big batch delete
                var batch = new BatchStatement();
                foreach (var rFind in record_find)
                {
                    var boundStatements =
                        await BuildBoundStatements_ForAuthorizationCodeHandleDelete(rFind.ClientId, rFind.Key);

                    batch.AddRange(boundStatements);
                }
                await session.ExecuteAsync(batch).ConfigureAwait(false);

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
        public async Task <IEnumerable <global::IdentityServer3.Core.Models.Scope> > FindScopesByNamesAsync(
            IEnumerable <string> scopeNames,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                MyMappings.Init();
                cancellationToken.ThrowIfCancellationRequested();

                var queryInValues = from item in scopeNames
                                    select string.Format("'{0}'", item);

                var inValues = string.Join(",", queryInValues);
                var query    = string.Format("SELECT * FROM scopes_by_name WHERE name IN ({0})", inValues);


                var     session = CassandraSession;
                IMapper mapper  = new Mapper(session);
                var     result  = await mapper.FetchAsync <ScopeMappedRecord>(query);


                List <global::IdentityServer3.Core.Models.Scope> finalResult = new List <Scope>();

                foreach (var scopeMappedRecord in result)
                {
                    scopeMappedRecord.Claims =
                        JsonConvert.DeserializeObject <List <ScopeClaim> >(scopeMappedRecord.ClaimsDocument);
                    finalResult.Add(scopeMappedRecord);
                }

                return(finalResult);
            }
            catch (Exception e)
            {
                return(null);
            }
        }