spring-webflux-pac4jis the Spring WebFlux implementation of pac4j, the security engine for Java. If it is useful to you, please ⭐ star pac4j on GitHub: it helps other developers discover it!
The spring-webflux-pac4j project is an easy and powerful security library for Spring Webflux / Spring Boot web applications and web services. It supports authentication and authorization, but also logout and advanced features like session fixation and CSRF protection.
It's based on the pac4j security engine. It's available under the Apache 2 license.
| spring-webflux-pac4j | JDK | pac4j | Spring |
|---|---|---|---|
| version >= 3 | 17 | v6 | v6 | v7 |
| version >= 2 | 17 | v5 | v6 |
| version >= 1 | 11 | v5 | v5 |
- A client represents an authentication mechanism. It performs the login process and returns a user profile. An indirect client is for web application authentication while a direct client is for web services authentication:
▸ OpenID Connect - SAML - CAS - OAuth - HTTP - LDAP - SQL - JWT - MongoDB - Kerberos - IP address - Kerberos (SPNEGO) - REST API
- An authorizer is meant to check authorizations on the authenticated user profile(s) or on the current web context:
▸ Roles / permissions - Anonymous / remember-me / (fully) authenticated - Profile type, attribute - CORS - CSRF - Security headers - IP address, HTTP method
-
A matcher defines whether the
SecurityFiltermust be applied and can be used for additional web processing -
The
SecurityFilterprotects an url by checking that the user is authenticated and that the authorizations are valid, according to the clients and authorizers configuration. If the user is not authenticated, it performs authentication for direct clients or starts the login process for indirect clients -
The
CallbackControllerfinishes the login process for an indirect client -
The
LogoutControllerlogs out the user from the application and triggers the logout at the identity provider level.
- the security configuration
- the callback configuration, only for web applications
- the logout configuration
Since version 3.0.2, URL-encoded form parameters are available to pac4j alongside query parameters; query values take precedence when a name appears in both. The raw body remains available to authentication clients and downstream WebFlux handlers.
The callback body and forms handled by the security filter or logout controller
are limited to 262144 bytes (256 KiB) by default. Larger requests receive HTTP
413 before pac4j runs. Configure pac4j.callback.maxBodySize or
pac4j.logout.maxBodySize (in bytes), or call setMaxBodySize(int) on the
controller or SecurityFilter. When a form passes through several components,
configure each component's limit as needed. These limits are independent of
Spring's codec limits.
Note that the security filter buffers and parses every URL-encoded form request it processes, even when the request does not target pac4j: applications accepting URL-encoded forms larger than 256 KiB on protected URLs must raise its limit.
Behind a reverse proxy, enable forwarded header handling for your trusted proxy:
with Spring Boot, set server.forward-headers-strategy to framework (Spring's
ForwardedHeaderTransformer) or native (Reactor Netty). pac4j uses the
resulting request URI for public host, port and HTTPS information.
See the callback, logout and security pages for details and the migration guide when upgrading from 3.0.1.
Run the build with JDK 17, matching the CI and PMD target:
PMD_JAVA_DISABLE_AUX_CLASSPATH_WARNINGS=true mvn verifyThe Maven PMD plugin supplies the project's dependencies, and PMD adds the platform classes from the JDK running Maven. With JDK 17, the platform matches the analysis target. The environment variable only disables PMD's auxiliary classpath diagnostics; rule checks and type resolution remain enabled.
Spring Webflux boot demo: spring-webflux-pac4j-boot-demo.
Spring Security reactive boot demo: spring-security-reactive-pac4j-boot-demo.
The latest released version is the .
The next version is under development.
See the release notes.
See the migration guide as well.
You can use the mailing lists or the commercial support.
