Custom LoginFormsProvider is failing

I am currently trying to implement a custom login forms provider. I have a sample class extension and a factory extension to FreeMarkerLoginFormsProvider and FreeMarkerLoginFormsProviderFactory.

public class CustomLoginFormsProvider extends FreeMarkerLoginFormsProvider {

private static final Logger logger = Logger.getLogger(CustomLoginFormsProvider.class);

public CustomLoginFormsProvider(KeycloakSession session) {

public class CustomLoginFormsProviderFactory extends FreeMarkerLoginFormsProviderFactory {

public static final String PROVIDER_ID = "nameri-pro-freemarker";
public LoginFormsProvider create(KeycloakSession session) {
    return new CustomLoginFormsProvider(session);

public String getId() {
    return PROVIDER_ID;

I have also provided the META-INF file with the name org.keycloak.forms.login.LoginFormsProviderFactory and with the correct factory class.

I am always getting the NULL pointer exception.

2024-07-01 18:23:15,272 ERROR [] (executor-thread-9) Uncaught server error: java.lang.NullPointerException: Cannot invoke “org.keycloak.forms.login.LoginFormsProvider.setAuthenticationSession(org.keycloak.sessions.AuthenticationSessionModel)” because the return value of “org.keycloak.models.KeycloakSession.getProvider(java.lang.Class)” is null

Is this functionality now obsolete or am I doing something wrong ?

Keycloak can make problem when you don’t have defined default provider.
First check if you provider is visible in here:
Screenshot 2024-07-04 at 15.36.28

Then try to add something like:


in your config.

1 Like