User Federation Provider can't find resources exported by dependency

Hi guys, how are you? I’m a developer from Brazil and i’m trying to use Keycloak as an authorization server for my microservices.

I was able to deploy a Keycloak in Standalone Mode on Docker, and Deployed a User Federation Provider that will handle authentication of my external database users.

This provider have a common dependency that exports a yml with my external database connections.
The yml file is listed on my provider jar, but i get an error when i try to read it.

I tried to search about some possible solutions, but i dont found anything.

This is my Dockerfile:

FROM jboss/keycloak:12.0.4

COPY ./build/libs/*-all.jar /opt/jboss/keycloak/standalone/deployments/keycloak-user-federation.jar

This is my decompiled provider jar (i’m trying to access database.yml):

This is my jboss-deployment-structure.xml:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
        <dependencies>
            <module name="org.apache.commons.lang" />
        </dependencies>
        <resources>
            <resource-root path="/" />
        </resources>
    </deployment>
</jboss-deployment-structure>

Can anyone help me? I’ll really appreciate

What is the code you are using to load it? Something like this.getClass().getResourceAsStream("database.yml")? I’ve done a similar thing, and I’ve noticed that there is some variation of the path you must use based on how your packaging is done. You might have to use "/database.yml" or put it in some package and use "/com/example/database.yml". In any case, post your code that loads it, and the exception you’re seeing. Then, we might be able to help further.

Hi xgp, how are you?

First of all, thanks for the answer.

I’m using ClassGraph to read all my yml files.
This is the code that i’m using:

List<YAMLResource> ymls = new ArrayList<>();

try (ScanResult scanResult = new ClassGraph().scan()) {
     scanResult
         .getResourcesWithExtension("yml")
         .forEachByteArray((Resource res, byte[] content) -> {
                    ymls.add(new YAMLResource(res.getPath(), true));
         });
}

This code works outside keycloak, on my other applications.

I hope this might help understanding the problem.

Thanks!

Can you try running these, to see if they can load it?

this.getClass().getResourceAsStream("database.yml")
this.getClass().getResourceAsStream("/database.yml")

I’m guessing this might be an issue with using that helper inside Jboss/Wildfly. Have you got ClassGraph to work inside Wildfly? I see a few posts that indicate people have had trouble with it, and it may require some additional configuration in your jboss deployment descriptor.

That works!

It was a bug envolving ClassGraph and Wildfly. This is the [issue] that helped me found the problem(Use classgraph with wildfly modules · Issue #287 · classgraph/classgraph · GitHub).

But, now i’m having some trouble with a wildfly dependency.
Do you have any tip for updating wildfly dependencies? It looks that jandex has some difficulties to index guava 30.0-jre and that bug was fixed on a newer version, but i have no clue on how to update jandex on keycloak.

I don’t have any suggestions. Probably a better question for the Wildfly community.