viewof currentHour = Inputs.range([0, 23], {
label: "Current hour (24h format)",
step: 1,
value: 10
})
viewof userRole = Inputs.select(
["Basic User (READ, EXECUTE)", "Power User (READ, WRITE, EXECUTE, CREATE)", "Operator (+ DELETE, ADMIN_READ)", "Admin (+ ADMIN_WRITE, GRANT, REVOKE, AUDIT)", "Superuser (all capabilities)"],
{label: "User role", value: "Admin (+ ADMIN_WRITE, GRANT, REVOKE, AUDIT)"}
)Try It: Time-Based Access Control Simulator
Try It: Time-Based Access Control Simulator
animation
authentication
security
Try Change Current hour (24h format) from 10 to 2.
Observe Compare Access and Reason for Firmware Update at 2 and 10.
Explain Explain why Firmware Update requires both its capabilities and the time window from 2:00 to 6:00.
Technical boundaries. Access decisions combine the selected role's fixed capabilities with resource time windows. The selected hour must be at or after the start and before the end.
NoteTry It: Time-Based Access Control Simulator
Select an hour of the day and a user role to see which resources are accessible. This demonstrates how ABAC combines capability checks with time-based restrictions.
{
const hour = currentHour;
const role = userRole;
const roleCaps = {
"Basic User (READ, EXECUTE)": 0x0005,
"Power User (READ, WRITE, EXECUTE, CREATE)": 0x0017,
"Operator (+ DELETE, ADMIN_READ)": 0x003F,
"Admin (+ ADMIN_WRITE, GRANT, REVOKE, AUDIT)": 0x03FF,
"Superuser (all capabilities)": 0xFFFF
};
const userCap = roleCaps[role] || 0;
const resources = [
{id: "RES_SENSOR", name: "Sensor Data", cap: 0x0001, audit: false, timeLimited: false, start: 0, end: 24},
{id: "RES_CONFIG", name: "Configuration", cap: 0x0002, audit: true, timeLimited: false, start: 0, end: 24},
{id: "RES_CONTROL", name: "Device Control", cap: 0x0004, audit: true, timeLimited: false, start: 0, end: 24},
{id: "RES_LOGS", name: "System Logs", cap: 0x0200, audit: true, timeLimited: true, start: 8, end: 18},
{id: "RES_USERS", name: "User Management", cap: 0x0040, audit: true, timeLimited: true, start: 9, end: 17},
{id: "RES_FIRMWARE", name: "Firmware Update", cap: 0x0044, audit: true, timeLimited: true, start: 2, end: 6},
{id: "RES_EMERGENCY", name: "Emergency Override", cap: 0x0400, audit: true, timeLimited: false, start: 0, end: 24},
{id: "RES_DEBUG", name: "Debug Console", cap: 0x0800, audit: true, timeLimited: true, start: 9, end: 17}
];
const rows = resources.map(r => {
const hasCap = (userCap & r.cap) === r.cap;
const inWindow = !r.timeLimited || (hour >= r.start && hour < r.end);
const granted = hasCap && inWindow;
let reason = "";
if (!hasCap && !inWindow) reason = "Missing capability + outside time window";
else if (!hasCap) reason = "Missing required capability";
else if (!inWindow) reason = "Outside allowed hours (" + r.start + ":00-" + r.end + ":00)";
else reason = "All checks passed";
const bg = granted ? "#e8f5e9" : "#ffebee";
const icon = granted ? "GRANTED" : "DENIED";
const iconColor = granted ? "#16A085" : "#E74C3C";
const timeStr = r.timeLimited ? r.start + ":00-" + r.end + ":00" : "24/7";
return `<tr style="background:${bg}">
<td style="padding:4px 8px;font-weight:bold">${r.name}</td>
<td style="padding:4px 8px;font-family:monospace;font-size:0.85em">0x${r.cap.toString(16).padStart(4,"0").toUpperCase()}</td>
<td style="padding:4px 8px">${timeStr}</td>
<td style="padding:4px 8px;text-align:center;color:${iconColor};font-weight:bold">${icon}</td>
<td style="padding:4px 8px;font-size:0.85em;color:#7F8C8D">${reason}</td>
</tr>`;
}).join("");
const grantedCount = resources.filter(r => {
const hasCap = (userCap & r.cap) === r.cap;
const inWindow = !r.timeLimited || (hour >= r.start && hour < r.end);
return hasCap && inWindow;
}).length;
const hourLabel = hour.toString().padStart(2, "0") + ":00";
const barW = 580;
const segW = barW / 24;
const hourBars = [];
for (let h = 0; h < 24; h++) {
const accessible = resources.filter(r => {
const hasCap = (userCap & r.cap) === r.cap;
const inWin = !r.timeLimited || (h >= r.start && h < r.end);
return hasCap && inWin;
}).length;
const intensity = accessible / resources.length;
const x = 40 + h * segW;
const isCurrent = h === hour;
hourBars.push(`<rect x="${x}" y="10" width="${segW - 1}" height="30" fill="${isCurrent ? '#E67E22' : '#3498DB'}" opacity="${0.15 + intensity * 0.7}" rx="2"/>
<text x="${x + segW / 2}" y="28" text-anchor="middle" font-size="8" fill="${isCurrent ? 'white' : '#2C3E50'}" font-weight="${isCurrent ? 'bold' : 'normal'}">${accessible}</text>
${h % 4 === 0 ? `<text x="${x}" y="52" text-anchor="middle" font-size="9" fill="#7F8C8D">${h}h</text>` : ""}`);
}
return html`<p class="auth-wide-scroll-hint" id="auth-window-scroll-hint">↔ Scroll horizontally to inspect every access decision and reason.</p>
<div class="auth-wide-scroll" role="region" tabindex="0" aria-label="Time-window access decisions table" aria-describedby="auth-window-scroll-hint"><div style="font-family:sans-serif">
<div style="background:#f0f7ff;border:1px solid #3498DB;border-radius:6px;padding:12px;margin:8px 0">
<strong style="color:#2C3E50">At ${hourLabel}, role "${role.split(" (")[0]}" can access ${grantedCount} of ${resources.length} resources</strong>
</div>
<p style="font-size:0.85em;color:#7F8C8D;margin:4px 0">Accessible resources per hour (number = count of accessible resources, orange = selected hour):</p>
<svg width="${barW + 80}" height="58" style="display:block;margin:4px 0">
${hourBars.join("")}
</svg>
<table style="border-collapse:collapse;width:100%;font-size:0.85em;margin-top:8px">
<tr style="background:#2C3E50;color:white">
<th style="padding:4px 8px;text-align:left">Resource</th>
<th style="padding:4px 8px;text-align:left">Required Cap</th>
<th style="padding:4px 8px;text-align:left">Time Window</th>
<th style="padding:4px 8px;text-align:center">Access</th>
<th style="padding:4px 8px;text-align:left">Reason</th>
</tr>
${rows}
</table>
</div></div>`;
}