Browse Source

Refactored Client aggregate for IDS4.

pull/206/head
Halil İbrahim Kalkan 8 years ago
parent
commit
60158af464
  1. 2
      src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientIdPRestrictionConsts.cs
  2. 32
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs
  3. 12
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientClaim.cs
  4. 5
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientGrantType.cs
  5. 14
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientIdPRestriction.cs
  6. 2
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUri.cs
  7. 14
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientProperty.cs
  8. 2
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientSecret.cs
  9. 4
      src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContext.cs

2
src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientIdPRestrictionConsts.cs

@ -2,6 +2,6 @@
{ {
public class ClientIdPRestrictionConsts public class ClientIdPRestrictionConsts
{ {
public const int ProviderMaxLength = 200; public const int ProviderMaxLength = 64;
} }
} }

32
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using IdentityServer4; using IdentityServer4;
using IdentityServer4.Models; using IdentityServer4.Models;
using JetBrains.Annotations;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
using Volo.Abp.Guids; using Volo.Abp.Guids;
@ -101,8 +102,10 @@ namespace Volo.Abp.IdentityServer.Clients
} }
public Client(Guid id, string clientId) public Client(Guid id, [NotNull] string clientId)
{ {
Check.NotNull(clientId, nameof(clientId));
Id = id; Id = id;
ClientId = clientId; ClientId = clientId;
@ -136,7 +139,7 @@ namespace Volo.Abp.IdentityServer.Clients
Properties = new List<ClientProperty>(); Properties = new List<ClientProperty>();
} }
public virtual void AddGrantType(string grantType) public virtual void AddGrantType([NotNull] string grantType)
{ {
AllowedGrantTypes.Add(new ClientGrantType(Id, grantType)); AllowedGrantTypes.Add(new ClientGrantType(Id, grantType));
} }
@ -150,29 +153,44 @@ namespace Volo.Abp.IdentityServer.Clients
); );
} }
public virtual void AddSecret(string value, DateTime? expiration = null, string type = IdentityServerConstants.SecretTypes.SharedSecret, string description = null) public virtual void AddSecret([NotNull] string value, DateTime? expiration = null, string type = IdentityServerConstants.SecretTypes.SharedSecret, string description = null)
{ {
ClientSecrets.Add(new ClientSecret(Id, value, expiration, type, description)); ClientSecrets.Add(new ClientSecret(Id, value, expiration, type, description));
} }
public virtual void AddScope(string scope) public virtual void AddScope([NotNull] string scope)
{ {
AllowedScopes.Add(new ClientScope(Id, scope)); AllowedScopes.Add(new ClientScope(Id, scope));
} }
public virtual void AddCorsOrigin(string origin) public virtual void AddCorsOrigin([NotNull] string origin)
{ {
AllowedCorsOrigins.Add(new ClientCorsOrigin(Id, origin)); AllowedCorsOrigins.Add(new ClientCorsOrigin(Id, origin));
} }
public virtual void AddRedirectUri(string redirectUri) public virtual void AddRedirectUri([NotNull] string redirectUri)
{ {
RedirectUris.Add(new ClientRedirectUri(Id, redirectUri)); RedirectUris.Add(new ClientRedirectUri(Id, redirectUri));
} }
public virtual void AddPostLogoutRedirectUri(string postLogoutRedirectUri) public virtual void AddPostLogoutRedirectUri([NotNull] string postLogoutRedirectUri)
{ {
PostLogoutRedirectUris.Add(new ClientPostLogoutRedirectUri(Id, postLogoutRedirectUri)); PostLogoutRedirectUris.Add(new ClientPostLogoutRedirectUri(Id, postLogoutRedirectUri));
} }
public virtual void AddIdentityProviderRestriction([NotNull] string provider)
{
IdentityProviderRestrictions.Add(new ClientIdPRestriction(Id, provider));
}
public virtual void AddProperty([NotNull] string key)
{
Properties.Add(new ClientProperty(Id, key));
}
public virtual void AddClaim(IGuidGenerator guidGenerator, [NotNull] string type, string value)
{
Claims.Add(new ClientClaim(guidGenerator.Create(), Id, type, value));
}
} }
} }

12
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientClaim.cs

@ -1,24 +1,30 @@
using System; using System;
using JetBrains.Annotations;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
namespace Volo.Abp.IdentityServer.Clients namespace Volo.Abp.IdentityServer.Clients
{ {
public class ClientClaim : Entity<Guid> public class ClientClaim : Entity<Guid>
{ {
public virtual Guid ClientId { get; set; }
public virtual string Type { get; set; } public virtual string Type { get; set; }
public virtual string Value { get; set; } public virtual string Value { get; set; }
public virtual Guid ClientId { get; set; }
protected ClientClaim() protected ClientClaim()
{ {
} }
public ClientClaim(Guid id) protected internal ClientClaim(Guid id, Guid clientId, [NotNull] string type, string value)
{ {
Check.NotNull(type, nameof(type));
Id = id; Id = id;
ClientId = clientId;
Type = type;
Value = value;
} }
} }
} }

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

