Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caused by: java.lang.NullPointerException: Cannot invoke "java.util.Map.get(Object)" because "customAttributes" is null #1010

Closed
moritzschmitz-oviva opened this issue Apr 17, 2024 · 2 comments · Fixed by #1184
Assignees
Labels

Comments

@moritzschmitz-oviva
Copy link

moritzschmitz-oviva commented Apr 17, 2024

Current Behavior

I am receiving this error Caused by: java.lang.NullPointerException: Cannot invoke "java.util.Map.get(Object)" because "customAttributes" is null when trying to import a realm config via keycloak-config-cli.

Error message:

Caused by: java.lang.NullPointerException: Cannot invoke "java.util.Map.get(Object)" because "customAttributes" is null
  at de.adorsys.keycloak.config.service.checksum.ChecksumService.hasToBeUpdated(ChecksumService.java:64)
  at de.adorsys.keycloak.config.service.RealmImportService.updateRealmIfNecessary(RealmImportService.java:151)
  at de.adorsys.keycloak.config.service.RealmImportService.doImport(RealmImportService.java:144)
  at de.adorsys.keycloak.config.KeycloakConfigRunner.run(KeycloakConfigRunner.java:79)
  at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:768)
  ... 13 common frames omitted

Expected Behavior

Well, I was hoping at least for a more meaningful error message.

Steps To Reproduce

Get files from: https://gist.github.com/moritzschmitz-oviva/4b629a0cd88ef1962bde54ca57c64c83.

mkdir tmp
wget https://gist.github.com/moritzschmitz-oviva/4b629a0cd88ef1962bde54ca57c64c83/archive/964cfb4ea0dc3b449390a87b2eeb71992e04bf4d.zip
unzip 964cfb4ea0dc3b449390a87b2eeb71992e04bf4d.zip -d tmp
rm 964cfb4ea0dc3b449390a87b2eeb71992e04bf4d.zip
cd tmp/4b629a0cd88ef1962bde54ca57c64c83-964cfb4ea0dc3b449390a87b2eeb71992e04bf4d
mkdir -p before
mv before-some-realm.json before/some-realm.json
mkdir -p changes
mv changes-some-realm.json changes/some-realm.json
docker compose up kcc

Without using my setup, it should be reproducible like this as well:

  1. Import {"id":"test","realm":"test","attributes":{}} to Keycloak via kc.sh import.
  2. Import {"id":"test","realm":"test","displayName":"just-a-name"} to Keycloak via keycloak-config-cli.

Environment

  • Keycloak Version: 23.0.7
  • keycloak-config-cli Version: 5.12.0-23.0.7

Anything else?

My goal is to migrate an existing Keycloak installation to using keycloak-config-cli. To ensure I am not changing more or less than what we need I import the current realm config into a local instance, apply config via keycloak-config-cli and then export it again to check for unexpected differences.

@davidfrickert
Copy link

davidfrickert commented Jul 31, 2024

I also experience the same issue, but only get it when running keycloak-config-cli while the Keycloak cluster nodes are still starting up (i.e. cluster is not in a healthy state)

But indeed NPE is not helpful

@AssahBismarkabah
Copy link
Collaborator

AssahBismarkabah commented Nov 6, 2024

Hi @davidfrickert,

Thank you for bringing this to my attention. I replicated your development environment and identified that the root cause originates from the handling of the id associated with the realm. The import logic retrieves configurations based on the representation of the name as seen in ChecksumService. This inconsistency resulted in a mismatch between the ID and the realm name, creating the issue where the realm could not be located. To resolve this, please remove the IDs from your JSON import; that should rectify the problem.

{
  "realm": "some-realm",
  "attributes": {
    "cibaBackchannelTokenDeliveryMode": "poll",
    "cibaExpiresIn": "120",
    "cibaAuthRequestedUserHint": "login_hint",
    "parRequestUriLifespan": "60",
    "cibaInterval": "5",
    "realmReusableOtpCode": "false"
  }
}
{
  "realm": "some-realm",
  "displayName": "displayName"
}
+] Running 3/0Container 4b629a0cd88ef1962bde54ca57c64c83-964cfb4ea0dc3b449390a87b2eeb71992e04bf4d-mysql-1   Running                   0.0sContainer 4b629a0cd88ef1962bde54ca57c64c83-964cfb4ea0dc3b449390a87b2eeb71992e04bf4d-idp-1     Running                   0.0sContainer 4b629a0cd88ef1962bde54ca57c64c83-964cfb4ea0dc3b449390a87b2eeb71992e04bf4d-import-1  Created                   0.0s 
Attaching to kcc-1
kcc-1  | 2024-11-06 12:14:15.075  INFO 1 --- [           main] d.a.k.config.KeycloakConfigApplication   : Starting KeycloakConfigApplication v5.12.0 using Java 17.0.10 on d9bb29bbf078 with PID 1 (/app/keycloak-config-cli.jar started by nobody in /)
kcc-1  | 2024-11-06 12:14:15.079  INFO 1 --- [           main] d.a.k.config.KeycloakConfigApplication   : No active profile set, falling back to 1 default profile: "default"
kcc-1  | 2024-11-06 12:14:16.176  INFO 1 --- [           main] d.a.k.config.KeycloakConfigApplication   : Started KeycloakConfigApplication in 2.039 seconds (JVM running for 2.781)
kcc-1  | 2024-11-06 12:14:17.854  INFO 1 --- [           main] d.a.k.config.KeycloakConfigRunner        : Importing file 'file:/changes/some-realm.json'
kcc-1  | 2024-11-06 12:14:21.729  INFO 1 --- [           main] d.a.k.config.KeycloakConfigRunner        : keycloak-config-cli running in 00:04.211.
kcc-1 exited with code 0

Screenshot from 2024-11-06 15-29-43

I improved the logging mechanism by incorporating more descriptive messages for enhanced clarity and debugging efficiency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging a pull request may close this issue.

3 participants