Repository navigation
[Admin API v2] Skeleton prototype #39322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
vmuzikar
merged 15 commits into
keycloak:feature/admin-api-v2
from
mabartos:admin-api-v2-skeleton
May 6, 2025
+1,080
−3
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
bc1ed83
Add new ClientRepresentation
mabartos c730b89
Add APIs
mabartos e08cd24
Add ApiModelMapper SPI
mabartos 82e3464
Add MapStruct as default ApiModelMapper
mabartos e083766
Add default APIs implementations
mabartos 1edf09d
Provide Service SPI and ClientService
mabartos bfbe728
Add default Keycloak services and Client service
mabartos b9c63ce
Add ModelMapper to shared modules
mabartos 2321b38
Implement Client service, add ServiceException class
mabartos 307c4d7
Use ClientService in Client REST API
mabartos d6fe20b
Update rest/admin-api/src/main/java/org/keycloak/admin/api/client/Cli…
mabartos 135e91d
Fix ModelMapperSpi
mabartos 4a5aa03
Use /admin/api/v2 as a root path
mabartos 04966b2
Support latest API version by default
mabartos ff830f2
Rename path param to comply with API spec
mabartos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
225 changes: 225 additions & 0 deletions
225
core/src/main/java/org/keycloak/representations/admin/v2/ClientRepresentation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,225 @@ | ||
| package org.keycloak.representations.admin.v2; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonInclude; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.fasterxml.jackson.annotation.JsonPropertyDescription; | ||
|
|
||
| import java.util.Set; | ||
|
|
||
| @JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
| public class ClientRepresentation { | ||
|
|
||
| @JsonProperty(required = true) | ||
| @JsonPropertyDescription("ID uniquely identifying this client") | ||
| private String clientId; | ||
|
|
||
| @JsonPropertyDescription("Human readable name of the client") | ||
| private String displayName; | ||
|
|
||
| @JsonPropertyDescription("Human readable description of the client") | ||
| private String description; | ||
|
|
||
| @JsonPropertyDescription("The protocol used to communicate with the client") | ||
| private String protocol; | ||
|
|
||
| @JsonPropertyDescription("Whether this client is enabled") | ||
| private Boolean enabled; | ||
|
|
||
| @JsonPropertyDescription("URL to the application's homepage that is represented by this client") | ||
| private String appUrl; | ||
|
|
||
| @JsonPropertyDescription("URLs that the browser can redirect to after login") | ||
| private Set<String> appRedirectUrls; | ||
|
|
||
| @JsonPropertyDescription("Login flows that are enabled for this client") | ||
| private Set<String> loginFlows; | ||
|
|
||
| @JsonPropertyDescription("Authentication configuration for this client") | ||
| private Auth auth; | ||
|
|
||
| @JsonPropertyDescription("Web origins that are allowed to make requests to this client") | ||
| private Set<String> webOrigins; | ||
|
|
||
| @JsonPropertyDescription("Roles associated with this client") | ||
| private Set<String> roles; | ||
|
|
||
| @JsonPropertyDescription("Service account configuration for this client") | ||
| private ServiceAccount serviceAccount; | ||
|
|
||
| public ClientRepresentation() {} | ||
|
|
||
| public ClientRepresentation(String clientId) { | ||
| this.clientId = clientId; | ||
| } | ||
|
|
||
| public String getClientId() { | ||
| return clientId; | ||
| } | ||
|
|
||
| public void setClientId(String clientId) { | ||
| this.clientId = clientId; | ||
| } | ||
|
|
||
| public String getDisplayName() { | ||
| return displayName; | ||
| } | ||
|
|
||
| public void setDisplayName(String displayName) { | ||
| this.displayName = displayName; | ||
| } | ||
|
|
||
| public String getDescription() { | ||
| return description; | ||
| } | ||
|
|
||
| public void setDescription(String description) { | ||
| this.description = description; | ||
| } | ||
|
|
||
| public String getProtocol() { | ||
| return protocol; | ||
| } | ||
|
|
||
| public void setProtocol(String protocol) { | ||
| this.protocol = protocol; | ||
| } | ||
|
|
||
| public Boolean getEnabled() { | ||
| return enabled; | ||
| } | ||
|
|
||
| public void setEnabled(Boolean enabled) { | ||
| this.enabled = enabled; | ||
| } | ||
|
|
||
| public String getAppUrl() { | ||
| return appUrl; | ||
| } | ||
|
|
||
| public void setAppUrl(String appUrl) { | ||
| this.appUrl = appUrl; | ||
| } | ||
|
|
||
| public Set<String> getAppRedirectUrls() { | ||
| return appRedirectUrls; | ||
| } | ||
|
|
||
| public void setAppRedirectUrls(Set<String> appRedirectUrls) { | ||
| this.appRedirectUrls = appRedirectUrls; | ||
| } | ||
|
|
||
| public Set<String> getLoginFlows() { | ||
| return loginFlows; | ||
| } | ||
|
|
||
| public void setLoginFlows(Set<String> loginFlows) { | ||
| this.loginFlows = loginFlows; | ||
| } | ||
|
|
||
| public Auth getAuth() { | ||
| return auth; | ||
| } | ||
|
|
||
| public void setAuth(Auth auth) { | ||
| this.auth = auth; | ||
| } | ||
|
|
||
| public Set<String> getWebOrigins() { | ||
| return webOrigins; | ||
| } | ||
|
|
||
| public void setWebOrigins(Set<String> webOrigins) { | ||
| this.webOrigins = webOrigins; | ||
| } | ||
|
|
||
| public Set<String> getRoles() { | ||
| return roles; | ||
| } | ||
|
|
||
| public void setRoles(Set<String> roles) { | ||
| this.roles = roles; | ||
| } | ||
|
|
||
| public ServiceAccount getServiceAccount() { | ||
| return serviceAccount; | ||
| } | ||
|
|
||
| public void setServiceAccount(ServiceAccount serviceAccount) { | ||
| this.serviceAccount = serviceAccount; | ||
| } | ||
|
|
||
| @JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
| public static class Auth { | ||
|
|
||
| @JsonPropertyDescription("Whether authentication is enabled for this client") | ||
| private Boolean enabled; | ||
|
|
||
| @JsonPropertyDescription("Which authentication method is used for this client") | ||
| private String method; | ||
|
|
||
| @JsonPropertyDescription("Secret used to authenticate this client with Secret authentication") | ||
| private String secret; | ||
|
|
||
| @JsonPropertyDescription("Public key used to authenticate this client with Signed JWT authentication") | ||
| private String certificate; | ||
|
|
||
| public Boolean getEnabled() { | ||
| return enabled; | ||
| } | ||
|
|
||
| public void setEnabled(Boolean enabled) { | ||
| this.enabled = enabled; | ||
| } | ||
|
|
||
| public String getMethod() { | ||
| return method; | ||
| } | ||
|
|
||
| public void setMethod(String method) { | ||
| this.method = method; | ||
| } | ||
|
|
||
| public String getSecret() { | ||
| return secret; | ||
| } | ||
|
|
||
| public void setSecret(String secret) { | ||
| this.secret = secret; | ||
| } | ||
|
|
||
| public String getCertificate() { | ||
| return certificate; | ||
| } | ||
|
|
||
| public void setCertificate(String certificate) { | ||
| this.certificate = certificate; | ||
| } | ||
| } | ||
|
|
||
| @JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
| public static class ServiceAccount { | ||
|
|
||
| @JsonPropertyDescription("Whether the service account is enabled") | ||
| private Boolean enabled; | ||
|
|
||
| @JsonPropertyDescription("Roles assigned to the service account") | ||
| private Set<String> roles; | ||
|
|
||
| public Boolean getEnabled() { | ||
| return enabled; | ||
| } | ||
|
|
||
| public void setEnabled(Boolean enabled) { | ||
| this.enabled = enabled; | ||
| } | ||
|
|
||
| public Set<String> getRoles() { | ||
| return roles; | ||
| } | ||
|
|
||
| public void setRoles(Set<String> roles) { | ||
| this.roles = roles; | ||
| } | ||
| } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| < 10BC8 ?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>org.keycloak</groupId> | ||
| <artifactId>keycloak-rest-parent</artifactId> | ||
| <version>999.0.0-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <artifactId>keycloak-admin-api</artifactId> | ||
| <name>Keycloak Admin REST API v2</name> | ||
|
|
||
| <properties> | ||
| <maven.compiler.source>17</maven.compiler.source> | ||
| <maven.compiler.target>17</maven.compiler.target> | ||
| <maven.compiler.release>17</maven.compiler.release> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.keycloak</groupId> | ||
| <artifactId>keycloak-core</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.keycloak</groupId> | ||
| <artifactId>keycloak-server-spi</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>jakarta.ws.rs</groupId> | ||
| <artifactId>jakarta.ws.rs-api</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.keycloak</groupId> | ||
| <artifactId>keycloak-services</artifactId> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> |
11 changes: 11 additions & 0 deletions
11
rest/admin-api/src/main/java/org/keycloak/admin/api/AdminApi.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package org.keycloak.admin.api; | ||
|
|
||
| import jakarta.ws.rs.Path; | ||
| import org.keycloak.admin.api.realm.RealmsApi; | ||
| import org.keycloak.provider.Provider; | ||
|
|
||
| public interface AdminApi extends Provider { | ||
|
|
||
| @Path("realms") | ||
| RealmsApi realms(); | ||
| } |
34 changes: 34 additions & 0 deletions
34
rest/admin-api/src/main/java/org/keycloak/admin/api/AdminRootV2.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package org.keycloak.admin.api; | ||
|
|
||
| import jakarta.ws.rs.OPTIONS; | ||
| import jakarta.ws.rs.Path; | ||
| import jakarta.ws.rs.core.Context; | ||
| import org.eclipse.microprofile.openapi.annotations.Operation; | ||
| import org.keycloak.models.KeycloakSession; | ||
| import org.keycloak.services.resources.admin.AdminCorsPreflightService; | ||
|
|
||
| @jakarta.ws.rs.ext.Provider | ||
| @Path("admin/api") | ||
| public class AdminRootV2 { | ||
|
mabartos marked this conversation as resolved.
Resolved
|
||
|
|
||
| @Context | ||
| protected KeycloakSession session; | ||
|
|
||
| @Path("") | ||
| public AdminApi latestAdminApi() { | ||
| // we could return the latest Admin API if no version is specified | ||
| return new DefaultAdminApi(session); | ||
| } | ||
|
|
||
| @Path("v2") | ||
| public AdminApi adminApi() { | ||
| return new DefaultAdminApi(session); | ||
| } | ||
|
|
||
| @Path("{any:.*}") | ||
| @OPTIONS | ||
| @Operation(hidden = true) | ||
| public Object preFlight() { | ||
| return new AdminCorsPreflightService(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about productization but I assume it's build time only processor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I've checked, it is fully productized.