Base solution for your next web application
Open Closed

TryLoginFromExternalAuthenticationSources & SaveChangesAsync #5593


User avatar
0
sddev created

Hi,

We're setting up LDAP Authentication using the guides.

So far, LDAP Authentication works flawlessly. However it doesn't seem to save in the database.

Although the CreateAsync methods seem to work, ie

return await this.Store.CreateAsync(user, this.CancellationToken);

it appears that in AbpLoginManager.cs, this line,

wait UnitOfWorkManager.Current.SaveChangesAsync();

does not work.

Because when in the function LoginAsyncInternal, when the following line is called:

return await CreateLoginResultAsync(user, tenant);

the

await UserManager.UpdateAsync(user);

line in the function is unable to run because it cannot find the user.

Could you advise further?

Regards, Simon Dean


8 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    @SDdev are there any error message in the Log file (App_Data/Logs/Logs.txt) ?

  • User Avatar
    0
    sddev created

    Hi,

    I have located the following exception, which doesn't really tell me anything as far as I can. Interestingly, every time it tries to create a user, the user id does increase. I started on 15, it's now on 21. However nothing seems to get saved in the database which is rather curious.

    The logs are:

    ERROR 2018-09-13 16:00:59,135 [5    ] Mvc.ExceptionHandling.AbpExceptionFilter - There is no such an entity. Entity type: ACUTEC.TimeAndAttendance.Authorization.Users.User, id: 21
    Abp.Domain.Entities.EntityNotFoundException: There is no such an entity. Entity type: ACUTEC.TimeAndAttendance.Authorization.Users.User, id: 21
       at Abp.Domain.Repositories.AbpRepositoryBase`2.<GetAsync>d__21.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Abp.Threading.InternalAsyncHelper.<AwaitTaskWithPostActionAndFinallyAndGetResult>d__5`1.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Abp.Authorization.Users.AbpUserStore`2.&lt;GetUserNameFromDatabaseAsync&gt;d__88.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Abp.Authorization.Users.AbpUserManager`2.&lt;UpdateAsync&gt;d__47.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Abp.Authorization.AbpLogInManager`3.&lt;CreateLoginResultAsync&gt;d__38.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Abp.Authorization.AbpLogInManager`3.&lt;LoginAsyncInternal&gt;d__37.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Abp.Authorization.AbpLogInManager`3.&lt;LoginAsync&gt;d__36.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Abp.Threading.InternalAsyncHelper.<AwaitTaskWithPostActionAndFinallyAndGetResult>d__5`1.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at ACUTEC.TimeAndAttendance.Web.Controllers.TokenAuthController.<GetLoginResultAsync>d__36.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at ACUTEC.TimeAndAttendance.Web.Controllers.TokenAuthController.&lt;Authenticate&gt;d__23.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at lambda_method(Closure , Object )
       at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
       at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
       at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__10.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
       at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
       at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeInnerFilterAsync>d__14.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
       at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextExceptionFilterAsync>d__23.MoveNext()
    INFO  2018-09-13 16:00:59,657 [5    ] etCore.Mvc.Internal.ObjectResultExecutor - Executing ObjectResult, writing value Microsoft.AspNetCore.Mvc.ControllerContext.
    INFO  2018-09-13 16:00:59,769 [5    ] ore.Mvc.Internal.ControllerActionInvoker - Executed action ACUTEC.TimeAndAttendance.Web.Controllers.TokenAuthController.Authenticate (ACUTEC.TimeAndAttendance.Web.Core) in 119691.8196ms
    INFO  2018-09-13 16:00:59,786 [5    ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 121212.3609ms 404 application/json; charset=utf-8
    
  • User Avatar
    0
    sddev created

    If I try to manually run the commands in the debug stack on line 323 and 334 of AbpLoginManager (ie await UserManager.CreateAsync(user) and await UnitOfWorkManager.Current.SaveChangesAsync() I get the following results:

    CreateAsync: The function evaluation requires all threads to run SaveChangesAsync: Cannot apply unary operator to non-primitive value

    Im not seeing anything obvious however.

    Regards, Simon Dean

  • User Avatar
    0
    ismcagdas created
    Support Team

    @SDdev

    • Are you using the latest version of ABP ?
    • Are you trying with the host or a tenant ?
  • User Avatar
    0
    ismcagdas created
    Support Team

    @sddev any news ?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Closing because of inactivity. Please reopen the topic if you are not able to solve the problem.

  • User Avatar
    0
    sddev created

    Sorry for the delay in updating.

    We're using a version of ASP.NET Zero that was originally downloaded in April.

    Through the login page, we're selecting a Tenant, and then going to Login. The TryLoginFromExternalAuthenticationSources as far as I know should be trying to log in to our LDAP Server and indeed this works fine. However then when trying to create the user, it fails as above.

    Regards, Simon Dean

  • User Avatar
    0
    sddev created

    Can confirm this now works as expected in 5.6.2