Configure Extension with UiPageProvider #1

Merged
kritzl merged 11 commits from addUiPageProvider into main 2026-03-31 17:53:07 +02:00
Showing only changes of commit 5e791af057 - Show all commits

add null checks

kritzl 2026-03-31 14:31:07 +02:00
Signed by: kritzl
SSH key fingerprint: SHA256:5BmINP9VjZWaUk5Z+2CTut1KFhwLtd0ZynMekKbtViM

View file

@ -54,6 +54,10 @@ public class AdminUiPage implements UiPageProvider, UiPageProviderFactory<Compon
Pattern slugPattern = Pattern.compile("^[a-zA-Z0-9_-]*$"); Pattern slugPattern = Pattern.compile("^[a-zA-Z0-9_-]*$");
String configAttributeSlug = model.getConfig().getFirst("slug"); String configAttributeSlug = model.getConfig().getFirst("slug");
if (configAttributeSlug == null) {
hasError = true;

Currently this gives us an ugly exception in the Keycloak logs for an empty slug, as configAttributeSlug is then null. Not critical as it still just errors, but we should probably check, if configAttributeSlug is null. I guess then adding a null check to all the other config$things is probably a good idea as well.

Currently this gives us an ugly exception in the Keycloak logs for an empty slug, as `configAttributeSlug` is then `null`. Not critical as it still just errors, but we should probably check, if `configAttributeSlug` is `null`. I guess then adding a null check to all the other `config$thing`s is probably a good idea as well.
errorString += " • [Slug] can not be empty\n";
}
if (!slugPattern.matcher(configAttributeSlug).matches()) { if (!slugPattern.matcher(configAttributeSlug).matches()) {
hasError = true; hasError = true;
@ -61,6 +65,11 @@ public class AdminUiPage implements UiPageProvider, UiPageProviderFactory<Compon
} }
String configAuthRole = model.getConfig().getFirst("auth-role"); String configAuthRole = model.getConfig().getFirst("auth-role");
if (configAuthRole == null) {
hasError = true;
errorString += " • [Auth Role] can not be empty\n";
}
RoleModel authRole = realm.getRole(configAuthRole); RoleModel authRole = realm.getRole(configAuthRole);
if (authRole == null) { if (authRole == null) {
hasError = true; hasError = true;
@ -68,6 +77,11 @@ public class AdminUiPage implements UiPageProvider, UiPageProviderFactory<Compon
} }
String configMatchRole = model.getConfig().getFirst("match-role"); String configMatchRole = model.getConfig().getFirst("match-role");
if (configMatchRole == null) {
hasError = true;
errorString += " • [Match Role] can not be empty\n";
}
RoleModel matchRole = realm.getRole(configMatchRole); RoleModel matchRole = realm.getRole(configMatchRole);
if (matchRole == null) { if (matchRole == null) {
hasError = true; hasError = true;
@ -77,6 +91,10 @@ public class AdminUiPage implements UiPageProvider, UiPageProviderFactory<Compon
UserProfileProvider profileProvider = session.getProvider(UserProfileProvider.class); UserProfileProvider profileProvider = session.getProvider(UserProfileProvider.class);
UPConfig upconfig = profileProvider.getConfiguration(); UPConfig upconfig = profileProvider.getConfiguration();
String configAttributeGroup = model.getConfig().getFirst("attribute-group"); String configAttributeGroup = model.getConfig().getFirst("attribute-group");
if (configAttributeGroup == null) {
hasError = true;
errorString += " • [Attribute Group] can not be empty\n";
}
if (!upconfig.getGroups().stream().anyMatch(g -> g.getName().equals(configAttributeGroup))) { if (!upconfig.getGroups().stream().anyMatch(g -> g.getName().equals(configAttributeGroup))) {
hasError = true; hasError = true;
errorString += " • [Attribute Group] does not exist\n"; errorString += " • [Attribute Group] does not exist\n";