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

Improve tenant resolving with tenant qualified URL enabled #182

Merged
Merged
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 @@ -33,6 +33,7 @@
import org.wso2.carbon.identity.core.model.ExpressionNode;
import org.wso2.carbon.identity.core.model.FilterTreeBuilder;
import org.wso2.carbon.identity.core.model.Node;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.identity.rest.api.user.application.v1.core.function.ApplicationBasicInfoToApiModel;
import org.wso2.carbon.identity.rest.api.user.application.v1.model.ApplicationListResponse;
import org.wso2.carbon.identity.rest.api.user.application.v1.model.ApplicationResponse;
Expand Down Expand Up @@ -71,7 +72,7 @@ public ApplicationResponse getApplication(String applicationId) {

try {

String tenantDomain = ContextLoader.getTenantDomainFromContext();
String tenantDomain = IdentityTenantUtil.resolveTenantDomain();
ApplicationBasicInfo applicationBasicInfo = ApplicationServiceHolder.getDiscoverableApplicationManager()
.getDiscoverableApplicationBasicInfoByResourceId(applicationId, tenantDomain);
if (applicationBasicInfo == null) {
Expand Down Expand Up @@ -104,7 +105,7 @@ public ApplicationListResponse getApplications(String attributes, Integer limit,

handleNotImplementedCapabilities(attributes, sortOrder, sortBy);

String tenantDomain = ContextLoader.getTenantDomainFromContext();
String tenantDomain = IdentityTenantUtil.resolveTenantDomain();
String filterFormatted = buildFilter(filter);
try {
List<ApplicationBasicInfo> applicationBasicInfos = ApplicationServiceHolder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.api.user.common.ContextLoader;
import org.wso2.carbon.identity.api.user.common.function.UniqueIdToUser;
import org.wso2.carbon.identity.application.common.model.User;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.identity.rest.api.user.association.v1.MeApiService;
import org.wso2.carbon.identity.rest.api.user.association.v1.core.UserAssociationService;
import org.wso2.carbon.identity.rest.api.user.association.v1.dto.AssociationUserRequestDTO;
Expand Down Expand Up @@ -86,7 +86,7 @@ private String getFullyQualifiedUsernameFromContext() {
private String getFullyQualifiedUserName(String userId) {

User user = new UniqueIdToUser().apply(UserAssociationServiceHolder.getRealmService(), userId,
ContextLoader.getTenantDomainFromContext());
IdentityTenantUtil.resolveTenantDomain());
return user.toFullQualifiedUsername();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.wso2.carbon.identity.rest.api.user.association.v1.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.wso2.carbon.identity.api.user.common.ContextLoader;
import org.wso2.carbon.identity.api.user.common.function.UniqueIdToUser;
import org.wso2.carbon.identity.application.common.model.User;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.identity.rest.api.user.association.v1.UserIdApiService;
import org.wso2.carbon.identity.rest.api.user.association.v1.core.UserAssociationService;
import org.wso2.carbon.identity.rest.api.user.association.v1.util.UserAssociationServiceHolder;
Expand Down Expand Up @@ -34,7 +34,7 @@ public Response userIdAssociationsGet(String userId) {
private String getUser(String userId) {

User user = new UniqueIdToUser().apply(UserAssociationServiceHolder.getRealmService(), userId,
ContextLoader.getTenantDomainFromContext());
IdentityTenantUtil.resolveTenantDomain());
return user.toFullQualifiedUsername();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.api.user.common.ContextLoader;
import org.wso2.carbon.identity.api.user.common.function.UniqueIdToUser;
import org.wso2.carbon.identity.application.common.model.User;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.identity.rest.api.user.authorized.apps.v1.UserIdApiService;
import org.wso2.carbon.identity.rest.api.user.authorized.apps.v1.core.AuthorizedAppsService;
import org.wso2.carbon.identity.rest.api.user.authorized.apps.v1.dto.AuthorizedAppDTO;
Expand Down Expand Up @@ -74,6 +74,6 @@ public Response listUserAuthorizedAppsByAppId(String userId, String applicationI

private User getUser(String userId) {

return new UniqueIdToUser().apply(realmService, userId, ContextLoader.getTenantDomainFromContext());
return new UniqueIdToUser().apply(realmService, userId, IdentityTenantUtil.resolveTenantDomain());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.apache.commons.logging.LogFactory;

import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.api.user.common.ContextLoader;
import org.wso2.carbon.identity.api.user.common.error.APIError;
import org.wso2.carbon.identity.api.user.common.error.ErrorResponse;
import org.wso2.carbon.identity.api.user.common.function.UserToUniqueId;
Expand Down Expand Up @@ -234,7 +233,7 @@ public List<AuthorizedAppDTO> listUserAuthorizedApps(User user) {
*/
public void deleteIssuedTokensByAppId(String applicationId) {

String tenantDomain = ContextLoader.getTenantDomainFromContext();
String tenantDomain = IdentityTenantUtil.resolveTenantDomain();
ServiceProvider application = getServiceProvider(applicationId, tenantDomain);

// Extract the inbound authentication request config for the given inbound type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.api.user.common.ContextLoader;
import org.wso2.carbon.identity.api.user.common.function.UniqueIdToUser;
import org.wso2.carbon.identity.application.common.model.User;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.UserIdApiService;
import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.core.AuthorizedAppsService;
import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.dto.AuthorizedAppDTO;
Expand Down Expand Up @@ -75,6 +75,6 @@ public Response listUserAuthorizedAppsByAppId(String userId, String applicationI

private User getUser(String userId) {

return new UniqueIdToUser().apply(realmService, userId, ContextLoader.getTenantDomainFromContext());
return new UniqueIdToUser().apply(realmService, userId, IdentityTenantUtil.resolveTenantDomain());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import org.wso2.carbon.identity.api.user.challenge.common.ChallengeQuestionServiceHolder;
import org.wso2.carbon.identity.api.user.challenge.common.Constant;
import org.wso2.carbon.identity.api.user.common.Constants;
import org.wso2.carbon.identity.api.user.common.ContextLoader;
import org.wso2.carbon.identity.api.user.common.error.APIError;
import org.wso2.carbon.identity.api.user.common.error.ErrorResponse;
import org.wso2.carbon.identity.application.common.model.User;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.identity.recovery.IdentityRecoveryClientException;
import org.wso2.carbon.identity.recovery.IdentityRecoveryException;
import org.wso2.carbon.identity.recovery.model.ChallengeQuestion;
Expand Down Expand Up @@ -65,7 +65,7 @@ public List<ChallengeSetDTO> getChallengesForUser(User user, Integer offset, Int

try {
return buildChallengesDTO(ChallengeQuestionServiceHolder.getChallengeQuestionManager()
.getAllChallengeQuestionsForUser(ContextLoader.getTenantDomainFromContext(), user), offset, limit);
.getAllChallengeQuestionsForUser(IdentityTenantUtil.resolveTenantDomain(), user), offset, limit);
} catch (IdentityRecoveryException e) {
throw handleIdentityRecoveryException(e,
Constant.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_CHALLENGES_FOR_USER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.wso2.carbon.identity.api.user.challenge.common.ChallengeQuestionServiceHolder;
import org.wso2.carbon.identity.api.user.common.ContextLoader;
import org.wso2.carbon.identity.api.user.common.function.UniqueIdToUser;
import org.wso2.carbon.identity.application.common.model.User;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.identity.rest.api.user.challenge.v1.UserIdApiService;
import org.wso2.carbon.identity.rest.api.user.challenge.v1.core.UserChallengeService;
import org.wso2.carbon.identity.rest.api.user.challenge.v1.dto.ChallengeAnswerDTO;
Expand Down Expand Up @@ -108,6 +108,6 @@ private URI getUserChallengeAnswersLocation(String userId) {
private User getUser(String userId) {

return new UniqueIdToUser().apply(ChallengeQuestionServiceHolder.getRealmService(), userId,
ContextLoader.getTenantDomainFromContext());
IdentityTenantUtil.resolveTenantDomain());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static String getUsernameFromContext() {
*/
public static User getUserFromContext() {

return getUser(getTenantDomainFromContext(), getUsernameFromContext());
return getUser(IdentityTenantUtil.resolveTenantDomain(), getUsernameFromContext());
}


Expand Down Expand Up @@ -166,7 +166,8 @@ public static org.wso2.carbon.identity.application.common.model.User getUser(org
public static URI buildURI(String endpoint) {

String tenantQualifiedRelativePath =
String.format(TENANT_CONTEXT_PATH_COMPONENT, getTenantDomainFromContext()) + USER_API_PATH_COMPONENT;
String.format(TENANT_CONTEXT_PATH_COMPONENT, IdentityTenantUtil.resolveTenantDomain()) +
USER_API_PATH_COMPONENT;
String url = tenantQualifiedRelativePath + endpoint;
return URI.create(url);
}
Expand Down Expand Up @@ -228,7 +229,7 @@ private static String getContext(String endpoint) {
if (IdentityTenantUtil.isTenantQualifiedUrlsEnabled()) {
context = USER_API_PATH_COMPONENT + endpoint;
} else {
context = String.format(TENANT_CONTEXT_PATH_COMPONENT, getTenantDomainFromContext()) +
context = String.format(TENANT_CONTEXT_PATH_COMPONENT, IdentityTenantUtil.resolveTenantDomain()) +
USER_API_PATH_COMPONENT + endpoint;
}
return context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.wso2.carbon.extension.identity.verification.mgt.model.IdVProperty;
import org.wso2.carbon.extension.identity.verification.mgt.model.IdentityVerifierData;
import org.wso2.carbon.extension.identity.verification.mgt.utils.IdentityVerificationConstants;
import org.wso2.carbon.identity.api.user.common.ContextLoader;
import org.wso2.carbon.identity.api.user.common.error.APIError;
import org.wso2.carbon.identity.api.user.common.error.ErrorResponse;
import org.wso2.carbon.identity.api.user.idv.common.Constants;
Expand Down Expand Up @@ -415,7 +414,7 @@ private String includeData(Constants.ErrorMessage error, String data) {

private int getTenantId() {

String tenantDomain = ContextLoader.getTenantDomainFromContext();
String tenantDomain = IdentityTenantUtil.resolveTenantDomain();
if (StringUtils.isBlank(tenantDomain)) {
throw handleException(
Response.Status.INTERNAL_SERVER_ERROR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private String getUserName() {

private String getTenantDomain() {

return ContextLoader.getTenantDomainFromContext();
return IdentityTenantUtil.resolveTenantDomain();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.wso2.carbon.identity.rest.api.user.session.v1.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.wso2.carbon.identity.api.user.common.ContextLoader;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.identity.rest.api.user.session.v1.SessionsApiService;
import org.wso2.carbon.identity.rest.api.user.session.v1.core.SessionManagementService;
import org.wso2.carbon.identity.rest.api.user.session.v1.dto.SearchResponseDTO;
Expand All @@ -35,7 +35,7 @@ public class SessionsApiServiceImpl extends SessionsApiService {
@Override
public Response getSessions(String filter, Integer limit, Long since, Long until) {

SearchResponseDTO responseDTO = sessionManagementService.getSessions(ContextLoader.getTenantDomainFromContext(),
SearchResponseDTO responseDTO = sessionManagementService.getSessions(IdentityTenantUtil.resolveTenantDomain(),
filter, limit, since, until);

return Response.ok().entity(responseDTO).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.identity.api.user.common.ContextLoader;
import org.wso2.carbon.identity.api.user.common.Util;
import org.wso2.carbon.identity.api.user.session.common.util.SessionManagementServiceHolder;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.identity.rest.api.user.session.v1.UserIdApiService;
import org.wso2.carbon.identity.rest.api.user.session.v1.core.SessionManagementService;
import org.wso2.carbon.identity.rest.api.user.session.v1.dto.SessionDTO;
Expand All @@ -52,7 +52,7 @@ public class UserIdApiServiceImpl extends UserIdApiService {
public Response getSessionBySessionId(String userId, String sessionId) {

Util.validateUserId(SessionManagementServiceHolder.getRealmService(), userId,
ContextLoader.getTenantDomainFromContext());
IdentityTenantUtil.resolveTenantDomain());

Optional<SessionDTO> session = sessionManagementService.getSessionBySessionId(userId, sessionId);
if (session.isPresent()) {
Expand All @@ -66,7 +66,7 @@ public Response getSessionBySessionId(String userId, String sessionId) {
public Response getSessionsByUserId(String userId, Integer limit, Integer offset, String filter, String sort) {

Util.validateUserId(SessionManagementServiceHolder.getRealmService(), userId,
ContextLoader.getTenantDomainFromContext());
IdentityTenantUtil.resolveTenantDomain());

SessionsDTO sessionsOfUser = sessionManagementService.getSessionsByUserId(userId, limit, offset, filter, sort);
if (sessionsOfUser == null || sessionsOfUser.getSessions().isEmpty()) {
Expand All @@ -80,7 +80,7 @@ public Response getSessionsByUserId(String userId, Integer limit, Integer offset
public Response terminateSessionBySessionId(String userId, String sessionId) {

Util.validateUserId(SessionManagementServiceHolder.getRealmService(), userId,
ContextLoader.getTenantDomainFromContext());
IdentityTenantUtil.resolveTenantDomain());
sessionManagementService.terminateSessionBySessionId(userId, sessionId);
return Response.noContent().build();
}
Expand Down Expand Up @@ -112,7 +112,7 @@ public Response terminateSessionsByUserId(String userId) {
}

Util.validateUserId(SessionManagementServiceHolder.getRealmService(), userId,
ContextLoader.getTenantDomainFromContext());
IdentityTenantUtil.resolveTenantDomain());
sessionManagementService.terminateSessionsByUserId(userId);
return Response.noContent().build();
} catch (UserStoreException e) {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@
<org.apache.felix.annotations.version>1.2.4</org.apache.felix.annotations.version>
<carbon.kernel.version>4.9.0</carbon.kernel.version>
<identity.governance.version>1.8.73</identity.governance.version>
<carbon.identity.framework.version>5.25.90</carbon.identity.framework.version>
<carbon.identity.framework.version>5.25.380</carbon.identity.framework.version>
<carbon.identity.account.association.version>5.3.7</carbon.identity.account.association.version>
<maven.findbugsplugin.version>3.0.5</maven.findbugsplugin.version>
<carbon.business-process.version>4.5.2</carbon.business-process.version>
Expand Down
Loading