Skip to content

Commit

Permalink
Validate user store domain of the parent user invitation flow
Browse files Browse the repository at this point in the history
  • Loading branch information
sadilchamishka committed Oct 17, 2024
1 parent f4c7039 commit 58deac0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_INVALID_GROUP;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_INVALID_INVITATION_ID;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_INVALID_ROLE;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_INVALID_USER_STORE_DOMAIN;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_INVITATION_EXPIRED;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_INVITED_USER_EMAIL_NOT_FOUND;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_NO_INVITATION_FOR_USER;
Expand Down Expand Up @@ -149,6 +150,7 @@ public List<InvitationResult> createInvitations(InvitationDO invitationDO) throw
String parentTenantDomain = resolveTenantDomain(parentOrgId);
int parentTenantId = IdentityTenantUtil.getTenantId(parentTenantDomain);
AbstractUserStoreManager userStoreManager = getAbstractUserStoreManager(parentTenantId);
validateInvitedUserStoreDomain(userStoreManager, invitationDO.getUserDomain());
for (String username : invitationDO.getUsernamesList()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Creating invitation for the user: " + username + " in the organization: " +
Expand Down Expand Up @@ -732,6 +734,17 @@ private void validateGroupAssignments(InvitationDO invitation, String invitedTen
}
}

private void validateInvitedUserStoreDomain(AbstractUserStoreManager userStoreManager, String domain)
throws UserInvitationMgtException {

LOG.debug("Validating the user store domain of the invitation.");
if (userStoreManager.getSecondaryUserStoreManager(domain) == null) {
throw new UserInvitationMgtClientException(ERROR_CODE_INVALID_USER_STORE_DOMAIN.getCode(),
ERROR_CODE_INVALID_USER_STORE_DOMAIN.getMessage(),
String.format(ERROR_CODE_INVALID_USER_STORE_DOMAIN.getDescription(), domain));
}
}

private String resolveTenantDomain(String orgId) throws UserInvitationMgtServerException {

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ public enum ErrorMessage {
ERROR_CODE_GROUP_EXISTENCE("10035",
"Error while checking the group existence.",
"Could not resolve the group existence from the given list."),
ERROR_CODE_INVALID_USER_STORE_DOMAIN("10036",
"Invalid user store domain specified in the invitation.",
"Could not find a user store domain with identifier %s."),

// DAO layer errors
ERROR_CODE_STORE_INVITATION("10501",
Expand Down

0 comments on commit 58deac0

Please sign in to comment.