Class InMemorySecuredResourceScanner
- All Implemented Interfaces:
jakarta.servlet.ServletContextListener,EventListener
AbstractSecuredResourceScanner.
This is the declarative (InMemory) approach to access control — the default
provided by the DynTabs library. Secured resources and their allowed roles are
declared directly in annotations (@DynTab(securedResource=true, allowedRoles=...)
and @AccessCheck(allowedRoles=...)) and stored in memory at deploy time.
Stores secured resources in a static ConcurrentHashMap, keyed by resource identifier
(either @DynTab.uniqueIdentifier for tab-level security, or fully qualified method name
for method-level security). Also stores the declared allowedRoles for each resource,
which are read by the paired InMemoryAccessCheckInterceptor at runtime.
Must be paired with InMemoryAccessCheckInterceptor.
Alternative: For applications needing dynamic, admin-managed access rules,
the developer creates a custom DBSecuredResourceScanner (extending
AbstractSecuredResourceScanner) that writes resources to a database table,
ignoring the allowedRoles annotation attribute. Access rules are then managed
through an Admin UI and enforced by a custom DBAccessCheckInterceptor.
Registration in web.xml:
<listener>
<listener-class>security.InMemorySecuredResourceScanner</listener-class>
</listener>
- Author:
- DynTabs
- See Also:
-
Field Summary
Fields inherited from class security.AbstractSecuredResourceScanner
log -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetAllowedRoles(String resource) Returns the allowed roles for a secured resource, as declared in the annotation.Returns an unmodifiable view of all registered secured resources.static StringgetDisplayName(String resource) Returns the display name of a secured resource.static booleanisSecuredResource(String resource) Checks if a resource is registered as secured.protected voidregisterSecuredResource(Class<?> cls, String resource, String resourceDisplayName, String[] allowedRoles) Called when a secured resource is discovered (a@DynTabwithsecuredResource=true, or a method annotated with@AccessCheck).protected voidun_registerSecuredResource(Class<?> cls, String resource, String resourceDisplayName) Called when a resource is found NOT to be secured (e.g.,@DynTabwithsecuredResource=false, or a method without@AccessCheck).Methods inherited from class security.AbstractSecuredResourceScanner
contextDestroyed, contextInitialized
-
Constructor Details
-
InMemorySecuredResourceScanner
public InMemorySecuredResourceScanner()
-
-
Method Details
-
registerSecuredResource
protected void registerSecuredResource(Class<?> cls, String resource, String resourceDisplayName, String[] allowedRoles) Description copied from class:AbstractSecuredResourceScannerCalled when a secured resource is discovered (a@DynTabwithsecuredResource=true, or a method annotated with@AccessCheck).InMemory implementations store both the resource and its
allowedRolesin memory. DB implementations write the resource to a database table (typically ignoringallowedRoles, since roles are managed via Admin UI).- Specified by:
registerSecuredResourcein classAbstractSecuredResourceScanner- Parameters:
cls- the class containing the secured resourceresource- the resource identifier (uniqueIdentifierfor tabs, fully qualified method name for methods)resourceDisplayName- human-readable name for admin UIsallowedRoles- roles declared in the annotation (may be empty; used by InMemory implementations, ignored by DB implementations)
-
un_registerSecuredResource
protected void un_registerSecuredResource(Class<?> cls, String resource, String resourceDisplayName) Description copied from class:AbstractSecuredResourceScannerCalled when a resource is found NOT to be secured (e.g.,@DynTabwithsecuredResource=false, or a method without@AccessCheck).Useful for cleanup — removing previously registered resources that have been un-secured in a redeployment.
- Specified by:
un_registerSecuredResourcein classAbstractSecuredResourceScanner- Parameters:
cls- the class containing the resourceresource- the resource identifierresourceDisplayName- human-readable name (may be null)
-
isSecuredResource
Checks if a resource is registered as secured.- Parameters:
resource- the resource identifier (@DynTab.uniqueIdentifieror fully qualified method name)- Returns:
- true if the resource requires access control
-
getDisplayName
Returns the display name of a secured resource.- Parameters:
resource- the resource identifier- Returns:
- the display name, or null if not a secured resource
-
getAllowedRoles
Returns the allowed roles for a secured resource, as declared in the annotation.- Parameters:
resource- the resource identifier- Returns:
- unmodifiable set of role names, or empty set if no roles declared
-
getAllSecuredResources
Returns an unmodifiable view of all registered secured resources.- Returns:
- set of secured resource identifiers
-