Search code examples
javawindowskeycloakevent-listenerkeycloak-services

Custom Event Listener for Keycloak of version 18.0.0


I am trying to create an event listener for Keycloak: Project structure and META-INF.services.org.keycloak.events.EventListenerProviderFactory

CustomEventListenerProviderFactory:

public class CustomEventListenerProviderFactory implements EventListenerProviderFactory {

    private static final String LISTENER_ID = "event-listener-extension";

    @Override
    public EventListenerProvider create(KeycloakSession session) {
        return new CustomEventListenerProvider();
    }

    @Override
    public void init(Config.Scope scope) {

    }

    @Override
    public void postInit(KeycloakSessionFactory keycloakSessionFactory) {

    }

    @Override
    public void close() {

    }

    @Override
    public String getId() {
        return LISTENER_ID;
    }

}

CustomEventListenerProvider:

@Slf4j
@NoArgsConstructor
public class CustomEventListenerProvider implements EventListenerProvider {

    @Override
    public void onEvent(Event event) {
      log.info("Caught event {}", EventUtils.toString(event));
    }

    @Override
    public void onEvent(AdminEvent adminEvent, boolean b) {
        log.info("Caught admin event {}", EventUtils.toString(adminEvent));

        List<CustomAdminEvent> events = new LinkedList<>();
        events.add(new PasswordResetEvent(adminEvent));

        events.stream().filter(CustomAdminEvent::isValid).forEach(CustomAdminEvent::process);
    }

    @Override
    public void close() {

    }
}

But when I run mvn clean package and copy target folder after mvn commands the jar file into the path to deployment folder and then run the command to start Keycloak in cmd

kc.bat start-dev --http-port 8082

No custom events are displayed.

Events in Keycloak


Solution

  • Png

    Just put the provider files in the providers folder. Put the theme files in the theme folder. No more, no less. Also read READMNE.md in those folders....