Restriction on logging into the application by role

How can I prevent a user from logging into a jmix application via Keycloak if they do not have a special role? After an exception occurs, how can it be handled correctly in order to get to the keycloak login page where there will be an error message?
jmix 1.4

Hi,

This can be configured in Keycloak. See StackOverflow discussion.