@nattyjs/core 0.0.1-beta.28 → 0.0.1-beta.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -873,6 +873,14 @@ class ActionExecutedContext extends AbstractExecutionContext {
873
873
  }
874
874
  }
875
875
 
876
+ class AuthorizationContext extends AbstractExecutionContext {
877
+ constructor(models, context, routeInfo, config) {
878
+ super(context, routeInfo);
879
+ this.models = models;
880
+ this.config = config;
881
+ }
882
+ }
883
+
876
884
  class RequestProcessor extends RouteParser {
877
885
  constructor() {
878
886
  super(...arguments);
@@ -883,9 +891,6 @@ class RequestProcessor extends RouteParser {
883
891
  case RequestPipeline.onAuthentication:
884
892
  await this.onAuthentication();
885
893
  break;
886
- case RequestPipeline.onAuthorization:
887
- await this.onAuthorization();
888
- break;
889
894
  }
890
895
  }
891
896
  resolveFilter(instance) {
@@ -911,21 +916,27 @@ class RequestProcessor extends RouteParser {
911
916
  this.httpContext.user = result;
912
917
  if (!result.isAuthenticate && !anonymousInfo.controllerConfig && !anonymousInfo.methodConfig)
913
918
  throw new UnauthorizedAccessException(authenticationFilter.onFailedResponse());
914
- await this.onAuthorization();
915
919
  }
916
920
  }
917
- async onAuthorization() {
921
+ async onAuthorization(methodParameters) {
918
922
  const authorization = common.commonContainer.globalConfig.authorization;
919
923
  const authorizationFilter = authorization ? this.resolveFilter(authorization) : void 0;
920
924
  const authorizeConfig = decoratorStateContainer.getInfo(this.routeInfo.controller.name, this.routeInfo.methodInfo.name, DecoratorType.authorize);
921
925
  const authenticationOnly = decoratorStateContainer.getInfo(this.routeInfo.controller.name, this.routeInfo.methodInfo.name, DecoratorType.authenticationOnly);
922
926
  if (this.httpContext.user?.isAuthenticate && authorizationFilter && (!authenticationOnly.controllerConfig && !authenticationOnly.methodConfig)) {
923
- const result = await authorizationFilter.onAuthorization(this.httpContext, authorizeConfig.methodConfig || authorizeConfig.controllerConfig);
927
+ const authorizationContext = new AuthorizationContext(
928
+ methodParameters.filter((t) => t instanceof ModelBindingContext),
929
+ this.httpContext,
930
+ this.routeInfo,
931
+ authorizeConfig.methodConfig || authorizeConfig.controllerConfig
932
+ );
933
+ const result = await authorizationFilter.onAuthorization(authorizationContext);
924
934
  if (!result)
925
935
  throw new ForbiddenAccessException(authorizationFilter.onFailedAuthorization());
926
936
  }
927
937
  }
928
938
  async onActionExecuting(methodParameters) {
939
+ await this.onAuthorization(methodParameters);
929
940
  let actionFilters = common.commonContainer.globalConfig.actionFilters || [];
930
941
  const actionFiltersConfig = decoratorStateContainer.getInfo(this.routeInfo.controller.name, this.routeInfo.methodInfo.name, DecoratorType.useFilter);
931
942
  actionFilters = [...actionFilters, ...actionFiltersConfig.controllerConfig?.actionFilters || [], ...actionFiltersConfig.methodConfig?.actionFilters || []];
package/dist/index.mjs CHANGED
@@ -871,6 +871,14 @@ class ActionExecutedContext extends AbstractExecutionContext {
871
871
  }
872
872
  }
873
873
 
874
+ class AuthorizationContext extends AbstractExecutionContext {
875
+ constructor(models, context, routeInfo, config) {
876
+ super(context, routeInfo);
877
+ this.models = models;
878
+ this.config = config;
879
+ }
880
+ }
881
+
874
882
  class RequestProcessor extends RouteParser {
875
883
  constructor() {
876
884
  super(...arguments);
@@ -881,9 +889,6 @@ class RequestProcessor extends RouteParser {
881
889
  case RequestPipeline.onAuthentication:
882
890
  await this.onAuthentication();
883
891
  break;
884
- case RequestPipeline.onAuthorization:
885
- await this.onAuthorization();
886
- break;
887
892
  }
888
893
  }
889
894
  resolveFilter(instance) {
@@ -909,21 +914,27 @@ class RequestProcessor extends RouteParser {
909
914
  this.httpContext.user = result;
910
915
  if (!result.isAuthenticate && !anonymousInfo.controllerConfig && !anonymousInfo.methodConfig)
911
916
  throw new UnauthorizedAccessException(authenticationFilter.onFailedResponse());
912
- await this.onAuthorization();
913
917
  }
914
918
  }
915
- async onAuthorization() {
919
+ async onAuthorization(methodParameters) {
916
920
  const authorization = commonContainer.globalConfig.authorization;
917
921
  const authorizationFilter = authorization ? this.resolveFilter(authorization) : void 0;
918
922
  const authorizeConfig = decoratorStateContainer.getInfo(this.routeInfo.controller.name, this.routeInfo.methodInfo.name, DecoratorType.authorize);
919
923
  const authenticationOnly = decoratorStateContainer.getInfo(this.routeInfo.controller.name, this.routeInfo.methodInfo.name, DecoratorType.authenticationOnly);
920
924
  if (this.httpContext.user?.isAuthenticate && authorizationFilter && (!authenticationOnly.controllerConfig && !authenticationOnly.methodConfig)) {
921
- const result = await authorizationFilter.onAuthorization(this.httpContext, authorizeConfig.methodConfig || authorizeConfig.controllerConfig);
925
+ const authorizationContext = new AuthorizationContext(
926
+ methodParameters.filter((t) => t instanceof ModelBindingContext),
927
+ this.httpContext,
928
+ this.routeInfo,
929
+ authorizeConfig.methodConfig || authorizeConfig.controllerConfig
930
+ );
931
+ const result = await authorizationFilter.onAuthorization(authorizationContext);
922
932
  if (!result)
923
933
  throw new ForbiddenAccessException(authorizationFilter.onFailedAuthorization());
924
934
  }
925
935
  }
926
936
  async onActionExecuting(methodParameters) {
937
+ await this.onAuthorization(methodParameters);
927
938
  let actionFilters = commonContainer.globalConfig.actionFilters || [];
928
939
  const actionFiltersConfig = decoratorStateContainer.getInfo(this.routeInfo.controller.name, this.routeInfo.methodInfo.name, DecoratorType.useFilter);
929
940
  actionFilters = [...actionFilters, ...actionFiltersConfig.controllerConfig?.actionFilters || [], ...actionFiltersConfig.methodConfig?.actionFilters || []];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nattyjs/core",
3
- "version": "0.0.1-beta.28",
3
+ "version": "0.0.1-beta.29",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "ajayojha",
@@ -17,7 +17,7 @@
17
17
  "dependencies": {
18
18
  "tsyringe": "^4.7.0",
19
19
  "path-to-regexp": "6.2.1",
20
- "@nattyjs/common": "0.0.1-beta.28"
20
+ "@nattyjs/common": "0.0.1-beta.29"
21
21
  },
22
22
  "devDependencies": {
23
23
  "unbuild": "1.2.1"