Skip to content

Commit 8a23e87

Browse files
committed
Add Auth clearCache
1 parent 20e140c commit 8a23e87

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

OpenFlow/src/Auth.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ export class Auth {
5050
this.RemoveUser(key, type);
5151
return null;
5252
}
53+
public static async clearCache() {
54+
if (this.authorizationCache == null) return;
55+
const keys: string[] = Object.keys(this.authorizationCache);
56+
for (let i = keys.length - 1; i >= 0; i--) {
57+
let key: string = keys[i];
58+
var res: CachedUser = this.authorizationCache[key];
59+
if (res === null || res === undefined) continue;
60+
this.RemoveUser(key, res.type);
61+
}
62+
}
5363
public static async cleanCache() {
5464
try {
5565
if (this.authorizationCache == null) return;

OpenFlow/src/DatabaseConnection.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,12 @@ export class DatabaseConnection extends events.EventEmitter {
10601060
Logger.otel.endSpan(mongodbspan);
10611061
Logger.otel.endTimer(ot_end, DatabaseConnection.mongodb_replace, { collection: collectionname });
10621062
DBHelper.cached_roles = [];
1063+
if (item._type === "role") {
1064+
const r: Role = (item as any);
1065+
if (r.members.length > 0) {
1066+
Auth.clearCache();
1067+
}
1068+
}
10631069
}
10641070
if (collectionname === "config" && item._type === "oauthclient") {
10651071
if (user.HasRoleName("admins")) {
@@ -1142,6 +1148,10 @@ export class DatabaseConnection extends events.EventEmitter {
11421148
}
11431149
}
11441150
}
1151+
if (item._type === "role") {
1152+
const r: Role = item as any;
1153+
if (r.members.length > 0) Auth.clearCache();
1154+
}
11451155
}
11461156
item._version = 0;
11471157
if (item._id != null) {
@@ -1579,7 +1589,9 @@ export class DatabaseConnection extends events.EventEmitter {
15791589
q.item = await this.Cleanmembers(q.item as any, original);
15801590
DBHelper.cached_roles = [];
15811591
}
1582-
1592+
if (q.item._type === "role") {
1593+
Auth.clearCache();
1594+
}
15831595
if (q.collectionname != "fs.files") {
15841596
const ot_end = Logger.otel.startTimer();
15851597
const mongodbspan: Span = Logger.otel.startSubSpan("mongodb.replaceOne", span);
@@ -1977,6 +1989,9 @@ export class DatabaseConnection extends events.EventEmitter {
19771989
this.DeleteOne(r._id, "config", jwt, span);
19781990
}
19791991
}
1992+
if (collectionname == "users" && doc._type == "role") {
1993+
Auth.clearCache();
1994+
}
19801995
}
19811996
} catch (error) {
19821997
span.recordException(error);

0 commit comments

Comments
 (0)