How micronaut-projects/micronaut-security works
Project Type and Purpose
• This is a multi‐module, open‐source security framework for the Micronaut JVM platform.
• It provides pluggable security capabilities—core authentication/authorization, JWT, OAuth2, CSRF, LDAP, session support, AOT code generation, and annotations.
High-Level Architecture (Components)
A. Core Module (“security”)
• Contains the central filter chain, authentication providers, handlers, rules, configuration properties, converters, and events.
B. Annotation Module (“security-annotations”)
• Provides compile-time annotation mappings and visitor infrastructure.
C. AOT Module (“security-aot”)
• Generates ahead-of-time code for optimized metadata and provider wiring.
D. Feature Modules
1. security-csrf – CSRF token lifecycle (generators, filters, resolvers, validators)
2. security-jwt – JWT support (config, encryption, signature, parsing, validation, endpoints)
3. security-oauth2 – OAuth2/OpenID Connect client endpoints, state management, flows, token endpoints
4. security-ldap – LDAP‐backed authentication provider
5. security-session – HTTP session‐based authentication
E. BOM Module (“security-bom”)
• Centralized dependency management for all modules.
F. Documentation & Guides (src/main/docs)
G. Test Suites / Examples
• End-to-end and integration tests (test-suite-*), sample auth server and clients.
Relationships and Dependencies
• All feature modules depend on the Core module and the Annotations module.
• The AOT module depends on Core and feature modules to generate code for each feature.
• The BOM module aggregates versions of Core, Annotations, AOT, and feature modules.
• Documentation sits outside code modules but refers to each feature.
• Test suites pull in combinations of modules to exercise flows (e.g., JWT, OAuth2).
• Build system: Gradle with GitHub Actions pipelines invoking snapshots, releases, AOT builds.
Architectural Patterns & Principles
• Modular design—each feature in its own Gradle subproject, clean separation.
• Pluggable filter chain—Core defines AuthenticationFetcher, SecurityFilter, with feature modules providing implementations.
• Factory/Condition pattern—conditional beans and factories enable or disable features at runtime via config.
• Ahead-Of-Time code generation for Graal and performance optimizations.
• Annotation processors to reduce reflection and support native images.
Detail and Extensibility Points
• Extension points in Core (AuthenticationProvider, SecurityRule).
• How feature modules register implementations via META-INF/services (annotation consumers).
• AOT code generators discovering services and producing “GeneratedFile” outputs.