KEYCLOAK-17610: WhoAMI doesn't support CORS

This commit is contained in:
Stan Silvert 2021-03-28 15:59:24 -04:00 committed by Stian Thorgersen
parent 07ea524433
commit ca49840266

View file

@ -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 <T> HashSet<T> union(Set<T> set1, Set<T> set2) {
if (set1 == null && set2 == null) {
return null;