Skip to content

Single auth check for authorized resource filtering#4818

Merged
nishantmonu51 merged 4 commits intoapache:masterfrom
jon-wei:authfix
Sep 19, 2017
Merged

Single auth check for authorized resource filtering#4818
nishantmonu51 merged 4 commits intoapache:masterfrom
jon-wei:authfix

Conversation

@jon-wei
Copy link
Copy Markdown
Contributor

@jon-wei jon-wei commented Sep 18, 2017

Fixes #4813

Changes the AuthorizationUtils.filterAuthorizedResources() method and SupervisorResource to prevent multiple authorization checks being performed on requests (See #4816 (review) for context).

@jon-wei jon-wei added the Bug label Sep 18, 2017
@jon-wei jon-wei added this to the 0.11.0 milestone Sep 18, 2017
Copy link
Copy Markdown
Member

@nishantmonu51 nishantmonu51 left a comment

Choose a reason for hiding this comment

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

changes seem good.
If possible, would be nice to add test for this

@jon-wei
Copy link
Copy Markdown
Contributor Author

jon-wei commented Sep 18, 2017

@nishantmonu51

Hm, I don't know how to setup tests like SupervisorResourceTest with the servlet filters that would be used in a real environment (like PreResponseAuthorizationCheckFilter), any ideas there?

final AuthorizerMapper authorizerMapper
final Function<? super ResType, Iterable<ResourceAction>> resourceActionGenerator,
final AuthorizerMapper authorizerMapper,
final Collection<? super ResType> filteredResources
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What's the reason for having an out-parameter instead of returning a Collection<ResType> or Iterable<ResType>? I'm wondering since out-params are harder to comprehend than return values.

I'm thinking that many callers would want to directly use a returned filteredResources, and for the callers that don't, they could do:

Iterables.addAll(filteredResources, filterAuthorizedResources(...))`

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have the out-parameter so that the caller can control the type of the Collection that gets the filtered values.

I implemented that way after seeing that SupervisorResource uses Sets for storing supervisor ids, maybe a future caller really cares about using a Set to avoid duplicates, and I thought it'd be better to have the caller pass in the output collection to avoid having to create extra lists and copy them over into other structures.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In that case, I think it's best for filterAuthorizedResources to return an Iterable< ResType> (and maybe accept one as well, instead of the Collection it accepts now). There won't be any need to create useless collections since the caller can iterate the iterable and directly insert it into the target collection, using Iterables.addAll.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

alright, changed filtereAuthorizedResources to return Iterable

final Set<String> authorizedSupervisorIds = Sets.newHashSet();

// If there were no supervisorIds, go ahead and authorize the request.
if (supervisorIds.size() == 0) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it necessary to have a separate branch for this case? Shouldn't filterAuthorizedResources on an empty list do the same thing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's not, I had it there just to avoid creating the resource generating function if there were on supervisorIds, removed this

Copy link
Copy Markdown
Contributor

@gianm gianm left a comment

Choose a reason for hiding this comment

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

LGTM after CI. thanks @jon-wei!

Copy link
Copy Markdown
Member

@nishantmonu51 nishantmonu51 left a comment

Choose a reason for hiding this comment

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

👍

@nishantmonu51 nishantmonu51 merged commit 3a4a483 into apache:master Sep 19, 2017
@jon-wei jon-wei deleted the authfix branch October 6, 2017 21:40
supervisorHistory.keySet()
);

final Map<String, List<VersionedSupervisorSpec>> authorizedSupervisorHistory = Maps.filterKeys(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This object is unused. Something is wrong with this code.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for noticing. #5459 fixes it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks for the catching that, opened a fix at #5460

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants