OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.45k stars 2.41k forks source link

Token Validation Settings Page Display Error on OC 1.9.x latest preview version #15525

Open hyzx86 opened 8 months ago

hyzx86 commented 8 months ago

Describe the bug

To Reproduce

Fist I need to clarify that , when I copy my site data to the OC source code project,then running this page without any problems, I would like to know if I have made some breaking changes recently, which causes me to need to adjust some of my code?

I've checked this document to make sure my code has made all the adjustments. https://github.com/OrchardCMS/OrchardCore/blob/main/src/docs/releases/1.9.0.md

My project is based on Nuget package of OC, everything was fine under 1.8 version, but after upgrading to 1.9, some strange phenomenon occurred.

First, there was a problem in the openid login process, when requesting tokens, the browser reported an error.

I tried to locate the problem, using the latest code of local OC package and copy the dll and pdb to my project, then start my project (Ctrl + F5), and then go to the source code of OC and click Append to process. When I opened the Token Validation menu, the debugger began to report an error. http://localhost:2919/salesportal/Admin/OrchardCore.OpenId/ValidationConfiguration/Index? admin=-571533867

At present, it seems that except for this page, other pages can be opened normally. image

Expected behavior

The page should open normally

Screenshots

Warning session is empty, at line 56

image

The following is part of the log content

2024-03-16 01:18:51.1505|SalesProtalDev|00-0e98ef483974295a3617d686c1b8f7f9-fabd85d9c9f4782b-00||OrchardCore.Environment.Shell.ShellHost|DEBUG|Creating shell context for tenant 'TestInit' 
2024-03-16 01:18:51.1509|SalesProtalDev|00-0e98ef483974295a3617d686c1b8f7f9-fabd85d9c9f4782b-00||OrchardCore.Environment.Shell.Builders.ShellContextFactory|INFO|Creating shell context for tenant 'TestInit' 
2024-03-16 01:18:51.1509|SalesProtalDev|00-0e98ef483974295a3617d686c1b8f7f9-fabd85d9c9f4782b-00||OrchardCore.Environment.Shell.Builders.ShellContextFactory|DEBUG|Creating described context for tenant 'TestInit' 
2024-03-16 01:18:51.1509|SalesProtalDev|00-0e98ef483974295a3617d686c1b8f7f9-fabd85d9c9f4782b-00||OrchardCore.Environment.Shell.Builders.CompositionStrategy|DEBUG|Composing blueprint 
2024-03-16 01:18:51.1509|SalesProtalDev|00-0e98ef483974295a3617d686c1b8f7f9-fabd85d9c9f4782b-00||OrchardCore.Environment.Shell.Builders.CompositionStrategy|DEBUG|Done composing blueprint 
2024-03-16 01:34:04.6558|SalesProtalDev|0HN252BB33S3J||OrchardCore.Modules.ModularBackgroundService|INFO|Start processing background task 'OrchardCore.PublishLater.Services.ScheduledPublishingBackgroundTask' on tenant 'SalesProtalDev'. 
2024-03-16 01:34:04.7647|SalesProtalDev|0HN252BB33S3J||YesSql|DEBUG|SELECT * FROM [PublishLaterPartIndex] AS [PublishLaterPartIndex_a1] WHERE ((([PublishLaterPartIndex_a1].[Latest] = @p0) and ([PublishLaterPartIndex_a1].[Published] <> @p1)) and ([PublishLaterPartIndex_a1].[ScheduledPublishDateTimeUtc] < @p2)) 
2024-03-16 01:34:04.7914|SalesProtalDev|0HN252BB33S3J||OrchardCore.Modules.ModularBackgroundService|INFO|Finished processing background task 'OrchardCore.PublishLater.Services.ScheduledPublishingBackgroundTask' on tenant 'SalesProtalDev'. 
2024-03-16 01:34:04.7914|SalesProtalDev|0HN252BB33S3J||OrchardCore.Modules.ModularBackgroundService|INFO|Start processing background task 'OrchardCore.ArchiveLater.Services.ScheduledArchivingBackgroundTask' on tenant 'SalesProtalDev'. 
2024-03-16 01:34:04.7914|SalesProtalDev|0HN252BB33S3J||YesSql|DEBUG|SELECT * FROM [ArchiveLaterPartIndex] AS [ArchiveLaterPartIndex_a1] WHERE ((([ArchiveLaterPartIndex_a1].[Latest] = @p0) and ([ArchiveLaterPartIndex_a1].[Published] = @p1)) and ([ArchiveLaterPartIndex_a1].[ScheduledArchiveDateTimeUtc] < @p2)) 
2024-03-16 01:34:04.7914|SalesProtalDev|0HN252BB33S3J||OrchardCore.Modules.ModularBackgroundService|INFO|Finished processing background task 'OrchardCore.ArchiveLater.Services.ScheduledArchivingBackgroundTask' on tenant 'SalesProtalDev'. 
2024-03-16 01:34:04.7914|SalesProtalDev|0HN252BB33S3J||OrchardCore.Modules.ModularBackgroundService|INFO|Start processing background task 'OrchardCore.Search.Lucene.IndexingBackgroundTask' on tenant 'SalesProtalDev'. 
2024-03-16 01:34:04.8395|SalesProtalDev|0HN252BB33S3J||OrchardCore.Modules.ModularBackgroundService|INFO|Finished processing background task 'OrchardCore.Search.Lucene.IndexingBackgroundTask' on tenant 'SalesProtalDev'. 
2024-03-16 01:34:04.8395|SalesProtalDev|0HN252BB33S3J||OrchardCore.Modules.ModularBackgroundService|INFO|Start processing background task 'OrchardCore.OpenId.Tasks.OpenIdBackgroundTask' on tenant 'SalesProtalDev'. 
2024-03-16 01:34:05.2260|SalesProtalDev|00-0e98ef483974295a3617d686c1b8f7f9-fabd85d9c9f4782b-00||OrchardCore.DisplayManagement.DisplayManager|ERROR|IDisplayDriver`1 thrown from OrchardCore.OpenId.Drivers.OpenIdValidationSettingsDisplayDriver by NullReferenceException System.NullReferenceException: Object reference not set to an instance of an object.
   at YesSql.QueryExtensions.Query[T](ISession session, String collection)
   at OrchardCore.Data.Documents.DocumentStore.GetOrCreateImmutableAsync[T](Func`1 factoryAsync) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Data.YesSql\Documents\DocumentStore.cs:line 56
   at OrchardCore.Environment.Shell.Data.Descriptors.ShellDescriptorManager.GetShellDescriptorAsync() in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Infrastructure\Shell\ShellDescriptorManager.cs:line 57
   at OrchardCore.Environment.Shell.Builders.ShellContextFactory.<>c__DisplayClass5_0.<<OrchardCore-Environment-Shell-Builders-IShellContextFactory-CreateShellContextAsync>b__0>d.MoveNext() in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore\Shell\Builders\ShellContextFactory.cs:line 44
