简体   繁体   中英

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

Png

Just provider in providers folder. Themes in theme folders. No more, no less. Also read READMNE.md in those folders....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM