Add account password changes and administrator resets
This commit is contained in:
1 parent
23e28a7dcb
commit
060b36682d
14 files changed
+263
-26
No files matched your search
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const crypto = require('node:crypto');
|
||||
const { BpmVault } = require('../../platform/security/vault.cjs');
|
||||
const { loadPlaywright, browserOptions } = require('../../platform/browser.cjs');
|
||||
const { BpmListClient } = require('./list-client.cjs');
|
||||
@@ -37,7 +38,7 @@ class BpmSessionManager {
|
||||
}
|
||||
this.browserFactory = browserFactory || (() => loadPlaywright().chromium.launch(browserOptions()));
|
||||
this.probe = probe || this.defaultProbe.bind(this);
|
||||
this.sessions = new Map(); this.operations = new Map(); this.disabled = new Set(); this.stopped = false;
|
||||
this.sessions = new Map(); this.operations = new Map(); this.disabled = new Set(); this.revokedSessionHashes=new Set(); this.stopped = false;
|
||||
}
|
||||
allowed(url) { try { const parsed = new URL(url); return !parsed.username && !parsed.password && this.allowedOrigins.has(parsed.origin); } catch { return false; } }
|
||||
vault() { return this._vault ||= new BpmVault({ stateDir: this.stateDir }); }
|
||||
@@ -139,6 +140,7 @@ class BpmSessionManager {
|
||||
authorize(connection, principal) {
|
||||
if (!connection || typeof connection.id !== 'string' || !connection.id || connection.id.length > 200) throw error('连接标识无效。');
|
||||
if (!principal?.sessionId || !principal.user || !['admin','operator'].includes(principal.user.role) || (principal.user.role !== 'admin' && connection.owner !== principal.user.username)) throw error('只有连接负责人或管理员可以操作。',403);
|
||||
if(this.revokedSessionHashes.has(crypto.createHash('sha256').update(principal.sessionId).digest('hex')))throw error('工作台登录已失效,请重新登录。',401);
|
||||
if (this.stopped) throw error('BPM 服务正在关闭。',503);
|
||||
if (connection.status === 'disabled' || this.disabled.has(connection.id)) throw error('此 BPM 连接已停用。',409);
|
||||
}
|
||||
@@ -271,6 +273,7 @@ class BpmSessionManager {
|
||||
this.authorize(connection,principal);
|
||||
if (lease.blocked || !this.allowed(lease.page.url())) throw error('已阻止离开允许的 BPM 域名。',403);
|
||||
await this.fillSavedAccount(lease);
|
||||
this.authorize(connection,principal);
|
||||
return lease;
|
||||
} catch (cause) { await this.closeLease(connection.id); throw safe(cause); }
|
||||
}
|
||||
@@ -278,6 +281,7 @@ class BpmSessionManager {
|
||||
return this.run(connection?.id,async()=>{
|
||||
this.authorize(connection,principal);
|
||||
const lease=this.sessions.has(connection.id) ? await this.getLease(connection.id,principal,true) : await this.create(connection,principal);
|
||||
this.authorize(connection,principal);
|
||||
return { active:true,viewport:{width:1280,height:800},expiresAt:new Date(lease.expiresAt).toISOString(),host:new URL(lease.page.url()).host };
|
||||
});
|
||||
}
|
||||
@@ -393,6 +397,11 @@ class BpmSessionManager {
|
||||
}
|
||||
async close(id,principal) { return this.run(id,async()=>{ if (!this.sessions.has(id)) return {active:false}; await this.getLease(id,principal,false,true); await this.closeLease(id); return {active:false}; }); }
|
||||
async releaseSession(sessionId) { await Promise.all([...this.sessions.values()].filter(lease=>lease.sessionId===sessionId).map(lease=>this.run(lease.id,()=>this.closeLease(lease.id)))); }
|
||||
async releaseSessionHashes(hashes) {
|
||||
const revoked=new Set(hashes);
|
||||
for(const hash of revoked)this.revokedSessionHashes.add(hash);
|
||||
await Promise.all([...this.sessions.values()].filter(lease=>revoked.has(crypto.createHash('sha256').update(lease.sessionId).digest('hex'))).map(lease=>this.run(lease.id,()=>this.closeLease(lease.id))));
|
||||
}
|
||||
async disable(id) { this.disabled.add(id); await this.run(id,async()=>{ await this.closeLease(id); await this.vault().remove(id); await this.vault().remove('account:'+id); }); }
|
||||
async shutdown() {
|
||||
this.stopped=true;
|
||||
|
||||
Reference in new issue
Block a user