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

fix(authorization): make sure an authorizer is only invoked once per request #4535

Merged
merged 1 commit into from
Jan 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(authorization): make sure an authorizer is only invoked once per …
…request

Fixes #4351
raymondfeng committed Jan 29, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 9741fed79d49148d3067b90ff3a55b49c689d0a6
Original file line number Diff line number Diff line change
@@ -37,15 +37,15 @@ describe('Authorization', () => {
},
]);
expect(orderId).to.eql('order-1');
expect(events).to.containEql('OrderController.prototype.placeOrder');
expect(events).to.eql(['OrderController.prototype.placeOrder']);
});

it('denies cancelOrder for regular user', async () => {
const result = invokeMethod(controller, 'cancelOrder', reqCtx, [
'order-01',
]);
await expect(result).to.be.rejectedWith('Access denied');
expect(events).to.containEql('OrderController.prototype.cancelOrder');
expect(events).to.eql(['OrderController.prototype.cancelOrder']);
});

class Order {
7 changes: 1 addition & 6 deletions packages/authorization/src/authorize-interceptor.ts
Original file line number Diff line number Diff line change
@@ -10,8 +10,6 @@ import {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
config,
Context,
filterByTag,
inject,
Interceptor,
InvocationContext,
Next,
@@ -37,8 +35,6 @@ export class AuthorizationInterceptor implements Provider<Interceptor> {
private options: AuthorizationOptions;

constructor(
@inject(filterByTag(AuthorizationTags.AUTHORIZER))
private authorizers: Authorizer[],
@config({fromBinding: AuthorizationBindings.COMPONENT})
options: AuthorizationOptions = {},
) {
@@ -87,13 +83,12 @@ export class AuthorizationInterceptor implements Provider<Interceptor> {
};

debug('Security context for %s', description, authorizationCtx);
let authorizers = await loadAuthorizers(
const authorizers = await loadAuthorizers(
invocationCtx,
metadata.voters ?? [],
);

let finalDecision = this.options.defaultDecision;
authorizers = authorizers.concat(this.authorizers);
for (const fn of authorizers) {
const decision = await fn(authorizationCtx, metadata);
debug('Decision', decision);