mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-14 00:43:28 +08:00
Expose udsAuth Cordis service for request identity and workspace paths.
Lets plugins such as dsh-ops-cron resolve empNo/role, provisioned cwd, and stamp session owners without reading roles.json directly. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
c41991057d
commit
bc93392a02
1 changed files with 67 additions and 1 deletions
|
|
@ -875,7 +875,73 @@ async function initServices(ctx, config) {
|
||||||
getWorkspaceRegistry: () => _workspaceRegistry,
|
getWorkspaceRegistry: () => _workspaceRegistry,
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.logger?.info?.('[uds-auth] Initialized (ACL + workspaces)')
|
const { resolveWorkspaceRoot } = await import('./workspace-provision.js')
|
||||||
|
const { join } = await import('node:path')
|
||||||
|
|
||||||
|
function displayNameOf(identity) {
|
||||||
|
const uc = identity?.userContext || {}
|
||||||
|
return String(
|
||||||
|
uc.displayName || uc.userName || uc.username || uc.name || identity?.empNo || '',
|
||||||
|
).trim() || (identity?.empNo || '')
|
||||||
|
}
|
||||||
|
|
||||||
|
const udsAuth = {
|
||||||
|
async resolveRequestIdentity(req) {
|
||||||
|
const identity = await resolveIdentity(req)
|
||||||
|
if (!identity?.empNo) return null
|
||||||
|
return {
|
||||||
|
empNo: identity.empNo,
|
||||||
|
role: identity.role,
|
||||||
|
permissions: identity.permissions || {},
|
||||||
|
displayName: displayNameOf(identity),
|
||||||
|
kind: identity.kind || 'uds',
|
||||||
|
userContext: identity.userContext || null,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
resolveRequestIdentitySync(req) {
|
||||||
|
const identity = resolveIdentitySync(req)
|
||||||
|
if (!identity?.empNo) return null
|
||||||
|
return {
|
||||||
|
empNo: identity.empNo,
|
||||||
|
role: identity.role,
|
||||||
|
permissions: identity.permissions || {},
|
||||||
|
displayName: displayNameOf(identity),
|
||||||
|
kind: identity.kind || 'uds',
|
||||||
|
userContext: identity.userContext || null,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
canViewAllJobs(identity) {
|
||||||
|
return !!identity?.permissions?.canViewAllSessions
|
||||||
|
},
|
||||||
|
getProvisionedWorkspacePath(empNo) {
|
||||||
|
if (!empNo) return null
|
||||||
|
const row = _userWorkspaces?.get(String(empNo))
|
||||||
|
if (row?.path) return row.path
|
||||||
|
return join(resolveWorkspaceRoot(_currentConfig?.workspaceRoot), String(empNo))
|
||||||
|
},
|
||||||
|
async ensureProvisionedWorkspace(empNo) {
|
||||||
|
return ensureUserWorkspace(empNo)
|
||||||
|
},
|
||||||
|
isUserPath(empNo, candidatePath) {
|
||||||
|
if (!_userWorkspaces) return false
|
||||||
|
return _userWorkspaces.isUserPath(
|
||||||
|
empNo,
|
||||||
|
candidatePath,
|
||||||
|
_currentConfig?.workspaceRoot,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
stampSessionOwner(sessionId, empNo) {
|
||||||
|
if (!_sessionAcl || !sessionId || !empNo) return
|
||||||
|
if (String(empNo).startsWith('__')) return
|
||||||
|
_sessionAcl.setOwner(sessionId, empNo)
|
||||||
|
},
|
||||||
|
getSessionOwner(sessionId) {
|
||||||
|
return _sessionAcl?.getOwner(sessionId) || null
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.provide('udsAuth', udsAuth)
|
||||||
|
ctx.logger?.info?.('[uds-auth] Initialized (ACL + workspaces + udsAuth service)')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
ctx.logger?.error?.('[uds-auth] Init failed: ' + (err.message || err))
|
ctx.logger?.error?.('[uds-auth] Init failed: ' + (err.message || err))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue