Skip to content

Conversation

@Yasasr1
Copy link
Contributor

@Yasasr1 Yasasr1 commented Oct 27, 2025

This pull request adds support for organization-aware user session retrieval in the conditional authentication user functions module. The main changes involve integrating the organization management service, updating session retrieval logic to handle organization-based tenant domains, and updating dependencies and service references accordingly.

Organization Management Integration:

  • Added OrganizationManager as an OSGi service reference in UserFunctionsServiceComponent, with corresponding bind and unbind methods to manage its lifecycle.
  • Updated UserFunctionsServiceHolder to store and provide access to the OrganizationManager instance.

User Session Retrieval Enhancements:

  • Modified GetUserSessionsFunctionImpl to resolve the tenant domain using the accessing organization (if present) via OrganizationManager, accessing organization contains the organization id of the B2B organization during B2B logins. This will be null during B2C logins.
  • Updated the call to getSessionsByUserId to pass the resolved tenant domain for accurate session management.

Dependency and Import Updates:

  • Added org.wso2.carbon.identity.organization.management.service as a compile-time dependency and removed its test scope dependency in pom.xml. Also updated package import ranges to include organization management service and exception packages.

Related issue

Copilot AI review requested due to automatic review settings October 27, 2025 09:10
Comment on lines +91 to +94
try {
tenantDomain = UserFunctionsServiceHolder.getInstance().getOrganizationManager()
.resolveTenantDomain(userAccessingOrganization);
} catch (OrganizationManagementException e) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 2

