-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid reflection when registering Spring-Boot as a Keycloak Platform
Fixes #37
- Loading branch information
1 parent
0e85a2b
commit 4ac3a12
Showing
3 changed files
with
68 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 0 additions & 69 deletions
69
...src/main/java/com/github/thomasdarimont/keycloak/embedded/support/SpringBootPlatform.java
This file was deleted.
Oops, something went wrong.
64 changes: 64 additions & 0 deletions
64
.../java/com/github/thomasdarimont/keycloak/embedded/support/SpringBootPlatformProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.github.thomasdarimont.keycloak.embedded.support; | ||
|
||
import com.google.auto.service.AutoService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.keycloak.platform.PlatformProvider; | ||
import org.keycloak.services.ServicesLogger; | ||
import org.springframework.boot.context.event.ApplicationReadyEvent; | ||
import org.springframework.context.ApplicationEvent; | ||
import org.springframework.context.event.ContextStoppedEvent; | ||
import org.springframework.context.event.SmartApplicationListener; | ||
|
||
@Slf4j | ||
@AutoService(PlatformProvider.class) | ||
public class SpringBootPlatformProvider implements PlatformProvider, SmartApplicationListener { | ||
|
||
Runnable onStartup; | ||
|
||
Runnable onShutdown; | ||
|
||
@Override | ||
public void onApplicationEvent(ApplicationEvent event) { | ||
|
||
if (event instanceof ApplicationReadyEvent) { | ||
startup(); | ||
} else if (event instanceof ContextStoppedEvent) { | ||
shutdown(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) { | ||
return ApplicationReadyEvent.class.equals(eventType) || ContextStoppedEvent.class.equals(eventType); | ||
} | ||
|
||
@Override | ||
public String getListenerId() { | ||
return this.getClass().getName(); | ||
} | ||
|
||
@Override | ||
public void onStartup(@SuppressWarnings("hiding") Runnable onStartup) { | ||
this.onStartup = onStartup; | ||
} | ||
|
||
@Override | ||
public void onShutdown(@SuppressWarnings("hiding") Runnable onShutdown) { | ||
this.onShutdown = onShutdown; | ||
} | ||
|
||
@Override | ||
public void exit(Throwable cause) { | ||
log.error("exit", cause); | ||
ServicesLogger.LOGGER.fatal(cause); | ||
throw new RuntimeException(cause); | ||
} | ||
|
||
private void shutdown() { | ||
this.onShutdown.run(); | ||
} | ||
|
||
private void startup() { | ||
this.onStartup.run(); | ||
} | ||
} |