@celljs/security 3.0.0

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.
Files changed (344) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/cell.yml +36 -0
  4. package/lib/browser/index.d.ts +2 -0
  5. package/lib/browser/index.d.ts.map +1 -0
  6. package/lib/browser/index.js +18 -0
  7. package/lib/browser/index.js.map +1 -0
  8. package/lib/browser/module.d.ts +4 -0
  9. package/lib/browser/module.d.ts.map +1 -0
  10. package/lib/browser/module.js +6 -0
  11. package/lib/browser/module.js.map +1 -0
  12. package/lib/browser/user/index.d.ts +3 -0
  13. package/lib/browser/user/index.d.ts.map +1 -0
  14. package/lib/browser/user/index.js +19 -0
  15. package/lib/browser/user/index.js.map +1 -0
  16. package/lib/browser/user/user-manager.d.ts +23 -0
  17. package/lib/browser/user/user-manager.d.ts.map +1 -0
  18. package/lib/browser/user/user-manager.js +125 -0
  19. package/lib/browser/user/user-manager.js.map +1 -0
  20. package/lib/browser/user/user-protocol.d.ts +10 -0
  21. package/lib/browser/user/user-protocol.d.ts.map +1 -0
  22. package/lib/browser/user/user-protocol.js +5 -0
  23. package/lib/browser/user/user-protocol.js.map +1 -0
  24. package/lib/common/index.d.ts +2 -0
  25. package/lib/common/index.d.ts.map +1 -0
  26. package/lib/common/index.js +18 -0
  27. package/lib/common/index.js.map +1 -0
  28. package/lib/common/security-protocol.d.ts +60 -0
  29. package/lib/common/security-protocol.d.ts.map +1 -0
  30. package/lib/common/security-protocol.js +33 -0
  31. package/lib/common/security-protocol.js.map +1 -0
  32. package/lib/node/access/access-decision-manager.d.ts +9 -0
  33. package/lib/node/access/access-decision-manager.d.ts.map +1 -0
  34. package/lib/node/access/access-decision-manager.js +56 -0
  35. package/lib/node/access/access-decision-manager.js.map +1 -0
  36. package/lib/node/access/access-decision-utils.d.ts +5 -0
  37. package/lib/node/access/access-decision-utils.d.ts.map +1 -0
  38. package/lib/node/access/access-decision-utils.js +23 -0
  39. package/lib/node/access/access-decision-utils.js.map +1 -0
  40. package/lib/node/access/access-decision-voter.d.ts +14 -0
  41. package/lib/node/access/access-decision-voter.d.ts.map +1 -0
  42. package/lib/node/access/access-decision-voter.js +86 -0
  43. package/lib/node/access/access-decision-voter.js.map +1 -0
  44. package/lib/node/access/access-protocol.d.ts +75 -0
  45. package/lib/node/access/access-protocol.d.ts.map +1 -0
  46. package/lib/node/access/access-protocol.js +20 -0
  47. package/lib/node/access/access-protocol.js.map +1 -0
  48. package/lib/node/access/action-name-resolver.d.ts +5 -0
  49. package/lib/node/access/action-name-resolver.d.ts.map +1 -0
  50. package/lib/node/access/action-name-resolver.js +30 -0
  51. package/lib/node/access/action-name-resolver.js.map +1 -0
  52. package/lib/node/access/index.d.ts +12 -0
  53. package/lib/node/access/index.d.ts.map +1 -0
  54. package/lib/node/access/index.js +28 -0
  55. package/lib/node/access/index.js.map +1 -0
  56. package/lib/node/access/jexl-engine-provider.d.ts +6 -0
  57. package/lib/node/access/jexl-engine-provider.d.ts.map +1 -0
  58. package/lib/node/access/jexl-engine-provider.js +25 -0
  59. package/lib/node/access/jexl-engine-provider.js.map +1 -0
  60. package/lib/node/access/method-advice.d.ts +17 -0
  61. package/lib/node/access/method-advice.d.ts.map +1 -0
  62. package/lib/node/access/method-advice.js +81 -0
  63. package/lib/node/access/method-advice.js.map +1 -0
  64. package/lib/node/access/policy-provider.d.ts +17 -0
  65. package/lib/node/access/policy-provider.d.ts.map +1 -0
  66. package/lib/node/access/policy-provider.js +84 -0
  67. package/lib/node/access/policy-provider.js.map +1 -0
  68. package/lib/node/access/policy-resolver.d.ts +15 -0
  69. package/lib/node/access/policy-resolver.d.ts.map +1 -0
  70. package/lib/node/access/policy-resolver.js +91 -0
  71. package/lib/node/access/policy-resolver.js.map +1 -0
  72. package/lib/node/access/resource-name-resolver.d.ts +7 -0
  73. package/lib/node/access/resource-name-resolver.d.ts.map +1 -0
  74. package/lib/node/access/resource-name-resolver.js +57 -0
  75. package/lib/node/access/resource-name-resolver.js.map +1 -0
  76. package/lib/node/access/security-metadata-source.d.ts +7 -0
  77. package/lib/node/access/security-metadata-source.d.ts.map +1 -0
  78. package/lib/node/access/security-metadata-source.js +58 -0
  79. package/lib/node/access/security-metadata-source.js.map +1 -0
  80. package/lib/node/annotation/action.d.ts +2 -0
  81. package/lib/node/annotation/action.d.ts.map +1 -0
  82. package/lib/node/annotation/action.js +11 -0
  83. package/lib/node/annotation/action.js.map +1 -0
  84. package/lib/node/annotation/anonymous.d.ts +2 -0
  85. package/lib/node/annotation/anonymous.d.ts.map +1 -0
  86. package/lib/node/annotation/anonymous.js +10 -0
  87. package/lib/node/annotation/anonymous.js.map +1 -0
  88. package/lib/node/annotation/authenticated.d.ts +2 -0
  89. package/lib/node/annotation/authenticated.d.ts.map +1 -0
  90. package/lib/node/annotation/authenticated.js +10 -0
  91. package/lib/node/annotation/authenticated.js.map +1 -0
  92. package/lib/node/annotation/authorize.d.ts +11 -0
  93. package/lib/node/annotation/authorize.d.ts.map +1 -0
  94. package/lib/node/annotation/authorize.js +40 -0
  95. package/lib/node/annotation/authorize.js.map +1 -0
  96. package/lib/node/annotation/index.d.ts +8 -0
  97. package/lib/node/annotation/index.d.ts.map +1 -0
  98. package/lib/node/annotation/index.js +24 -0
  99. package/lib/node/annotation/index.js.map +1 -0
  100. package/lib/node/annotation/post-authorize.d.ts +2 -0
  101. package/lib/node/annotation/post-authorize.d.ts.map +1 -0
  102. package/lib/node/annotation/post-authorize.js +10 -0
  103. package/lib/node/annotation/post-authorize.js.map +1 -0
  104. package/lib/node/annotation/pre-authorize.d.ts +2 -0
  105. package/lib/node/annotation/pre-authorize.d.ts.map +1 -0
  106. package/lib/node/annotation/pre-authorize.js +10 -0
  107. package/lib/node/annotation/pre-authorize.js.map +1 -0
  108. package/lib/node/annotation/resource.d.ts +2 -0
  109. package/lib/node/annotation/resource.d.ts.map +1 -0
  110. package/lib/node/annotation/resource.js +16 -0
  111. package/lib/node/annotation/resource.js.map +1 -0
  112. package/lib/node/authentication/authentication-manager.d.ts +10 -0
  113. package/lib/node/authentication/authentication-manager.d.ts.map +1 -0
  114. package/lib/node/authentication/authentication-manager.js +81 -0
  115. package/lib/node/authentication/authentication-manager.js.map +1 -0
  116. package/lib/node/authentication/authentication-middleware.d.ts +8 -0
  117. package/lib/node/authentication/authentication-middleware.d.ts.map +1 -0
  118. package/lib/node/authentication/authentication-middleware.js +36 -0
  119. package/lib/node/authentication/authentication-middleware.js.map +1 -0
  120. package/lib/node/authentication/authentication-protocol.d.ts +30 -0
  121. package/lib/node/authentication/authentication-protocol.d.ts.map +1 -0
  122. package/lib/node/authentication/authentication-protocol.js +12 -0
  123. package/lib/node/authentication/authentication-protocol.js.map +1 -0
  124. package/lib/node/authentication/authentication-provider.d.ts +33 -0
  125. package/lib/node/authentication/authentication-provider.d.ts.map +1 -0
  126. package/lib/node/authentication/authentication-provider.js +174 -0
  127. package/lib/node/authentication/authentication-provider.js.map +1 -0
  128. package/lib/node/authentication/authentication-success-handler.d.ts +16 -0
  129. package/lib/node/authentication/authentication-success-handler.d.ts.map +1 -0
  130. package/lib/node/authentication/authentication-success-handler.js +97 -0
  131. package/lib/node/authentication/authentication-success-handler.js.map +1 -0
  132. package/lib/node/authentication/index.d.ts +6 -0
  133. package/lib/node/authentication/index.d.ts.map +1 -0
  134. package/lib/node/authentication/index.js +22 -0
  135. package/lib/node/authentication/index.js.map +1 -0
  136. package/lib/node/cache/cache-protocol.d.ts +16 -0
  137. package/lib/node/cache/cache-protocol.d.ts.map +1 -0
  138. package/lib/node/cache/cache-protocol.js +6 -0
  139. package/lib/node/cache/cache-protocol.js.map +1 -0
  140. package/lib/node/cache/index.d.ts +3 -0
  141. package/lib/node/cache/index.d.ts.map +1 -0
  142. package/lib/node/cache/index.js +19 -0
  143. package/lib/node/cache/index.js.map +1 -0
  144. package/lib/node/cache/request-cache.d.ts +10 -0
  145. package/lib/node/cache/request-cache.d.ts.map +1 -0
  146. package/lib/node/cache/request-cache.js +52 -0
  147. package/lib/node/cache/request-cache.js.map +1 -0
  148. package/lib/node/constants.d.ts +6 -0
  149. package/lib/node/constants.d.ts.map +1 -0
  150. package/lib/node/constants.js +9 -0
  151. package/lib/node/constants.js.map +1 -0
  152. package/lib/node/context/context-protocol.d.ts +22 -0
  153. package/lib/node/context/context-protocol.d.ts.map +1 -0
  154. package/lib/node/context/context-protocol.js +30 -0
  155. package/lib/node/context/context-protocol.js.map +1 -0
  156. package/lib/node/context/index.d.ts +5 -0
  157. package/lib/node/context/index.d.ts.map +1 -0
  158. package/lib/node/context/index.js +21 -0
  159. package/lib/node/context/index.js.map +1 -0
  160. package/lib/node/context/security-context-middleware.d.ts +9 -0
  161. package/lib/node/context/security-context-middleware.d.ts.map +1 -0
  162. package/lib/node/context/security-context-middleware.js +44 -0
  163. package/lib/node/context/security-context-middleware.js.map +1 -0
  164. package/lib/node/context/security-context-store.d.ts +8 -0
  165. package/lib/node/context/security-context-store.d.ts.map +1 -0
  166. package/lib/node/context/security-context-store.js +40 -0
  167. package/lib/node/context/security-context-store.js.map +1 -0
  168. package/lib/node/context/security-context-strategy.d.ts +9 -0
  169. package/lib/node/context/security-context-strategy.d.ts.map +1 -0
  170. package/lib/node/context/security-context-strategy.js +32 -0
  171. package/lib/node/context/security-context-strategy.js.map +1 -0
  172. package/lib/node/crypto/index.d.ts +3 -0
  173. package/lib/node/crypto/index.d.ts.map +1 -0
  174. package/lib/node/crypto/index.js +19 -0
  175. package/lib/node/crypto/index.js.map +1 -0
  176. package/lib/node/crypto/keygen/base64-string-key-generator.d.ts +6 -0
  177. package/lib/node/crypto/keygen/base64-string-key-generator.d.ts.map +1 -0
  178. package/lib/node/crypto/keygen/base64-string-key-generator.js +30 -0
  179. package/lib/node/crypto/keygen/base64-string-key-generator.js.map +1 -0
  180. package/lib/node/crypto/keygen/index.d.ts +3 -0
  181. package/lib/node/crypto/keygen/index.d.ts.map +1 -0
  182. package/lib/node/crypto/keygen/index.js +19 -0
  183. package/lib/node/crypto/keygen/index.js.map +1 -0
  184. package/lib/node/crypto/keygen/keygen-protocol.d.ts +5 -0
  185. package/lib/node/crypto/keygen/keygen-protocol.d.ts.map +1 -0
  186. package/lib/node/crypto/keygen/keygen-protocol.js +5 -0
  187. package/lib/node/crypto/keygen/keygen-protocol.js.map +1 -0
  188. package/lib/node/crypto/password/index.d.ts +3 -0
  189. package/lib/node/crypto/password/index.d.ts.map +1 -0
  190. package/lib/node/crypto/password/index.js +19 -0
  191. package/lib/node/crypto/password/index.js.map +1 -0
  192. package/lib/node/crypto/password/password-encoder.d.ts +9 -0
  193. package/lib/node/crypto/password/password-encoder.d.ts.map +1 -0
  194. package/lib/node/crypto/password/password-encoder.js +51 -0
  195. package/lib/node/crypto/password/password-encoder.js.map +1 -0
  196. package/lib/node/crypto/password/password-protocol.d.ts +6 -0
  197. package/lib/node/crypto/password/password-protocol.d.ts.map +1 -0
  198. package/lib/node/crypto/password/password-protocol.js +5 -0
  199. package/lib/node/crypto/password/password-protocol.js.map +1 -0
  200. package/lib/node/error/error-handler.d.ts +19 -0
  201. package/lib/node/error/error-handler.d.ts.map +1 -0
  202. package/lib/node/error/error-handler.js +81 -0
  203. package/lib/node/error/error-handler.js.map +1 -0
  204. package/lib/node/error/error-protocol.d.ts +3 -0
  205. package/lib/node/error/error-protocol.d.ts.map +1 -0
  206. package/lib/node/error/error-protocol.js +7 -0
  207. package/lib/node/error/error-protocol.js.map +1 -0
  208. package/lib/node/error/error.d.ts +21 -0
  209. package/lib/node/error/error.d.ts.map +1 -0
  210. package/lib/node/error/error.js +35 -0
  211. package/lib/node/error/error.js.map +1 -0
  212. package/lib/node/error/index.d.ts +4 -0
  213. package/lib/node/error/index.d.ts.map +1 -0
  214. package/lib/node/error/index.js +20 -0
  215. package/lib/node/error/index.js.map +1 -0
  216. package/lib/node/index.d.ts +11 -0
  217. package/lib/node/index.d.ts.map +1 -0
  218. package/lib/node/index.js +27 -0
  219. package/lib/node/index.js.map +1 -0
  220. package/lib/node/logout/index.d.ts +5 -0
  221. package/lib/node/logout/index.d.ts.map +1 -0
  222. package/lib/node/logout/index.js +21 -0
  223. package/lib/node/logout/index.js.map +1 -0
  224. package/lib/node/logout/logout-handler.d.ts +5 -0
  225. package/lib/node/logout/logout-handler.d.ts.map +1 -0
  226. package/lib/node/logout/logout-handler.js +22 -0
  227. package/lib/node/logout/logout-handler.js.map +1 -0
  228. package/lib/node/logout/logout-middleware.d.ts +16 -0
  229. package/lib/node/logout/logout-middleware.d.ts.map +1 -0
  230. package/lib/node/logout/logout-middleware.js +66 -0
  231. package/lib/node/logout/logout-middleware.js.map +1 -0
  232. package/lib/node/logout/logout-protocol.d.ts +12 -0
  233. package/lib/node/logout/logout-protocol.d.ts.map +1 -0
  234. package/lib/node/logout/logout-protocol.js +9 -0
  235. package/lib/node/logout/logout-protocol.js.map +1 -0
  236. package/lib/node/logout/logout-success-handler-provider.d.ts +8 -0
  237. package/lib/node/logout/logout-success-handler-provider.d.ts.map +1 -0
  238. package/lib/node/logout/logout-success-handler-provider.js +35 -0
  239. package/lib/node/logout/logout-success-handler-provider.js.map +1 -0
  240. package/lib/node/logout/logout-success-handler.d.ts +9 -0
  241. package/lib/node/logout/logout-success-handler.d.ts.map +1 -0
  242. package/lib/node/logout/logout-success-handler.js +39 -0
  243. package/lib/node/logout/logout-success-handler.js.map +1 -0
  244. package/lib/node/module.d.ts +5 -0
  245. package/lib/node/module.d.ts.map +1 -0
  246. package/lib/node/module.js +7 -0
  247. package/lib/node/module.js.map +1 -0
  248. package/lib/node/user/index.d.ts +6 -0
  249. package/lib/node/user/index.d.ts.map +1 -0
  250. package/lib/node/user/index.js +22 -0
  251. package/lib/node/user/index.js.map +1 -0
  252. package/lib/node/user/user-checker.d.ts +8 -0
  253. package/lib/node/user/user-checker.d.ts.map +1 -0
  254. package/lib/node/user/user-checker.js +44 -0
  255. package/lib/node/user/user-checker.js.map +1 -0
  256. package/lib/node/user/user-mapper.d.ts +9 -0
  257. package/lib/node/user/user-mapper.d.ts.map +1 -0
  258. package/lib/node/user/user-mapper.js +40 -0
  259. package/lib/node/user/user-mapper.js.map +1 -0
  260. package/lib/node/user/user-middleware.d.ts +11 -0
  261. package/lib/node/user/user-middleware.d.ts.map +1 -0
  262. package/lib/node/user/user-middleware.js +55 -0
  263. package/lib/node/user/user-middleware.js.map +1 -0
  264. package/lib/node/user/user-protocol.d.ts +15 -0
  265. package/lib/node/user/user-protocol.d.ts.map +1 -0
  266. package/lib/node/user/user-protocol.js +9 -0
  267. package/lib/node/user/user-protocol.js.map +1 -0
  268. package/lib/node/user/user-service.d.ts +7 -0
  269. package/lib/node/user/user-service.d.ts.map +1 -0
  270. package/lib/node/user/user-service.js +42 -0
  271. package/lib/node/user/user-service.js.map +1 -0
  272. package/lib/package.spec.d.ts +1 -0
  273. package/lib/package.spec.d.ts.map +1 -0
  274. package/lib/package.spec.js +4 -0
  275. package/lib/package.spec.js.map +1 -0
  276. package/package.json +53 -0
  277. package/src/browser/index.ts +1 -0
  278. package/src/browser/module.ts +4 -0
  279. package/src/browser/user/index.ts +2 -0
  280. package/src/browser/user/user-manager.ts +103 -0
  281. package/src/browser/user/user-protocol.ts +11 -0
  282. package/src/common/index.ts +1 -0
  283. package/src/common/security-protocol.ts +65 -0
  284. package/src/node/access/access-decision-manager.ts +43 -0
  285. package/src/node/access/access-decision-utils.ts +18 -0
  286. package/src/node/access/access-decision-voter.ts +73 -0
  287. package/src/node/access/access-protocol.ts +93 -0
  288. package/src/node/access/action-name-resolver.ts +19 -0
  289. package/src/node/access/index.ts +11 -0
  290. package/src/node/access/jexl-engine-provider.ts +18 -0
  291. package/src/node/access/method-advice.ts +64 -0
  292. package/src/node/access/policy-provider.ts +64 -0
  293. package/src/node/access/policy-resolver.ts +79 -0
  294. package/src/node/access/resource-name-resolver.ts +41 -0
  295. package/src/node/access/security-metadata-source.ts +47 -0
  296. package/src/node/annotation/action.ts +8 -0
  297. package/src/node/annotation/anonymous.ts +6 -0
  298. package/src/node/annotation/authenticated.ts +6 -0
  299. package/src/node/annotation/authorize.ts +39 -0
  300. package/src/node/annotation/index.ts +7 -0
  301. package/src/node/annotation/post-authorize.ts +6 -0
  302. package/src/node/annotation/pre-authorize.ts +6 -0
  303. package/src/node/annotation/resource.ts +12 -0
  304. package/src/node/authentication/authentication-manager.ts +61 -0
  305. package/src/node/authentication/authentication-middleware.ts +21 -0
  306. package/src/node/authentication/authentication-protocol.ts +37 -0
  307. package/src/node/authentication/authentication-provider.ts +155 -0
  308. package/src/node/authentication/authentication-success-handler.ts +83 -0
  309. package/src/node/authentication/index.ts +5 -0
  310. package/src/node/cache/cache-protocol.ts +17 -0
  311. package/src/node/cache/index.ts +2 -0
  312. package/src/node/cache/request-cache.ts +38 -0
  313. package/src/node/constants.ts +5 -0
  314. package/src/node/context/context-protocol.ts +43 -0
  315. package/src/node/context/index.ts +4 -0
  316. package/src/node/context/security-context-middleware.ts +28 -0
  317. package/src/node/context/security-context-store.ts +25 -0
  318. package/src/node/context/security-context-strategy.ts +24 -0
  319. package/src/node/crypto/index.ts +2 -0
  320. package/src/node/crypto/keygen/base64-string-key-generator.ts +15 -0
  321. package/src/node/crypto/keygen/index.ts +2 -0
  322. package/src/node/crypto/keygen/keygen-protocol.ts +7 -0
  323. package/src/node/crypto/password/index.ts +2 -0
  324. package/src/node/crypto/password/password-encoder.ts +39 -0
  325. package/src/node/crypto/password/password-protocol.ts +6 -0
  326. package/src/node/error/error-handler.ts +58 -0
  327. package/src/node/error/error-protocol.ts +5 -0
  328. package/src/node/error/error.ts +41 -0
  329. package/src/node/error/index.ts +3 -0
  330. package/src/node/index.ts +10 -0
  331. package/src/node/logout/index.ts +4 -0
  332. package/src/node/logout/logout-handler.ts +12 -0
  333. package/src/node/logout/logout-middleware.ts +49 -0
  334. package/src/node/logout/logout-protocol.ts +17 -0
  335. package/src/node/logout/logout-success-handler-provider.ts +21 -0
  336. package/src/node/logout/logout-success-handler.ts +22 -0
  337. package/src/node/module.ts +5 -0
  338. package/src/node/user/index.ts +6 -0
  339. package/src/node/user/user-checker.ts +37 -0
  340. package/src/node/user/user-mapper.ts +26 -0
  341. package/src/node/user/user-middleware.ts +40 -0
  342. package/src/node/user/user-protocol.ts +20 -0
  343. package/src/node/user/user-service.ts +28 -0
  344. package/src/package.spec.ts +4 -0
