public async Task <IdentityResult> DeleteRollupAsync(
            Neo4jIdentityServer4ApiResource apiResource,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            apiResource.ThrowIfNull(nameof(apiResource));

            try
            {
                var cypher = $@"
                MATCH 
                    (:{IdSrv4ApiResource}{{Name: $p0}})-[:{Neo4jConstants.Relationships.HasRollup}]->
                    (r:{IdSrv4ApiResourceRollup}) 
                DETACH DELETE r";

                await Session.RunAsync(cypher,
                                       Params.Create(apiResource.Name));

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
        public async Task <IdentityResult> DeleteApiResourceAsync(
            Neo4jIdentityServer4ApiResource apiResource,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            apiResource.ThrowIfNull(nameof(apiResource));
            await DeleteApiScopesAsync(apiResource, cancellationToken);

            try
            {
                var cypher = $@"
                MATCH (r:{IdSrv4ApiResource}{{Name: $p0}})
                DETACH DELETE r";

                await Session.RunAsync(cypher, Params.Create(apiResource.Name));
                await RaiseApiResourceChangeEventAsync(apiResource);

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
        private async Task <IdentityResult> AddRollupAsync(
            Neo4jIdentityServer4ApiResource apiResource,
            ApiResourceRollup rollup,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            apiResource.ThrowIfNull(nameof(apiResource));
            rollup.ThrowIfNull(nameof(rollup));

            try
            {
                var cypher = $@"
                    MATCH (c:{IdSrv4ApiResource}{{Name: $p0}})        
                    MERGE (rollup:{IdSrv4ApiResourceRollup} {"$p1".AsMapForNoNull<ApiResourceRollup>(rollup)})
                    MERGE (c)-[:{Neo4jConstants.Relationships.HasRollup}]->(rollup)";

                var result = await Session.RunAsync(cypher, Params.Create(apiResource.Name, rollup));

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
        public async Task <ApiResource> GetRollupAsync(
            Neo4jIdentityServer4ApiResource apiResource,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            apiResource.ThrowIfNull(nameof(apiResource));

            var cypher = $@"
                MATCH 
                    (:{IdSrv4ApiResource}{{Name: $p0}})-[:{Neo4jConstants.Relationships.HasRollup}]->
                    (r:{IdSrv4ApiResourceRollup})
                RETURN r{{ .* }}";

            var result = await Session.RunAsync(cypher,
                                                Params.Create(apiResource.Name));

            IdentityServer4.Models.ApiResource model = null;
            var foundRecord =
                await result.SingleOrDefaultAsync(r => r.MapTo <ApiResourceRollup>("r"));

            if (foundRecord == null)
            {
                model = await RollupAsync(apiResource, cancellationToken);
            }
            else
            {
                model = JsonConvert.DeserializeObject <ApiResource>(foundRecord.ApiResourceJson);
            }

            return(model);
        }
        public async Task <IdentityResult> DeleteApiSecretAsync(
            Neo4jIdentityServer4ApiResource apiResource,
            Neo4jIdentityServer4ApiSecret apiSecret,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            apiResource.ThrowIfNull(nameof(apiResource));
            apiSecret.ThrowIfNull(nameof(apiSecret));

            try
            {
                var cypher = $@"
                MATCH 
                    (r:{IdSrv4ApiResource}{{Name: $p0}})-[:{Neo4jConstants.Relationships.HasSecret}]->
                    (s:{IdSrv4ApiSecret}{{Type: $p1,Value: $p2}}) 
                DETACH DELETE s";

                await Session.RunAsync(cypher,
                                       Params.Create(
                                           apiResource.Name,
                                           apiSecret.Type, apiSecret.Value));
                await RaiseApiResourceChangeEventAsync(apiResource);

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
        public async Task <IdentityResult> AddApiSecretAsync(
            Neo4jIdentityServer4ApiResource apiResource,
            Neo4jIdentityServer4ApiSecret apiSecret,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            apiResource.ThrowIfNull(nameof(apiResource));
            apiSecret.ThrowIfNull(nameof(apiSecret));

            try
            {
                var cypher = $@"
                MATCH 
                    (r:{IdSrv4ApiResource}{{Name: $p0}}) 
                MERGE 
                    (s:{IdSrv4ApiSecret} {"$p1".AsMapForNoNull<Neo4jIdentityServer4ApiSecret>(apiSecret)})
                MERGE 
                    (r)-[:{Neo4jConstants.Relationships.HasSecret}]->(s)";

                var result = await Session.RunAsync(cypher, Params.Create(apiResource.Name, apiSecret));
                await RaiseApiResourceChangeEventAsync(apiResource);

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
コード例 #7
0
        public async Task <Scope> RollupAsync(
            Neo4jIdentityServer4ApiResource apiResource,
            Neo4jIdentityServer4ApiScope apiScope,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            apiResource.ThrowIfNull(nameof(apiResource));
            apiScope.ThrowIfNull(nameof(apiScope));

            await RaiseApiScopeChangeEventAsync(apiResource, apiScope);

            var finalResult   = new Client();
            var apiScopeFound = await GetApiScopeAsync(apiResource, apiScope, cancellationToken);

            var model          = apiScopeFound.ToModel();
            var apiScopeClaims = await GetApiScopeClaimsAsync(apiResource, apiScopeFound, cancellationToken);

            if (apiScopeClaims != null)
            {
                foreach (var item in apiScopeClaims)
                {
                    model.UserClaims.Add(item.Type);
                }
            }
            var rollup = new ApiScopeRollup()
            {
                ApiScopeJson = JsonConvert.SerializeObject(model),
            };
            var result = await AddRollupAsync(apiResource, apiScopeFound, rollup, cancellationToken);

            return(model);
        }
コード例 #8
0
        public async Task <Neo4jIdentityServer4ApiScopeClaim> GetApiScopeClaimAsync(
            Neo4jIdentityServer4ApiResource apiResource,
            Neo4jIdentityServer4ApiScope apiScope,
            Neo4jIdentityServer4ApiScopeClaim apiScopeClaim,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            apiResource.ThrowIfNull(nameof(apiResource));
            apiScope.ThrowIfNull(nameof(apiScope));

            var cypher = $@"
                MATCH 
                    (:{IdSrv4ApiResource}{{Name: $p0}})-[:{Neo4jConstants.Relationships.HasScope}]->
                    (:{IdSrv4ClientApiScope}{{Name: $p1}})-[:{Neo4jConstants.Relationships.HasClaim}]->
                    (s:{IdSrv4ClientApiScopeClaim}{{Type: $p2}})
                RETURN s {{ .* }}";

            var result = await Session.RunAsync(cypher,
                                                Params.Create(apiResource.Name, apiScope.Name, apiScopeClaim.Type));

            var record =
                await result.SingleOrDefaultAsync(r => r.MapTo <Neo4jIdentityServer4ApiScopeClaim>("s"));

            return(record);
        }
コード例 #9
0
        public async Task <IdentityResult> UpdateApiScopeAsync(
            Neo4jIdentityServer4ApiResource apiResource,
            Neo4jIdentityServer4ApiScope apiScope,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            apiResource.ThrowIfNull(nameof(apiResource));
            apiScope.ThrowIfNull(nameof(apiScope));

            try
            {
                var cypher = $@"
                    MATCH 
                        (:{IdSrv4ApiResource}{{Name: $p0}})
                        -[:{Neo4jConstants.Relationships.HasScope}]->
                        (apiScope:{IdSrv4ClientApiScope}{{Name: $p1}})
                    SET apiScope = $p1";

                await Session.RunAsync(cypher, Params.Create(apiResource.Name, apiScope.Name, apiScope.ConvertToMap()));

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
        public async Task <ApiResource> RollupAsync(
            Neo4jIdentityServer4ApiResource apiResource,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            apiResource.ThrowIfNull(nameof(apiResource));
            var foundApiResource = await GetApiResourceAsync(apiResource, cancellationToken);

            ApiResource model = null;

            if (foundApiResource != null)
            {
                model = foundApiResource.ToModel();
                var secrets = await GetApiSecretsAsync(apiResource, cancellationToken);

                foreach (var secret in secrets)
                {
                    model.ApiSecrets.Add(secret.ToModel());
                }

                var claims = await GetApiResourceClaimsAsync(apiResource, cancellationToken);

                foreach (var claim in claims)
                {
                    model.UserClaims.Add(claim.Type);
                }

                var apiScopes = await GetApiScopesAsync(apiResource, cancellationToken);

                foreach (var apiScope in apiScopes)
                {
                    var apiScopeModel = await GetRollupAsync(apiResource, apiScope, cancellationToken);

                    model.Scopes.Add(apiScopeModel);
                }

                var distinctList = model.Scopes.Distinct(new ModelsScopeComparer());
                model.Scopes = distinctList.ToList();

                var rollup = new ApiResourceRollup()
                {
                    ApiResourceJson = JsonConvert.SerializeObject(model),
                };
                await AddRollupAsync(apiResource, rollup);
            }


            return(model);
        }
コード例 #11
0
        public async Task <IdentityResult> DeleteApiScopesAsync(
            Neo4jIdentityServer4ApiResource apiResource,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            apiResource.ThrowIfNull(nameof(apiResource));
            var apiScopes = await GetApiScopesAsync(apiResource, cancellationToken);

            foreach (var apiScope in apiScopes)
            {
                await DeleteApiScopeAsync(apiResource, apiScope, cancellationToken);
            }
            return(IdentityResult.Success);
        }
        public async Task <Neo4jIdentityServer4ApiResource> GetApiResourceAsync(
            Neo4jIdentityServer4ApiResource apiResource,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            apiResource.ThrowIfNull(nameof(apiResource));

            var cypher = $@"
                MATCH (r:{IdSrv4ApiResource}{{Name: $p0}})
                RETURN r {{ .* }}";

            var result = await Session.RunAsync(cypher, Params.Create(apiResource.Name));

            var grantTypeRecord =
                await result.SingleOrDefaultAsync(r => r.MapTo <Neo4jIdentityServer4ApiResource>("r"));

            return(grantTypeRecord);
        }
        public async Task <IdentityResult> CreateApiResourceAsync(
            Neo4jIdentityServer4ApiResource apiResource,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            apiResource.ThrowIfNull(nameof(apiResource));
            try
            {
                var cypher = $@"CREATE (r:{IdSrv4ApiResource} $p0)";
                await Session.RunAsync(cypher, Params.Create(apiResource.ConvertToMap()));
                await RaiseApiResourceChangeEventAsync(apiResource);

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
        public async Task <IList <Neo4jIdentityServer4ApiSecret> > GetApiSecretsAsync(
            Neo4jIdentityServer4ApiResource apiResource,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            apiResource.ThrowIfNull(nameof(apiResource));

            var cypher = $@"
                MATCH 
                    (:{IdSrv4ApiResource}{{Name: $p0}})-[:{Neo4jConstants.Relationships.HasSecret}]->
                    (s:{IdSrv4ApiSecret})
                RETURN 
                    s{{ .* }}";

            var result = await Session.RunAsync(cypher, Params.Create(apiResource.Name));

            var records = await result.ToListAsync(r => r.MapTo <Neo4jIdentityServer4ApiSecret>("s"));

            return(records);
        }
コード例 #15
0
        public async Task <Neo4jIdentityServer4ApiScope> GetApiScopeAsync(
            Neo4jIdentityServer4ApiResource apiResource,
            Neo4jIdentityServer4ApiScope apiScope,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            apiResource.ThrowIfNull(nameof(apiResource));
            apiScope.ThrowIfNull(nameof(apiScope));

            var cypher = $@"
                MATCH (apiResource:{IdSrv4ApiResource})-[:{Neo4jConstants.Relationships.HasScope}]->(apiScope:{IdSrv4ClientApiScope})
                WHERE apiResource.Name = $p0 AND apiScope.Name = $p1
                RETURN apiScope {{ .* }}";

            var result = await Session.RunAsync(cypher, Params.Create(apiResource.Name, apiScope.Name));

            var record =
                await result.SingleOrDefaultAsync(r => r.MapTo <Neo4jIdentityServer4ApiScope>("apiScope"));

            return(record);
        }