mirror of
https://github.com/keycloak/keycloak.git
synced 2026-05-07 15:41:29 -05:00
KEYCLOAK-1070 Migration for adding names to builtin clients
This commit is contained in:
@@ -8,6 +8,7 @@ import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
@@ -21,17 +22,33 @@ public class MigrationTo1_2_0_RC1 {
|
||||
if (client == null) {
|
||||
client = KeycloakModelUtils.createClient(realm, Constants.BROKER_SERVICE_CLIENT_ID);
|
||||
client.setEnabled(true);
|
||||
client.setName("${client_" + Constants.BROKER_SERVICE_CLIENT_ID + "}");
|
||||
client.setFullScopeAllowed(false);
|
||||
|
||||
for (String role : Constants.BROKER_SERVICE_ROLES) {
|
||||
client.addRole(role).setDescription("${role_"+role+"}");
|
||||
client.addRole(role).setDescription("${role_"+ role.toLowerCase().replaceAll("_", "-") +"}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setupClientNames(RealmModel realm) {
|
||||
Map<String, ClientModel> clients = realm.getClientNameMap();
|
||||
|
||||
setupClientName(clients, Constants.ACCOUNT_MANAGEMENT_CLIENT_ID);
|
||||
setupClientName(clients, Constants.ADMIN_CONSOLE_CLIENT_ID);
|
||||
setupClientName(clients, Constants.REALM_MANAGEMENT_CLIENT_ID);
|
||||
}
|
||||
|
||||
private void setupClientName(Map<String, ClientModel> clients, String clientId) {
|
||||
ClientModel client = clients.get(clientId);
|
||||
if (client != null && client.getName() == null) client.setName("${client_" + clientId + "}");
|
||||
}
|
||||
|
||||
public void migrate(KeycloakSession session) {
|
||||
List<RealmModel> realms = session.realms().getRealms();
|
||||
for (RealmModel realm : realms) {
|
||||
setupBrokerService(realm);
|
||||
setupClientNames(realm);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ public interface Constants {
|
||||
|
||||
String ACCOUNT_MANAGEMENT_CLIENT_ID = "account";
|
||||
String BROKER_SERVICE_CLIENT_ID = "broker";
|
||||
String REALM_MANAGEMENT_CLIENT_ID = "realm-management";
|
||||
|
||||
String INSTALLED_APP_URN = "urn:ietf:wg:oauth:2.0:oob";
|
||||
String INSTALLED_APP_URL = "http://localhost";
|
||||
|
||||
Reference in New Issue
Block a user