@@ -0,0 +1,18 @@
1
+ import { ContainerUtil } from '@celljs/core';
2
+ import { AuthorizeType, Policy } from '../../common';
3
+ import { SecurityContext } from '../context';
4
+ import { AccessDecisionManager } from './access-protocol';
5
+
6
+ export namespace AccessDecisionUtils {
7
+ export function decide(resource: string, action: string, policies: Policy[] = [], principal?: any) {
8
+ const accessDecisionManager = ContainerUtil.get<AccessDecisionManager>(AccessDecisionManager);
9
+ return accessDecisionManager.decide({
10
+ authorizeType: AuthorizeType.Pre,
11
+ action,
12
+ resource,
13
+ principal: principal || SecurityContext.getAuthentication().principal,
14
+ policies,
15
+ grant: 0
16
+ });
17
+ }
18
+ }
@@ -0,0 +1,73 @@
1
+ import { SecurityMetadata, AccessDecisionVoter, ACCESS_DENIED, ACCESS_GRANTED, ACCESS_ABSTAIN,
2
+ POLICY_BASED_VOTER_PRIORITY, PolicyResolver, PolicyProvider, TENANT_VOTER_PRIORITY } from './access-protocol';
3
+ import { Component, Autowired } from '@celljs/core';
4
+ import { Context } from '@celljs/web/lib/node';
5
+ import { SecurityContext } from '../context';
6
+
7
+ @Component(AccessDecisionVoter)
8
+ export class PolicyBasedVoter implements AccessDecisionVoter {
9
+
10
+ readonly priority = POLICY_BASED_VOTER_PRIORITY;
11
+
12
+ @Autowired(PolicyResolver)
13
+ protected readonly policyResolvers: PolicyResolver[];
14
+
15
+ @Autowired(PolicyProvider)
16
+ protected readonly policyProviders: PolicyProvider[];
17
+
18
+ async vote(securityMetadata: SecurityMetadata): Promise<number> {
19
+ const policies = [ ...securityMetadata.policies ];
20
+ const ctx = {
21
+ resource: securityMetadata.resource,
22
+ principal: securityMetadata.principal,
23
+ type: securityMetadata.authorizeType
24
+ };
25
+
26
+ for (const policyProvider of this.policyProviders) {
27
+ policies.push(...await policyProvider.provide(ctx));
28
+ }
29
+
30
+ for (const policy of policies) {
31
+ for (const policyResolver of this.policyResolvers) {
32
+ if (await policyResolver.support(policy, securityMetadata)) {
33
+ const result = await policyResolver.resolve(policy, securityMetadata);
34
+ if (result === ACCESS_GRANTED) {
35
+ securityMetadata.grant++;
36
+ } else if (result === ACCESS_DENIED) {
37
+ return ACCESS_DENIED;
38
+ }
39
+ }
40
+ }
41
+ }
42
+ if (securityMetadata.grant > 0) {
43
+ return ACCESS_GRANTED;
44
+ }
45
+ if (securityMetadata.grant === 0) {
46
+ return ACCESS_ABSTAIN;
47
+ }
48
+ return ACCESS_DENIED;
49
+ }
50
+
51
+ async support(securityMetadata: SecurityMetadata): Promise<boolean> {
52
+ return true;
53
+ }
54
+
55
+ }
56
+
57
+ @Component(AccessDecisionVoter)
58
+ export class TenantVoter implements AccessDecisionVoter {
59
+
60
+ readonly priority = TENANT_VOTER_PRIORITY;
61
+
62
+ async vote(securityMetadata: SecurityMetadata): Promise<number> {
63
+ if (Context.getTenant() === SecurityContext.getAuthentication().name) {
64
+ return ACCESS_GRANTED;
65
+ }
66
+ return ACCESS_ABSTAIN;
67
+ }
68
+
69
+ async support(securityMetadata: SecurityMetadata): Promise<boolean> {
70
+ return true;
71
+ }
72
+
73
+ }
@@ -0,0 +1,93 @@
1
+ import { AuthorizeType, Policy } from '../../common';
2
+
3
+ export const AccessDecisionManager = Symbol('AccessDecisionManager');
4
+ export const AccessDecisionVoter = Symbol('AccessDecisionVoter');
5
+ export const SecurityMetadataSource = Symbol('SecurityMetadataSource');
6
+ export const PolicyResolver = Symbol('PolicyResolver');
7
+ export const SecurityExpressionContextHandler = Symbol('SecurityExpressionContextHandler');
8
+ export const JexlEngineProvider = Symbol('JexlEngineProvider');
9
+ export const PolicyProvider = Symbol('PolicyProvider');
10
+ export const PolicyFactory = Symbol('PolicyFactory');
11
+ export const ResourceNameResolver = Symbol('ResourceNameResolver');
12
+ export const ActionNameResolver = Symbol('ActionNameResolver');
13
+
14
+ export const SECURITY_EXPRESSION_CONTEXT_KEY = 'SecurityExpressionContext';
15
+
16
+ export const ACCESS_GRANTED = 1;
17
+ export const ACCESS_ABSTAIN = 0;
18
+ export const ACCESS_DENIED = -1;
19
+
20
+ export const TENANT_VOTER_PRIORITY = 2000;
21
+ export const POLICY_BASED_VOTER_PRIORITY = TENANT_VOTER_PRIORITY - 100;
22
+
23
+ export interface PolicyContext {
24
+ principal: any;
25
+ type: AuthorizeType;
26
+ resource: string;
27
+ }
28
+
29
+ export interface PolicyProvider {
30
+ provide(ctx: PolicyContext): Promise<Policy[]>;
31
+ }
32
+
33
+ export interface PolicyFactory {
34
+ create(options: any): Promise<Policy>;
35
+ support(options: any): Promise<boolean>;
36
+ }
37
+
38
+ export interface PolicyResolver {
39
+ resolve(policy: Policy, securityMetadata: SecurityMetadata): Promise<number>;
40
+ support(policy: Policy, securityMetadata: SecurityMetadata): Promise<boolean>;
41
+ }
42
+
43
+ export interface JexlEngineProvider<T> {
44
+ provide(): T
45
+ }
46
+
47
+ export interface SecurityExpressionContextHandler {
48
+ handle(context: any): Promise<void>
49
+ }
50
+
51
+ export interface SecurityMetadata {
52
+ authorizeType: AuthorizeType;
53
+ action: string;
54
+ resource: string;
55
+ principal: any;
56
+ policies: Policy[];
57
+ grant: number;
58
+ }
59
+
60
+ export interface SecurityMetadataContext {
61
+ }
62
+
63
+ export interface MethodSecurityMetadataContext extends SecurityMetadataContext {
64
+ grant: number;
65
+ authorizeType: AuthorizeType
66
+ method: string;
67
+ args: any[];
68
+ target: any;
69
+ returnValue?: any
70
+
71
+ }
72
+
73
+ export interface SecurityMetadataSource {
74
+ load(context: SecurityMetadataContext): Promise<SecurityMetadata>;
75
+ }
76
+
77
+ export interface AccessDecisionManager {
78
+ decide(securityMetadata: SecurityMetadata): Promise<void>;
79
+ }
80
+
81
+ export interface AccessDecisionVoter {
82
+ vote(securityMetadata: SecurityMetadata): Promise<number>;
83
+ support(securityMetadata: SecurityMetadata): Promise<boolean>;
84
+ readonly priority: number;
85
+ }
86
+
87
+ export interface ResourceNameResolver {
88
+ resolve(ctx: MethodSecurityMetadataContext): Promise<string[]>;
89
+ }
90
+
91
+ export interface ActionNameResolver {
92
+ resolve(ctx: MethodSecurityMetadataContext): Promise<string>;
93
+ }
@@ -0,0 +1,19 @@
1
+ import { MethodSecurityMetadataContext, ActionNameResolver } from './access-protocol';
2
+ import { Component, getOwnMetadata } from '@celljs/core';
3
+ import { METADATA_KEY } from '../constants';
4
+
5
+ @Component(ActionNameResolver)
6
+ export class DefaultActionNameResolver implements ActionNameResolver {
7
+
8
+ async resolve(ctx: MethodSecurityMetadataContext): Promise<string> {
9
+ const classResources: string[] = getOwnMetadata(METADATA_KEY.resource, ctx.target.constructor);
10
+ const actions: string[] = getOwnMetadata(METADATA_KEY.action, ctx.target.constructor, ctx.method);
11
+ const action = actions.length ? actions[0] : ctx.method;
12
+ if (classResources.length) {
13
+ return `${classResources[0]}:${action}`;
14
+ } else {
15
+ return `${ctx.target.constructor.name}:${action}`;
16
+ }
17
+
18
+ }
19
+ }
@@ -0,0 +1,11 @@
1
+ export * from './access-decision-manager';
2
+ export * from './access-protocol';
3
+ export * from './access-decision-voter';
4
+ export * from './method-advice';
5
+ export * from './policy-provider';
6
+ export * from './policy-resolver';
7
+ export * from './security-metadata-source';
8
+ export * from './resource-name-resolver';
9
+ export * from './action-name-resolver';
10
+ export * from './access-decision-utils';
11
+ export * from './jexl-engine-provider';
@@ -0,0 +1,18 @@
1
+ import { Component } from '@celljs/core';
2
+ import { JexlEngineProvider } from './access-protocol';
3
+ import { Jexl } from 'jexl';
4
+
5
+ @Component(JexlEngineProvider)
6
+ export class JexlEngineProviderImpl implements JexlEngineProvider<any> {
7
+
8
+ protected jexlEngine: any;
9
+
10
+ provide(): any {
11
+
12
+ if (!this.jexlEngine) {
13
+ this.jexlEngine = new Jexl();
14
+ }
15
+ return this.jexlEngine;
16
+ }
17
+
18
+ }
@@ -0,0 +1,64 @@
1
+ import { MethodBeforeAdvice, Autowired, Aspect, AfterReturningAdvice, Value, ConfigUtil, Injectable } from '@celljs/core';
2
+ import { AccessDecisionManager, MethodSecurityMetadataContext, ResourceNameResolver, SecurityMetadataSource, SECURITY_EXPRESSION_CONTEXT_KEY } from './access-protocol';
3
+ import { AOP_POINTCUT } from '@celljs/web';
4
+ import { SecurityContext } from '../context';
5
+ import { AuthorizeType } from '../../common';
6
+ import { Context } from '@celljs/web/lib/node';
7
+
8
+ const pointcut = ConfigUtil.getRaw().cell.security.aop?.pointcut || AOP_POINTCUT;
9
+
10
+ @Injectable()
11
+ export abstract class AbstractSecurityMethodAdivice {
12
+
13
+ @Autowired(AccessDecisionManager)
14
+ protected readonly accessDecisionManager: AccessDecisionManager;
15
+
16
+ @Autowired(SecurityMetadataSource)
17
+ protected readonly securityMetadataSource: SecurityMetadataSource;
18
+
19
+ @Autowired(ResourceNameResolver)
20
+ protected readonly resourceNameResolver: ResourceNameResolver;
21
+
22
+ @Value('cell.security.enabled')
23
+ protected readonly enabled: boolean;
24
+
25
+ protected needAccessDecision(method: string | number | symbol) {
26
+ return this.enabled && typeof method === 'string' && SecurityContext.getCurrent();
27
+ }
28
+ }
29
+
30
+ @Aspect({ id: MethodBeforeAdvice, pointcut })
31
+ export class SecurityMethodBeforeAdivice extends AbstractSecurityMethodAdivice implements MethodBeforeAdvice {
32
+
33
+ async before(method: string | number | symbol, args: any[], target: any): Promise<void> {
34
+ if (this.needAccessDecision(method)) {
35
+ const ctx: MethodSecurityMetadataContext = { method: method as string, args, target, authorizeType: AuthorizeType.Pre, grant: 0 };
36
+ const securityMetadata = await this.securityMetadataSource.load(ctx);
37
+ const resouces = await this.resourceNameResolver.resolve(ctx);
38
+ for (const resource of resouces) {
39
+ securityMetadata.resource = resource;
40
+ await this.accessDecisionManager.decide(securityMetadata);
41
+ }
42
+ }
43
+ }
44
+
45
+ }
46
+
47
+ @Aspect({ id: AfterReturningAdvice, pointcut })
48
+ export class SecurityAfterReturningAdvice extends AbstractSecurityMethodAdivice implements AfterReturningAdvice {
49
+
50
+ async afterReturning(returnValue: any, method: string | number | symbol, args: any[], target: any): Promise<void> {
51
+ if (this.needAccessDecision(method)) {
52
+ const oldCtx = Context.getAttr<MethodSecurityMetadataContext>(SECURITY_EXPRESSION_CONTEXT_KEY);
53
+ const newCtx = { method: method as string, args, target, returnValue, authorizeType: AuthorizeType.Post, grant: oldCtx.grant };
54
+ const securityMetadata = await this.securityMetadataSource.load(newCtx);
55
+ const resouces = await this.resourceNameResolver.resolve(newCtx);
56
+ for (const resource of resouces) {
57
+ securityMetadata.resource = resource;
58
+ await this.accessDecisionManager.decide(securityMetadata);
59
+ }
60
+ }
61
+ }
62
+
63
+ }
64
+
@@ -0,0 +1,64 @@
1
+ import { PolicyContext, PolicyProvider } from './access-protocol';
2
+ import { Component, Value, PostConstruct } from '@celljs/core';
3
+ import { AuthorizeType, Policy } from '../../common';
4
+ import { contains } from 'micromatch';
5
+
6
+ @Component(PolicyProvider)
7
+ export class PrincipalPolicyProvider implements PolicyProvider {
8
+
9
+ async provide(ctx: PolicyContext): Promise<Policy[]> {
10
+ const { principal, type } = ctx;
11
+ const policies: Policy[] = principal && principal.policies || [];
12
+ return policies.filter(p => p.authorizeType === type);
13
+ }
14
+ }
15
+
16
+ @Component(PolicyProvider)
17
+ export class ResourcePolicyProvider implements PolicyProvider {
18
+
19
+ @Value('cell.security.policy')
20
+ protected readonly policyMap?: { [resource: string]: (Policy[] | Policy) };
21
+
22
+ protected readonly metadata = {
23
+ [AuthorizeType.Pre]: new Map<string, Policy[]>(),
24
+ [AuthorizeType.Post]: new Map<string, Policy[]>()
25
+ };
26
+
27
+ @PostConstruct()
28
+ protected init(): void {
29
+ if (this.policyMap) {
30
+ for (const pattarn of Object.keys(this.policyMap)) {
31
+ const temp = this.policyMap[pattarn];
32
+ if (!temp) {
33
+ continue;
34
+ }
35
+ const policies = Array.isArray(temp) ? temp : [ temp ];
36
+
37
+ for (const policy of policies) {
38
+ if (policy.authorizeType !== AuthorizeType.Post) {
39
+ policy.authorizeType = AuthorizeType.Pre;
40
+ }
41
+ const map = this.metadata[policy.authorizeType];
42
+ let ps = map.get(pattarn);
43
+ if (!ps) {
44
+ ps = [];
45
+ map.set(pattarn, ps);
46
+ }
47
+ ps.push(policy);
48
+ }
49
+ }
50
+ }
51
+ }
52
+
53
+ async provide(ctx: PolicyContext): Promise<Policy[]> {
54
+ const { resource, type } = ctx;
55
+ const map = this.metadata[type];
56
+ const policies: Policy[] = [];
57
+ for (const pattarn of map.keys()) {
58
+ if (contains(resource, pattarn)) {
59
+ policies.push(...map.get(pattarn)!);
60
+ }
61
+ }
62
+ return policies;
63
+ }
64
+ }
@@ -0,0 +1,79 @@
1
+ import { ACCESS_ABSTAIN, ACCESS_DENIED, ACCESS_GRANTED, JexlEngineProvider, PolicyResolver, SecurityMetadata, SECURITY_EXPRESSION_CONTEXT_KEY } from './access-protocol';
2
+ import { Autowired, Component } from '@celljs/core';
3
+ import { Context } from '@celljs/web/lib/node';
4
+ import { AclPolicy, Effect, ElPolicy, Policy, PolicyType, Statement } from '../../common';
5
+ import { contains } from 'micromatch';
6
+
7
+ @Component(PolicyResolver)
8
+ export class ElPolicyResolver implements PolicyResolver {
9
+
10
+ @Autowired(JexlEngineProvider)
11
+ protected readonly jexlEngineProvider: JexlEngineProvider<any>;
12
+
13
+ async resolve(policy: ElPolicy, securityMetadata: SecurityMetadata): Promise<number> {
14
+ const expression = this.jexlEngineProvider.provide().createExpression(policy.el);
15
+ // eslint-disable-next-line no-eval
16
+ const result = await expression.eval(policy.context || Context.getAttr(SECURITY_EXPRESSION_CONTEXT_KEY));
17
+ if (result === true) {
18
+ return ACCESS_GRANTED;
19
+ };
20
+ return ACCESS_DENIED;
21
+ }
22
+
23
+ async support(policy: Policy, securityMetadata: SecurityMetadata): Promise<boolean> {
24
+ return policy.type === PolicyType.el;
25
+ }
26
+ }
27
+
28
+ @Component(PolicyResolver)
29
+ export class AclPolicyResolver implements PolicyResolver {
30
+
31
+ protected match(pattern: string, resource: string) {
32
+ return contains(resource, pattern);
33
+ }
34
+
35
+ protected toArray(value: string | string[]) {
36
+ return Array.isArray(value) ? value : [value];
37
+
38
+ }
39
+
40
+ async resolve(policy: AclPolicy, securityMetadata: SecurityMetadata): Promise<number> {
41
+ const acl = policy as AclPolicy;
42
+ let grant = 0;
43
+ for (const statement of acl.statement) {
44
+ const result = this.resolveStatement(statement, securityMetadata);
45
+ if (result === ACCESS_DENIED) {
46
+ return ACCESS_DENIED;
47
+ } else if (result === ACCESS_GRANTED) {
48
+ grant++;
49
+ }
50
+ }
51
+ if (grant > 0) {
52
+ return ACCESS_GRANTED;
53
+ }
54
+ return ACCESS_ABSTAIN;
55
+ }
56
+
57
+ protected resolveStatement(statement: Statement, securityMetadata: SecurityMetadata) {
58
+ const resources = this.toArray(statement.resource);
59
+ for (const pattern of resources) {
60
+ if (this.match(pattern, securityMetadata.resource)) {
61
+ const actions = this.toArray(statement.action);
62
+ for (const actionPattern of actions) {
63
+ if (this.match(actionPattern, securityMetadata.action)) {
64
+ if (statement.effect === Effect.Allow) {
65
+ return ACCESS_GRANTED;
66
+ }
67
+ return ACCESS_DENIED;
68
+ }
69
+ }
70
+ break;
71
+ }
72
+ }
73
+ return ACCESS_ABSTAIN;
74
+ }
75
+
76
+ async support(policy: Policy, securityMetadata: SecurityMetadata): Promise<boolean> {
77
+ return policy.type === PolicyType.acl;
78
+ }
79
+ }
@@ -0,0 +1,41 @@
1
+ import { MethodSecurityMetadataContext, ResourceNameResolver } from './access-protocol';
2
+ import { Component, Value, TENANT_ENABLED, getOwnMetadata } from '@celljs/core';
3
+ import { METADATA_KEY } from '../constants';
4
+ import { evalSync } from 'jexl';
5
+ import { Context } from '@celljs/web/lib/node';
6
+
7
+ @Component(ResourceNameResolver)
8
+ export class DefaultResourceNameResolver implements ResourceNameResolver {
9
+
10
+ @Value(TENANT_ENABLED)
11
+ protected tenantEnabled: boolean;
12
+
13
+ async resolve(ctx: MethodSecurityMetadataContext): Promise<string[]> {
14
+ const classResources: string[] = getOwnMetadata(METADATA_KEY.resource, ctx.target.constructor);
15
+ const methodResources: string[] = getOwnMetadata(METADATA_KEY.resource, ctx.target.constructor, ctx.method);
16
+ let resources: string[] = [];
17
+ if (classResources.length && methodResources.length) {
18
+ for (const resource of methodResources) {
19
+ // eslint-disable-next-line no-eval
20
+ resources.push(`${classResources[0]}:${evalSync(resource?.toString(), ctx)}`);
21
+ }
22
+ } else if (methodResources.length) {
23
+ // eslint-disable-next-line no-eval
24
+ resources = methodResources.map(r => evalSync(r?.toString(), ctx)?.toString());
25
+ } else if (classResources.length) {
26
+ resources = classResources;
27
+ } else {
28
+ resources = [ctx.target.constructor.name];
29
+ }
30
+
31
+ return this.appendTenantIfNeed(resources);
32
+ }
33
+
34
+ protected async appendTenantIfNeed(resources: string[]) {
35
+ if (this.tenantEnabled) {
36
+ const tenant = Context.getTenant();
37
+ return resources.map(r => `${tenant}:${r}`);
38
+ }
39
+ return resources;
40
+ }
41
+ }
@@ -0,0 +1,47 @@
1
+ import { Component, Autowired, Optional, getOwnMetadata } from '@celljs/core';
2
+ import {
3
+ SecurityMetadataSource, SecurityMetadata, MethodSecurityMetadataContext,
4
+ SecurityExpressionContextHandler, SECURITY_EXPRESSION_CONTEXT_KEY, ActionNameResolver } from './access-protocol';
5
+ import { SecurityContext } from '../context';
6
+ import { METADATA_KEY } from '../constants';
7
+ import { Context } from '@celljs/web/lib/node';
8
+ import { Policy } from '../../common';
9
+
10
+ @Component(SecurityMetadataSource)
11
+ export class MethodSecurityMetadataSource implements SecurityMetadataSource {
12
+
13
+ @Autowired(SecurityExpressionContextHandler) @Optional()
14
+ protected readonly securityExpressionContextHandler: SecurityExpressionContextHandler;
15
+
16
+ @Autowired(ActionNameResolver)
17
+ protected readonly actionNameResolver: ActionNameResolver;
18
+
19
+ async load(context: MethodSecurityMetadataContext): Promise<SecurityMetadata> {
20
+ const classPolicies: Policy[] = getOwnMetadata(METADATA_KEY.authorize, context.target.constructor);
21
+ const methodPolicies: Policy[] = getOwnMetadata(METADATA_KEY.authorize, context.target.constructor, context.method);
22
+ const ctx = {
23
+ ...context,
24
+ ...SecurityContext.getAuthentication()
25
+ };
26
+ if (this.securityExpressionContextHandler) {
27
+ await this.securityExpressionContextHandler.handle(ctx);
28
+ }
29
+ Context.setAttr(SECURITY_EXPRESSION_CONTEXT_KEY, ctx);
30
+ const policies = classPolicies.concat(...methodPolicies)
31
+ .filter(item => item.authorizeType === context.authorizeType);
32
+ const action = await this.actionNameResolver.resolve(context);
33
+ return {
34
+ authorizeType: context.authorizeType,
35
+ principal: SecurityContext.getAuthentication().principal,
36
+ action,
37
+ resource: '',
38
+ policies: policies,
39
+ get grant() {
40
+ return ctx.grant;
41
+ },
42
+ set grant(grant: number) {
43
+ ctx.grant = grant;
44
+ }
45
+ };
46
+ }
47
+ }
@@ -0,0 +1,8 @@
1
+ import { METADATA_KEY } from '../constants';
2
+
3
+ export const Action = function (name: string) {
4
+ return (target: any, targetKey: string | symbol, descriptor: any) => {
5
+ Reflect.defineMetadata(METADATA_KEY.action, name, target.constructor, targetKey);
6
+ };
7
+
8
+ };
@@ -0,0 +1,6 @@
1
+ import { Authorize } from './authorize';
2
+ import { AuthorizeType } from '../../common';
3
+
4
+ export const Anonymous = function () {
5
+ return Authorize({ el: 'true', authorizeType: AuthorizeType.Pre });
6
+ };
@@ -0,0 +1,6 @@
1
+ import { AuthorizeType } from '../../common';
2
+ import { Authorize } from './authorize';
3
+
4
+ export const Authenticated = function () {
5
+ return Authorize({ el: 'authenticated', authorizeType: AuthorizeType.Pre });
6
+ };
@@ -0,0 +1,39 @@
1
+ import { METADATA_KEY } from '../constants';
2
+ import { AuthorizeType, Policy, PolicyType } from '../../common';
3
+
4
+ export interface ElOption {
5
+ el: string;
6
+ authorizeType: AuthorizeType;
7
+ }
8
+
9
+ export namespace ElOption {
10
+ export function is(option: any): option is ElOption {
11
+ return option && (option.el !== undefined || option.authorizeType);
12
+ }
13
+ }
14
+
15
+ export const Authorize = function (elOrElOptionOrPolicy: string | ElOption | Policy) {
16
+ const policy = getPolicy(elOrElOptionOrPolicy);
17
+ return (target: any, targetKey?: string | symbol, descriptor?: any) => {
18
+ if (targetKey) {
19
+ const policies: Policy[] = Reflect.getOwnMetadata(METADATA_KEY.authorize, target.constructor, targetKey) || [];
20
+ policies.push(policy);
21
+ Reflect.defineMetadata(METADATA_KEY.authorize, policies, target.constructor, targetKey);
22
+ } else {
23
+ const policies: Policy[] = Reflect.getOwnMetadata(METADATA_KEY.authorize, target.constructor) || [];
24
+ policies.push(policy);
25
+ Reflect.defineMetadata(METADATA_KEY.authorize, policies, target);
26
+ }
27
+ };
28
+
29
+ };
30
+
31
+ export function getPolicy(elOrElOptionOrPolicy: string | ElOption | Policy) {
32
+ let policy = <Policy>elOrElOptionOrPolicy;
33
+ if (typeof elOrElOptionOrPolicy === 'string') {
34
+ policy = { authorizeType: AuthorizeType.Pre, el: elOrElOptionOrPolicy, type: PolicyType.el };
35
+ } else if (elOrElOptionOrPolicy.el) {
36
+ policy = { type: PolicyType.el, ...elOrElOptionOrPolicy};
37
+ }
38
+ return policy;
39
+ }
@@ -0,0 +1,7 @@
1
+ export * from './anonymous';
2
+ export * from './authenticated';
3
+ export * from './authorize';
4
+ export * from './post-authorize';
5
+ export * from './pre-authorize';
6
+ export * from './resource';
7
+ export * from './action';
@@ -0,0 +1,6 @@
1
+ import { Authorize } from './authorize';
2
+ import { AuthorizeType } from '../../common';
3
+
4
+ export const PostAuthorize = function (el: string) {
5
+ return Authorize({ el, authorizeType: AuthorizeType.Post });
6
+ };
@@ -0,0 +1,6 @@
1
+ import { Authorize } from './authorize';
2
+ import { AuthorizeType } from '../../common';
3
+
4
+ export const PreAuthorize = function (el: string) {
5
+ return Authorize({ el, authorizeType: AuthorizeType.Pre });
6
+ };
@@ -0,0 +1,12 @@
1
+ import { METADATA_KEY } from '../constants';
2
+
3
+ export const Resource = function (...resources: string[]) {
4
+ return (target: any, targetKey?: string | symbol, descriptor?: any) => {
5
+ if (targetKey) {
6
+ Reflect.defineMetadata(METADATA_KEY.resource, resources, target.constructor, targetKey);
7
+ } else {
8
+ Reflect.defineMetadata(METADATA_KEY.resource, resources, target);
9
+ }
10
+ };
11
+
12
+ };