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

Fix bug #12789

Merged
merged 1 commit into from
Jan 28, 2025
Merged

Fix bug #12789

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import org.wso2.carbon.apimgt.api.doc.model.Parameter;
import org.wso2.carbon.apimgt.api.dto.GatewayVisibilityPermissionConfigurationDTO;
import org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO;
import org.wso2.carbon.apimgt.api.dto.OrganizationDetailsDTO;
import org.wso2.carbon.apimgt.api.model.API;
import org.wso2.carbon.apimgt.api.model.APICategory;
import org.wso2.carbon.apimgt.api.model.APIIdentifier;
Expand Down Expand Up @@ -11120,4 +11121,27 @@ public static Boolean isOrgWideAppUpdateEnabled() {
return Boolean.getBoolean(
APIConstants.ORGANIZATION_WIDE_APPLICATION_UPDATE_ENABLED);
}

public static String getOrganizationIdFromExternalReference(String referenceId, String organizationName,
String rootOrganization) throws APIManagementException {
String organizationId = null;
OrganizationDetailsDTO orgDetails = ApiMgtDAO.getInstance().getOrganizationDetalsByExternalOrgId(referenceId,
rootOrganization);
if (orgDetails != null) {
organizationId = orgDetails.getOrganizationId();
} else {
// No organization entry in the db. add entry without parent info.

OrganizationDetailsDTO info = new OrganizationDetailsDTO();
info.setExternalOrganizationReference(referenceId);
info.setTenantDomain(rootOrganization);
info.setName(organizationName);
OrganizationDetailsDTO addedInfo = ApiMgtDAO.getInstance().addOrganization(info);
if (addedInfo != null) {
organizationId = addedInfo.getOrganizationId();
}

}
return organizationId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ public boolean authenticate(Message message) throws APIManagementException {
try {
if (tokenInfo == null) {
tokenInfo = getTokenMetaData(accessToken);
tokenInfo.setUserOrganizationInfo(getOrganizationInfo(tokenInfo.getEndUserName()));
if (tokenInfo.getEndUserName() != null) {
tokenInfo.setUserOrganizationInfo(getOrganizationInfo(tokenInfo.getEndUserName()));
}
}
} catch (APIManagementException e) {
log.error("Error while retrieving token information for token: " + accessToken, e);
Expand Down Expand Up @@ -251,7 +253,7 @@ protected String getConfigurationElementValue(String property) {
.getFirstProperty(property);
}

public OrganizationInfo getOrganizationInfo(String username) {
public OrganizationInfo getOrganizationInfo(String username) throws APIManagementException {
if (log.isDebugEnabled()) {
log.debug("Retrieving organization information for user: " + username);
}
Expand All @@ -272,8 +274,7 @@ public OrganizationInfo getOrganizationInfo(String username) {
if (StringUtils.isBlank(orgIdClaim)) {
orgIdClaim = "http://wso2.org/claims/organizationId";
}



String organization = null;
String organizationId = null;
try {
Expand Down Expand Up @@ -307,18 +308,20 @@ public OrganizationInfo getOrganizationInfo(String username) {
if (realm.getClaimManager().getClaim(orgIdClaim) != null) {
organizationId =
manager.getUserClaimValue(MultitenantUtils.getTenantAwareUsername(username), orgIdClaim, null);
// Get the internal organization id using externa id
//organizationId = APIUtil.getOrganizationIdFromExternalReference(organizationId, organization, tenantDomain); // TODO enable this after org add UI
}
orgInfo.setName(organization);
orgInfo.setOrganizationId(organizationId);

if (log.isDebugEnabled()) {
log.debug("organization = " + organization + " ,organizationId = " + organizationId);
}
} catch (JSONException e) {
log.error("Exception occured while trying to get group Identifier from login response", e);
} catch (org.wso2.carbon.user.api.UserStoreException e) {
log.error("Error while checking user existence for " + username, e);
}
String error = "Error while checking user existence for " + username;
log.error(error, e);
throw new APIManagementException(error, e);
}

return orgInfo;
}
Expand Down