@ -1,4 +1,5 @@
using System; using System;
using JetBrains.Annotations;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
namespace Volo.Abp.IdentityServer.Clients namespace Volo.Abp.IdentityServer.Clients
@ -14,8 +15,10 @@ namespace Volo.Abp.IdentityServer.Clients
} }
protected internal ClientGrantType(Guid clientId, string grantType) protected internal ClientGrantType(Guid clientId, [NotNull] string grantType)
{ {
Check.NotNull(grantType, nameof(grantType));
ClientId = clientId; ClientId = clientId;
GrantType = grantType; GrantType = grantType;
} }

14
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientIdPRestriction.cs

@ -1,22 +1,26 @@
using System; using System;
using JetBrains.Annotations;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
namespace Volo.Abp.IdentityServer.Clients namespace Volo.Abp.IdentityServer.Clients
{ {
public class ClientIdPRestriction : Entity<Guid> public class ClientIdPRestriction : Entity
{ {
public virtual string Provider { get; set; }
public virtual Guid ClientId { get; set; } public virtual Guid ClientId { get; set; }
public virtual string Provider { get; set; }
protected ClientIdPRestriction() protected ClientIdPRestriction()
{ {
} }
public ClientIdPRestriction(Guid id) protected internal ClientIdPRestriction(Guid clientId, [NotNull] string provider)
{ {
Id = id; Check.NotNull(provider, nameof(provider));
ClientId = clientId;
Provider = provider;
} }
} }
} }

2
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUri.cs

@ -4,7 +4,7 @@ using Volo.Abp.Domain.Entities;
namespace Volo.Abp.IdentityServer.Clients namespace Volo.Abp.IdentityServer.Clients
{ {
public class ClientPostLogoutRedirectUri : Entity<Guid> public class ClientPostLogoutRedirectUri : Entity
{ {
public virtual Guid ClientId { get; protected set; } public virtual Guid ClientId { get; protected set; }

14
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientProperty.cs

@ -1,24 +1,28 @@
using System; using System;
using JetBrains.Annotations;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
namespace Volo.Abp.IdentityServer.Clients namespace Volo.Abp.IdentityServer.Clients
{ {
public class ClientProperty : Entity<Guid> public class ClientProperty : Entity
{ {
public virtual Guid ClientId { get; set; }
public virtual string Key { get; set; } public virtual string Key { get; set; }
public virtual string Value { get; set; } public virtual string Value { get; set; }
public virtual Guid ClientId { get; set; }
protected ClientProperty() protected ClientProperty()
{ {
} }
public ClientProperty(Guid id) protected internal ClientProperty(Guid clientId, [NotNull] string key)
{ {
Id = id; Check.NotNull(key, nameof(key));
ClientId = clientId;
Key = key;
} }
} }
} }

2
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientSecret.cs

@ -14,7 +14,7 @@ namespace Volo.Abp.IdentityServer.Clients
} }
protected internal ClientSecret( protected internal ClientSecret(
Guid clientId, Guid clientId,
[NotNull] string value, [NotNull] string value,
DateTime? expiration = null, DateTime? expiration = null,
string type = IdentityServerConstants.SecretTypes.SharedSecret, string type = IdentityServerConstants.SecretTypes.SharedSecret,

4
src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContext.cs

@ -144,6 +144,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
{ {
idPRestriction.ToTable(TablePrefix + "ClientIdPRestrictions"); idPRestriction.ToTable(TablePrefix + "ClientIdPRestrictions");
idPRestriction.HasKey(x => new {x.ClientId, x.Provider});
idPRestriction.Property(x => x.Provider).HasMaxLength(ClientIdPRestrictionConsts.ProviderMaxLength).IsRequired(); idPRestriction.Property(x => x.Provider).HasMaxLength(ClientIdPRestrictionConsts.ProviderMaxLength).IsRequired();
}); });
@ -160,6 +162,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
{ {
property.ToTable(TablePrefix + "ClientProperties"); property.ToTable(TablePrefix + "ClientProperties");
property.HasKey(x => new {x.ClientId, x.Key});
property.Property(x => x.Key).HasMaxLength(ClientPropertyConsts.KeyMaxLength).IsRequired(); property.Property(x => x.Key).HasMaxLength(ClientPropertyConsts.KeyMaxLength).IsRequired();
property.Property(x => x.Value).HasMaxLength(ClientPropertyConsts.ValueMaxLength).IsRequired(); property.Property(x => x.Value).HasMaxLength(ClientPropertyConsts.ValueMaxLength).IsRequired();
}); });

Loading…
Cancel
Save