Skip to content

Repository files navigation

Maven Central Build status Java 17+ Spring WebFlux 6.x+ Apache 2 license

spring-webflux-pac4j is 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

Main concepts and components:

  1. 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

  1. 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

  1. A matcher defines whether the SecurityFilter must be applied and can be used for additional web processing

  2. The SecurityFilter protects 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

  3. The CallbackController finishes the login process for an indirect client

  4. The LogoutController logs out the user from the application and triggers the logout at the identity provider level.

Usage

2) Define:

- the callback configuration, only for web applications

Request bodies and proxies

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.

Build

Run the build with JDK 17, matching the CI and PMD target:

PMD_JAVA_DISABLE_AUX_CLASSPATH_WARNINGS=true mvn verify

The 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.

Demos

Spring Webflux boot demo: spring-webflux-pac4j-boot-demo.

Spring Security reactive boot demo: spring-security-reactive-pac4j-boot-demo.

Versions

The latest released version is the Maven Central.

The next version is under development.

See the release notes.

See the migration guide as well.

Need help?

You can use the mailing lists or the commercial support.

Releases

Packages

Used by

Contributors

Languages