Catch model exception when creating the admin user

Closes #32356

Signed-off-by: rmartinc <rmartinc@redhat.com>
This commit is contained in:
rmartinc 2024-10-22 18:05:34 +02:00 committed by Alexander Schwartz
parent e1520deb72
commit f548517f5b

View file

@ -43,6 +43,7 @@ import org.keycloak.cookie.CookieProvider;
import org.keycloak.cookie.CookieType;
import org.keycloak.http.HttpRequest;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.ModelException;
import org.keycloak.services.ServicesLogger;
import org.keycloak.services.managers.ApplianceBootstrap;
import org.keycloak.services.util.CacheControlUtil;
@ -133,10 +134,16 @@ public class WelcomeResource {
return createWelcomePage(null, "Password and confirmation doesn't match");
}
expireCsrfCookie();
try {
ApplianceBootstrap applianceBootstrap = new ApplianceBootstrap(session);
applianceBootstrap.createMasterRealmUser(username, password);
} catch (ModelException e) {
session.getTransactionManager().rollback();
logger.error("Error creating the administrative user", e);
return createWelcomePage(null, "Error creating the administrative user: " + e.getMessage());
}
expireCsrfCookie();
shouldBootstrap.set(false);
ServicesLogger.LOGGER.createdTemporaryAdminUser(username);