hello maliming thanks for the help issue is resolved
hi mailiming, i need to use the IdentityUserOrganizationUnit in my existing project scenario how can i use it as a Repository. Thanks
hi maliming , Able to use the controller Thanks a lot . can you please explain where the issue occurred and how we can identify it , where do we need to fix the code if there is any Thanks
hi Maliming , i have tried above but still im not able to test my Api function it is not at all hitting the controller can you please help
hello sure PFB code :
Entity table: AuthenticationPolicy
public class AuthenticationPolicy : FullAuditedEntity<Guid>, IMultiTenant
{
public Guid? TenantId { get; set;}
public string Name { get; set;}
public string Identity { get; set; }
public IdentityType IdentityType { get; set;}
public int MFALevels { get; set;}
public string Authentications { get; set; }
public string AlternateAuthentications { get; set; }
}
Repository Declaration:
public interface IAuthenticationPolicyRepository : IRepository<AuthenticationPolicy, Guid>
{
Task<List<AuthenticationPolicy>> GetListAsync(
string filterText = null,
string policyName=null,
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
CancellationToken cancellationToken = default
);
Task<long> GetCountAsync(
string filterText = null,
string policyName=null,
CancellationToken cancellationToken = default);
}
Repository Implimentation:
public class EFCoreAuthenticationPolicyRepository : EfCoreRepository<IdentityProDbContext, AuthenticationPolicy, Guid>, IAuthenticationPolicyRepository
{
public EFCoreAuthenticationPolicyRepository(IDbContextProvider<IdentityProDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
public async Task<long> GetCountAsync(
string filterText = null,
string policyName = null,
CancellationToken cancellationToken = default)
{
var query = ApplyFilter((await GetDbSetAsync()), filterText, policyName);
return await query.LongCountAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<AuthenticationPolicy>> GetListAsync(
string filterText = null,
string policyName = null,
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
CancellationToken cancellationToken = default)
{
var query = ApplyFilter((await GetQueryableAsync()), filterText, policyName);
query = query.OrderBy(string.IsNullOrWhiteSpace(sorting) ? AuthenticationPolicyConsts.GetDefaultSorting(false) : sorting);
return await query.PageBy(skipCount, maxResultCount).ToListAsync(cancellationToken);
}
protected virtual IQueryable<AuthenticationPolicy> ApplyFilter(
IQueryable<AuthenticationPolicy> query,
string filtertext,
string policyName=null)
{
return query.WhereIf(!string.IsNullOrWhiteSpace(filtertext), e => e.Name.Contains(filtertext))
.WhereIf(!string.IsNullOrWhiteSpace(policyName), e => e.Name.Contains(policyName));
}
}
Entity table: TenantAuthentications
public class TenantAuthentications : FullAuditedEntity<Guid>,IMultiTenant
{
public Guid? TenantId { get; set; }
public bool MFA { get; set; }
public AuthenticationOptions PrimaryAuthentication { get; set; }
public AuthenticationOptions SecondaryAuthentication { get; set; }
public string AlternateAuthentications { get; set; }
public bool EnableAdaptiveAuthentication { get; set; }
}
Repository Declaration :
using Volo.Abp.Domain.Repositories;
namespace Volo.Abp.Identity.AuthPolicy
{
public interface ITenantAuthenticationsRepository : IRepository<TenantAuthentications, Guid>
{
}
}
Repository Implimentation
public class EFCoreTenantAuthenticatiosRepository : EfCoreRepository<IdentityProDbContext, TenantAuthentications, Guid>, ITenantAuthenticationsRepository
{
public EFCoreTenantAuthenticatiosRepository(IDbContextProvider<IdentityProDbContext> dbContextProvider)
:base(dbContextProvider)
{
}
}
Efcore web module
typeof(AbpIdentityProDomainModule),
typeof(AbpIdentityEntityFrameworkCoreModule))]
public class AbpIdentityProEntityFrameworkCoreModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAbpDbContext<IdentityProDbContext>(options =>
{
options.ReplaceDbContext<IIdentityDbContext, IIdentityProDbContext>();
});
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
}
}
Hi,
Here i am providing the code and error log
Code: IAuthenticationPolicyAppService interface :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
namespace Volo.Abp.Identity.AuthPolicy
{
public interface IAuthenticationPolicyAppService : IApplicationService
{
Task<PagedResultDto<AuthPolicyResponseDto>> GetAllAuthenticationPoliciesListAsync(GetAllRequestDto input);
}
}
AuthenticationPolicyAppService class :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using System.Linq.Dynamic.Core;
namespace Volo.Abp.Identity.AuthPolicy
{
//[Authorize(IdentityPermissions.AuthenticationPolicy.Default)]
public class AuthenticationPolicyAppService : ApplicationService, IAuthenticationPolicyAppService
{
private readonly IAuthenticationPolicyRepository _authenticationPolicyRepository;
private readonly ITenantAuthenticationsRepository _tenantAuthenticationsRepository;
private readonly IIdentityUserRepository _identityUserRepository;
private readonly IOrganizationUnitRepository _organizationUnitRepository;
private readonly IRepository<IdentityUserOrganizationUnit> _IdentityUserOrganizationUnitRepository;
public AuthenticationPolicyAppService(IAuthenticationPolicyRepository authenticationPolicyRepository, ITenantAuthenticationsRepository tenantAuthenticationsRepository,
IIdentityUserRepository identityUserRepository, IOrganizationUnitRepository organizationUnitRepository,
IRepository<IdentityUserOrganizationUnit> IdentityUserOrganizationUnitRepository)
{
_authenticationPolicyRepository = authenticationPolicyRepository;
_identityUserRepository = identityUserRepository;
_organizationUnitRepository = organizationUnitRepository;
_IdentityUserOrganizationUnitRepository = IdentityUserOrganizationUnitRepository;
_tenantAuthenticationsRepository = tenantAuthenticationsRepository;
}
//For Authentication policies...
public async Task<PagedResultDto<AuthPolicyResponseDto>> GetAllAuthenticationPoliciesListAsync(GetAllRequestDto input)
{
var totalCount = await _authenticationPolicyRepository.GetCountAsync(input.Filter, input.PolicyName);
var items = await _authenticationPolicyRepository.GetListAsync(input.Filter, input.PolicyName, input.Sorting, input.MaxResultCount, input.SkipCount);
var policiesList = items.Select(x => new AuthPolicyResponseDto
{
Name = x.Name,
IdentityType = x.IdentityType.ToString(),
Identity = GetUserOrGroupName(x.IdentityType, x.Identity).ToString(),
MFALevels = x.MFALevels,
Authentications = x.Authentications,
AlternateAuthentications = x.AlternateAuthentications
}).ToList();
return new PagedResultDto<AuthPolicyResponseDto>
{
TotalCount = totalCount,
Items = policiesList
};
}
}
}
//ITenantPolicyAppservice interface...
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
namespace Volo.Abp.Identity.AuthPolicy
{
public interface ITenantPolicyAppService : IApplicationService
{
Task<TenantPolicyDto> GetTenantAuthenticationPolicyAsync();
Task<BaseResponseDto> UpdateTenantAuthenticationPolicy(TenantPolicyDto input);
}
}
Implimentation...
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
namespace Volo.Abp.Identity.AuthPolicy
{
public class TenantPolicyAppService : ApplicationService, ITenantPolicyAppService
{
public readonly ITenantAuthenticationsRepository _tenantAuthenticationsRepository;
public TenantPolicyAppService (ITenantAuthenticationsRepository tenantAuthenticationsRepository)
{
_tenantAuthenticationsRepository = tenantAuthenticationsRepository;
}
public async Task<TenantPolicyDto> GetTenantAuthenticationPolicyAsync()
{
using (CurrentTenant.Change(this.CurrentTenant?.Id))
{
var tenantauthpolicy = _tenantAuthenticationsRepository.GetListAsync().Result.FirstOrDefault();
return new TenantPolicyDto
{
MFA = tenantauthpolicy.MFA,
PrimaryAuthentication = tenantauthpolicy.PrimaryAuthentication,
SecondaryAuthentication =tenantauthpolicy.SecondaryAuthentication,
AlternateAuthentications =tenantauthpolicy.AlternateAuthentications,
EnableAdaptiveAuthentication =tenantauthpolicy.EnableAdaptiveAuthentication
};
}
}
public async Task<BaseResponseDto> UpdateTenantAuthenticationPolicy(TenantPolicyDto input)
{
using (CurrentTenant.Change(this.CurrentTenant?.Id))
{
var updatetenantauthpolicy = _tenantAuthenticationsRepository.GetListAsync().Result.FirstOrDefault();
if (updatetenantauthpolicy != null)
{
updatetenantauthpolicy.MFA = input.MFA;
updatetenantauthpolicy.PrimaryAuthentication = input.PrimaryAuthentication;
updatetenantauthpolicy.SecondaryAuthentication = input.SecondaryAuthentication;
updatetenantauthpolicy.AlternateAuthentications = input.AlternateAuthentications;
updatetenantauthpolicy.EnableAdaptiveAuthentication = input.EnableAdaptiveAuthentication;
await _tenantAuthenticationsRepository.UpdateAsync(updatetenantauthpolicy,true);
}
else
{
var createpolicy = new TenantAuthentications()
{
TenantId = this.CurrentTenant?.Id,
MFA = input.MFA,
PrimaryAuthentication = input.PrimaryAuthentication,
SecondaryAuthentication = input.SecondaryAuthentication,
AlternateAuthentications = input.AlternateAuthentications,
EnableAdaptiveAuthentication = input.EnableAdaptiveAuthentication
};
await _tenantAuthenticationsRepository.InsertAsync(createpolicy,true);
}
return new BaseResponseDto
{
Message = "Success",
status = true
};
}
}
}
}
This is my code
ErrorLog:
2024-07-19 11:04:17.508 +05:30 [INF] Executing endpoint 'Volo.Abp.Identity.IdentityAuthenticationPoliciesController.GetAllAuthenticationPoliciesListAsync (Volo.Abp.Identity.Pro.HttpApi)'
2024-07-19 11:04:17.512 +05:30 [INF] Route matched with {area = "identity", controller = "AuthenticationPolicies", action = "GetAllAuthenticationPoliciesList", page = ""}. Executing controller action with signature System.Threading.Tasks.Task`1[Volo.Abp.Application.Dtos.PagedResultDto`1[Volo.Abp.Identity.AuthPolicy.AuthPolicyResponseDto]] GetAllAuthenticationPoliciesListAsync(Volo.Abp.Identity.AuthPolicy.GetAllRequestDto) on controller Volo.Abp.Identity.IdentityAuthenticationPoliciesController (Volo.Abp.Identity.Pro.HttpApi).
2024-07-19 11:04:17.533 +05:30 [ERR] ---------- RemoteServiceErrorInfo ----------
{
"code": null,
"message": "An internal error occurred during your request!",
"details": null,
"data": {
"ActivatorChain": "Volo.Abp.Identity.IdentityAuthenticationPoliciesController -> Volo.Abp.Identity.AuthPolicy.AuthenticationPolicyAppService"
},
"validationErrors": null
}
2024-07-19 11:04:17.534 +05:30 [ERR] An exception was thrown while activating Volo.Abp.Identity.IdentityAuthenticationPoliciesController -> Volo.Abp.Identity.AuthPolicy.AuthenticationPolicyAppService.
Autofac.Core.DependencyResolutionException: An exception was thrown while activating Volo.Abp.Identity.IdentityAuthenticationPoliciesController -> Volo.Abp.Identity.AuthPolicy.AuthenticationPolicyAppService.
---> Autofac.Core.DependencyResolutionException: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'Volo.Abp.Identity.AuthPolicy.AuthenticationPolicyAppService' can be invoked with the available services and parameters:
Cannot resolve parameter 'Volo.Abp.Identity.AuthPolicy.ITenantAuthenticationsRepository tenantAuthenticationsRepository' of constructor 'Void .ctor(Volo.Abp.Identity.AuthPolicy.IAuthenticationPolicyRepository, Volo.Abp.Identity.AuthPolicy.ITenantAuthenticationsRepository, Volo.Abp.Identity.IIdentityUserRepository, Volo.Abp.Identity.IOrganizationUnitRepository, Volo.Abp.Domain.Repositories.IRepository`1[Volo.Abp.Identity.IdentityUserOrganizationUnit])'.
at Autofac.Core.Activators.Reflection.ReflectionActivator.<>c__DisplayClass12_0.<UseSingleConstructorActivation>b__0(ResolveRequestContext ctxt, Action`1 next)
at Autofac.Core.Resolving.Middleware.DisposalTrackingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
at Autofac.Builder.RegistrationBuilder`3.<>c__DisplayClass41_0.<PropertiesAutowired>b__0(ResolveRequestContext ctxt, Action`1 next)
at Autofac.Extras.DynamicProxy.RegistrationExtensions.<>c__DisplayClass8_0`3.<EnableInterfaceInterceptors>b__1(ResolveRequestContext ctxt, Action`1 next)
at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
--- End of inner exception stack trace ---
at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
at Autofac.Core.Resolving.Middleware.SharingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
at Autofac.Core.Resolving.Middleware.CircularDependencyDetectorMiddleware.Execute(ResolveRequestContext context, Action`1 next)
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, ResolveRequest request)
at Autofac.Core.Resolving.ResolveOperation.ExecuteOperation(ResolveRequest request)
at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)
at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters)
at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass6_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
2024-07-19 11:04:17.536 +05:30 [ERR] ---------- Exception Data ----------
ActivatorChain = Volo.Abp.Identity.IdentityAuthenticationPoliciesController -> Volo.Abp.Identity.AuthPolicy.AuthenticationPolicyAppService
2024-07-19 11:04:17.552 +05:30 [INF] Executing ObjectResult, writing value of type 'Volo.Abp.Http.RemoteServiceErrorResponse'.
2024-07-19 11:04:17.557 +05:30 [INF] Executed action Volo.Abp.Identity.IdentityAuthenticationPoliciesController.GetAllAuthenticationPoliciesListAsync (Volo.Abp.Identity.Pro.HttpApi) in 44.0186ms
2024-07-19 11:04:17.557 +05:30 [INF] Executed endpoint 'Volo.Abp.Identity.IdentityAuthenticationPoliciesController.GetAllAuthenticationPoliciesListAsync (Volo.Abp.Identity.Pro.HttpApi)'
2024-07-19 11:04:17.557 +05:30 [INF] Request finished HTTP/2 GET https://localhost:44347/api/identity/authentication-policies/authentication-policies-list - - - 500 - application/json;+charset=utf-8 74.7870ms
2024-07-19 11:04:17.602 +05:30 [INF] Background job started
2024-07-19 11:04:17.605 +05:30 [INF] Background job complted!! it will run agian
2024-07-19 11:04:20.621 +05:30 [INF] Background job started
2024-07-19 11:04:20.630 +05:30 [INF] Background job complted!! it will run agian
2024-07-19 11:04:23.642 +05:30 [INF] Background job started