Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Admin Console Interface Not Reflecting Updated Realm Attribute (using UiTabProvider) Value After REST API Update #37170

@carlosrodovalho

Description

@carlosrodovalho

Before reporting an issue

  • I have read and understood the above terms for submitting issues, and I understand that my issue may be closed without action if I do not follow them.

Area

admin/ui

Describe the bug

I am experiencing an issue with my implementation of the ThemeUiTab class. The implementation works correctly when updating the realm attribute using the administrative interface. However, when I use the REST API to update the realm attribute, the new attribute is saved (as confirmed by checking Keycloak's database), but the input field in the administrative interface still displays the old value, saved using the administrative interface.

I have tried reloading Keycloak, but the interface does not load the new value from the database.

For reference, I implemented the example from the following repository:
https://github.com/keycloak/keycloak-quickstarts/blob/latest/extension/extend-admin-console-spi/src/main/java/org/keycloak/admin/ui/ThemeUiTab.java

Version

26.0.7

Regression

  • The issue is a regression

Expected behavior

The input created added to the realm attributes shoud load the data store on the database, regardless of how it was saved (by using the interface or by using the rest api)

Actual behavior

The input keeps the last value stored using the adminstrative interface

How to Reproduce?

  1. Implement a custom SPI to add the realm attribute to the interface, as this example:
package org.keycloak.admin.ui;

import org.keycloak.Config;
import org.keycloak.component.ComponentModel;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.KeycloakSessionFactory;
import org.keycloak.models.RealmModel;
import org.keycloak.provider.ProviderConfigProperty;
import org.keycloak.provider.ProviderConfigurationBuilder;
import org.keycloak.services.ui.extend.UiTabProvider;
import org.keycloak.services.ui.extend.UiTabProviderFactory;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ThemeUiTab implements UiTabProvider, UiTabProviderFactory<ComponentModel> {    

    @Override
    public String getId() {
        return "Attributes";
    }

    @Override
    public String getHelpText() {
        return null;
    }

    @Override
    public void init(Config.Scope config) {
    }

    @Override
    public void postInit(KeycloakSessionFactory factory) {
    }

    @Override
    public void close() {
    }
    
    @Override
    public void onCreate(KeycloakSession session, RealmModel realm, ComponentModel model) {
        realm.setAttribute("userauthurl", model.get("userauthurl"));
    }

    @Override
    public void onUpdate(KeycloakSession session, RealmModel realm, ComponentModel oldModel, ComponentModel newModel) {
        realm.setAttribute("userauthurl", newModel.get("userauthurl"));
    }

    @Override
    public List<ProviderConfigProperty> getConfigProperties() {
        final ProviderConfigurationBuilder builder = ProviderConfigurationBuilder.create();
        builder.property()
                .name("userauthurl")
                .label("User Authorization Data Host")
                .helpText("The host used by Keycloak to fetch user authorization data (perfis do VirtualIF) and add them to the token.")
                .type(ProviderConfigProperty.STRING_TYPE)
                .add();
        return builder.build();
    }

    @Override
    public String getPath() {
        return "/:realm/realm-settings/:tab?";
    }

    @Override
    public Map<String, String> getParams() {
        Map<String, String> params = new HashMap<>();
        params.put("tab", "attributes");
        return params;
    }
}
  1. Enable DECLARATIVE_UI on Keycloak server and restart.
  2. Save a value to the realm attribute using the administrative interface.
  3. Check the saved value on the interface and on Keycloak's database
  4. Use the REST API to change this value (PUT request to admin/realms/{realm-id} passing in the body:
{    
    "attributes": {
        "userauthurl": "http://api.homologacao6virtualif.iftm.edu.br"
    }    
}
  1. Check the value on the database and Keycloak administrative UI

Image

Anything else?

Thanks in advance for the greate work!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions