Browse Source

identity server clients refactor

pull/1070/head
Yunus Emre Kalkan 8 years ago
parent
commit
1a3f20b59b
  1. 105
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs
  2. 17
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientClaim.cs
  3. 7
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientCorsOrigin.cs
  4. 5
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientGrantType.cs
  5. 5
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientIdPRestriction.cs
  6. 5
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUri.cs
  7. 5
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientProperty.cs
  8. 5
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientRedirectUri.cs
  9. 6
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientScope.cs
  10. 2
      modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContextModelCreatingExtensions.cs

105
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs

@ -144,18 +144,19 @@ namespace Volo.Abp.IdentityServer.Clients
AllowedGrantTypes.Add(new ClientGrantType(Id, grantType));
}
public virtual void AddGrantTypes(IEnumerable<string> grantTypes)
public virtual void RemoveAllAllowedGrantTypes()
{
AllowedGrantTypes.AddRange(
grantTypes.Select(
grantType => new ClientGrantType(Id, grantType)
)
);
AllowedGrantTypes.Clear();
}
public virtual void RemoveAllAllowedGrantTypes()
public virtual void RemoveGrantType(string grantType)
{
AllowedGrantTypes.Clear();
AllowedGrantTypes.RemoveAll(r => r.GrantType == grantType);
}
public virtual ClientGrantType FindGrantType(string grantType)
{
return AllowedGrantTypes.FirstOrDefault(r => r.GrantType == grantType);
}
public virtual void AddSecret([NotNull] string value, DateTime? expiration = null, string type = IdentityServerConstants.SecretTypes.SharedSecret, string description = null)
@ -183,6 +184,16 @@ namespace Volo.Abp.IdentityServer.Clients
AllowedScopes.Clear();
}
public virtual void RemoveScope(string scope)
{
AllowedScopes.RemoveAll(r => r.Scope == scope);
}
public virtual ClientScope FindScope(string scope)
{
return AllowedScopes.FirstOrDefault(r => r.Scope == scope);
}
public virtual void AddCorsOrigin([NotNull] string origin)
{
AllowedCorsOrigins.Add(new ClientCorsOrigin(Id, origin));
@ -198,29 +209,49 @@ namespace Volo.Abp.IdentityServer.Clients
PostLogoutRedirectUris.Add(new ClientPostLogoutRedirectUri(Id, postLogoutRedirectUri));
}
public virtual void RemoveAllCorsOrigin()
public virtual void RemoveAllCorsOrigins()
{
AllowedCorsOrigins.Clear();
}
public virtual void RemoveAllRedirectUri()
public virtual void RemoveCorsOrigin(string uri)
{
AllowedCorsOrigins.RemoveAll(c => c.Origin == uri);
}
public virtual void RemoveAllRedirectUris()
{
RedirectUris.Clear();
}
public virtual void RemoveAllPostLogoutRedirectUri()
public virtual void RemoveRedirectUri(string uri)
{
RedirectUris.RemoveAll(r => r.RedirectUri == uri);
}
public virtual void RemoveAllPostLogoutRedirectUris()
{
PostLogoutRedirectUris.Clear();
}
public virtual void AddIdentityProviderRestriction([NotNull] string provider)
public virtual void RemovePostLogoutRedirectUri(string uri)
{
IdentityProviderRestrictions.Add(new ClientIdPRestriction(Id, provider));
PostLogoutRedirectUris.RemoveAll(p => p.PostLogoutRedirectUri == uri);
}
public virtual void RemoveAllIdentityProviderRestriction()
public virtual ClientCorsOrigin FindCorsOrigin(string uri)
{
IdentityProviderRestrictions.Clear();
return AllowedCorsOrigins.FirstOrDefault(c => c.Origin == uri);
}
public virtual ClientRedirectUri FindRedirectUri(string uri)
{
return RedirectUris.FirstOrDefault(r => r.RedirectUri == uri);
}
public virtual ClientPostLogoutRedirectUri FindPostLogoutRedirectUri(string uri)
{
return PostLogoutRedirectUris.FirstOrDefault(p => p.PostLogoutRedirectUri == uri);
}
public virtual void AddProperty([NotNull] string key, [NotNull] string value)
@ -233,14 +264,54 @@ namespace Volo.Abp.IdentityServer.Clients
Properties.Clear();
}
public virtual void AddClaim(IGuidGenerator guidGenerator, [NotNull] string type, string value)
public virtual void RemoveProperty(string key, string value)
{
Claims.Add(new ClientClaim(guidGenerator.Create(), Id, type, value));
Properties.RemoveAll(c => c.Value == value && c.Key == key);
}
public virtual ClientProperty FindProperty(string key, string value)
{
return Properties.FirstOrDefault(c => c.Key == key && c.Value == value);
}
public virtual void AddClaim([NotNull] string value, string type)
{
Claims.Add(new ClientClaim(Id, type, value));
}
public virtual void RemoveAllClaims()
{
Claims.Clear();
}
public virtual void RemoveClaim(string value, string type)
{
Claims.RemoveAll(c => c.Value == value && c.Type == type);
}
public virtual ClientClaim FindClaim(string value, string type)
{
return Claims.FirstOrDefault(c => c.Type == type && c.Value == value);
}
public virtual void AddIdentityProviderRestriction([NotNull] string provider)
{
IdentityProviderRestrictions.Add(new ClientIdPRestriction(Id, provider));
}
public virtual void RemoveAllIdentityProviderRestrictions()
{
IdentityProviderRestrictions.Clear();
}
public virtual void RemoveIdentityProviderRestriction(string provider)
{
IdentityProviderRestrictions.RemoveAll(r => r.Provider == provider);
}
public virtual ClientIdPRestriction FindIdentityProviderRestriction(string provider)
{
return IdentityProviderRestrictions.FirstOrDefault(r => r.Provider == provider);
}
}
}

