Class CertPermissionMapper
java.lang.Object
com.loomcache.server.security.CertPermissionMapper
Maps TLS certificate Common Names (CN) to permission levels.
Configuration maps CN patterns to CertPermissionMapper.PermissionLevel values:
READ_ONLY, READ_WRITE, or ADMIN.
Supports exact match and wildcard prefix matching (e.g., "cluster-*" matches "cluster-node1", "cluster-node2"). When multiple patterns match, exact matches take priority over wildcard matches, and among wildcards, the longest prefix wins.
Thread-safe and immutable after construction.
- Since:
- 2.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumPermission levels for certificate-based authorization. -
Constructor Summary
ConstructorsConstructorDescriptionCertPermissionMapper(Map<String, CertPermissionMapper.PermissionLevel> cnMappings) Creates a new mapper from CN-to-permission-level string mappings. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringExtract the Common Name (CN) from an X.509 certificate's subject distinguished name.parsePermissionLevel(String level) Parse a permission level string to the enum value.@Nullable CertPermissionMapper.PermissionLevelResolve the permission level for a given Common Name.@Nullable CertPermissionMapper.PermissionLevelExtract the Common Name from an X.509 certificate and resolve its permission level.
-
Constructor Details
-
CertPermissionMapper
Creates a new mapper from CN-to-permission-level string mappings.- Parameters:
cnMappings- map of CN pattern to permission level (must not be null)- Throws:
NullPointerException- if cnMappings is nullIllegalArgumentException- if a permission level string is invalid
-
-
Method Details
-
resolve
Resolve the permission level for a given Common Name.Resolution order:
- Exact match (highest priority)
- Longest wildcard prefix match
- Default:
null(no access — unmapped CNs are denied)
- Parameters:
commonName- the certificate CN to resolve (must not be null)- Returns:
- the resolved permission level, or null if no mapping matches (deny access)
-
resolveFromCertificate
Extract the Common Name from an X.509 certificate and resolve its permission level.- Parameters:
cert- the X.509 certificate (must not be null)- Returns:
- the resolved permission level, or null if no mapping matches (deny access)
-
extractCommonName
Extract the Common Name (CN) from an X.509 certificate's subject distinguished name.- Parameters:
cert- the X.509 certificate (must not be null)- Returns:
- the CN value, or an empty string if no CN is present or parsing fails
-
parsePermissionLevel
Parse a permission level string to the enum value.- Parameters:
level- the permission level string (must not be null)- Returns:
- the parsed permission level
- Throws:
IllegalArgumentException- if the string is not a valid permission level
-