Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Make AuthorizeFilter constructable #5274

Merged
merged 2 commits into from
Sep 14, 2016
Merged

Make AuthorizeFilter constructable #5274

merged 2 commits into from
Sep 14, 2016

Conversation

pranavkm
Copy link
Contributor

Fixes #5253

@pranavkm
Copy link
Contributor Author

cc @rynowak \ @kichalla

/// Initializes a new instance of <see cref="AuthorizeFilter"/>.
/// </summary>
/// <param name="authorizeData">The <see cref="IAuthorizeData"/> to combine into an <see cref="IAuthorizeData"/>.</param>
public AuthorizeFilter(IEnumerable<IAuthorizeData> authorizeData)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add one more constructor which takes in a policy name for convenience? (probably other properties like roles and active authentication schemes too)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not super sure we need that. The motive for this bug wasn't to make it simplify the ctor but more about making it possible to add AuthFilter as a global filter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be super nice to have the policy name as a ctor. That will be the most common way to use this as a global filter.

@@ -61,18 +61,18 @@ public void OnProvidersExecuting(ApplicationModelProviderContext context)
}
}

private AuthorizeFilter GetFilter(IEnumerable<IAuthorizeData> authData)
public static AuthorizeFilter GetFilter(IAuthorizationPolicyProvider policyProvider, IEnumerable<IAuthorizeData> authData)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this would be a static factory method on AuthorizeFilter, but this API should go away eventually, so lets keep it where it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought as much. It's kinda awful.

@rynowak
Copy link
Member

rynowak commented Sep 14, 2016

⌚ for a ctor that takes a policy name

.BuildServiceProvider();

// Act
var result = factory.CreateInstance(serviceProvider);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you make one more call and the result should be same

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the same?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean the filter instance on one more call to CreateInstance should create the same instance of the filter (I ask this because the other tests here short circuit in the if condition and do not go through DI)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think CreateInstance has to return the same instance every time. The filter provider should cache the value for you as long as the filter is reusable.

@pranavkm
Copy link
Contributor Author

Updated

@kichalla
Copy link
Member

:shipit:

1 similar comment
@rynowak
Copy link
Member

rynowak commented Sep 14, 2016

:shipit:

@pranavkm pranavkm merged commit a480378 into dev Sep 14, 2016
@pranavkm pranavkm deleted the prkrishn/5254 branch September 14, 2016 20:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants