diff --git a/components/org.wso2.carbon.identity.organization.user.invitation.management/pom.xml b/components/org.wso2.carbon.identity.organization.user.invitation.management/pom.xml
index 8a15d7ba6..16bf67d37 100644
--- a/components/org.wso2.carbon.identity.organization.user.invitation.management/pom.xml
+++ b/components/org.wso2.carbon.identity.organization.user.invitation.management/pom.xml
@@ -64,6 +64,10 @@
org.wso2.carbon.identity.framework
org.wso2.carbon.identity.event
+
+ org.wso2.carbon.identity.framework
+ org.wso2.carbon.identity.role.v2.mgt.core
+
org.testng
@@ -137,6 +141,9 @@
org.wso2.carbon.user.core.listener;version="${carbon.kernel.package.import.version.range}",
org.wso2.carbon.user.core.service;version="${carbon.kernel.package.import.version.range}",
org.wso2.carbon.user.core.util;version="${carbon.kernel.package.import.version.range}",
+ org.wso2.carbon.identity.role.v2.mgt.core;version="${carbon.identity.package.import.version.range}",
+ org.wso2.carbon.identity.role.v2.mgt.core.exception;version="${carbon.identity.package.import.version.range}",
+ org.wso2.carbon.identity.role.v2.mgt.core.model;version="${carbon.identity.package.import.version.range}",
org.wso2.carbon.identity.organization.management.organization.user.sharing;version="${org.wso2.identity.organization.mgt.imp.pkg.version.range}",
org.wso2.carbon.identity.organization.management.organization.user.sharing.constant;version="${org.wso2.identity.organization.mgt.imp.pkg.version.range}",
org.wso2.carbon.identity.organization.management.organization.user.sharing.models;version="${org.wso2.identity.organization.mgt.imp.pkg.version.range}",
diff --git a/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/InvitationCoreServiceImpl.java b/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/InvitationCoreServiceImpl.java
index a3816e5e9..13e40c50c 100644
--- a/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/InvitationCoreServiceImpl.java
+++ b/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/InvitationCoreServiceImpl.java
@@ -39,8 +39,12 @@
import org.wso2.carbon.identity.organization.user.invitation.management.exception.UserInvitationMgtException;
import org.wso2.carbon.identity.organization.user.invitation.management.exception.UserInvitationMgtServerException;
import org.wso2.carbon.identity.organization.user.invitation.management.internal.UserInvitationMgtDataHolder;
+import org.wso2.carbon.identity.organization.user.invitation.management.models.AudienceInfo;
import org.wso2.carbon.identity.organization.user.invitation.management.models.Invitation;
import org.wso2.carbon.identity.organization.user.invitation.management.models.RoleAssignments;
+import org.wso2.carbon.identity.role.v2.mgt.core.RoleManagementService;
+import org.wso2.carbon.identity.role.v2.mgt.core.exception.IdentityRoleManagementException;
+import org.wso2.carbon.identity.role.v2.mgt.core.model.Role;
import org.wso2.carbon.user.api.UserRealm;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.core.common.AbstractUserStoreManager;
@@ -51,6 +55,7 @@
import java.sql.Timestamp;
import java.time.Instant;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -73,11 +78,13 @@
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_CONSTRUCT_REDIRECT_URL;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_CREATE_INVITATION;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_EVENT_HANDLE;
+import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_GET_ROLE_ASSIGNMENTS_BY_ROLE_ID;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_GET_TENANT_FROM_ORG;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_GET_USER_STORE_MANAGER;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_INVALID_CONFIRMATION_CODE;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_INVALID_FILTER;
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_INVITATION_EXPIRED;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_NO_INVITATION_FOR_USER;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_UNABLE_TO_RESEND_INVITATION;
@@ -107,6 +114,8 @@ public Invitation createInvitation(Invitation invitation) throws UserInvitationM
String organizationId = Utils.getOrganizationId();
OrganizationManager organizationManager = UserInvitationMgtDataHolder.getInstance()
.getOrganizationManagerService();
+ RoleManagementService roleManagementService = UserInvitationMgtDataHolder.getInstance()
+ .getRoleManagementService();
Invitation createdInvitation;
try {
// Checking the parent organization id
@@ -125,6 +134,7 @@ public Invitation createInvitation(Invitation invitation) throws UserInvitationM
String.format(ERROR_CODE_ACTIVE_INVITATION_EXISTS.getDescription(), invitation.getUsername()));
}
int parentTenantId = IdentityTenantUtil.getTenantId(parentTenantDomain);
+ String invitedTenantDomain = organizationManager.resolveTenantDomain(organizationId);
AbstractUserStoreManager userStoreManager = getAbstractUserStoreManager(parentTenantId);
String userDomainQualifiedUserName = UserCoreUtil
.addDomainToName(invitation.getUsername(), invitation.getUserDomain());
@@ -141,16 +151,22 @@ public Invitation createInvitation(Invitation invitation) throws UserInvitationM
invitation.setInvitedOrganizationId(organizationId);
invitation.setStatus(STATUS_PENDING);
if (ArrayUtils.isNotEmpty(invitation.getRoleAssignments())) {
- // ToDO : Check the role existence by introducing a role validation service.
-
+ for (RoleAssignments roleAssignment : invitation.getRoleAssignments()) {
+ if (!roleManagementService.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()));
+ }
+ }
}
invitation.setInvitationId(UUID.randomUUID().toString());
invitation.setConfirmationCode(UUID.randomUUID().toString());
userInvitationDAO.createInvitation(invitation);
createdInvitation = userInvitationDAO.getInvitationByInvitationId(invitation.getInvitationId());
+ processingRoleAssignments(createdInvitation.getRoleAssignments(), invitedTenantDomain);
// Trigger the event for invitation creation
triggerInvitationAddNotification(createdInvitation);
- } catch (UserStoreException | OrganizationManagementException e) {
+ } catch (UserStoreException | OrganizationManagementException | IdentityRoleManagementException e) {
throw new UserInvitationMgtServerException(ERROR_CODE_CREATE_INVITATION.getCode(),
ERROR_CODE_CREATE_INVITATION.getMessage(),
String.format(ERROR_CODE_CREATE_INVITATION.getDescription(), invitation.getUsername()), e);
@@ -167,6 +183,8 @@ public boolean acceptInvitation(String confirmationCode) throws UserInvitationMg
try {
OrganizationManager organizationManager = UserInvitationMgtDataHolder.getInstance()
.getOrganizationManagerService();
+ RoleManagementService roleManagementService = UserInvitationMgtDataHolder.getInstance()
+ .getRoleManagementService();
String invitedOrganizationId = invitation.getInvitedOrganizationId();
String invitedTenantDomain = organizationManager.resolveTenantDomain(invitedOrganizationId);
int invitedTenantId = IdentityTenantUtil.getTenantId(invitedTenantDomain);
@@ -187,13 +205,24 @@ public boolean acceptInvitation(String confirmationCode) throws UserInvitationMg
String userId = getInvitedUserId(invitation);
getOrganizationUserSharingService().shareOrganizationUser(invitedOrganizationId, userId,
invitation.getUserOrganizationId());
+ String associatedUserId = getOrganizationUserSharingService()
+ .getUserAssociationOfAssociatedUserByOrgId(userId,
+ invitedOrganizationId).getUserId();
// Trigger event to add the role assignments if any available in the invitation.
if (ArrayUtils.isNotEmpty(invitation.getRoleAssignments())) {
- // Get the available group name for the group in the invited organization.
- String availableGroupName = getAvailableGroupName();
- userStoreManager.addRole(availableGroupName, new String[]{invitation.getUserDomain()}, null);
- triggerRoleAssignmentEvent(invitedOrganizationId, availableGroupName,
- Arrays.asList(invitation.getRoleAssignments()));
+ for (RoleAssignments roleAssignments : invitation.getRoleAssignments()) {
+ if (roleManagementService.isExistingRole(roleAssignments.getRoleId(),
+ invitedTenantDomain)) {
+ roleManagementService.updateUserListOfRole(roleAssignments.getRoleId(),
+ Collections.singletonList(associatedUserId), Collections.emptyList(),
+ invitedTenantDomain);
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Role: " + roleAssignments.getRoleId()
+ + " is not exist in the invitedTenantDomain : " + invitedTenantDomain);
+ }
+ }
+ }
}
// Removing the invitation since the user is added to the organization.
if (LOG.isDebugEnabled()) {
@@ -203,7 +232,7 @@ public boolean acceptInvitation(String confirmationCode) throws UserInvitationMg
}
userInvitationDAO.deleteInvitation(invitation.getInvitationId());
return true;
- } catch (UserStoreException | OrganizationManagementException e) {
+ } catch (UserStoreException | OrganizationManagementException | IdentityRoleManagementException e) {
UserCoreUtil.removeSkipPasswordPatternValidationThreadLocal();
throw new UserInvitationMgtServerException(ERROR_CODE_ACCEPT_INVITATION.getCode(),
ERROR_CODE_ACCEPT_INVITATION.getMessage(),
@@ -264,6 +293,9 @@ public List getInvitations(String filter) throws UserInvitationMgtEx
String organizationId = Utils.getOrganizationId();
List invitations = userInvitationDAO.getInvitationsByOrganization(organizationId, filterParam,
filterOperation, filterValue);
+ for (Invitation invitation : invitations) {
+ processingRoleAssignments(invitation.getRoleAssignments(), invitation.getInvitedOrganizationId());
+ }
Instant currentTime = Instant.now();
for (Invitation invitation : invitations) {
invitation.setStatus(STATUS_PENDING);
@@ -465,4 +497,30 @@ private OrganizationManager getOrganizationManager() {
return UserInvitationMgtDataHolder.getInstance().getOrganizationManagerService();
}
+
+ private void processingRoleAssignments(RoleAssignments[] roleAssignments, String invitedTenantId)
+ throws UserInvitationMgtServerException {
+
+ RoleManagementService roleManagementService = UserInvitationMgtDataHolder.getInstance()
+ .getRoleManagementService();
+ Role roleInfo;
+ for (RoleAssignments roleAssignment : roleAssignments) {
+ try {
+ roleInfo = roleManagementService.getRoleWithoutUsers(roleAssignment.getRoleId(),
+ invitedTenantId);
+ AudienceInfo audienceInfo = new AudienceInfo();
+ audienceInfo.setApplicationType(roleInfo.getAudience());
+ audienceInfo.setApplicationId(roleInfo.getAudienceId());
+ audienceInfo.setApplicationName(roleInfo.getAudienceName());
+ roleAssignment.setAudience(audienceInfo);
+ roleAssignment.setRoleName(roleInfo.getName());
+ } catch (IdentityRoleManagementException e) {
+ throw new UserInvitationMgtServerException(ERROR_CODE_GET_ROLE_ASSIGNMENTS_BY_ROLE_ID.getCode(),
+ ERROR_CODE_GET_ROLE_ASSIGNMENTS_BY_ROLE_ID.getMessage(),
+ String.format(ERROR_CODE_GET_ROLE_ASSIGNMENTS_BY_ROLE_ID.getDescription(),
+ roleAssignment.getRoleId()), e);
+ }
+
+ }
+ }
}
diff --git a/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/constant/SQLConstants.java b/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/constant/SQLConstants.java
index 7f116799f..2863094a0 100644
--- a/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/constant/SQLConstants.java
+++ b/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/constant/SQLConstants.java
@@ -62,6 +62,7 @@ public static final class SQLQueries {
"USER_NAME, DOMAIN_NAME, EMAIL, USER_ORG_ID, INVITED_ORG_ID, STATUS, CREATED_AT, EXPIRED_AT, " +
"USER_REDIRECT_URL FROM IDN_ORG_USER_INVITATION WHERE USER_NAME = ? AND DOMAIN_NAME = ? AND " +
"USER_ORG_ID = ? AND INVITED_ORG_ID = ? AND EXPIRED_AT > CURRENT_TIMESTAMP";
+ public static final String GET_APP_ID_BY_ROLE_ID = "SELECT APP_ID FROM APP_ROLE_ASSOCIATION WHERE ROLE_ID = ?";
}
/**
diff --git a/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/constant/UserInvitationMgtConstants.java b/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/constant/UserInvitationMgtConstants.java
index ff0473aeb..cd6616e1f 100644
--- a/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/constant/UserInvitationMgtConstants.java
+++ b/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/constant/UserInvitationMgtConstants.java
@@ -120,6 +120,9 @@ public enum ErrorMessage {
ERROR_CODE_INVALID_USER("10028",
"Invalid user identification provided.",
"Authenticated user %s is not entitled for the invitation."),
+ ERROR_CODE_INVALID_ROLE("10029",
+ "Invalid role identification provided.",
+ "Could not find a role with given roleId %s."),
// DAO layer errors
ERROR_CODE_STORE_INVITATION("10501",
@@ -178,7 +181,13 @@ public enum ErrorMessage {
"Unable to get the organization associations for the user %s."),
ERROR_CODE_GET_ORG_ASSOCIATION_FOR_USER("10519",
"Unable to get the organization association.",
- "Unable to get the organization association for the user %s.");
+ "Unable to get the organization association for the user %s."),
+ ERROR_CODE_GET_APPLICATION_ID("10520",
+ "Unable to retrieve the application id.",
+ "Could not retrieve the applicationId for the roleId %s."),
+ ERROR_CODE_GET_ROLE_ASSIGNMENTS_BY_ROLE_ID("10521",
+ "Unable to retrieve the role assignments.",
+ "Could not retrieve the role assignments for the roleId %s.");
private final String code;
private final String message;
diff --git a/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/dao/UserInvitationDAOImpl.java b/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/dao/UserInvitationDAOImpl.java
index 22a6452d2..7cdf48ec5 100644
--- a/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/dao/UserInvitationDAOImpl.java
+++ b/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/dao/UserInvitationDAOImpl.java
@@ -57,6 +57,7 @@
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.SQLConstants.SQLQueries.DELETE_INVITATION_BY_INVITATION_ID;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.SQLConstants.SQLQueries.DELETE_ROLE_ASSIGNMENTS_BY_INVITATION_ID;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.SQLConstants.SQLQueries.GET_ACTIVE_INVITATION_BY_USER;
+import static org.wso2.carbon.identity.organization.user.invitation.management.constant.SQLConstants.SQLQueries.GET_APP_ID_BY_ROLE_ID;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.SQLConstants.SQLQueries.GET_INVITATIONS_BY_INVITED_ORG_ID;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.SQLConstants.SQLQueries.GET_INVITATIONS_BY_INVITED_ORG_ID_WITH_STATUS_FILTER_EXPIRED;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.SQLConstants.SQLQueries.GET_INVITATIONS_BY_INVITED_ORG_ID_WITH_STATUS_FILTER_PENDING;
@@ -70,6 +71,7 @@
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_DELETE_INVITATION_BY_ID;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_DELETE_INVITATION_DETAILS;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_DELETE_ROLE_ASSIGNMENTS_BY_INVITATION;
+import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_GET_APPLICATION_ID;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_GET_INVITATION;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_GET_INVITATION_BY_CONF_CODE;
import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_GET_INVITATION_BY_USER;
@@ -136,14 +138,12 @@ public void createInvitation(Invitation invitation) throws UserInvitationMgtExce
try (PreparedStatement invitationRoleAssignmentPrepStat =
connection.prepareStatement(STORE_ROLE_ASSIGNMENTS)) {
for (RoleAssignments roleAssignment : invitation.getRoleAssignments()) {
- String applicationId = roleAssignment.getApplicationId();
- if (roleAssignment.getRoles() != null) {
- for (String role : roleAssignment.getRoles()) {
- invitationRoleAssignmentPrepStat.setString(1, invitation.getInvitationId());
- invitationRoleAssignmentPrepStat.setString(2, applicationId);
- invitationRoleAssignmentPrepStat.setString(3, role);
- invitationRoleAssignmentPrepStat.addBatch();
- }
+ String applicationId = getApplicationIdByRoleID(connection, roleAssignment.getRole());
+ if (StringUtils.isNotEmpty(applicationId)) {
+ invitationRoleAssignmentPrepStat.setString(1, invitation.getInvitationId());
+ invitationRoleAssignmentPrepStat.setString(2, applicationId);
+ invitationRoleAssignmentPrepStat.setString(3, roleAssignment.getRole());
+ invitationRoleAssignmentPrepStat.addBatch();
}
}
invitationRoleAssignmentPrepStat.executeBatch();
@@ -202,15 +202,14 @@ public Invitation getInvitationByInvitationId(String invitationId)
while (roleAssignmentsResultSet.next()) {
RoleAssignments roleAssignment = new RoleAssignments();
roleAssignment.setApplicationId(roleAssignmentsResultSet.getString(COLUMN_NAME_APP_ID));
- roleAssignment.setRole(roleAssignmentsResultSet.getString(COLUMN_NAME_ROLE_ID));
+ roleAssignment.setRoleId(roleAssignmentsResultSet.getString(COLUMN_NAME_ROLE_ID));
roleAssignmentsResultList.add(roleAssignment);
}
}
} catch (SQLException e) {
throw handleServerException(ERROR_CODE_RETRIEVE_ROLE_ASSIGNMENTS, invitationId, e);
}
- List roleAssignmentsList = processRoleAssignments(roleAssignmentsResultList);
- invitation.setRoleAssignments(roleAssignmentsList.toArray(new RoleAssignments[0]));
+ invitation.setRoleAssignments(roleAssignmentsResultList.toArray(new RoleAssignments[0]));
} catch (SQLException e) {
throw handleServerException(ERROR_CODE_GET_INVITATION, invitationId, e);
}
@@ -305,12 +304,11 @@ public List getInvitationsByOrganization(String organizationId, Stri
roleAssignment.setInvitationId(roleAssignmentsResultSet.
getString(COLUMN_NAME_INVITATION_ID));
roleAssignment.setApplicationId(roleAssignmentsResultSet.getString(COLUMN_NAME_APP_ID));
- roleAssignment.setRole(roleAssignmentsResultSet.getString(COLUMN_NAME_ROLE_ID));
+ roleAssignment.setRoleId(roleAssignmentsResultSet.getString(COLUMN_NAME_ROLE_ID));
roleAssignmentsResultList.add(roleAssignment);
}
}
- List roleAssignmentsList = processRoleAssignments(roleAssignmentsResultList);
- invitation.setRoleAssignments(roleAssignmentsList.toArray(new RoleAssignments[0]));
+ invitation.setRoleAssignments(roleAssignmentsResultList.toArray(new RoleAssignments[0]));
}
} catch (SQLException e) {
throw handleServerException(ERROR_CODE_RETRIEVE_ROLE_ASSIGNMENTS_FOR_INVITATION_BY_ORG_ID,
@@ -438,4 +436,19 @@ private String processDescription(UserInvitationMgtConstants.ErrorMessage error,
}
return description;
}
+
+ private String getApplicationIdByRoleID(Connection connection, String roleID) throws UserInvitationMgtException {
+
+ try (PreparedStatement appIdRetrievalPrepStat = connection.prepareStatement(GET_APP_ID_BY_ROLE_ID)) {
+ appIdRetrievalPrepStat.setString(1, roleID);
+ try (ResultSet resultSet = appIdRetrievalPrepStat.executeQuery()) {
+ if (resultSet.next()) {
+ return resultSet.getString(1);
+ }
+ }
+ } catch (SQLException e) {
+ throw handleServerException(ERROR_CODE_GET_APPLICATION_ID, null, e);
+ }
+ return null;
+ }
}
diff --git a/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/internal/UserInvitationMgtDataHolder.java b/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/internal/UserInvitationMgtDataHolder.java
index e985a848b..6918db876 100644
--- a/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/internal/UserInvitationMgtDataHolder.java
+++ b/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/internal/UserInvitationMgtDataHolder.java
@@ -21,6 +21,7 @@
import org.wso2.carbon.identity.event.services.IdentityEventService;
import org.wso2.carbon.identity.organization.management.organization.user.sharing.OrganizationUserSharingService;
import org.wso2.carbon.identity.organization.management.service.OrganizationManager;
+import org.wso2.carbon.identity.role.v2.mgt.core.RoleManagementService;
import org.wso2.carbon.user.core.service.RealmService;
/**
@@ -34,6 +35,7 @@ public class UserInvitationMgtDataHolder {
private IdentityEventService identityEventService;
private OrganizationManager organizationManager;
private OrganizationUserSharingService organizationUserSharingService;
+ private RoleManagementService roleManagementService;
public static UserInvitationMgtDataHolder getInstance() {
@@ -80,4 +82,24 @@ public void setOrganizationUserSharingService(
this.organizationUserSharingService = organizationUserSharingService;
}
+
+ /**
+ * Get the Role manager service.
+ *
+ * @return Role manager service.
+ */
+ public RoleManagementService getRoleManagementService() {
+
+ return roleManagementService;
+ }
+
+ /**
+ * Set the Role manager service.
+ *
+ * @param roleManagementService Role manager service.
+ */
+ public void setRoleManagementService(RoleManagementService roleManagementService) {
+
+ this.roleManagementService = roleManagementService;
+ }
}
diff --git a/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/internal/UserInvitationMgtServiceComponent.java b/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/internal/UserInvitationMgtServiceComponent.java
index bd05edbce..4ccb561eb 100644
--- a/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/internal/UserInvitationMgtServiceComponent.java
+++ b/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/internal/UserInvitationMgtServiceComponent.java
@@ -34,6 +34,7 @@
import org.wso2.carbon.identity.organization.user.invitation.management.InvitationCoreService;
import org.wso2.carbon.identity.organization.user.invitation.management.InvitationCoreServiceImpl;
import org.wso2.carbon.identity.organization.user.invitation.management.handler.UserInvitationEventHandler;
+import org.wso2.carbon.identity.role.v2.mgt.core.RoleManagementService;
import org.wso2.carbon.user.core.service.RealmService;
/**
@@ -137,4 +138,20 @@ protected void unsetOrganizationUserAssociationService(
UserInvitationMgtDataHolder.getInstance().setOrganizationUserSharingService(null);
LOG.debug("Unset organization user association Service.");
}
+
+ @Reference(
+ name = "RoleManagementService",
+ service = RoleManagementService.class,
+ cardinality = ReferenceCardinality.MANDATORY,
+ policy = ReferencePolicy.DYNAMIC,
+ unbind = "unsetRoleManagementService")
+ protected void setRoleManagementService(RoleManagementService roleManagementService) {
+
+ UserInvitationMgtDataHolder.getInstance().setRoleManagementService(roleManagementService);
+ }
+
+ protected void unsetRoleManagementService(RoleManagementService roleManagementService) {
+
+ UserInvitationMgtDataHolder.getInstance().setRoleManagementService(null);
+ }
}
diff --git a/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/models/AudienceInfo.java b/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/models/AudienceInfo.java
new file mode 100644
index 000000000..aab9b7cf1
--- /dev/null
+++ b/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/models/AudienceInfo.java
@@ -0,0 +1,59 @@
+/*
+ * 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;
+
+/**
+ * Model that contains the invitation's audience related details.
+ */
+public class AudienceInfo {
+
+ private String applicationId;
+ private String applicationName;
+ private String applicationType;
+
+ public String getApplicationId() {
+
+ return applicationId;
+ }
+
+ public void setApplicationId(String applicationId) {
+
+ this.applicationId = applicationId;
+ }
+
+ public String getApplicationName() {
+
+ return applicationName;
+ }
+
+ public void setApplicationName(String applicationName) {
+
+ this.applicationName = applicationName;
+ }
+
+ public String getApplicationType() {
+
+ return applicationType;
+ }
+
+ public void setApplicationType(String applicationType) {
+
+ this.applicationType = applicationType;
+ }
+}
diff --git a/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/models/RoleAssignments.java b/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/models/RoleAssignments.java
index 435d4202a..1f5de7b1e 100644
--- a/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/models/RoleAssignments.java
+++ b/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/models/RoleAssignments.java
@@ -24,8 +24,11 @@
public class RoleAssignments {
private String invitationId;
+ private AudienceInfo audience;
private String applicationId;
private String applicationName;
+ private String roleName;
+ private String roleId;
private String[] roles;
private String role;
@@ -81,4 +84,34 @@ public void setRole(String role) {
this.role = role;
}
+
+ public String getRoleName() {
+
+ return roleName;
+ }
+
+ public void setRoleName(String roleName) {
+
+ this.roleName = roleName;
+ }
+
+ public String getRoleId() {
+
+ return roleId;
+ }
+
+ public void setRoleId(String roleId) {
+
+ this.roleId = roleId;
+ }
+
+ public AudienceInfo getAudience() {
+
+ return audience;
+ }
+
+ public void setAudience(AudienceInfo audience) {
+
+ this.audience = audience;
+ }
}
diff --git a/components/org.wso2.carbon.identity.organization.user.invitation.management/src/test/resources/dbscripts/h2.sql b/components/org.wso2.carbon.identity.organization.user.invitation.management/src/test/resources/dbscripts/h2.sql
index c07bdfd51..cc1274752 100644
--- a/components/org.wso2.carbon.identity.organization.user.invitation.management/src/test/resources/dbscripts/h2.sql
+++ b/components/org.wso2.carbon.identity.organization.user.invitation.management/src/test/resources/dbscripts/h2.sql
@@ -22,3 +22,36 @@ CREATE TABLE IF NOT EXISTS IDN_ORG_USER_INVITE_ROLE_ASSIGNMENT(
PRIMARY KEY (INVITATION_ID, APPLICATION_ID, ROLE_ID),
FOREIGN KEY (INVITATION_ID) REFERENCES IDN_ORG_USER_INVITATION(INVITATION_ID) ON DELETE CASCADE
);
+
+CREATE TABLE IF NOT EXISTS SP_APP (
+ ID INTEGER NOT NULL AUTO_INCREMENT,
+ TENANT_ID INTEGER NOT NULL,
+ APP_NAME VARCHAR (255) NOT NULL ,
+ USER_STORE VARCHAR (255) NOT NULL,
+ USERNAME VARCHAR (255) NOT NULL ,
+ DESCRIPTION VARCHAR (1024),
+ ROLE_CLAIM VARCHAR (512),
+ AUTH_TYPE VARCHAR (255) NOT NULL,
+ PROVISIONING_USERSTORE_DOMAIN VARCHAR (512),
+ IS_LOCAL_CLAIM_DIALECT CHAR(1) DEFAULT '1',
+ IS_SEND_LOCAL_SUBJECT_ID CHAR(1) DEFAULT '0',
+ IS_SEND_AUTH_LIST_OF_IDPS CHAR(1) DEFAULT '0',
+ IS_USE_TENANT_DOMAIN_SUBJECT CHAR(1) DEFAULT '1',
+ IS_USE_USER_DOMAIN_SUBJECT CHAR(1) DEFAULT '1',
+ ENABLE_AUTHORIZATION CHAR(1) DEFAULT '0',
+ SUBJECT_CLAIM_URI VARCHAR (512),
+ IS_SAAS_APP CHAR(1) DEFAULT '0',
+ IS_DUMB_MODE CHAR(1) DEFAULT '0',
+ UUID CHAR(36),
+ IMAGE_URL VARCHAR(1024),
+ ACCESS_URL VARCHAR(1024),
+ IS_DISCOVERABLE CHAR(1) DEFAULT '0',
+ PRIMARY KEY (ID)
+ );
+
+CREATE TABLE IF NOT EXISTS APP_ROLE_ASSOCIATION (
+ APP_ID CHAR(36) NOT NULL,
+ ROLE_ID VARCHAR(255) NOT NULL,
+ PRIMARY KEY (APP_ID, ROLE_ID),
+ FOREIGN KEY (APP_ID) REFERENCES SP_APP(UUID) ON DELETE CASCADE
+);