Skip to content

Conversation

@bibhuti230185
Copy link
Contributor

This PR adds the Organization Mapper feature to the Keycloak event listener module, enabling mapping of organization names from identity providers (Keycloak/LDAP) to SW360 internal organization names.
Changes Made
New Files:
OrganizationMapper.java - Core mapping logic with intelligent lazy loading and thread-safe initialization
orgmapping.properties - Externalized configuration file with documentation
OrganizationMapperTest.java - Unit tests covering initialization, thread safety, and edge cases
Sw360KeycloakUserEventServiceTest.java - Integration tests for organization mapping during user events
Modified Files:
Sw360KeycloakUserEventService.java - Integrated OrganizationMapper for department mapping during login

Issue:
#3581

Suggest Reviewer

@GMishx

How To Test?

Prerequisites

  1. SW360 application deployed and running
  2. Keycloak configured as identity provider
  3. Access to CouchDB for verification
  4. Test user accounts with different organization attributes in Keycloak

Test Configuration

Option 1: Using External Configuration (Recommended)

Place orgmapping.properties in system config path: /etc/sw360/orgmapping.properties

# Enable custom mapping
enable.custom.mapping=true
match.prefix=false

# Example mappings
mapping.1=External Company A
mapping.1.target=PARTNER_A

mapping.2=DEPT_Engineering
mapping.2.target=ENGINEERING

Option 2: Using Bundled Configuration

Modify orgmapping.properties in source: keycloak/event-listeners/src/main/resources/orgmapping.properties


Test Cases

TC1: Default Behavior (Custom Mapping Disabled)

Precondition: enable.custom.mapping=false in configuration

Step Action Expected Result
1 Login to SW360 via Keycloak with user having org "TestOrg" Login successful
2 Check user profile in SW360 UI Department shows "TestOrg" (unchanged)
3 Verify in CouchDB: sw360users database User document has department: "TestOrg"

TC2: Custom Mapping Enabled (Exact Match)

Precondition:

  • enable.custom.mapping=true
  • match.prefix=false
  • Mapping configured: External Company APARTNER_A
Step Action Expected Result
1 Login with user having org "External Company A" Login successful
2 Check user profile in SW360 UI Department shows "PARTNER_A"
3 Verify in CouchDB User document has department: "PARTNER_A"
4 Login with user having org "External Company B" (no mapping) Department shows "External Company B" (unchanged)

TC3: Prefix Matching Enabled

Precondition:

  • enable.custom.mapping=true
  • match.prefix=true
  • Mapping configured: DEPT_DEPARTMENT
Step Action Expected Result
1 Login with user having org "DEPT_Engineering" Department shows "DEPARTMENT"
2 Login with user having org "DEPT_Sales" Department shows "DEPARTMENT"
3 Login with user having org "OTHER_Team" Department shows "OTHER_Team" (unchanged)

TC4: External Configuration Override

Precondition:

  • Bundled config has enable.custom.mapping=false
  • External config at /etc/sw360/orgmapping.properties has enable.custom.mapping=true
Step Action Expected Result
1 Restart SW360/Keycloak services Services start successfully
2 Check logs for "Organization mapping properties loaded" External config path logged
3 Login and verify mapping is applied Mapping works as per external config

TC5: Lazy Loading / Retry Mechanism

Precondition: Configuration file initially missing, then added

Step Action Expected Result
1 Start SW360 without config file Logs show "No organization mapping properties found"
2 Add config file to /etc/sw360/ File placed successfully
3 Login to SW360 Re-attempt logged, mapping applied

Notes

  • Organization mapping happens during Keycloak login event
  • Changes to configuration require service restart to take effect
  • External configuration takes precedence over bundled defaults

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant