|
| 1 | +[id="provisioning-users-from-rhsso-to-the-software-catalog"] |
| 2 | += Creating a custom transformer to provision users from Red Hat Single-Sign On (RHSSO) to the software catalog |
| 3 | + |
| 4 | +To customize how RHSSO users and groups are mapped to {product} entities, you can create a backend module that uses the `keycloakTransformerExtensionPoint` to provide custom user and group transformers for the Keycloak backend. |
| 5 | + |
| 6 | +.Prerequisites |
| 7 | +* You have xref:provisioning-users-from-rhsso-to-the-software-catalog[enabled provisioning users from Red Hat Single-Sign On (RHSSO) to the software catalog]. |
| 8 | + |
| 9 | +.Procedure |
| 10 | +. Create a new backend module with the `yarn new` command. |
| 11 | + |
| 12 | +. Add your custom user and group transformers to the `keycloakTransformerExtensionPoint`. |
| 13 | + |
| 14 | ++ |
| 15 | +The following is an example of how the backend module can be defined: |
| 16 | ++ |
| 17 | +.`plugins/__<module-name>__/src/module.ts` |
| 18 | +[source,javascript] |
| 19 | +---- |
| 20 | +import { |
| 21 | + GroupTransformer, |
| 22 | + keycloakTransformerExtensionPoint, |
| 23 | + UserTransformer, |
| 24 | +} from '@janus-idp/backstage-plugin-keycloak-backend'; |
| 25 | +
|
| 26 | +const customGroupTransformer: GroupTransformer = async ( |
| 27 | + entity, // entity output from default parser |
| 28 | + realm, // Keycloak realm name |
| 29 | + groups, // Keycloak group representation |
| 30 | +) => { |
| 31 | + /* apply transformations */ |
| 32 | + return entity; |
| 33 | +}; |
| 34 | +const customUserTransformer: UserTransformer = async ( |
| 35 | + entity, // entity output from default parser |
| 36 | + user, // Keycloak user representation |
| 37 | + realm, // Keycloak realm name |
| 38 | + groups, // Keycloak group representation |
| 39 | +) => { |
| 40 | + /* apply transformations */ |
| 41 | + return entity; |
| 42 | +}; |
| 43 | +
|
| 44 | +export const keycloakBackendModuleTransformer = createBackendModule({ |
| 45 | + pluginId: 'catalog', |
| 46 | + moduleId: 'keycloak-transformer', |
| 47 | + register(reg) { |
| 48 | + reg.registerInit({ |
| 49 | + deps: { |
| 50 | + keycloak: keycloakTransformerExtensionPoint, |
| 51 | + }, |
| 52 | + async init({ keycloak }) { |
| 53 | + keycloak.setUserTransformer(customUserTransformer); |
| 54 | + keycloak.setGroupTransformer(customGroupTransformer); |
| 55 | + /* highlight-add-end */ |
| 56 | + }, |
| 57 | + }); |
| 58 | + }, |
| 59 | +}); |
| 60 | +---- |
| 61 | ++ |
| 62 | +[IMPORTANT] |
| 63 | +==== |
| 64 | +The module's `pluginId` must be set to `catalog` to match the `pluginId` of the `keycloak-backend`; otherwise, the module fails to initialize. |
| 65 | +==== |
| 66 | + |
| 67 | +. Install this new backend module into your {product-short} backend. |
| 68 | ++ |
| 69 | +[source,javascript] |
| 70 | +---- |
| 71 | +backend.add(import(backstage-plugin-catalog-backend-module-keycloak-transformer)) |
| 72 | +---- |
| 73 | + |
| 74 | +.Verification |
| 75 | + |
| 76 | +* {product-short} imports the users and groups each time when started. |
| 77 | +Check the console logs to verify that the synchronization is completed. |
| 78 | ++ |
| 79 | +.Successful synchronization example: |
| 80 | +[source,json] |
| 81 | +---- |
| 82 | +{"class":"KeycloakOrgEntityProvider","level":"info","message":"Read 3 Keycloak users and 2 Keycloak groups in 1.5 seconds. Committing...","plugin":"catalog","service":"backstage","taskId":"KeycloakOrgEntityProvider:default:refresh","taskInstanceId":"bf0467ff-8ac4-4702-911c-380270e44dea","timestamp":"2024-09-25 13:58:04"} |
| 83 | +{"class":"KeycloakOrgEntityProvider","level":"info","message":"Committed 3 Keycloak users and 2 Keycloak groups in 0.0 seconds.","plugin":"catalog","service":"backstage","taskId":"KeycloakOrgEntityProvider:default:refresh","taskInstanceId":"bf0467ff-8ac4-4702-911c-380270e44dea","timestamp":"2024-09-25 13:58:04"} |
| 84 | +---- |
| 85 | + |
| 86 | +* After the first import is complete, navigate to the *Catalog* page and select **User** to view the list of users. |
| 87 | + |
| 88 | +* When you select a user, you see the information imported from RHSSO. |
| 89 | + |
| 90 | +* You can select a group, view the list, and access or review the information imported from RHSSO. |
| 91 | + |
| 92 | +* You can log in with an RHSSO account. |
0 commit comments