Suggested change
try {
tenantDomain = UserFunctionsServiceHolder.getInstance().getOrganizationManager()
.resolveTenantDomain(userAccessingOrganization);
} catch (OrganizationManagementException e) {
try {
tenantDomain = UserFunctionsServiceHolder.getInstance().getOrganizationManager()
.resolveTenantDomain(userAccessingOrganization);
if (LOG.isDebugEnabled()) {
LOG.debug("Resolved tenant domain: " + tenantDomain + " for organization: " + userAccessingOrganization);
}
} catch (OrganizationManagementException e) {

Comment on lines +300 to +303
protected void setOrganizationManager(OrganizationManager organizationManager) {

UserFunctionsServiceHolder.getInstance().setOrganizationManager(organizationManager);
LOG.debug("Organization manager service is set in the conditional authentication user functions bundle.");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 3

Suggested change
protected void setOrganizationManager(OrganizationManager organizationManager) {
UserFunctionsServiceHolder.getInstance().setOrganizationManager(organizationManager);
LOG.debug("Organization manager service is set in the conditional authentication user functions bundle.");
protected void setOrganizationManager(OrganizationManager organizationManager) {
UserFunctionsServiceHolder.getInstance().setOrganizationManager(organizationManager);
if (LOG.isDebugEnabled()) {
LOG.debug("Organization manager service is set in the conditional authentication user functions bundle.");
}

Comment on lines +306 to +309
protected void unsetOrganizationManager(OrganizationManager organizationManager) {

UserFunctionsServiceHolder.getInstance().setOrganizationManager(null);
LOG.debug("Organization manager service is unset in the conditional authentication user functions bundle.");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 4

Suggested change
protected void unsetOrganizationManager(OrganizationManager organizationManager) {
UserFunctionsServiceHolder.getInstance().setOrganizationManager(null);
LOG.debug("Organization manager service is unset in the conditional authentication user functions bundle.");
protected void unsetOrganizationManager(OrganizationManager organizationManager) {
UserFunctionsServiceHolder.getInstance().setOrganizationManager(null);
if (LOG.isDebugEnabled()) {
LOG.debug("Organization manager service is unset in the conditional authentication user functions bundle.");
}

Comment on lines +117 to +120
public void setOrganizationManager(OrganizationManager organizationManager) {

this.organizationManager = organizationManager;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 5

Suggested change
public void setOrganizationManager(OrganizationManager organizationManager) {
this.organizationManager = organizationManager;
}
public void setOrganizationManager(OrganizationManager organizationManager) {
if (organizationManager != null) {
log.debug("OrganizationManager service is set in UserFunctionsServiceHolder.");
}
this.organizationManager = organizationManager;
}

Copy link

@wso2-engineering wso2-engineering bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Agent Log Improvement Checklist

⚠️ Warning: AI-Generated Review Comments

  • The log-related comments and suggestions in this review were generated by an AI tool to assist with identifying potential improvements. Purpose of reviewing the code for log improvements is to improve the troubleshooting capabilities of our products.
  • Please make sure to manually review and validate all suggestions before applying any changes. Not every code suggestion would make sense or add value to our purpose. Therefore, you have the freedom to decide which of the suggestions are helpful.

✅ Before merging this pull request:

  • Review all AI-generated comments for accuracy and relevance.
  • Complete and verify the table below. We need your feedback to measure the accuracy of these suggestions and the value they add. If you are rejecting a certain code suggestion, please mention the reason briefly in the suggestion for us to capture it.
Comment Accepted (Y/N) Reason
#### Log Improvement Suggestion No: 2
#### Log Improvement Suggestion No: 3
#### Log Improvement Suggestion No: 4
#### Log Improvement Suggestion No: 5

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request enhances the conditional authentication user functions to support organization-aware user session retrieval during B2B logins. The key improvement is resolving the correct tenant domain using the accessing organization ID when retrieving user sessions.

Key Changes:

  • Integrated OrganizationManager service to resolve tenant domains for B2B organization contexts
  • Modified getUserSessions to use the resolved tenant domain instead of the user's default tenant domain
  • Updated dependency management to include organization management service at compile scope

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pom.xml Moved organization management service dependency from test to compile scope and added version range property
GetUserSessionsFunctionImplTest.java Added comprehensive unit tests covering standard sessions, empty results, organization-based sessions, and error handling
UserFunctionsServiceHolder.java Added getter and setter methods for OrganizationManager instance
UserFunctionsServiceComponent.java Registered OrganizationManager as an OSGi service reference with bind/unbind methods
GetUserSessionsFunctionImpl.java Implemented tenant domain resolution logic using accessing organization and updated session retrieval call
components/.../pom.xml Added OSGi import packages for organization management service and exception classes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +86 to +101
private String getUserTenantDomain(AuthenticatedUser authenticatedUser) throws UserSessionRetrievalException {

String tenantDomain = authenticatedUser.getTenantDomain();
String userAccessingOrganization = authenticatedUser.getAccessingOrganization();
if (StringUtils.isNotBlank(userAccessingOrganization)) {
try {
tenantDomain = UserFunctionsServiceHolder.getInstance().getOrganizationManager()
.resolveTenantDomain(userAccessingOrganization);
} catch (OrganizationManagementException e) {
throw new UserSessionRetrievalException(
"Error occurred while resolving tenant domain of user accessing organization: " +
userAccessingOrganization, e);
}
}
return tenantDomain;
}
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The method concatenates the organization ID directly into the error message on line 96-97. Consider using String.format() or structured logging to improve readability and maintainability of the error message.

Copilot uses AI. Check for mistakes.
protected void setOrganizationManager(OrganizationManager organizationManager) {

UserFunctionsServiceHolder.getInstance().setOrganizationManager(organizationManager);
LOG.debug("Organization manager service is set in the conditional authentication user functions bundle.");
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected inconsistent punctuation in debug message: removed period to match the style of the unset method on line 309.

Suggested change
LOG.debug("Organization manager service is set in the conditional authentication user functions bundle.");
LOG.debug("Organization manager service is set in the conditional authentication user functions bundle");

Copilot uses AI. Check for mistakes.
protected void unsetOrganizationManager(OrganizationManager organizationManager) {

UserFunctionsServiceHolder.getInstance().setOrganizationManager(null);
LOG.debug("Organization manager service is unset in the conditional authentication user functions bundle.");
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected inconsistent punctuation in debug message: removed period to match the style used in other unset methods (e.g., line 291).

Suggested change
LOG.debug("Organization manager service is unset in the conditional authentication user functions bundle.");
LOG.debug("Organization manager service is unset in the conditional authentication user functions bundle");

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Oct 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 38.06%. Comparing base (bab8169) to head (ef41983).
⚠️ Report is 5 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #218      +/-   ##
============================================
+ Coverage     38.04%   38.06%   +0.01%     
  Complexity      418      418              
============================================
  Files           114      114              
  Lines          3817     3815       -2     
  Branches        457      457              
============================================
  Hits           1452     1452              
+ Misses         2207     2205       -2     
  Partials        158      158              
Flag Coverage Δ
unit 43.33% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jenkins-is-staging
Copy link

PR builder started
Link: https://github.com/wso2/product-is/actions/runs/18838760478

@jenkins-is-staging
Copy link

PR builder completed
Link: https://github.com/wso2/product-is/actions/runs/18838760478
Status: success

Copy link

@jenkins-is-staging jenkins-is-staging left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving the pull request based on the successful pr build https://github.com/wso2/product-is/actions/runs/18838760478

@Yasasr1 Yasasr1 merged commit aa6b8a6 into wso2-extensions:master Oct 28, 2025
4 checks passed
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.

3 participants