8

I have a SPI implementation which is:

  • Custom SPI, directly implemented via SPI interface
  • has an external jar which does not exist in JBoss base

1) EAR deployment: I tried EAR deployment and deploy my .ear to /standalone/deployments. This solves the external jar problem which is bundled within EAR's lib folder. But now SPI is not initializing (which I saw when I debug) and also I get an exception when I trigger the SPI:

11:34:02,185 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: Keycloak 9.0.2 (WildFly Core 10.0.3.Final) started in 12070ms - Started 732 of 1031 services (613 services are lazy, passive or on-demand)
11:34:18,209 ERROR [org.keycloak.services.error.KeycloakErrorHandler] (default task-1) Uncaught server error: java.lang.NullPointerException
        at org.keycloak.keycloak-services@9.0.2//org.keycloak.services.DefaultKeycloakSessionFactory.getAllProviderIds(DefaultKeycloakSessionFactory.java:362)

Then I thought maybe keycloak is not able to import extended SPI via standalone/deployment deployment, which is also mentioned here if you develop custom SPI keycloak suggests (or requires?) module deployment.

2) Then I tried module deployment; now I can see that my custom SPI is initializing, but now keycloak can not find my external JAR.

13:17:05,682 FATAL [org.keycloak.services] (ServerService Thread Pool -- 65) java.lang.RuntimeException: org.jboss.modules.ModuleNotFoundException: com.orbitz.consul

As a solution, I found somewhere that I can put my dependent jar and all its dependent jar's to ${KEYCLOAK_HOME}\modules\system\layers\keycloak but I don't want to install my external JAR and its all dependencies manually to keycloak's base (maybe automatically somehow?). Any solution?

Script to deploy as a module:

./jboss-cli.bat --command="module add --name=de.easy.one.bouncer.spi.registry --resources=target/registry-spi-1.0.1-SNAPSHOT.jar --dependencies=org.keycloak.keycloak-core,org.keycloak.keycloak-services,org.keycloak.keycloak-server-spi,org.keycloak.keycloak-server-spi-private,javax.api,javax.ws.rs.api,com.fasterxml.jackson.core.jackson-core,com.fasterxml.jackson.core.jackson-databind,com.fasterxml.jackson.core.jackson-annotations,org.jboss.logging,com.orbitz.consul"

And added it to standalone.xml as follows:

<provider>module:de.easy.one.bouncer.spi.registry</provider>

META-INF/services


file name --> file content

org.keycloak.provider.Spi --> de.easy.one.bouncer.spi.registry.spi.RegistryProviderSpi

de.easy.one.bouncer.spi.registry.spi.RegistryProviderFactory --> de.easy.one.bouncer.spi.registry.consul.ConsulRegistryProviderFactory


my pom.xml

<dependencies>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <scope>provided</scope>
        <optional>true</optional>
    </dependency>

    <dependency>
        <groupId>org.keycloak</groupId>
        <artifactId>keycloak-server-spi</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.keycloak</groupId>
        <artifactId>keycloak-server-spi-private</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.keycloak</groupId>
        <artifactId>keycloak-services</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- this is not provided and I want to use as external jar -->
    <dependency>
        <groupId>com.orbitz.consul</groupId>
        <artifactId>consul-client</artifactId>
        <version>1.4.2</version>
    </dependency>
</dependencies>
cmlonder
  • 2,370
  • 23
  • 35

1 Answers1

0

Try to create a UBER JAR package with all non-provided dependencies inside

pom.xml:

    <properties>
        <uber-jar.name>${project.artifactId}</uber-jar.name>
        <shade.plugin.version>3.2.1</shade.plugin.version>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>${shade.plugin.version}</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <finalName>${uber-jar.name}</finalName>
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>

                                    <!-- Anti-`Invalid signature file digest` -->
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
xardbaiz
  • 684
  • 7
  • 17