Repository navigation
Cannot load multiple SPI Login Event Listeners #38220
Replies: 3 comments 7 replies
|
I'm not sure if this is the reason, but have you changed the ID of the plugin to be different between them? For example: private static final String PROVIDER_ID = "your-plugin-name-1";
public String getId() {
return PROVIDER_ID;
} |
|
I think I have found the problem, even if I do not understand why it does not work. I load the plugin configuration from a public class KeycloakLoginEventListenerConfigService {
private static String pluginName;
public static String getPluginName() {
return pluginName;
}
static {
try (InputStream input = KeycloakLoginEventListenerConfigService.class.getClassLoader().getResourceAsStream("config.properties")) {
Properties prop = new Properties();
if (input != null) {
prop.load(input);
pluginName = prop.getProperty("keycloak.plugin.name");
// more props here
}
} catch(IOException e) {
throw new RuntimeException(String.format("Unable to find load variables from the configuration file"));
}
}
}I then use these values for my stuff, but the plugin name value is also used as the ID here: public class KeycloakLoginEventListenerProviderFactory implements EventListenerProviderFactory {
private static final Logger LOG = Logger.getLogger(KeycloakLoginEventListenerProviderFactory.class);
@Override
public EventListenerProvider create(KeycloakSession keycloakSession) {
return new KeycloakLoginEventListener(keycloakSession);
}
@Override
public void init(Config.Scope scope) {
LOG.infof("PLUGIN NAME => %s", KeycloakLoginEventListenerConfigService.getPluginName());
}
@Override
public void postInit(KeycloakSessionFactory keycloakSessionFactory) {
}
@Override
public void close() {
}
@Override
public String getId() {
// Here I return the plugin name that works as an ID
return KeycloakLoginEventListenerConfigService.getPluginName();
}
}If I add a This is still a problem for me though, since I need to package multiple jars with different configs so I cannot hardcode anything. I will need to find a way to make this work. |
|
So hardcoding the ID did not completely solve the problem. The two plugins were loading but the second one was loading the same configuration as the first one for some reason. |
Uh oh!
There was an error while loading. Please reload this page.
I have been battling with this for two days. Basically I want to to load two SPI Login Event Listeners into Keycloak, so I can choose which one to use or use a combination of both depending on which realm I am.
I know that my SPI plugin works, I have been using for a long time. I have created a new one that is basically the same, but just with some static variables having a different values.
If I load one plugin at a time, it works. If I put both jars in the providers folder, only the first one is loaded.
Just to be sure the plugins are using a different package namespace, and also I have solved all the "split packages" warnings that I was seeing at startup.
At the moment I don't see any warn or error, but I just see that Quarkus loads only the first plugin, and not the second. But I am sure that the plugin is there in the providers folder, and also I am sure that Quaskus could see it since it was lamenting about the split packages in plugin-1.jar and plugin-2.jar.
So first of all, should I be able to load multiple plugins related to the login event? If so, why the second one is never loaded?
All reactions