コード例 #1
0
        public async Task <IdentityResult> DeleteIdentityClaimAsync(Neo4jIdentityServer4IdentityResource identityResource,
                                                                    Neo4jIdentityServer4IdentityClaim identityClaim, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            identityResource.ThrowIfNull(nameof(identityResource));
            identityClaim.ThrowIfNull(nameof(identityClaim));

            try
            {
                var cypher = $@"
                MATCH 
                    (r:{IdSrv4IdentityResource}{{Name: $p0}})-[:{Neo4jConstants.Relationships.HasClaim}]->
                    (c:{IdSrv4IdentityClaim}{{Type: $p1}}) 
                DETACH DELETE c";

                await Session.RunAsync(cypher,
                                       Params.Create(
                                           identityResource.Name,
                                           identityClaim.Type));
                await RaiseIdentityResourceChangeEventAsync(identityResource);

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
コード例 #2
0
        public async Task <IdentityResult> AddIdentityClaimAsync(Neo4jIdentityServer4IdentityResource identityResource,
                                                                 Neo4jIdentityServer4IdentityClaim identityClaim, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            identityResource.ThrowIfNull(nameof(identityResource));
            identityClaim.ThrowIfNull(nameof(identityClaim));

            try
            {
                var cypher = $@"
                MATCH 
                    (r:{IdSrv4IdentityResource}{{Name: $p0}}) 
                MERGE 
                    (l:{IdSrv4IdentityClaim} {"$p1".AsMapForNoNull<Neo4jIdentityServer4IdentityClaim>(identityClaim)})
                MERGE 
                    (r)-[:{Neo4jConstants.Relationships.HasClaim}]->(l)";

                var result = await Session.RunAsync(cypher, Params.Create(identityResource.Name, identityClaim));
                await RaiseIdentityResourceChangeEventAsync(identityResource);

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
コード例 #3
0
        public async Task <Neo4jIdentityServer4IdentityClaim> GetIdentityClaimAsync(Neo4jIdentityServer4IdentityResource identityResource,
                                                                                    Neo4jIdentityServer4IdentityClaim identityClaim, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            identityResource.ThrowIfNull(nameof(identityResource));
            identityClaim.ThrowIfNull(nameof(identityClaim));

            var cypher = $@"
                MATCH 
                    (r:{IdSrv4IdentityResource}{{Name: $p0}})-[:{Neo4jConstants.Relationships.HasClaim}]->
                    (c:{IdSrv4IdentityClaim}{{Type: $p1}}) 
                RETURN c {{ .* }}";

            var result = await Session.RunAsync(cypher, Params.Create(identityResource.Name, identityClaim.Type));

            var record =
                await result.SingleOrDefaultAsync(r => r.MapTo <Neo4jIdentityServer4IdentityClaim>("c"));

            return(record);
        }
コード例 #4
0
        public async Task <IdentityResult> InsertIdentityResource(
            IdentityResource model,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            model.ThrowIfNull(nameof(model));
            try
            {
                var dto    = model.ToNeo4jEntity();
                var result = await CreateIdentityResourceAsync(dto);

                if (!result.Succeeded)
                {
                    return(result);
                }
                foreach (var claim in model.UserClaims)
                {
                    var dtoClaim = new Neo4jIdentityServer4IdentityClaim()
                    {
                        Type = claim
                    };
                    result = await AddIdentityClaimAsync(dto, dtoClaim);

                    if (!result.Succeeded)
                    {
                        return(result);
                    }
                }

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
コード例 #5
0
 /// <summary>
 /// Maps an entity to a model.
 /// </summary>
 /// <param name="entity">The entity.</param>
 /// <returns></returns>
 public static string ToModel(this Neo4jIdentityServer4IdentityClaim entity)
 {
     return(Mapper.Map <string>(entity));
 }