--- End of stack trace from previous location ---
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Abstractions\Shell\Scope\ShellScope.cs:line 253
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Abstractions\Shell\Scope\ShellScope.cs:line 258
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Abstractions\Shell\Scope\ShellScope.cs:line 263
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Abstractions\Shell\Scope\ShellScope.cs:line 268
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Abstractions\Shell\Scope\ShellScope.cs:line 269
   at OrchardCore.Environment.Shell.Builders.ShellContextFactory.OrchardCore.Environment.Shell.Builders.IShellContextFactory.CreateShellContextAsync(ShellSettings settings) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore\Shell\Builders\ShellContextFactory.cs:line 41
   at OrchardCore.Environment.Shell.ShellHost.GetOrCreateShellContextAsync(ShellSettings settings) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore\Shell\ShellHost.cs:line 104
   at OrchardCore.Environment.Shell.ShellHost.GetScopeAsync(ShellSettings settings) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore\Shell\ShellHost.cs:line 136
   at OrchardCore.OpenId.Drivers.OpenIdValidationSettingsDisplayDriver.<>c__DisplayClass2_0.<<EditAsync>b__0>d.MoveNext() in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore.Modules\OrchardCore.OpenId\Drivers\OpenIdValidationSettingsDisplayDriver.cs:line 38
