Fork me on GitHub

What's new in pac4j v6?

1) Java version

First of all, pac4j v6 is based on the JDK 17 (LTS).

It means that you must pick the right pac4j version according to your JDK:

2) Renaming/cleaning

Several components have been removed or renamed. Notice that:

3) API contract

The API contract has changed on some points:

4) Lombok

Lombok is now used for pac4j and all its implementations.

5) Implementation design

The FindBest component, widely used in implementations, has been removed.

The customisations for the filters/controllers can only be done via the Config component and thanks to the FrameworkParameters.

Framework specificities (to set up by default) are specified (order matters):

Here is the old JEE SecurityFilter based on pac4j v5:

public class SecurityFilter extends AbstractConfigFilter implements SecurityEndpoint {

    ...

    @Override
    protected final void internalFilter(final HttpServletRequest request, final HttpServletResponse response,
                                        final FilterChain filterChain) throws IOException, ServletException {

        final Config config = getSharedConfig();

        final HttpActionAdapter bestAdapter = FindBest.httpActionAdapter(httpActionAdapter, config, JEEHttpActionAdapter.INSTANCE);
        final SecurityLogic bestLogic = FindBest.securityLogic(securityLogic, config, DefaultSecurityLogic.INSTANCE);

        final WebContext context = FindBest.webContextFactory(null, config, JEEContextFactory.INSTANCE).newContext(request, response);
        final SessionStore sessionStore = FindBest.sessionStoreFactory(null, config, JEESessionStoreFactory.INSTANCE).newSessionStore(request, response);

        bestLogic.perform(context, sessionStore, config, (ctx, session, profiles, parameters) -> {
            filterChain.doFilter(profiles.isEmpty() ? request : new Pac4JHttpServletRequestWrapper(request, profiles), response);
            return null;
        }, bestAdapter, clients, authorizers, matchers);
    }
}

Here is the new JEE SecurityFilter based on pac4j v6:

@Getter
@Setter
public class SecurityFilter extends AbstractConfigFilter implements SecurityEndpoint {

    ...

    @Override
    protected final void internalFilter(final HttpServletRequest request, final HttpServletResponse response,
                                        final FilterChain filterChain) throws IOException, ServletException {

        val config = getSharedConfig();

        FrameworkAdapter.INSTANCE.applyDefaultSettingsIfUndefined(config);

        config.getSecurityLogic().perform(config, (ctx, session, profiles) -> {
            filterChain.doFilter(profiles.isEmpty() ? request : new Pac4JHttpServletRequestWrapper(request, profiles), response);
            return null;
        }, clients, authorizers, matchers, new JEEFrameworkParameters(request, response));
    }
}

6) New implementations

As usual, new implementation versions have been released, based on pac4j v6:

More implementation upgrades are coming.

6) Learn more

Read the release notes for a thorough presentation of the changes.

Jérôme LELEU - January 2024