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.
Hi,
I have a requirement where my user should be prompted or redirected to change password screen after every 90 days. How can this be achieved ?
Hi,
I have do some code change in IdentityUserAppService, IdentityRoleAppService and ProfileAppService by overridding few methods. Now I want to do Unit Testing of the overridden methods, How do I do it ? Difficulty facing while writing Unit Testing :
_userAppService = GetRequiredService<IIdentityUserAppService>();
this means I am refering to IIdentityUserAppService
Methods not my overridden methods right ?In short In my code block I have to fake my login with a particular user as my method have this kind code : For example as below :
public virtual async Task<IdentityUserDto> CreateAsync(IdentityUserCreateDto input)
{
var user = new IdentityUser(
GuidGenerator.Create(),
input.UserName,
input.Email,
CurrentTenant.Id
);
if (logged in with user : xyz@abc.com) //then only I have to map extra properties other wise I dont have to map it
{
input.MapExtraPropertiesTo(user);
}
(await UserManager.CreateAsync(user, input.Password)).CheckErrors();
await UpdateUserByInput(user, input);
await CurrentUnitOfWork.SaveChangesAsync();
return ObjectMapper.Map<IdentityUser, IdentityUserDto>(user);
}
So in order to test this kind of code I have to create a session where my xyz@abc.com
user is logged in, then and then only I can check my code block right ?
Please help !!!
REQUIREMENT #1 I want don't want to show options like Claims, Set Password for my logged user in User tab, similarly for Roles. I have control over Edit and Delete from permission options itself, but I want for other options as well. Please refer to the screenshot for more understanding
REQUIREMENT #2 I dont want to show Organization Units from Create/Edit User as shown below :
How do I do it ?