Keycloak SPI: How to display custom error messages in the Admin console

Viewed 1844

I've implemented a Keycloak Storage Provider plugin that communicates with a remote user store. When an error occurs, I want that to be shown in the Admin UI. For example, in the Admin UI under Users you can display a list of users. You can then show/edit a given user's attributes by clicking on the user's ID link. When an error occurs, I throw an Exception. However this just shows up as an unknown server error. Is there any way to get the Admin UI to show the message in the exception or some other way to get the UI to display the error like a Status.setError() API I may have missed?

1 Answers

Try to use org.keycloak.models.ModelException(String message, Object ... parameters). I use it when i attempt to update password of user in external user storage. First param is a name of message key (see messages_??.properties localozation files in /theme folder of keycloak distribution), second param is a bunch of values that should be used for message templating.

org.keycloak.storage.ReadOnlyException is also shown well in UI.

Related