I have implemented override for SignInManager
and have done some custom logic check in CanSignInAsync()
method
If my custom logic fails I thrown Exception
ie. throw new AbpValidationException(...my_error_message...)
On angular side I am not getting any error response in json format to handle, it's directly throwing the below error, below are the details from network tab.
Volo.Abp.Validation.AbpValidationException: Inactive user
at SCV.Litmus.LitmusOverrides.LitmusSigInManager.CanSignInAsync(IdentityUser user) in D:\Litmus\Projects\ar-allocation\SCV.Litmus\aspnet-core\microservices\SCV.Litmus.IdentityServer\LitmusOverrides\LitmusSigInManager.cs:line 56
at Microsoft.AspNetCore.Identity.SignInManager`1.PreSignInCheck(TUser user)
at Microsoft.AspNetCore.Identity.SignInManager`1.CheckPasswordSignInAsync(TUser user, String password, Boolean lockoutOnFailure)
My expectation was something like this : https://docs.abp.io/en/abp/latest/Exception-Handling#validation-errors
{
"error": {
"code": "App:010046",
"message": "Your request is not valid, please correct and try again!",
"validationErrors": [{
"message": "Username should be minimum length of 3.",
"members": ["userName"]
},
{
"message": "Password is required",
"members": ["password"]
}]
}
}
How to get the above type of details by throwing error from SignInManager ?
Requirements
Current situation
I hope you got my requirements clear. Please suggest me the easiest way to achieve this.
How to get selected language for a logged in user i.e. english, chinese etc. at application service level
"tr" "pt-BR" "en" "zh-Hans" "sl"
and where is it stored in db ? i.e.which table ?
I want to perform some check for the user before loggin in. If user pass those check user should be able to login or else throw some validation error.
What is the better approach for this requirement ?
I tried implementing IUserValidator but its not working as per expected.
There is already another ticket going on with 2 different topic so creating this ticket for this topic https://support.abp.io/QA/Questions/1826/Customizing-Application-Modules-Extending-User-Entity-ie-ApbUsers#answer-3ac227f1-8d97-2c1e-25c5-39fef082cb09
Hi,
I refered https://docs.abp.io/en/abp/4.4/Authorization#iauthorizationservice document.
throw new AbpAuthorizationException("...");
this line of code should throw Authorization Failed error, but instead it is throwing Interval Server Error
I want to throw Authorization Failed error on certain permission check (custom logic).
I need to add one column to AbpUsers table which I can use while querying abpUsers table I followed this https://docs.abp.io/en/abp/4.4/Customizing-Application-Modules-Extending-Entities#entity-extensions-ef-core
I was able to do migration and update-database. Column was created in database but I was not able to find the column while querying.
var allUsers = await UserRepository.GetListAsync();
var myConditionalUsers = allUsers.Where(x => x.PropertyAdded == 1).ToList();
Not able to find PropertyAdded
Can you provide quick solution?
Hi,
I am using PostgreSQL and I have created few views in my database. How do I query those views in my AppService ?
DbSet<ViewName>/DbQuery<ViewName>
Can you please provide step by step Implementation guide? I will be very helpful.
Thanks
Hi,
I am not able to see security-logs
on UI.
And even AuditLogs are not visible even after giving permission for same.
Please guide me !!!
Hi,
We have created custom repositories for our entities as per https://docs.abp.io/en/abp/latest/Repositories#custom-repositories. In one of our repository we one method which executes postgreSQL function as below :
public async Task<bool> UpdateInvoiceStatusInBulk(InvoiceStatusUpdateBulkDto updateInvoiceList, CancellationToken cancellationToken = default)
{
var result = false;
var data = JsonConvert.SerializeObject(updateInvoiceList);
await EnsureConnectionOpenAsync(cancellationToken);
using (var command = CreateCommand("SELECT \"UpdateInvoiceStatus\"(@data)", CommandType.StoredProcedure, new NpgsqlParameter("@data", data)))
{
result = (bool)command.ExecuteScalarAsync(cancellationToken).Result;
}
return result;
}
Normally this method works fine.
But while unit testing for the method which call UpdateInvoiceStatusInBulk
method internally gives error i.e. Unable to cast object of type 'Microsoft.Data.Sqlite.SqliteConnection' to type 'Npgsql.NpgsqlConnection
This is just because while unit testing we use sqlite db which is provided by framework.
I am not able to do testing of the method which internally calls the above method. How do I resolve this issue ?
2021-05-14 14:14:46.482 +05:30 [ERR] One or more errors occurred. (ValueFactory attempted to access the Value property of this instance.)
System.AggregateException: One or more errors occurred. (ValueFactory attempted to access the Value property of this instance.)
---> System.InvalidOperationException: ValueFactory attempted to access the Value property of this instance.
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at Volo.Abp.Authorization.Permissions.PermissionDefinitionManager.get_PermissionDefinitions()
at Volo.Abp.Authorization.Permissions.PermissionDefinitionManager.GetOrNull(String name)
at Volo.Abp.Authorization.AbpAuthorizationPolicyProvider.GetPolicyAsync(String policyName)
at Microsoft.AspNetCore.Authorization.AuthorizationPolicy.CombineAsync(IAuthorizationPolicyProvider policyProvider, IEnumerable`1 authorizeData)
at Volo.Abp.Authorization.MethodInvocationAuthorizationService.CheckAsync(MethodInvocationAuthorizationContext context)
at Volo.Abp.Authorization.AuthorizationInterceptor.AuthorizeAsync(IAbpMethodInvocation invocation)
at Volo.Abp.Authorization.AuthorizationInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
at Volo.Abp.Auditing.AuditingInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
at Volo.Abp.Validation.ValidationInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
at SCV.Litmus.Permissions.AccessPermissionDefinitionProvider.GetRoles() in D:\Litmus\Projects\core-platform\SCV.Litmus\aspnet-core\modules\litmus-core\src\SCV.Litmus.Application.Contracts\Permissions\AccessPermissionDefinitionProvider.cs:line 35
at SCV.Litmus.Permissions.AccessPermissionDefinitionProvider.Define(IPermissionDefinitionContext context) in D:\Litmus\Projects\core-platform\SCV.Litmus\aspnet-core\modules\litmus-core\src\SCV.Litmus.Application.Contracts\Permissions\AccessPermissionDefinitionProvider.cs:line 25
at Volo.Abp.Authorization.Permissions.PermissionDefinitionManager.CreatePermissionGroupDefinitions()
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at Volo.Abp.Authorization.Permissions.PermissionDefinitionManager.CreatePermissionDefinitions()
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at Volo.Abp.Authorization.Permissions.PermissionDefinitionManager.get_PermissionDefinitions()
at Volo.Abp.Authorization.Permissions.PermissionDefinitionManager.GetPermissions()
at Volo.Abp.Authorization.AbpAuthorizationPolicyProvider.GetPoliciesNamesAsync()
at Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.AbpApplicationConfigurationAppService.GetAuthConfigAsync()
at Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.AbpApplicationConfigurationAppService.GetAsync()
at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
at Volo.Abp.Auditing.AuditingInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
at Volo.Abp.Validation.ValidationInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
at Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.AbpApplicationConfigurationController.GetAsync()
at lambda_method(Closure , Object )
at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
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 where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
I was trying to get dynamic value in PermissionDefinitionProvider below is the source code :
public class AccessPermissionDefinitionProvider : PermissionDefinitionProvider
{
private readonly ISomeAppService _someAppService;
public AccessPermissionDefinitionProvider(ISomeAppService someAppService)
{
_someAppService = someAppService;
}
public override void Define(IPermissionDefinitionContext context)
{
var myGroup = context.AddGroup("XYZAccessControl", L("Permission:XYZAccessControl"));
var somePermission = myGroup.AddPermission("XYZBased", L("Permission:XYZ"));
var fetchedData = GetData();
foreach (var item in fetchedData)
{
somePermission.AddChild(item);
}
}
private string[] GetData()
{
var data = _someAppService.GetSomeData().Result; //Just because await throws error here.
return data.select(x=> x.someValue).Distinct().ToArray();
}
private static LocalizableString L(string name)
{
return LocalizableString.Create<XYZResource>(name);
}
}
I cannot run the project as the above error is shown.
REQUIREMENT :
GetData()
with hardcode value it work's as per my expectation but the count is not increased/decreased once I select the permission from the permission tree. Not able to find how it works.Please provide correct approach to achieve this, If I am doing it in a wrong way. I need to achieve this as this is the mandatory requirement for my project.