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

Resolve user store domain not correctly set when trying organization switch grant #38

Conversation

sadilchamishka
Copy link
Contributor

Purpose

The user who intends to switch the organization can be belongs to primary user store or any defined user store of the organization. But when switching to an organization, the corresponding shared user always resides in the user store domain which is configured for the shared users. Hence the organization switch grant logic has to be improved to handle the shared user's domain correctly which will be eventually persisted as the user store domain of subject of the token issued.

@jenkins-is-staging
Copy link

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

@jenkins-is-staging
Copy link

PR builder completed
Link: https://github.com/wso2/product-is/actions/runs/12366405774
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/12366405774

private void resolveUserStoreDomain(AuthenticatedUser authenticatedUser, String organizationId)
throws IdentityOAuth2Exception {

String userStoreDomain = IdentityUtil.getProperty(ORG_USER_INVITATION_USER_DOMAIN);
Copy link
Contributor

Choose a reason for hiding this comment

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

When the userstore is configured as PRIMARY in this configuration but the userstore mgt configuration level if the admin has renamed the userstore name of PRIMARY, it is wrong to store PRIMARY as the userstore domain.
Let's gracefully handle that case. @DilshanSenarath has done similar fix in another place

Copy link
Contributor

Choose a reason for hiding this comment

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

Better to fix it by introducing a util method to get ORG_USER_INVITATION_USER_DOMAIN resolving this mentioned considtion, instead reading the config directly from IdentityUtil.getProperty(ORG_USER_INVITATION_USER_DOMAIN)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@HasiniSama Let's address the comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Better to have a util method which encapsulate the logic.

int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
userStoreDomain = getAbstractUserStoreManager(tenantId).getUser(authenticatedUser.getUserId(),
null).getUserStoreDomain();

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change


/* The shared user's domain can be different from the original user's domain. Hence, resolve the correct user
store domain. */
resolveUserStoreDomain(authenticatedUser, accessingOrgId);
Copy link
Contributor

Choose a reason for hiding this comment

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

for better readability, shall we return the relevant userstore from the private method and amend the authenticatedUser object in the main method

Copy link
Contributor

Choose a reason for hiding this comment

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

Change the method name accordingly

@@ -79,6 +84,7 @@ public class OrganizationSwitchGrant extends AbstractAuthorizationGrantHandler {
private static final Log LOG = LogFactory.getLog(OrganizationSwitchGrant.class);
private static final String TOKEN_BINDING_REFERENCE = "tokenBindingReference";
private static final String OAUTH_APP_PROPERTY = "OAuthAppDO";
public static final String ORG_USER_INVITATION_USER_DOMAIN = "OrganizationUserInvitation.PrimaryUserDomain";
Copy link
Contributor

Choose a reason for hiding this comment

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

Try to get this config from org mgt repos if there is no cyclic dependency issues. This will be resolved by doing https://github.com/wso2-extensions/identity-oauth2-grant-organization-switch/pull/38/files#r1903916703 anyway

@sadilchamishka sadilchamishka marked this pull request as draft January 6, 2025 09:49
@sadilchamishka
Copy link
Contributor Author

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