Skip to content

Commit

Permalink
fix(authorization): make sure an authorizer is only invoked once per …
Browse files Browse the repository at this point in the history
…request

Fixes #4351
  • Loading branch information
raymondfeng committed Jan 29, 2020
1 parent a681e14 commit b29bbeb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 1 addition & 6 deletions packages/authorization/src/authorize-interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
config,
Context,
filterByTag,
inject,
Interceptor,
InvocationContext,
Next,
Expand All @@ -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 = {},
) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b29bbeb

Please sign in to comment.