--- End of stack trace from previous location ---
   at OrchardCore.DisplayManagement.ShapeFactoryExtensions.<CreateAsync>g__Awaited|6_0[TModel](ValueTask task, IShape shape) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.DisplayManagement\IShapeFactory.cs:line 81
   at OrchardCore.DisplayManagement.Implementation.DefaultShapeFactory.CreateAsync(String shapeType, Func`1 shapeFactory, Action`1 creating, Action`1 created) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.DisplayManagement\Implementation\DefaultShapeFactory.cs:line 94
   at OrchardCore.DisplayManagement.Views.ShapeResult.ApplyImplementationAsync(BuildShapeContext context, String displayType) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.DisplayManagement\Views\ShapeResult.cs:line 105
   at OrchardCore.DisplayManagement.DisplayManager`1.<>c.<<BuildEditorAsync>b__6_0>d.MoveNext() in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.DisplayManagement\DisplayManager.cs:line 100
--- End of stack trace from previous location ---
   at OrchardCore.Modules.InvokeExtensions.InvokeAsync[TEvents,T1,T2](IEnumerable`1 events, Func`4 dispatch, T1 arg1, T2 arg2, ILogger logger) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Abstractions\Modules\Extensions\InvokeExtensions.cs:line 151    at YesSql.QueryExtensions.Query[T](ISession session, String collection)
   at OrchardCore.Data.Documents.DocumentStore.GetOrCreateImmutableAsync[T](Func`1 factoryAsync) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Data.YesSql\Documents\DocumentStore.cs:line 56
   at OrchardCore.Environment.Shell.Data.Descriptors.ShellDescriptorManager.GetShellDescriptorAsync() in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Infrastructure\Shell\ShellDescriptorManager.cs:line 57
   at OrchardCore.Environment.Shell.Builders.ShellContextFactory.<>c__DisplayClass5_0.<<OrchardCore-Environment-Shell-Builders-IShellContextFactory-CreateShellContextAsync>b__0>d.MoveNext() in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore\Shell\Builders\ShellContextFactory.cs:line 44
--- End of stack trace from previous location ---
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Abstractions\Shell\Scope\ShellScope.cs:line 253
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Abstractions\Shell\Scope\ShellScope.cs:line 258
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Abstractions\Shell\Scope\ShellScope.cs:line 263
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Abstractions\Shell\Scope\ShellScope.cs:line 268
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Abstractions\Shell\Scope\ShellScope.cs:line 269
   at OrchardCore.Environment.Shell.Builders.ShellContextFactory.OrchardCore.Environment.Shell.Builders.IShellContextFactory.CreateShellContextAsync(ShellSettings settings) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore\Shell\Builders\ShellContextFactory.cs:line 41
   at OrchardCore.Environment.Shell.ShellHost.GetOrCreateShellContextAsync(ShellSettings settings) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore\Shell\ShellHost.cs:line 104
   at OrchardCore.Environment.Shell.ShellHost.GetScopeAsync(ShellSettings settings) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore\Shell\ShellHost.cs:line 136
   at OrchardCore.OpenId.Drivers.OpenIdValidationSettingsDisplayDriver.<>c__DisplayClass2_0.<<EditAsync>b__0>d.MoveNext() in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore.Modules\OrchardCore.OpenId\Drivers\OpenIdValidationSettingsDisplayDriver.cs:line 38
--- End of stack trace from previous location ---
   at OrchardCore.DisplayManagement.ShapeFactoryExtensions.<CreateAsync>g__Awaited|6_0[TModel](ValueTask task, IShape shape) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.DisplayManagement\IShapeFactory.cs:line 81
   at OrchardCore.DisplayManagement.Implementation.DefaultShapeFactory.CreateAsync(String shapeType, Func`1 shapeFactory, Action`1 creating, Action`1 created) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.DisplayManagement\Implementation\DefaultShapeFactory.cs:line 94
   at OrchardCore.DisplayManagement.Views.ShapeResult.ApplyImplementationAsync(BuildShapeContext context, String displayType) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.DisplayManagement\Views\ShapeResult.cs:line 105
   at OrchardCore.DisplayManagement.DisplayManager`1.<>c.<<BuildEditorAsync>b__6_0>d.MoveNext() in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.DisplayManagement\DisplayManager.cs:line 100
--- End of stack trace from previous location ---
   at OrchardCore.Modules.InvokeExtensions.InvokeAsync[TEvents,T1,T2](IEnumerable`1 events, Func`4 dispatch, T1 arg1, T2 arg2, ILogger logger) in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Abstractions\Modules\Extensions\InvokeExtensions.cs:line 151
2024-03-16 01:34:05.2260|SalesProtalDev|00-0e98ef483974295a3617d686c1b8f7f9-fabd85d9c9f4782b-00||Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine|DEBUG|View lookup cache hit for view 'Index' in controller 'ValidationConfiguration'. 
2024-03-16 01:34:05.2260|SalesProtalDev|00-0e98ef483974295a3617d686c1b8f7f9-fabd85d9c9f4782b-00||Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor|INFO|Executing ViewResult, running view Index. 
2024-03-16 01:34:05.2260|SalesProtalDev|00-0e98ef483974295a3617d686c1b8f7f9-fabd85d9c9f4782b-00||Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor|DEBUG|The view path '/Areas/OrchardCore.OpenId/Views/ValidationConfiguration/Index.cshtml' was found in 0.124ms. 
hyzx86 commented 8 months ago

I've been looking for days, but I've finally located the problem 🤣

cc: @sebastienros @Skrypt @ns8482e

The full reproduction step is as follows

  1. Create a tenant name as Test1,

  2. Edit the tenants.json file to add a non-existent tenant such as

    "Default": {
    "VersionId": "4v0jtqy5xc08j7t2z6fw351zc4",
    "TenantId": "43nw8ze3xssp17hv7zbhbvx54e",
    "State": "Running"
    }, 
    // It is an actual existing tenant that you create through the default tenant
    // the folder does not actually exist at the "App_Data/Sites/FakeTenant" path
    "Test1": {
    "VersionId": "4v0jtqy5xc08j7t2z6fw351zc4xxx",
    "TenantId": "43nw8ze3xssp17hv7zbhbvx54xxxe",
    "State": "Running"
    },
    // just copy this block to oc, this tenant does not actually exist
    "FakeTenant": {
    "VersionId": "48p76vxdrxkgnyjxxffq5cpdm4",
    "TenantId": "4vpf12d9xq86rz5y0q6953pccm",
    "RequestUrlPrefix": "TestInit",
    "State": "Running"
    },

    (Please ignore the difference in the tenant name on my computer) image

  3. change the file target log level to Debug.

Then run the program and enable the 'OpenID Token Validation' module on tenant Test1. When you open the Token Validation page, you will see that it does not work properly.

2024-03-16 19:48:56.3071|Test1|00-b70f63553aaaf1aab54a58a0530ca134-1b40cf302ee7c007-00||OrchardCore.Environment.Shell.ShellHost|DEBUG|Creating shell context for tenant 'FakeTenant' 
2024-03-16 19:48:56.3071|Test1|00-b70f63553aaaf1aab54a58a0530ca134-1b40cf302ee7c007-00||OrchardCore.Environment.Shell.Builders.ShellContextFactory|INFO|Creating shell context for tenant 'FakeTenant' 
2024-03-16 19:48:56.3071|Test1|00-b70f63553aaaf1aab54a58a0530ca134-1b40cf302ee7c007-00||OrchardCore.Environment.Shell.Builders.ShellContextFactory|DEBUG|Creating described context for tenant 'FakeTenant' 
2024-03-16 19:48:56.3071|Test1|00-b70f63553aaaf1aab54a58a0530ca134-1b40cf302ee7c007-00||OrchardCore.Environment.Shell.Builders.CompositionStrategy|DEBUG|Composing blueprint 
2024-03-16 19:48:56.3071|Test1|00-b70f63553aaaf1aab54a58a0530ca134-1b40cf302ee7c007-00||OrchardCore.Environment.Shell.Builders.CompositionStrategy|DEBUG|Done composing blueprint 
2024-03-16 19:48:56.3178|Test1|00-b70f63553aaaf1aab54a58a0530ca134-1b40cf302ee7c007-00||OrchardCore.Environment.Shell.ShellHost|DEBUG|Registering shell context for tenant 'FakeTenant' 
2024-03-16 19:48:56.3448|Test1|00-b70f63553aaaf1aab54a58a0530ca134-1b40cf302ee7c007-00||OrchardCore.DisplayManagement.DisplayManager|ERROR|IDisplayDriver`1 thrown from OrchardCore.OpenId.Drivers.OpenIdValidationSettingsDisplayDriver by NullReferenceException System.NullReferenceException: Object reference not set to an instance of an object.
   at OrchardCore.Data.Migration.DataMigrationManager.GetDataMigrationRecordAsync() in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Data.YesSql\Migration\DataMigrationManager.cs:line 64
   at OrchardCore.Data.Migration.DataMigrationManager.GetFeaturesThatNeedUpdateAsync() in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Data.YesSql\Migration\DataMigrationManager.cs:line 78
   at OrchardCore.Data.Migration.DataMigrationManager.UpdateAllFeaturesAsync() in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Data.YesSql\Migration\DataMigrationManager.cs:line 334
   at OrchardCore.Environment.Shell.Scope.ShellScope.<>c.<<ActivateShellInternalAsync>b__43_0>d.MoveNext() in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\OrchardCore\src\OrchardCore\OrchardCore.Abstractions\Shell\Scope\ShellScope.cs:line 325

I think it should be related to #15511 As I mentioned there: https://github.com/OrchardCMS/OrchardCore/issues/15511#issuecomment-1997298472

MikeAlhayek commented 7 months ago

@hyzx86 thanks for providing the steps to reproduce the issue.

@sebastienros I do not think this is an issue we should care about. Here we are faking a running tenant in the tenants.json file where that tenant should not exists. When we try to build the site for this fake tenant, it failed to create ISession instance since there is no database connection given.

I am going to remove the 1.9 milestone tag from this issue.

hyzx86 commented 7 months ago

The e problem now is that we have to make sure that all tenants are connected to the database properly, otherwise any one wrong connection will cause strange problems for the other tenants.

MikeAlhayek commented 7 months ago

Yes. But this isn't a new behavior we introduced. It's been that way for a long time. At the end of the day, if you don't mess up or manually edit the core files, you won't end up in this corrupt state.

hyzx86 commented 7 months ago

In a multi-tenant scenario, if we expose a subtenant administrator to manage the tenant database, then if a user breaks the database, it will cause problems in other tenants' applications

This problem only exists in version 1.9.x and works fine in 1.8.x