Skip to content

Importing organizations fails if there are >10 organizations being updated #1493

@krook1024

Description

@krook1024

Current Behavior

When importing a realm with more than 10 organizations, only the first 10 are retrieved. This is because OrganizationRepository.getAll() calls .getAll() on the Keycloak resource, which defaults to a page size of 10. Organizations beyond the 10th are not found during the existence check, so a conflict emerges (trying to create existing organizations).

Expected Behavior

All organizations should be fetched regardless of count, using a paginated .list(firstResult, maxResults) call — consistent with how other repositories in the project handle this. I found an example ClientRepository.getAll(String realmName) does this particularly well.

Steps To Reproduce

1. Define more than 10 organizations in your realm config file.
2. Run `keycloak-config-cli` import against a Keycloak instance.
3. Run `keycloak-config-cli` again.
4. Observe that the import will fail because it will try to create an organization that already exists (one that didn't make it in the first 10 that's in the response) and receive a 409 Conflict response.

Deployment Method

Docker

Environment

  • Keycloak Version: 26.5.6
  • keycloak-config-cli Version: 6.5.0-26
  • Java Version: [e.g. 21]

I'm using the docker image docker.io/adorsys/keycloak-config-cli:6.5.0-26

Relevant configuration (sanitized)

I haven't tried this one but I'm using a similar setup:


{
  "realm": "org-feature-test",
  "organizationsEnabled": true,
  "organizations": [
    {
      "name": "Acme Corporation",
      "alias": "acme",
      "redirectUrl": "https://acme.com/redirect",
      "description": "Main organization for Acme Corporation",
      "domains": [
        { "name": "acme.com", "verified": false },
        { "name": "acme.org", "verified": true }
      ],
      "attributes": {
        "industry": ["Technology"],
        "location": ["San Francisco"],
        "employeeCount": ["1000+"]
      },
      "enabled": true
    },
    {
      "name": "Globex Industries",
      "alias": "globex",
      "redirectUrl": "https://globex.com/redirect",
      "description": "Industrial manufacturing conglomerate",
      "domains": [
        { "name": "globex.com", "verified": true }
      ],
      "attributes": {
        "industry": ["Manufacturing"],
        "location": ["Springfield"],
        "employeeCount": ["500-999"]
      },
      "enabled": true
    },
    {
      "name": "Initech Solutions",
      "alias": "initech",
      "redirectUrl": "https://initech.io/redirect",
      "description": "Enterprise software and consultancy",
      "domains": [
        { "name": "initech.io", "verified": true },
        { "name": "initech.com", "verified": false }
      ],
      "attributes": {
        "industry": ["Consulting"],
        "location": ["Austin"],
        "employeeCount": ["100-499"]
      },
      "enabled": true
    },
    {
      "name": "Umbrella Health",
      "alias": "umbrella-health",
      "redirectUrl": "https://umbrellahealth.com/redirect",
      "description": "Healthcare and pharmaceuticals provider",
      "domains": [
        { "name": "umbrellahealth.com", "verified": true }
      ],
      "attributes": {
        "industry": ["Healthcare"],
        "location": ["Chicago"],
        "employeeCount": ["1000+"]
      },
      "enabled": true
    },
    {
      "name": "Stark Dynamics",
      "alias": "stark-dynamics",
      "redirectUrl": "https://starkdynamics.com/redirect",
      "description": "Advanced engineering and defense systems",
      "domains": [
        { "name": "starkdynamics.com", "verified": true },
        { "name": "starktech.io", "verified": false }
      ],
      "attributes": {
        "industry": ["Defense"],
        "location": ["New York"],
        "employeeCount": ["1000+"]
      },
      "enabled": true
    },
    {
      "name": "Pied Piper",
      "alias": "pied-piper",
      "redirectUrl": "https://piedpiper.com/redirect",
      "description": "Next-generation compression technology startup",
      "domains": [
        { "name": "piedpiper.com", "verified": false }
      ],
      "attributes": {
        "industry": ["Technology"],
        "location": ["Palo Alto"],
        "employeeCount": ["1-49"]
      },
      "enabled": true
    },
    {
      "name": "Hooli Corp",
      "alias": "hooli",
      "redirectUrl": "https://hooli.com/redirect",
      "description": "Big tech platform and cloud services",
      "domains": [
        { "name": "hooli.com", "verified": true },
        { "name": "hooli.xyz", "verified": true }
      ],
      "attributes": {
        "industry": ["Technology"],
        "location": ["San Francisco"],
        "employeeCount": ["1000+"]
      },
      "enabled": true
    },
    {
      "name": "Dunder Mifflin",
      "alias": "dunder-mifflin",
      "redirectUrl": "https://dundermifflin.com/redirect",
      "description": "Regional paper supply company",
      "domains": [
        { "name": "dundermifflin.com", "verified": true }
      ],
      "attributes": {
        "industry": ["Retail"],
        "location": ["Scranton"],
        "employeeCount": ["50-99"]
      },
      "enabled": true
    },
    {
      "name": "Waystar Royco",
      "alias": "waystar",
      "redirectUrl": "https://waystar.com/redirect",
      "description": "Global media and entertainment conglomerate",
      "domains": [
        { "name": "waystar.com", "verified": true },
        { "name": "waystaroyco.com", "verified": false }
      ],
      "attributes": {
        "industry": ["Media"],
        "location": ["New York"],
        "employeeCount": ["1000+"]
      },
      "enabled": true
    },
    {
      "name": "Aperture Science",
      "alias": "aperture",
      "redirectUrl": "https://aperturescience.com/redirect",
      "description": "Scientific research and testing facility",
      "domains": [
        { "name": "aperturescience.com", "verified": true }
      ],
      "attributes": {
        "industry": ["Research"],
        "location": ["Upper Michigan"],
        "employeeCount": ["100-499"]
      },
      "enabled": true
    },
    {
      "name": "Veridian Dynamics",
      "alias": "veridian",
      "redirectUrl": "https://veridiandynamics.com/redirect",
      "description": "Biotech and consumer products corporation",
      "domains": [
        { "name": "veridiandynamics.com", "verified": true },
        { "name": "veridian.bio", "verified": false }
      ],
      "attributes": {
        "industry": ["Biotechnology"],
        "location": ["Boston"],
        "employeeCount": ["500-999"]
      },
      "enabled": true
    },
    {
      "name": "Soylent Corp",
      "alias": "soylent",
      "redirectUrl": "https://soylent.com/redirect",
      "description": "Alternative nutrition and food technology",
      "domains": [
        { "name": "soylent.com", "verified": true }
      ],
      "attributes": {
        "industry": ["Food Technology"],
        "location": ["Los Angeles"],
        "employeeCount": ["50-99"]
      },
      "enabled": false
    }
  ]
}

Logs / error output

2026-03-31T18:41:33.121+02:00  WARN  --- [           main] d.a.k.c.s.OrganizationImportService      : Failed to import organizations for realm 'xxxx'. Organizations require Keycloak 26.x or later. Error: Create method returned status Conflict (Code: 409); expected status: Created (201). Error: Conflict

Keycloak side:

2026-03-31 16:41:33,095 INFO  [com.keycloak.errorhandler.ErrorFilter] (executor-thread-1) Response map: {field=null, errorMessage=A organization with the same name already exists., params=null, errors=null}

Anything else?

No response

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions