Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NRE in GetPolicyRequirements() #24

Closed
VictorioBerra opened this issue Aug 27, 2018 · 2 comments
Closed

NRE in GetPolicyRequirements() #24

VictorioBerra opened this issue Aug 27, 2018 · 2 comments

Comments

@VictorioBerra
Copy link
Contributor

VictorioBerra commented Aug 27, 2018

Bare with me here, because I dont have a TON of information because I am encountering this error when I use another library called PolicyServer.

The NRE happens on this line:
https://github.com/Dotnet-Boxed/Framework/blob/master/Source/Boxed.AspNetCore.Swagger/FilterDescriptorExtensions.cs#L25

I get an NRE on that line, Policy is null because of the above library. I think we need to code more defensively here somehow. I believe the error is somewhere in here https://github.com/PolicyServer/PolicyServer.Local/blob/dev/src/PolicyServer.Local/AspNetCore/AuthorizationPolicyProvider.cs

Somehow, PolicyServer is creating its own handler and requirements. But I am not sure whats wrong. Why would Policy be blank? Maybe there is no policy? I mentioned this over in https://github.com/PolicyServer/PolicyServer.Local/issues/17

@VictorioBerra
Copy link
Contributor Author

This might be the fault of using an auth attribute without any policy. IE: [Authorize].

I found if I apply global authorization to my app, I do not get this error. But if I try and use PolicyServer via [Authorize("myPermission")] it blows up again:

Unhandled Exception
System.NullReferenceException: Object reference not set to an instance of an object.
   at Boxed.AspNetCore.Swagger.FilterDescriptorExtensions.GetPolicyRequirements(IList`1 filterDescriptors) in C:\projects\framework\Source\Boxed.AspNetCore.Swagger\FilterDescriptorExtensions.cs:line 25
   at Boxed.AspNetCore.Swagger.OperationFilters.ForbiddenResponseOperationFilter.Apply(Operation operation, OperationFilterContext context) in C:\projects\framework\Source\Boxed.AspNetCore.Swagger\OperationFilters\ForbiddenResponseOperationFilter.cs:line 30
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreateOperation(ApiDescription apiDescription, ISchemaRegistry schemaRegistry)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreatePathItem(IEnumerable`1 apiDescriptions, ISchemaRegistry schemaRegistry)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.<>c__DisplayClass5_0.<CreatePathItems>b__2(IGrouping`2 group)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreatePathItems(IEnumerable`1 apiDescriptions, ISchemaRegistry schemaRegistry)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(String documentName, String host, String basePath, String[] schemes)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
   at MyApp.API.Errors.ErrorHandlingMiddleware.Invoke(HttpContext context) in C:\Source\MyApp\src\MyApp.API\Errors\ErrorHandlingMiddleware.cs:line 26

@RehanSaeed
Copy link
Member

Thanks, merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants