Handles tag matching, access control logic, and hierarchical permissions. Provides utilities for generating random tokens, parsing tags, and checking access permissions with support for hierarchical and wildcard tags.
View on GitHub →-- In your extension:
function MyExtension.init(tac)
local Security = require("tac.core.security")
-- Check if a card has access to a door
local hasAccess, reason = Security.checkAccess(
{"tenant.1", "vip"}, -- Card tags
{"tenant.1"} -- Required tags
)
-- Parse tag strings
local tags = Security.parseTags("tenant.1, vip, admin.*")
-- Returns: {"tenant.1", "vip", "admin.*"}
-- Check wildcard tags
if Security.tagMatch("admin.view", {"admin.*"}) then
print("Has admin access")
end
end
SecurityCore.randomString(length)Generate a random string of given length Creates a cryptographically random string using alphanumeric characters. Useful for generating unique card IDs, tokens, or session identifiers.
length (number): Optional length of string (default: 128)SecurityCore.truncateCardId(cardId)Truncate card ID for display Shortens a card ID to first 9 characters followed by "..." for readable logging.
cardId (string): The full card ID to truncateSecurityCore.parseTags(str)Parse tags from string Converts a comma or space-separated string of tags into an array. Useful for parsing user input from forms or configuration files.
str (string): Comma or space-separated tags (e.g., "tenant.1, admin staff")SecurityCore.expandTagHierarchy(tag)Expand a tag into its hierarchy Splits a hierarchical tag into all its parent levels. For example, "tenant.1.a" expands to {"tenant", "tenant.1", "tenant.1.a"}. This allows a specific tag to satisfy requirements for any parent level.
tag (string): Dot-separated hierarchical tagSecurityCore.expandCardTags(tags)Expand a list of tags to include all parent tags Processes an array of tags, expanding each hierarchical tag into its parent levels. Wildcard tags (ending with ".*") are preserved as-is without expansion. Removes duplicates in the resulting array.
tags (table): Array of tag stringsSecurityCore.tagMatches(cardTag, doorTag)Check if a card tag satisfies a door requirement Determines if a single card tag grants access for a door requirement. Supports exact matches, hierarchical matching (card "tenant.1.a" satisfies door "tenant"), and wildcard card tags (card "tenant.*" satisfies any door tag starting with "tenant").
cardTag (string): Tag present on the card (may include ".*" wildcard)doorTag (string): Tag required by the doorSecurityCore.checkAccess(cardTags, doorTags)Check access permissions for a card against a door Main access control function that determines if a card's tags grant access to a door. Automatically expands card tags to include parent hierarchies, then checks if any card tag satisfies any door requirement. Special case: door tag "*" grants access to any card with at least one tag.
cardTags (table): Array of tag strings on the carddoorTags (table): Array of tag strings required by the door