Browse Source

identity server apiresource refactor

pull/1070/head
Yunus Emre Kalkan 8 years ago
parent
commit
1e643381c3
  1. 40
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResource.cs
  2. 7
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceClaim.cs
  3. 18
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScope.cs
  4. 5
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScopeClaim.cs
  5. 7
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiSecret.cs

40
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResource.cs

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using IdentityServer4;
using JetBrains.Annotations;
using Volo.Abp.Domain.Entities;
@ -57,16 +58,27 @@ namespace Volo.Abp.IdentityServer.ApiResources
Secrets.Add(new ApiSecret(Id, value, expiration, type, description));
}
public virtual void AddScope(
public virtual void RemoveSecret([NotNull] string value, string type = IdentityServerConstants.SecretTypes.SharedSecret)
{
Secrets.RemoveAll(s => s.Value == value && s.Type == type);
}
public virtual ApiSecret FindSecret([NotNull] string value, string type = IdentityServerConstants.SecretTypes.SharedSecret)
{
return Secrets.FirstOrDefault(s => s.Type == type && s.Value == value);
}
public virtual ApiScope AddScope(
[NotNull] string name,
string displayName = null,
string description = null,
bool required = false,
bool emphasize = false,
bool showInDiscoveryDocument = true,
ApiScopeClaim[] userClaims = null)
bool showInDiscoveryDocument = true)
{
Scopes.Add(new ApiScope(Id, name, displayName, description, required, emphasize, showInDiscoveryDocument));
var scope = new ApiScope(Id, name, displayName, description, required, emphasize, showInDiscoveryDocument);
Scopes.Add(scope);
return scope;
}
public virtual void AddUserClaim([NotNull] string type)
@ -79,6 +91,16 @@ namespace Volo.Abp.IdentityServer.ApiResources
UserClaims.Clear();
}
public virtual void RemoveClaim(string type)
{
UserClaims.RemoveAll(c => c.Type == type);
}
public virtual ApiResourceClaim FindClaim(string type)
{
return UserClaims.FirstOrDefault(c => c.Type == type);
}
public virtual void RemoveAllSecrets()
{
Secrets.Clear();
@ -92,5 +114,15 @@ namespace Volo.Abp.IdentityServer.ApiResources
}
Scopes.Clear();
}
public virtual void RemoveScope(string name)
{
Scopes.RemoveAll(r => r.Name == name);
}
public virtual ApiScope FindScope(string name)
{
return Scopes.FirstOrDefault(r => r.Name == name);
}
}
}

7
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceClaim.cs

@ -9,7 +9,12 @@ namespace Volo.Abp.IdentityServer.ApiResources
protected ApiResourceClaim()
{
}
public virtual bool Equals(Guid apiResourceId, [NotNull] string type)
{
return ApiResourceId == apiResourceId && Type == type;
}
protected internal ApiResourceClaim(Guid apiResourceId, [NotNull] string type)

18
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScope.cs

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using Volo.Abp.Domain.Entities;
@ -26,7 +27,12 @@ namespace Volo.Abp.IdentityServer.ApiResources
protected ApiScope()
{
}
public virtual bool Equals(Guid apiResourceId, [NotNull] string name)
{
return ApiResourceId == apiResourceId && Name == name;
}
protected internal ApiScope(
@ -61,6 +67,16 @@ namespace Volo.Abp.IdentityServer.ApiResources
UserClaims.Clear();
}
public virtual void RemoveClaim(string name, string type)
{
UserClaims.RemoveAll(r => r.Name == name && r.Type == type);
}
public virtual ApiScopeClaim FindClaim(string name, string type)
{
return UserClaims.FirstOrDefault(r => r.Name == name && r.Type == type);
}
public override object[] GetKeys()
{
return new object[] { ApiResourceId, Name };

5
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScopeClaim.cs

@ -15,6 +15,11 @@ namespace Volo.Abp.IdentityServer.ApiResources
}
public virtual bool Equals(Guid apiResourceId, [NotNull] string name, [NotNull] string type)
{
return ApiResourceId == apiResourceId && Name == name && Type == type;
}
protected internal ApiScopeClaim(Guid apiResourceId, [NotNull] string name, [NotNull] string type)
: base(type)
{

7
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiSecret.cs

@ -10,7 +10,12 @@ namespace Volo.Abp.IdentityServer.ApiResources
protected ApiSecret()
{
}
public virtual bool Equals(Guid apiResourceId, [NotNull] string value, string type = IdentityServerConstants.SecretTypes.SharedSecret)
{
return ApiResourceId == apiResourceId && Value == value && Type == type;
}
protected internal ApiSecret(

Loading…
Cancel
Save