diff --git a/services/src/main/java/org/keycloak/services/resources/admin/AdminConsole.java b/services/src/main/java/org/keycloak/services/resources/admin/AdminConsole.java index 889e1dd7ef..ca98ea6ba8 100644 --- a/services/src/main/java/org/keycloak/services/resources/admin/AdminConsole.java +++ b/services/src/main/java/org/keycloak/services/resources/admin/AdminConsole.java @@ -40,6 +40,7 @@ import org.keycloak.services.managers.AppAuthManager; import org.keycloak.services.managers.AuthenticationManager; import org.keycloak.services.managers.ClientManager; import org.keycloak.services.managers.RealmManager; +import org.keycloak.services.resources.Cors; import org.keycloak.theme.FreeMarkerException; import org.keycloak.theme.FreeMarkerUtil; import org.keycloak.theme.Theme; @@ -47,6 +48,7 @@ import org.keycloak.urls.UrlType; import org.keycloak.utils.MediaType; import javax.ws.rs.GET; +import javax.ws.rs.OPTIONS; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; @@ -186,6 +188,12 @@ public class AdminConsole { } return new ClientManager(new RealmManager(session)).toInstallationRepresentation(realm, consoleApp, session.getContext().getUri().getBaseUri()); } + @Path("whoami") + @OPTIONS + public Response whoAmIPreFlight() { + return new AdminCorsPreflightService(request).preflight(); + } + /** * Permission information * @@ -234,6 +242,9 @@ public class AdminConsole { Locale locale = session.getContext().resolveLocale(user); + Cors.add(request).allowedOrigins(authResult.getToken()).allowedMethods("GET").auth() + .build(response); + return Response.ok(new WhoAmI(user.getId(), realm.getName(), displayName, createRealm, realmAccess, locale)).build(); } @@ -250,7 +261,6 @@ public class AdminConsole { }); } - private static HashSet union(Set set1, Set set2) { if (set1 == null && set2 == null) { return null;