chyz 1.0.13-rc.20 → 1.0.13-rc.6
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/BaseChyz.ts +4 -19
- package/Examples/Controllers/ApiController.ts +22 -22
- package/Examples/Controllers/SiteController.ts +8 -18
- package/Examples/Models/Categories.ts +2 -1
- package/Examples/Models/KeycloakUser.ts +0 -4
- package/Examples/Models/User.ts +1 -8
- package/Examples/index.ts +0 -5
- package/Examples/log/app.log +0 -4322
- package/Examples/log/errors.log +0 -458
- package/README.md +12 -265
- package/base/ActionFilter.ts +1 -1
- package/base/BaseError.ts +1 -3
- package/base/Model.ts +29 -43
- package/base/ModelManager.ts +1 -6
- package/base/RestClient.ts +4 -4
- package/base/ValidationHttpException.ts +1 -1
- package/base/index.ts +0 -1
- package/dist/BaseChyz.js +4 -17
- package/dist/BaseChyz.js.map +1 -1
- package/dist/base/ActionFilter.js +1 -1
- package/dist/base/ActionFilter.js.map +1 -1
- package/dist/base/BaseError.js +1 -5
- package/dist/base/BaseError.js.map +1 -1
- package/dist/base/Model.js +2 -12
- package/dist/base/Model.js.map +1 -1
- package/dist/base/ModelManager.js +8 -0
- package/dist/base/ModelManager.js.map +1 -1
- package/dist/base/RestClient.js +4 -4
- package/dist/base/RestClient.js.map +1 -1
- package/dist/base/ValidationHttpException.js +1 -1
- package/dist/base/index.js +0 -1
- package/dist/base/index.js.map +1 -1
- package/dist/filters/AccessControl.js +3 -15
- package/dist/filters/AccessControl.js.map +1 -1
- package/dist/filters/AccessRule.js +38 -99
- package/dist/filters/AccessRule.js.map +1 -1
- package/dist/filters/auth/HttpBasicAuth.js +0 -65
- package/dist/filters/auth/HttpBasicAuth.js.map +1 -1
- package/dist/filters/auth/JwtHttpBearerAuth.js +1 -1
- package/dist/filters/auth/JwtHttpBearerAuth.js.map +1 -1
- package/dist/filters/auth/index.js +0 -1
- package/dist/filters/auth/index.js.map +1 -1
- package/dist/package.json +5 -4
- package/dist/web/WebUser.js +0 -78
- package/dist/web/WebUser.js.map +1 -1
- package/filters/AccessControl.ts +6 -19
- package/filters/AccessRule.ts +16 -61
- package/filters/auth/HttpBasicAuth.ts +0 -68
- package/filters/auth/JwtHttpBearerAuth.ts +1 -1
- package/filters/auth/index.ts +0 -1
- package/package.json +5 -4
- package/web/IdentityInterface.ts +0 -6
- package/web/WebUser.ts +1 -88
- package/Doc/Moel kullanma.md +0 -13
- package/Examples/Controllers/BasicApiController.ts +0 -121
- package/Examples/Models/AuthAssignment.ts +0 -50
- package/Examples/Models/AuthItem.ts +0 -59
- package/Examples/Models/AuthItemChild.ts +0 -49
- package/base/InvalidArgumentException.ts +0 -16
- package/dist/base/InvalidArgumentException.js +0 -18
- package/dist/base/InvalidArgumentException.js.map +0 -1
- package/dist/rbac/AuthAssignment.js +0 -45
- package/dist/rbac/AuthAssignment.js.map +0 -1
- package/dist/rbac/AuthItem.js +0 -52
- package/dist/rbac/AuthItem.js.map +0 -1
- package/dist/rbac/AuthItemChild.js +0 -44
- package/dist/rbac/AuthItemChild.js.map +0 -1
- package/dist/rbac/AuthManager.js +0 -359
- package/dist/rbac/AuthManager.js.map +0 -1
- package/rbac/AuthAssignment.ts +0 -50
- package/rbac/AuthItem.ts +0 -57
- package/rbac/AuthItemChild.ts +0 -50
- package/rbac/AuthManager.ts +0 -398
package/dist/web/WebUser.js
CHANGED
|
@@ -23,18 +23,7 @@ const BaseChyz_1 = __importDefault(require("../BaseChyz"));
|
|
|
23
23
|
const Component_1 = require("../base/Component");
|
|
24
24
|
const ForbiddenHttpException_1 = require("../base/ForbiddenHttpException");
|
|
25
25
|
const InvalidConfigException_1 = require("../base/InvalidConfigException");
|
|
26
|
-
const Utils_1 = __importDefault(require("../requiments/Utils"));
|
|
27
26
|
class WebUser extends Component_1.Component {
|
|
28
|
-
constructor() {
|
|
29
|
-
super(...arguments);
|
|
30
|
-
/**
|
|
31
|
-
* @var CheckAccessInterface|string|array The access checker object to use for checking access or the application
|
|
32
|
-
* component ID of the access checker.
|
|
33
|
-
* If not set the application auth manager will be used.
|
|
34
|
-
* @since 2.0.9
|
|
35
|
-
*/
|
|
36
|
-
this.accessChecker = null;
|
|
37
|
-
}
|
|
38
27
|
get identity() {
|
|
39
28
|
return this._identity;
|
|
40
29
|
}
|
|
@@ -94,73 +83,6 @@ class WebUser extends Component_1.Component {
|
|
|
94
83
|
}
|
|
95
84
|
afterLogin() {
|
|
96
85
|
}
|
|
97
|
-
getId() {
|
|
98
|
-
let identity = this.getIdentity();
|
|
99
|
-
return identity !== null ? identity.getId() : null;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Checks if the user can perform the operation as specified by the given permission.
|
|
103
|
-
*
|
|
104
|
-
* Note that you must configure "authManager" application component in order to use this method.
|
|
105
|
-
* Otherwise it will always return false.
|
|
106
|
-
*
|
|
107
|
-
* @param string $permissionName the name of the permission (e.g. "edit post") that needs access check.
|
|
108
|
-
* @param array $params name-value pairs that would be passed to the rules associated
|
|
109
|
-
* with the roles and permissions assigned to the user.
|
|
110
|
-
* @param bool $allowCaching whether to allow caching the result of access check.
|
|
111
|
-
* When this parameter is true (default), if the access check of an operation was performed
|
|
112
|
-
* before, its result will be directly returned when calling this method to check the same
|
|
113
|
-
* operation. If this parameter is false, this method will always call
|
|
114
|
-
* [[\yii\rbac\CheckAccessInterface::checkAccess()]] to obtain the up-to-date access result. Note that this
|
|
115
|
-
* caching is effective only within the same request and only works when `$params = []`.
|
|
116
|
-
* @return bool whether the user can perform the operation as specified by the given permission.
|
|
117
|
-
*/
|
|
118
|
-
// public function can($permissionName, $params = [], $allowCaching = true)
|
|
119
|
-
// {
|
|
120
|
-
// if ($allowCaching && empty($params) && isset($this->_access[$permissionName])) {
|
|
121
|
-
// return $this->_access[$permissionName];
|
|
122
|
-
// }
|
|
123
|
-
// if (($accessChecker = $this->getAccessChecker()) === null) {
|
|
124
|
-
// return false;
|
|
125
|
-
// }
|
|
126
|
-
// $access = $accessChecker->checkAccess($this->getId(), $permissionName, $params);
|
|
127
|
-
// if ($allowCaching && empty($params)) {
|
|
128
|
-
// $this->_access[$permissionName] = $access;
|
|
129
|
-
// }
|
|
130
|
-
//
|
|
131
|
-
// return $access;
|
|
132
|
-
// }
|
|
133
|
-
can(permissionName, params = [], allowCaching = true) {
|
|
134
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
-
let access;
|
|
136
|
-
let accessChecker;
|
|
137
|
-
if ((accessChecker = this.getAccessChecker()) == null)
|
|
138
|
-
return false;
|
|
139
|
-
access = yield accessChecker.checkAccess(this.getId(), permissionName, params);
|
|
140
|
-
if (allowCaching && Utils_1.default.isEmpty(params)) {
|
|
141
|
-
// this._access[$permissionName] = $access;
|
|
142
|
-
}
|
|
143
|
-
return access;
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Returns auth manager associated with the user component.
|
|
148
|
-
*
|
|
149
|
-
* By default this is the `authManager` application component.
|
|
150
|
-
* You may override this method to return a different auth manager instance if needed.
|
|
151
|
-
* @return \yii\rbac\ManagerInterface
|
|
152
|
-
* @since 2.0.6
|
|
153
|
-
*/
|
|
154
|
-
getAuthManager() {
|
|
155
|
-
return BaseChyz_1.default.getComponent('authManager');
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Returns the access checker used for checking access.
|
|
159
|
-
* @return CheckAccessInterface
|
|
160
|
-
*/
|
|
161
|
-
getAccessChecker() {
|
|
162
|
-
return this.accessChecker !== null ? this.accessChecker : this.getAuthManager();
|
|
163
|
-
}
|
|
164
86
|
}
|
|
165
87
|
exports.WebUser = WebUser;
|
|
166
88
|
//# sourceMappingURL=WebUser.js.map
|
package/dist/web/WebUser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebUser.js","sourceRoot":"","sources":["../../web/WebUser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;;;;;GAKG;AACH,2DAAmC;AACnC,iDAA4C;AAC5C,2EAAsE;AACtE,2EAAsE;
|
|
1
|
+
{"version":3,"file":"WebUser.js","sourceRoot":"","sources":["../../web/WebUser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;;;;;GAKG;AACH,2DAAmC;AACnC,iDAA4C;AAC5C,2EAAsE;AACtE,2EAAsE;AAGtE,MAAa,OAAQ,SAAQ,qBAAS;IASlC,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;IAED,IAAI,QAAQ,CAAC,KAAK;QACd,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;IAC3B,CAAC;IAEM,IAAI;QACP,KAAK,CAAC,IAAI,EAAE,CAAC;QAEb,IAAI,IAAI,CAAC,aAAa,KAAK,IAAI,EAAE;YAC7B,MAAM,IAAI,+CAAsB,CAAC,kCAAkC,CAAC,CAAC;SACxE;QAGD,IAAI,CAAC,aAAa,GAAG,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;IAElD,CAAC;IAEM,UAAU;QACb,OAAO,IAAI,CAAC,WAAW,EAAE,KAAK,IAAI,CAAC;IACvC,CAAC;IAEM,WAAW,CAAC,SAAS,GAAG,IAAI;QAC/B,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;IAEM,aAAa;QAEhB,MAAM,IAAI,+CAAsB,CAAC,kBAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC;IACnE,CAAC;IAGD;;;;OAIG;IACO,mBAAmB;IAE7B,CAAC;IAED;;;;OAIG;IACU,kBAAkB,CAAC,KAAU,EAAE,OAAY,IAAI;;YAExD,IAAI,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC;YAChC,IAAI,MAAM,CAAC,yBAAyB,EAAE;gBAClC,IAAI,CAAC,QAAQ,GAAG,MAAM,MAAM,CAAC,yBAAyB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;gBACnE,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;oBAC5C,OAAO,IAAI,CAAC,QAAQ,CAAC;iBACxB;aACJ;iBAAI;gBACD,kBAAQ,CAAC,KAAK,CAAC,8CAA8C,CAAC,CAAA;aACjE;YACD,OAAO,IAAI,CAAC;QAChB,CAAC;KAAA;IAEM,KAAK,CAAC,QAA2B,EAAE,QAAQ,GAAG,CAAC;QAElD,IAAI,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE;SAEhD;QACD,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,CAAA;IAC7B,CAAC;IAEM,WAAW,CAAC,QAAa,EAAE,WAAoB,EAAE,QAAgB;QAEpE,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,UAAU;IAEjB,CAAC;CACJ;AAvFD,0BAuFC"}
|
package/filters/AccessControl.ts
CHANGED
|
@@ -19,7 +19,6 @@ export class AccessControl extends ActionFilter {
|
|
|
19
19
|
|
|
20
20
|
public user: any = null;
|
|
21
21
|
public rules: any;
|
|
22
|
-
public denyCallback: any = null;
|
|
23
22
|
|
|
24
23
|
public init() {
|
|
25
24
|
super.init()
|
|
@@ -28,7 +27,7 @@ export class AccessControl extends ActionFilter {
|
|
|
28
27
|
this.user = Utils.cloneDeep(BaseChyz.getComponent("user")) ?? new WebUser();
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
this.rules.forEach((rule:
|
|
30
|
+
this.rules.forEach((rule:any, index:number) => {
|
|
32
31
|
if (rule === Object(rule)) {
|
|
33
32
|
this.rules[index] = Utils.createObject(new AccessRule(), rule);
|
|
34
33
|
}
|
|
@@ -36,7 +35,7 @@ export class AccessControl extends ActionFilter {
|
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
|
|
39
|
-
public async beforeAction(action:
|
|
38
|
+
public async beforeAction(action:any, request:Request) {
|
|
40
39
|
let allow;
|
|
41
40
|
// @ts-ignore
|
|
42
41
|
let user = request.user ?? this.user;
|
|
@@ -44,27 +43,15 @@ export class AccessControl extends ActionFilter {
|
|
|
44
43
|
user.identity = request.identity ?? null;
|
|
45
44
|
|
|
46
45
|
for (const rulesKey in this.rules) {
|
|
47
|
-
|
|
48
|
-
let rule = this.rules[rulesKey];
|
|
49
|
-
if ((allow = await rule.allows(action, user, request))) {
|
|
46
|
+
if ((allow = this.rules[rulesKey].allows(action, user, request))) {
|
|
50
47
|
return true;
|
|
51
48
|
} else if (allow === false) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
} else {
|
|
55
|
-
this.denyAccess(user);
|
|
56
|
-
}
|
|
49
|
+
this.denyAccess(user);
|
|
50
|
+
|
|
57
51
|
return false;
|
|
58
52
|
}
|
|
59
53
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (this.denyCallback != null) {
|
|
63
|
-
this.denyCallback.apply(null, action);
|
|
64
|
-
} else {
|
|
65
|
-
this.denyAccess(user);
|
|
66
|
-
}
|
|
67
|
-
|
|
54
|
+
this.denyAccess(user);
|
|
68
55
|
return false;
|
|
69
56
|
}
|
|
70
57
|
|
package/filters/AccessRule.ts
CHANGED
|
@@ -10,72 +10,35 @@ var _ = require('lodash');
|
|
|
10
10
|
import {Component} from "../base/Component";
|
|
11
11
|
import {InvalidConfigException} from "../base/InvalidConfigException";
|
|
12
12
|
import {Request, Response} from "express";
|
|
13
|
-
import Utils from "../requiments/Utils";
|
|
14
13
|
|
|
15
14
|
export class AccessRule extends Component {
|
|
16
15
|
|
|
17
16
|
/**
|
|
18
17
|
* @var bool whether this is an 'allow' rule or 'deny' rule.
|
|
19
18
|
*/
|
|
20
|
-
public allow:
|
|
19
|
+
public allow:any;
|
|
21
20
|
/**
|
|
22
21
|
* @var array list of action IDs that this rule applies to. The comparison is case-sensitive.
|
|
23
22
|
* If not set or empty, it means this rule applies to all actions.
|
|
24
23
|
*/
|
|
25
|
-
public actions:
|
|
24
|
+
public actions:any;
|
|
26
25
|
|
|
27
26
|
/**
|
|
28
27
|
* @var array list of the controller IDs that this rule applies to.
|
|
29
28
|
*/
|
|
30
|
-
public controllers:
|
|
29
|
+
public controllers:any;
|
|
31
30
|
|
|
32
31
|
/**
|
|
33
32
|
* - `?`: matches a guest user (not authenticated yet)
|
|
34
33
|
* - `@`: matches an authenticated user
|
|
35
34
|
*/
|
|
36
35
|
|
|
37
|
-
public roles:
|
|
36
|
+
public roles:any;
|
|
38
37
|
|
|
39
38
|
/**
|
|
40
39
|
* @var array list of RBAC (Role-Based Access Control) permissions that this rules applies to.
|
|
41
40
|
*/
|
|
42
|
-
public permissions:
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @var array|Closure parameters to pass to the [[User::can()]] function for evaluating
|
|
46
|
-
* user permissions in [[$roles]].
|
|
47
|
-
*
|
|
48
|
-
* If this is an array, it will be passed directly to [[User::can()]]. For example for passing an
|
|
49
|
-
* ID from the current request, you may use the following:
|
|
50
|
-
*
|
|
51
|
-
* ```php
|
|
52
|
-
* ['postId' => Yii::$app->request->get('id')]
|
|
53
|
-
* ```
|
|
54
|
-
*
|
|
55
|
-
* You may also specify a closure that returns an array. This can be used to
|
|
56
|
-
* evaluate the array values only if they are needed, for example when a model needs to be
|
|
57
|
-
* loaded like in the following code:
|
|
58
|
-
*
|
|
59
|
-
* ```php
|
|
60
|
-
* 'rules' => [
|
|
61
|
-
* [
|
|
62
|
-
* 'allow' => true,
|
|
63
|
-
* 'actions' => ['update'],
|
|
64
|
-
* 'roles' => ['updatePost'],
|
|
65
|
-
* 'roleParams' => function($rule) {
|
|
66
|
-
* return ['post' => Post::findOne(Yii::$app->request->get('id'))];
|
|
67
|
-
* },
|
|
68
|
-
* ],
|
|
69
|
-
* ],
|
|
70
|
-
* ```
|
|
71
|
-
*
|
|
72
|
-
* A reference to the [[AccessRule]] instance will be passed to the closure as the first parameter.
|
|
73
|
-
*
|
|
74
|
-
* @see roles
|
|
75
|
-
* @since 2.0.12
|
|
76
|
-
*/
|
|
77
|
-
public roleParams: any = [];
|
|
78
|
-
|
|
41
|
+
public permissions:any;
|
|
79
42
|
|
|
80
43
|
/**
|
|
81
44
|
* @var array list of user IP addresses that this rule applies to. An IP address
|
|
@@ -85,13 +48,13 @@ export class AccessRule extends Component {
|
|
|
85
48
|
* 20-bit private network block in RFC1918.
|
|
86
49
|
* If not set or empty, it means this rule applies to all IP addresses.
|
|
87
50
|
*/
|
|
88
|
-
public ips:
|
|
51
|
+
public ips:any;
|
|
89
52
|
|
|
90
53
|
|
|
91
|
-
public
|
|
54
|
+
public allows(action:any, user:WebUser, request:Request) {
|
|
92
55
|
if (
|
|
93
56
|
this.matchAction(action)
|
|
94
|
-
&&
|
|
57
|
+
&& this.matchRole(user)
|
|
95
58
|
) {
|
|
96
59
|
return this.allow
|
|
97
60
|
}
|
|
@@ -112,7 +75,7 @@ export class AccessRule extends Component {
|
|
|
112
75
|
* @param Action $action the action
|
|
113
76
|
* @return bool whether the rule applies to the action
|
|
114
77
|
*/
|
|
115
|
-
protected matchAction(action:
|
|
78
|
+
protected matchAction(action:any) {
|
|
116
79
|
return _.isEmpty(this.actions) || this.actions.includes(action.id);
|
|
117
80
|
}
|
|
118
81
|
|
|
@@ -120,7 +83,7 @@ export class AccessRule extends Component {
|
|
|
120
83
|
* @param Controller $controller the controller
|
|
121
84
|
* @return bool whether the rule applies to the controller
|
|
122
85
|
*/
|
|
123
|
-
protected matchController(controller:
|
|
86
|
+
protected matchController(controller:any) {
|
|
124
87
|
// if (empty($this->controllers)) {
|
|
125
88
|
// return true;
|
|
126
89
|
// }
|
|
@@ -135,23 +98,22 @@ export class AccessRule extends Component {
|
|
|
135
98
|
return false;
|
|
136
99
|
}
|
|
137
100
|
|
|
138
|
-
protected
|
|
139
|
-
let items =
|
|
101
|
+
protected matchRole(user:any) {
|
|
102
|
+
let items = _.isEmpty(this.roles) ? [] : this.roles;
|
|
140
103
|
|
|
141
|
-
if (!
|
|
142
|
-
items =
|
|
104
|
+
if (!_.isEmpty(this.permissions)) {
|
|
105
|
+
items = _.merge(items, this.permissions);
|
|
143
106
|
}
|
|
144
107
|
|
|
145
|
-
if (
|
|
108
|
+
if (_.isEmpty(items)) {
|
|
146
109
|
return true;
|
|
147
110
|
}
|
|
148
111
|
|
|
149
112
|
|
|
150
|
-
if (
|
|
113
|
+
if (user === false) {
|
|
151
114
|
throw new InvalidConfigException('The user application component must be available to specify roles in AccessRule.');
|
|
152
115
|
}
|
|
153
116
|
|
|
154
|
-
let roleParams: any = [];
|
|
155
117
|
for (const itemsKey in items) {
|
|
156
118
|
let item = items[itemsKey];
|
|
157
119
|
if (item === '?') {
|
|
@@ -164,13 +126,6 @@ export class AccessRule extends Component {
|
|
|
164
126
|
}
|
|
165
127
|
} else {
|
|
166
128
|
//roleparams
|
|
167
|
-
if (!Utils.isEmpty(this.roleParams)) {
|
|
168
|
-
roleParams = !Utils.isArray(this.roleParams) ? this.roleParams.apply(this) : this.roleParams;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (await user.can(item, this.roleParams)) {
|
|
172
|
-
return true;
|
|
173
|
-
}
|
|
174
129
|
}
|
|
175
130
|
}
|
|
176
131
|
|
|
@@ -5,71 +5,3 @@
|
|
|
5
5
|
* Github:https://github.com/cihan53/
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {HttpHeaderAuth} from "./HttpHeaderAuth";
|
|
9
|
-
import {Request, Response} from "express";
|
|
10
|
-
import {WebUser} from "../../web/WebUser";
|
|
11
|
-
import Utils from "../../requiments/Utils";
|
|
12
|
-
import {AuthMethod} from "./AuthMethod";
|
|
13
|
-
import {InvalidConfigException} from "../../base";
|
|
14
|
-
import BaseChyz from "../../BaseChyz";
|
|
15
|
-
|
|
16
|
-
export class HttpBasicAuth extends AuthMethod {
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @var string the HTTP header name
|
|
20
|
-
*/
|
|
21
|
-
public header = 'Authorization';
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @var string a pattern to use to extract the HTTP authentication value
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
public pattern = /^Basic\s+(.*?)$/;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @throws InvalidConfigException
|
|
33
|
-
*/
|
|
34
|
-
public init(): void {
|
|
35
|
-
super.init();
|
|
36
|
-
|
|
37
|
-
if (!this.pattern) {
|
|
38
|
-
throw new InvalidConfigException('You must provide pattern to use to extract the HTTP authentication value!');
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
this.user = BaseChyz.getComponent("user") ?? null;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
async authenticate(user: WebUser, request:Request, response:Response) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
let autHeader = this.getHeaderByKey(request.headers, this.header)
|
|
49
|
-
if (autHeader == null || (autHeader = this.patternCheck(autHeader, this.pattern)) == null) {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
let basicauth = autHeader[1].split(":")
|
|
54
|
-
|
|
55
|
-
let identity = await user.loginByAccessToken(basicauth, "HttpBasicAuth");
|
|
56
|
-
if (identity === null) {
|
|
57
|
-
this.challenge(response);
|
|
58
|
-
this.handleFailure(response);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return identity;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* @throws UnauthorizedHttpException
|
|
70
|
-
*/
|
|
71
|
-
public fail(response:Response): void {
|
|
72
|
-
this.challenge(response)
|
|
73
|
-
this.handleFailure(response);
|
|
74
|
-
}
|
|
75
|
-
}
|
package/filters/auth/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chyz",
|
|
3
|
-
"version": " 1.0.13-rc.
|
|
4
|
-
"description": "Nodejs
|
|
3
|
+
"version": " 1.0.13-rc.6",
|
|
4
|
+
"description": "Nodejs MicroServis Framework",
|
|
5
|
+
"main": "index.js",
|
|
5
6
|
"scripts": {
|
|
6
7
|
"dev": "nodemon -t --trace-warnings index.ts",
|
|
7
8
|
"debug": "ts-node index.ts",
|
|
8
9
|
"build": "rmdir /S /Q .\\dist && npx tsc && xcopy .\\log .\\dist\\log /e /i /h /Y && copy .\\package.json .\\dist\\package.json",
|
|
10
|
+
"publish": "cd dist && npm publish",
|
|
9
11
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
10
12
|
"postversion": "git push && git push --tags"
|
|
11
13
|
},
|
|
@@ -36,8 +38,7 @@
|
|
|
36
38
|
"pg": "^8.7.1",
|
|
37
39
|
"pg-hstore": "^2.3.4",
|
|
38
40
|
"reflect-metadata": "^0.1.13",
|
|
39
|
-
"sequelize": "^6.6.5"
|
|
40
|
-
"validate.js": "^0.13.1"
|
|
41
|
+
"sequelize": "^6.6.5"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
44
|
"@types/express": "^4.17.13",
|
package/web/IdentityInterface.ts
CHANGED
package/web/WebUser.ts
CHANGED
|
@@ -9,8 +9,6 @@ import {Component} from "../base/Component";
|
|
|
9
9
|
import {ForbiddenHttpException} from "../base/ForbiddenHttpException";
|
|
10
10
|
import {InvalidConfigException} from "../base/InvalidConfigException";
|
|
11
11
|
import {IdentityInterface} from "./IdentityInterface";
|
|
12
|
-
import Utils from "../requiments/Utils";
|
|
13
|
-
import {AuthManager} from "../rbac/AuthManager";
|
|
14
12
|
|
|
15
13
|
export class WebUser extends Component {
|
|
16
14
|
|
|
@@ -19,13 +17,6 @@ export class WebUser extends Component {
|
|
|
19
17
|
*/
|
|
20
18
|
public identityClass: any;
|
|
21
19
|
private _identity: any;
|
|
22
|
-
/**
|
|
23
|
-
* @var CheckAccessInterface|string|array The access checker object to use for checking access or the application
|
|
24
|
-
* component ID of the access checker.
|
|
25
|
-
* If not set the application auth manager will be used.
|
|
26
|
-
* @since 2.0.9
|
|
27
|
-
*/
|
|
28
|
-
public accessChecker: any = null;
|
|
29
20
|
|
|
30
21
|
|
|
31
22
|
get identity() {
|
|
@@ -84,7 +75,7 @@ export class WebUser extends Component {
|
|
|
84
75
|
if (this.identity && this.login(this.identity)) {
|
|
85
76
|
return this.identity;
|
|
86
77
|
}
|
|
87
|
-
}
|
|
78
|
+
}else{
|
|
88
79
|
BaseChyz.error("WebUser::findIdentityByAccessToken undefined")
|
|
89
80
|
}
|
|
90
81
|
return null;
|
|
@@ -106,82 +97,4 @@ export class WebUser extends Component {
|
|
|
106
97
|
public afterLogin() {
|
|
107
98
|
|
|
108
99
|
}
|
|
109
|
-
|
|
110
|
-
public getId() {
|
|
111
|
-
let identity = this.getIdentity();
|
|
112
|
-
return identity !== null ? identity.getId() : null;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Checks if the user can perform the operation as specified by the given permission.
|
|
117
|
-
*
|
|
118
|
-
* Note that you must configure "authManager" application component in order to use this method.
|
|
119
|
-
* Otherwise it will always return false.
|
|
120
|
-
*
|
|
121
|
-
* @param string $permissionName the name of the permission (e.g. "edit post") that needs access check.
|
|
122
|
-
* @param array $params name-value pairs that would be passed to the rules associated
|
|
123
|
-
* with the roles and permissions assigned to the user.
|
|
124
|
-
* @param bool $allowCaching whether to allow caching the result of access check.
|
|
125
|
-
* When this parameter is true (default), if the access check of an operation was performed
|
|
126
|
-
* before, its result will be directly returned when calling this method to check the same
|
|
127
|
-
* operation. If this parameter is false, this method will always call
|
|
128
|
-
* [[\yii\rbac\CheckAccessInterface::checkAccess()]] to obtain the up-to-date access result. Note that this
|
|
129
|
-
* caching is effective only within the same request and only works when `$params = []`.
|
|
130
|
-
* @return bool whether the user can perform the operation as specified by the given permission.
|
|
131
|
-
*/
|
|
132
|
-
// public function can($permissionName, $params = [], $allowCaching = true)
|
|
133
|
-
// {
|
|
134
|
-
// if ($allowCaching && empty($params) && isset($this->_access[$permissionName])) {
|
|
135
|
-
// return $this->_access[$permissionName];
|
|
136
|
-
// }
|
|
137
|
-
// if (($accessChecker = $this->getAccessChecker()) === null) {
|
|
138
|
-
// return false;
|
|
139
|
-
// }
|
|
140
|
-
// $access = $accessChecker->checkAccess($this->getId(), $permissionName, $params);
|
|
141
|
-
// if ($allowCaching && empty($params)) {
|
|
142
|
-
// $this->_access[$permissionName] = $access;
|
|
143
|
-
// }
|
|
144
|
-
//
|
|
145
|
-
// return $access;
|
|
146
|
-
// }
|
|
147
|
-
|
|
148
|
-
public async can(permissionName: string, params = [], allowCaching = true) {
|
|
149
|
-
|
|
150
|
-
let access;
|
|
151
|
-
let accessChecker: AuthManager;
|
|
152
|
-
if ((accessChecker = this.getAccessChecker()) == null)
|
|
153
|
-
return false;
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
access = await accessChecker.checkAccess(this.getId(), permissionName, params);
|
|
157
|
-
|
|
158
|
-
if (allowCaching && Utils.isEmpty(params)) {
|
|
159
|
-
// this._access[$permissionName] = $access;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return access;
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Returns auth manager associated with the user component.
|
|
168
|
-
*
|
|
169
|
-
* By default this is the `authManager` application component.
|
|
170
|
-
* You may override this method to return a different auth manager instance if needed.
|
|
171
|
-
* @return \yii\rbac\ManagerInterface
|
|
172
|
-
* @since 2.0.6
|
|
173
|
-
*/
|
|
174
|
-
protected getAuthManager(): AuthManager {
|
|
175
|
-
return BaseChyz.getComponent('authManager');
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Returns the access checker used for checking access.
|
|
180
|
-
* @return CheckAccessInterface
|
|
181
|
-
*/
|
|
182
|
-
protected getAccessChecker():AuthManager {
|
|
183
|
-
return this.accessChecker !== null ? this.accessChecker : this.getAuthManager();
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
187
100
|
}
|
package/Doc/Moel kullanma.md
DELETED