janus-idp / backstage-plugins

Plugins for Backstage
https://janus-idp.io
Apache License 2.0
151 stars 149 forks source link

Keycloak: Importing users without first AND last name properties fails #579

Closed tumido closed 1 year ago

tumido commented 1 year ago

Describe the bug If a Keycloak user doesn't have BOTH first and last name, the import to Backstage fails

To Reproduce Steps to reproduce the behavior:

  1. yarn workspace @janus-idp/backstage-plugin-keycloak-backend start
  2. A browser with http://localhost:8080/admin/master/console/#/janus-realm will open
  3. Wait for Keycloak Admin console from previous step to start
  4. Log in with admin username and admin password
  5. Go to Users in the left menu
  6. Click Add User
  7. Fill in Username only and click create
  8. Observe logs:
@janus-idp/backstage-plugin-keycloak-backend:start:plugin: 2023-07-27T12:54:22.194Z catalog info Read 1 Keycloak users and 1 Keycloak groups in 0.1 seconds. Committing... type=plugin class=KeycloakOrgEntityProvider taskId=KeycloakOrgEntityProvider:default:refresh taskInstanceId=82cacfdf-74c3-45f3-83a1-85eec47c43f6
@janus-idp/backstage-plugin-keycloak-backend:start:plugin: 2023-07-27T12:54:22.198Z catalog info Committed 1 Keycloak users and 1 Keycloak groups in 0.0 seconds. type=plugin class=KeycloakOrgEntityProvider taskId=KeycloakOrgEntityProvider:default:refresh taskInstanceId=82cacfdf-74c3-45f3-83a1-85eec47c43f6
@janus-idp/backstage-plugin-keycloak-backend:start:plugin: 2023-07-27T12:54:22.264Z catalog warn Processor BuiltinKindsEntityProcessor threw an error while validating the entity user:default/test; caused by TypeError: /spec/profile/displayName must NOT have fewer than 1 characters - limit: 1 type=plugin entity=user:default/test location=url:http://localhost:8080/admin/realms/janus-realm/users/b86c34f8-daf3-4075-9fa9-312a702b0a10

Expected behavior User is ingested

Screenshots

Additional context This is a good starting issue for troubleshooting the Keycloak plugin and learning about this repository. Please do not work on this, unless you are getting started around here. 🙂

navinyashende commented 1 year ago

I would like to work on this.

navinyashende commented 1 year ago

As per my analysis, the displayName is populated using combination of firstName and lastName. The check for displayName being non-empty is in backstage code. Can we populate displayName as username if both firstName and lastName are empty?

schultzp2020 commented 1 year ago

@tumido this is a duplicate of https://github.com/janus-idp/backstage-plugins/issues/274

schultzp2020 commented 1 year ago

@navinyashende Sorry, I should have noticed this is a duplicate issue. We can actually exclude the displayName property if firstName and lastName are missing because backstage defaults to the username property if displayName is undefined.

navinyashende commented 1 year ago

@schultzp2020 I see that you have closed your linked PR for #274. Since you are already working on that, can we close this issue?

schultzp2020 commented 1 year ago

@navinyashende I'm not currently working on it. I can assign you on the original issue if you'd like. I'll close this issue one you respond.

navinyashende commented 1 year ago

@schultzp2020 Sounds good to me. Please assign the original issue and close the current one