17
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientClaim.cs

@ -4,7 +4,7 @@ using Volo.Abp.Domain.Entities;
namespace Volo.Abp.IdentityServer.Clients
{
public class ClientClaim : Entity<Guid>
public class ClientClaim : Entity
{
public virtual Guid ClientId { get; set; }
@ -14,17 +14,26 @@ namespace Volo.Abp.IdentityServer.Clients
protected ClientClaim()
{
}
public virtual bool Equals(Guid clientId, string value, string type)
{
return ClientId == clientId && Type == type && Value == value;
}
protected internal ClientClaim(Guid id, Guid clientId, [NotNull] string type, string value)
protected internal ClientClaim(Guid clientId, [NotNull] string type, string value)
{
Check.NotNull(type, nameof(type));
Id = id;
ClientId = clientId;
Type = type;
Value = value;
}
public override object[] GetKeys()
{
return new object[] { ClientId, Type, Value };
}
}
}

7
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientCorsOrigin.cs

@ -12,7 +12,12 @@ namespace Volo.Abp.IdentityServer.Clients
protected ClientCorsOrigin()
{
}
public virtual bool Equals(Guid clientId, [NotNull] string uri)
{
return ClientId == clientId && Origin == uri;
}
protected internal ClientCorsOrigin(Guid clientId, [NotNull] string origin)

5
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientGrantType.cs

@ -15,6 +15,11 @@ namespace Volo.Abp.IdentityServer.Clients
}
public virtual bool Equals(Guid clientId, [NotNull] string grantType)
{
return ClientId == clientId && GrantType == grantType;
}
protected internal ClientGrantType(Guid clientId, [NotNull] string grantType)
{
Check.NotNull(grantType, nameof(grantType));

5
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientIdPRestriction.cs

@ -15,6 +15,11 @@ namespace Volo.Abp.IdentityServer.Clients
}
public virtual bool Equals(Guid clientId, [NotNull] string provider)
{
return ClientId == clientId && Provider == provider;
}
protected internal ClientIdPRestriction(Guid clientId, [NotNull] string provider)
{
Check.NotNull(provider, nameof(provider));

5
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUri.cs

@ -15,6 +15,11 @@ namespace Volo.Abp.IdentityServer.Clients
}
public virtual bool Equals(Guid clientId, [NotNull] string uri)
{
return ClientId == clientId && PostLogoutRedirectUri == uri;
}
protected internal ClientPostLogoutRedirectUri(Guid clientId, [NotNull] string postLogoutRedirectUri)
{
Check.NotNull(postLogoutRedirectUri, nameof(postLogoutRedirectUri));

5
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientProperty.cs

@ -17,6 +17,11 @@ namespace Volo.Abp.IdentityServer.Clients
}
public virtual bool Equals(Guid clientId, [NotNull] string key, string value)
{
return ClientId == clientId && Key == key && Value == value;
}
protected internal ClientProperty(Guid clientId, [NotNull] string key, [NotNull] string value)
{
Check.NotNull(key, nameof(key));

5
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientRedirectUri.cs

@ -15,6 +15,11 @@ namespace Volo.Abp.IdentityServer.Clients
}
public virtual bool Equals(Guid clientId, [NotNull] string uri)
{
return ClientId == clientId && RedirectUri == uri;
}
protected internal ClientRedirectUri(Guid clientId, [NotNull] string redirectUri)
{
Check.NotNull(redirectUri, nameof(redirectUri));

6
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientScope.cs

@ -1,4 +1,5 @@
using System;
using JetBrains.Annotations;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.IdentityServer.Clients
@ -14,6 +15,11 @@ namespace Volo.Abp.IdentityServer.Clients
}
public virtual bool Equals(Guid clientId, [NotNull] string scope)
{
return ClientId == clientId && Scope == scope;
}
protected internal ClientScope(Guid clientId, string scope)
{
ClientId = clientId;

2
modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContextModelCreatingExtensions.cs

@ -103,6 +103,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
{
claim.ToTable(tablePrefix + "ClientClaims", schema);
claim.HasKey(x => new { x.ClientId, x.Type, x.Value });
claim.Property(x => x.Type).HasMaxLength(ClientClaimConsts.TypeMaxLength).IsRequired();
claim.Property(x => x.Value).HasMaxLength(ClientClaimConsts.ValueMaxLength).IsRequired();
});

Loading…
Cancel
Save