Package security
Class AbstractSecuredResourceScanner
java.lang.Object
security.AbstractSecuredResourceScanner
- All Implemented Interfaces:
jakarta.servlet.ServletContextListener,EventListener
- Direct Known Subclasses:
InMemorySecuredResourceScanner
public abstract class AbstractSecuredResourceScanner
extends Object
implements jakarta.servlet.ServletContextListener
Abstract base class for a
ServletContextListener that scans CDI bean classes
at deploy time and discovers secured resources.
Reads the CDI beans package name from the "cdiBeansPackage" context-param
in web.xml:
<context-param>
<param-name>cdiBeansPackage</param-name>
<param-value>com.myapp.cdibeans</param-value>
</context-param>
Loads all classes from that package and scans for:
DynTabannotations on classes — ifDynTab.securedResource()istrue, callsregisterSecuredResource(Class, String, String, String[])with the tab'suniqueIdentifier,securedResourceDisplayName, andallowedRoles.AccessCheckannotations on methods — registers the fully qualified method name as a secured resource, with itsresourceDisplayNameandallowedRoles.
Two implementation strategies:
- Declarative (InMemory): Use
InMemorySecuredResourceScanner, which stores secured resources AND their allowed roles (from@DynTab.allowedRoles/@AccessCheck.allowedRoles) in memory. Paired withInMemoryAccessCheckInterceptor. This is the default approach provided by the DynTabs library — zero configuration, access rules are declared directly in annotations. - DB-based: The developer creates a custom
DBSecuredResourceScannerthat writes only the secured resource identifiers to a database table (ignoringallowedRoles). Access rules are managed through an Admin UI where an administrator grants roles permissions on resources. Paired with a customDBAccessCheckInterceptorthat reads allowed roles from the database.
- Author:
- DynTabs
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcontextDestroyed(jakarta.servlet.ServletContextEvent event) voidcontextInitialized(jakarta.servlet.ServletContextEvent event) protected abstract 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 abstract 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).
-
Field Details
-
log
protected static final org.slf4j.Logger log
-
-
Constructor Details
-
AbstractSecuredResourceScanner
public AbstractSecuredResourceScanner()
-
-
Method Details
-
contextInitialized
public void contextInitialized(jakarta.servlet.ServletContextEvent event) - Specified by:
contextInitializedin interfacejakarta.servlet.ServletContextListener
-
contextDestroyed
public void contextDestroyed(jakarta.servlet.ServletContextEvent event) - Specified by:
contextDestroyedin interfacejakarta.servlet.ServletContextListener
-
registerSecuredResource
protected abstract void registerSecuredResource(Class<?> cls, String resource, String resourceDisplayName, String[] allowedRoles) Called 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).- 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 abstract void un_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).Useful for cleanup — removing previously registered resources that have been un-secured in a redeployment.
- Parameters:
cls- the class containing the resourceresource- the resource identifierresourceDisplayName- human-readable name (may be null)
-