Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify Keycloak source code without recompiling the whole project

I'm trying to add some post quantum algorithms to Keycloak via custom SPI's and, to do so, I need to modify some core classes (mostly Provider classes) from Keycloak with my code so the system recognizes the new algorithms.

Unfortunately, recompile Keycloak is a toilsome job (that takes a lot of time), therefore modifying core files would make impracticable to run tests and stuff, while developing.

I've been studying Keycloak source files and noticed that the providers I need to modify (apparently) don't implement ProviderFactory interfaces, so (I think) it's not possible to modify these files with a SPI approach.

My questions are: Is it possible to modify such classes without recompiling entire Keycloak? Can I use custom SPI's to fix these problems? Should I try another solution? (I'm kinda out of ideas)

By the way, one of the classes I need to modify is BCPemUtilsProvider and I would like to do something like this:

    @Override
    protected String encode(Object obj) {
        if (obj == null) {
            return null;
        }

        try {
            StringWriter writer = new StringWriter();
            JcaPEMWriter pemWriter = new JcaPEMWriter(writer);

            /** 
             * MY CODE GOES HERE...
             */

            pemWriter.writeObject(obj);
            pemWriter.flush();
            pemWriter.close();
            String s = writer.toString();
            return removeBeginEnd(s);
        } catch (Exception e) {
            throw new PemException(e);
        }
    }
like image 697
Brendon Vicente Avatar asked Jun 28 '26 11:06

Brendon Vicente


1 Answers

I'm assuming you have a copy of the source code that eventually gets deployed on some server.

If so...

Most IDEs allow for hot code replacements during debugging sessions using JPDA, GDB or whatever.

I use JPDA to connect to a deployed ear and screw with some code without having to compile, build, redeploy, etc.

Technically, what it does, is that it opens a debugging session on the jvm that's hosted in the server container.

Obviously you need to enable jvm debugging on the server if it's required, and attach the debugger via socketAttach or whatever is compatible with your setup.

When you hot code replace, your IDE uploads bits of code and commands remote jvm to recompile distinct classes rather than redeploy the entire project inside the server container.

If you do this, remember that it's best practice to (deploy with latest changes) - finally upload all the stuff you change because it's a debugging API ... and more often than not, depending on how you mess with it, it may or may not start to behave unpredictably.

like image 180
EverNight Avatar answered Jul 01 '26 00:07

EverNight



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!