Closed alexmg closed 10 years ago
From alex.meyergleaves on October 30, 2013 07:45:53
This issue was closed by revision fd6e9da7b0e9 .
Status: Fixed
From alex.meyergleaves on October 30, 2013 08:03:51
I see what you are trying to achieve with the attributes.
The BypassApiKeyFilterAttribute is not an actual attribute so the reflection based GetCustomAttributes implementation will not find it. In the current Web API integration even if you did update the filter to derive from ActionFilterAttribute, unless you applied it to the action method as an attribute Web API would not find it.
I have added a fluent API to the ContainerBuilder for overriding filters at the controller or action level. The API works the same way you register filters. Under the hood it uses the new IOverrideFilter support.
In your ShortUrl project it would like this:
builder.Register(x => new ApiAuthorizationFilterAttribute())
.AsWebApiAuthorizationFilterFor
builder.OverrideAuthorizationFilterFor
builder.OverrideAuthorizationFilterFor
With this in place there is no need for your BypassApiKeyFilterAttribute. The ApiAuthorizationFilterAttribute will simply not be called for the matching actions (or controller if you like).
This is currently only available on the MyGet CI feed. https://www.myget.org/feed/autofac/package/Autofac.WebApi2 I am going to add the same thing to the MVC integration and will then push both packages to NuGet.org. If you could grab the package from MyGet and give it a test that would be appreciated.
From Rauber.M...@googlemail.com on October 30, 2013 08:24:03
This works like a charm!
The BypassApiKeyFilterAttribute is not an actual attribute so the reflection based GetCustomAttributes implementation will not find it. In the current Web API integration even if you did update the filter to derive from ActionFilterAttribute, unless you applied it to the action method as an attribute Web API would not find it. <<<
Yes, zonk... I read it over and over again. It's mentioned in the documentation, but I just didn't got it. Was a bit late yesterday :)
Thank you for the fast patch!
From Rauber.M...@googlemail.com on October 30, 2013 17:48:34
What steps will reproduce the problem? 1. Create a new ApiController
You can see the code on GitHub: https://github.com/ManuelRauber/ShortUrl/tree/Bypass The relevant files are:
Bootstrap: https://github.com/ManuelRauber/ShortUrl/blob/Bypass/ShortUrl/Common/Bootstrap.cs#L36 # Api-Attribute: https://github.com/ManuelRauber/ShortUrl/blob/Bypass/ShortUrl/Common/ApiAuthorizationFilterAttribute.cs#L50 # Bypass-Attribute: https://github.com/ManuelRauber/ShortUrl/blob/Bypass/ShortUrl/Common/BypassApiKeyFilterAttribute.cs
Original issue: http://code.google.com/p/autofac/issues/detail?id=465