Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanapriya committed Dec 7, 2023
1 parent d70069b commit 4dd8a1b
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public interface InvitationCoreService {
* Creates an invitation with the details coming from the user.
*
* @param invitation Contains the details that are required to create an invitation.
* @return The created invitation.
* @return The list of created invitations.
* @throws UserInvitationMgtException If an error occurs while creating the invitation.
*/
List<CreatedInvitation> createInvitations(InvitationDO invitation) throws UserInvitationMgtException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public List<CreatedInvitation> createInvitations(InvitationDO invitationDO) thro
createdInvitation.setUsername(username);
InvitationResult validationResult = userValidationResult(invitationDO, username, orgId);
try {
if ((SUCCESS_STATUS).equals(validationResult.getStatus())) {
if (SUCCESS_STATUS.equals(validationResult.getStatus())) {
// Checking the parent organization id
String parentOrgId = organizationManager.getParentOrganizationId(orgId);
String userDomainQualifiedUserName = UserCoreUtil
Expand Down Expand Up @@ -554,23 +554,19 @@ private boolean isConsoleAudienceAvailableInRole(InvitationDO invitation, String

private void validateRoleAssignments(InvitationDO invitation, String orgId) throws UserInvitationMgtException {

OrganizationManager organizationManager = UserInvitationMgtDataHolder.getInstance()
.getOrganizationManagerService();
RoleManagementService roleManagementService = getRoleManagementService();
try {
String invitedTenantDomain = organizationManager.resolveTenantDomain(orgId);
if (ArrayUtils.isNotEmpty(invitation.getRoleAssignments())) {
String invitedTenantDomain = getOrganizationManager().resolveTenantDomain(orgId);
for (RoleAssignments roleAssignment : invitation.getRoleAssignments()) {
if (!roleManagementService.isExistingRole(roleAssignment.getRole(), invitedTenantDomain)) {
if (!getRoleManagementService().isExistingRole(roleAssignment.getRole(), invitedTenantDomain)) {
throw new UserInvitationMgtClientException(ERROR_CODE_INVALID_ROLE.getCode(),
ERROR_CODE_INVALID_ROLE.getMessage(),
String.format(ERROR_CODE_INVALID_ROLE.getDescription(), roleAssignment.getRole()));
}
}
}
} catch (OrganizationManagementException | UserInvitationMgtClientException |
IdentityRoleManagementException e) {
throw new UserInvitationMgtException(ERROR_CODE_ROLE_EXISTENCE.getCode(),
} catch (OrganizationManagementException | IdentityRoleManagementException e) {
throw new UserInvitationMgtServerException(ERROR_CODE_ROLE_EXISTENCE.getCode(),
ERROR_CODE_ROLE_EXISTENCE.getMessage(),
String.format(ERROR_CODE_ROLE_EXISTENCE.getDescription()));
}
Expand All @@ -589,30 +585,24 @@ private InvitationResult userValidationResult(InvitationDO invitation, String us

InvitationResult result = new InvitationResult();
try {
OrganizationManager organizationManager = UserInvitationMgtDataHolder.getInstance()
.getOrganizationManagerService();
// Checking the parent organization id
String parentOrgId = organizationManager.getParentOrganizationId(invitedOrgId);
// Picking the parent organization's tenant domain
String parentTenantDomain = organizationManager.resolveTenantDomain(parentOrgId);
String userDomainQualifiedUserName = UserCoreUtil.addDomainToName(username, invitation.getUserDomain());
String invitedTenantDomain = getOrganizationManager().resolveTenantDomain(invitedOrgId);
String parentOrgId = getOrganizationManager().getParentOrganizationId(invitedOrgId);
String parentTenantDomain = getOrganizationManager().resolveTenantDomain(parentOrgId);
int parentTenantId = IdentityTenantUtil.getTenantId(parentTenantDomain);
String invitedTenantDomain = organizationManager
.resolveTenantDomain(invitedOrgId);
boolean isActiveInvitationAvailable = isActiveInvitationAvailable(username,
invitation.getUserDomain(), parentOrgId, invitedOrgId);
String userDomainQualifiedUserName = UserCoreUtil
.addDomainToName(username, invitation.getUserDomain());
AbstractUserStoreManager userStoreManager = getAbstractUserStoreManager(parentTenantId);
String invitedUserId = userStoreManager.getUserIDFromUserName(userDomainQualifiedUserName);
if (isUserExistAtInvitedOrganization(userDomainQualifiedUserName)) {
if (LOG.isDebugEnabled()) {
LOG.debug("User " + username + " is already exists in the organization "
LOG.debug("User " + invitedUserId + " is already exists in the organization "
+ invitedOrgId);
}
result.setStatus(FAIL_STATUS);
result.setErrorMsg(ERROR_CODE_USER_ALREADY_EXISTS_INVITED_ORGANIZATION);
return result;
}
boolean isActiveInvitationAvailable = isActiveInvitationAvailable(username,
invitation.getUserDomain(), parentOrgId, invitedOrgId);
if (isActiveInvitationAvailable) {
if (LOG.isDebugEnabled()) {
LOG.debug("Active invitation is already available for the user: " + username
Expand All @@ -624,7 +614,7 @@ private InvitationResult userValidationResult(InvitationDO invitation, String us
}
if (!userStoreManager.isExistingUser(userDomainQualifiedUserName)) {
if (LOG.isDebugEnabled()) {
LOG.debug("User: " + username + " is not exists in the organization: "
LOG.debug("User: " + invitedUserId + " is not exists in the organization: "
+ parentOrgId);
}
result.setStatus(FAIL_STATUS);
Expand All @@ -644,7 +634,7 @@ private InvitationResult userValidationResult(InvitationDO invitation, String us
if (isConsoleAudienceAvailableInRole(invitation, invitedTenantDomain) &&
!isInvitedUserHasConsoleAccess(invitedUserId, parentTenantDomain)) {
if (LOG.isDebugEnabled()) {
LOG.debug("The user: " + username + " is not having" +
LOG.debug("The user: " + invitedUserId + " is not having" +
" the console access.");
}
result.setStatus(FAIL_STATUS);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.identity.organization.user.invitation.management.models;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.identity.organization.user.invitation.management.models;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.identity.organization.user.invitation.management.models;

import org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants;
Expand Down

0 comments on commit 4dd8a1b

Please sign in to comment.