ch4mpy / spring-addons

Ease spring OAuth2 resource-servers configuration and testing
Apache License 2.0
521 stars 84 forks source link

Import keycloak realms with spring-addons-starters-rest #210

Closed ffroliva closed 3 months ago

ffroliva commented 3 months ago

First of all. Thank you for your project. It looks interesting and I am starting to explore it.

I saw that you've created the spring-addons-starters-rest using RestClient to access Keycloak API. That's an interesting alternative for:

<dependency>
    <groupId>org.keycloak</groupId>
    <artifactId>keycloak-admin-client</artifactId>
    <version>${keycloak-admin-client.version}</version>
</dependency>

I need to import the ream-export.json file. Is there an API available for that?

As far as I could check I could not find any thing in keycloak-admin-client to achieve that.

BTW, I am using this keycloak testcontainer which gives me this options but this is only for test purpose not for a real usecase.

<dependency>
    <groupId>com.github.dasniko</groupId>
    <artifactId>testcontainers-keycloak</artifactId>
    <version>3.3.0</version>
    <scope>test</scope>
</dependency>

Thank you in advance.

ch4mpy commented 3 months ago

Hi @ffrliva,

Please note that this spring-addons-starters-rest is "experemental" (see first README sentence): it is likely that Spring Security team adds some tools to ease RestClient OAuth2 configuration in comming releases, which could induce breaking changes to spring-addons-starters-rest (spring-addons is intended to complement Spring auto-configuration, not to develop alternatives).

Also, I don't think that keycloak-admin-client is deprecated (to my knowledge, only the client and resource server adapters are). Keeping the admin client for the uses cases you already got working seems a reasonable choice.

If you really want to replace keycloak-admin-client with REST requests you build yourself when creating realms, you might have a look at the REST admin API documentation. The POST /admin/realms seems to be what you are looking for (and I believe that the keycloak-admin-client is mostly helping to build requests to call this same admin API).

In any case, spring-addons aim is to help with Spring Security configuration for any OpenID Provider. It is not to replace all of Keycloak's code for Spring (even if it is pretty handy for that in many cases). Offering a one stop solution for importing keycloak realm is clearly off topic.