use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException in project identity-inbound-provisioning-scim2 by wso2-extensions.
the class SCIMRoleManagerTest method testUpdateRoleUpdateUserListOfRoleThrowingErrors.
@Test(dataProvider = "dataProviderForUpdateRoleUpdateUserListOfRoleThrowingErrors", expectedExceptions = { BadRequestException.class, CharonException.class })
public void testUpdateRoleUpdateUserListOfRoleThrowingErrors(String roleId, String oldRoleName, String newRoleName, String tenantDomain, String type, String sError) throws IdentityRoleManagementException, BadRequestException, CharonException, ConflictException, NotFoundException {
RoleBasicInfo roleBasicInfo = new RoleBasicInfo(roleId, newRoleName);
Role[] oldAndNewRoles = getOldAndNewRoleDummies(roleId, oldRoleName, newRoleName, type);
when(mockRoleManagementService.updateRoleName(anyString(), anyString(), anyString())).thenReturn(roleBasicInfo);
when(mockRoleManagementService.updateUserListOfRole(anyString(), anyListOf(String.class), anyListOf(String.class), anyString())).thenAnswer(invocationOnMock -> {
String roleIdArg = invocationOnMock.getArgumentAt(0, String.class);
String tenantDomainArg = invocationOnMock.getArgumentAt(3, String.class);
if (INVALID_ROLE_IDS.contains(roleIdArg)) {
String errorMessage = "Invalid scenario. Multiple roles found for the given role name: " + roleIdArg + " and tenantDomain: " + tenantDomain;
throw new IdentityRoleManagementClientException(INVALID_REQUEST.getCode(), errorMessage);
}
Throwable unExpectedErrors = unExpectedErrorThrower(tenantDomainArg, sError, "Error while updating users to the role: %s in the tenantDomain: %s", roleIdArg);
if (unExpectedErrors != null)
throw unExpectedErrors;
return roleBasicInfo;
});
SCIMRoleManager scimRoleManager = new SCIMRoleManager(mockRoleManagementService, tenantDomain);
scimRoleManager.updateRole(oldAndNewRoles[0], oldAndNewRoles[1]);
}
use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException in project identity-inbound-provisioning-scim2 by wso2-extensions.
the class SCIMRoleManagerTest method testListRolesWithPOSTInvalidLimit.
@Test(dataProvider = "dataProviderForListRolesWithPOSTInvalidLimit")
public void testListRolesWithPOSTInvalidLimit(String nodeType, Integer count) throws IdentityRoleManagementException {
Node rootNode = generateNodeBasedOnNodeType(nodeType, "name");
when(mockRoleManagementService.getRoles(anyInt(), anyInt(), anyString(), anyString(), anyString())).thenAnswer(invocationOnMock -> {
Integer countArg = invocationOnMock.getArgumentAt(0, Integer.class);
if (countArg != null && countArg < 0) {
String errorMessage = "Invalid limit requested. Limit value should be greater than or equal to zero. limit: " + count;
throw new IdentityRoleManagementClientException(INVALID_LIMIT.getCode(), errorMessage);
}
return null;
});
when(mockRoleManagementService.getRoles(anyString(), anyInt(), anyInt(), anyString(), anyString(), anyString())).thenAnswer(invocationOnMock -> {
Integer countArg = invocationOnMock.getArgumentAt(1, Integer.class);
if (countArg != null && countArg < 0) {
String errorMessage = "Invalid limit requested. Limit value should be greater than or equal to zero. limit: " + count;
throw new IdentityRoleManagementClientException(INVALID_LIMIT.getCode(), errorMessage);
}
return null;
});
SCIMRoleManager roleManager = new SCIMRoleManager(mockRoleManagementService, SAMPLE_TENANT_DOMAIN);
assertThrows(CharonException.class, () -> roleManager.listRolesWithPost(getDummySearchRequest(rootNode, 2, count, null, null)));
}
use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException in project identity-inbound-provisioning-scim2 by wso2-extensions.
the class SCIMRoleManagerTest method testListRolesWithGETInvalidOffset.
@Test(dataProvider = "dataProviderForListRolesWithGETInvalidOffset")
public void testListRolesWithGETInvalidOffset(String nodeType, Integer startIndex) throws IdentityRoleManagementException {
Node rootNode = generateNodeBasedOnNodeType(nodeType, null);
when(mockRoleManagementService.getRoles(anyInt(), anyInt(), anyString(), anyString(), anyString())).thenAnswer(invocationOnMock -> {
Integer startIndexArg = invocationOnMock.getArgumentAt(1, Integer.class);
if (startIndexArg != null && startIndexArg < 0) {
String errorMessage = "Invalid offset requested. Offset value should be greater " + "than or equal to zero. offset: " + startIndexArg;
throw new IdentityRoleManagementClientException(INVALID_LIMIT.getCode(), errorMessage);
}
return null;
});
when(mockRoleManagementService.getRoles(anyString(), anyInt(), anyInt(), anyString(), anyString(), anyString())).thenAnswer(invocationOnMock -> {
Integer startIndexArg = invocationOnMock.getArgumentAt(2, Integer.class);
if (startIndexArg != null && startIndexArg < 0) {
String errorMessage = "Invalid offset requested. offset value should be greater than or " + "equal to zero. offset: " + startIndexArg;
throw new IdentityRoleManagementClientException(INVALID_LIMIT.getCode(), errorMessage);
}
return null;
});
SCIMRoleManager roleManager = new SCIMRoleManager(mockRoleManagementService, SAMPLE_TENANT_DOMAIN);
assertThrows(CharonException.class, () -> roleManager.listRolesWithGET(rootNode, startIndex, 2, null, null));
}
use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException in project identity-inbound-provisioning-scim2 by wso2-extensions.
the class SCIMRoleManagerTest method testGetRoleNotFound.
@Test(dataProvider = "dataProviderForGetRoleNotFound")
public void testGetRoleNotFound(String roleId, String tenantDomain) throws IdentityRoleManagementException {
when(mockRoleManagementService.getRole(roleId, tenantDomain)).thenThrow(new IdentityRoleManagementClientException(ROLE_NOT_FOUND.getCode(), String.format("A role doesn't exist with id: %s in the tenantDomain: %s", roleId, tenantDomain)));
SCIMRoleManager scimRoleManager = new SCIMRoleManager(mockRoleManagementService, tenantDomain);
assertThrows(NotFoundException.class, () -> scimRoleManager.getRole(roleId, null));
}
use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException in project carbon-identity-framework by wso2.
the class RoleDAOImpl method updateGroupListOfRole.
@Override
public RoleBasicInfo updateGroupListOfRole(String roleID, List<String> newGroupIDList, List<String> deletedGroupIDList, String tenantDomain) throws IdentityRoleManagementException {
if (!isExistingRoleID(roleID, tenantDomain)) {
throw new IdentityRoleManagementClientException(ROLE_NOT_FOUND.getCode(), "Role id: " + roleID + " does not exist in the system.");
}
String roleName = getRoleNameByID(roleID, tenantDomain);
// Validate the group removal operation based on the default system roles.
validateGroupRemovalFromRole(deletedGroupIDList, roleName, tenantDomain);
if (CollectionUtils.isEmpty(newGroupIDList) && CollectionUtils.isEmpty(deletedGroupIDList)) {
if (log.isDebugEnabled()) {
log.debug("Group lists are empty.");
}
return new RoleBasicInfo(roleID, roleName);
}
String primaryDomainName = IdentityUtil.getPrimaryDomainName();
if (primaryDomainName != null) {
primaryDomainName = primaryDomainName.toUpperCase(Locale.ENGLISH);
}
// Resolve group names from group IDs.
Map<String, String> newGroupIdsToNames = getGroupNamesByIDs(newGroupIDList, tenantDomain);
List<String> newGroupNamesList = new ArrayList<>(newGroupIdsToNames.values());
Map<String, String> deletedGroupIdsToNames = getGroupNamesByIDs(deletedGroupIDList, tenantDomain);
List<String> deletedGroupNamesList = new ArrayList<>(deletedGroupIdsToNames.values());
int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
try (Connection connection = IdentityDatabaseUtil.getUserDBConnection(true)) {
try {
// Add new groups to the role.
String addGroupsSQL = ADD_GROUP_TO_ROLE_SQL;
String databaseProductName = connection.getMetaData().getDatabaseProductName();
if (MICROSOFT.equals(databaseProductName)) {
addGroupsSQL = ADD_GROUP_TO_ROLE_SQL_MSSQL;
}
processBatchUpdateForGroups(roleName, newGroupNamesList, tenantId, primaryDomainName, connection, addGroupsSQL);
// Delete existing groups from the role.
processBatchUpdateForGroups(roleName, deletedGroupNamesList, tenantId, primaryDomainName, connection, REMOVE_GROUP_FROM_ROLE_SQL);
IdentityDatabaseUtil.commitUserDBTransaction(connection);
} catch (SQLException e) {
IdentityDatabaseUtil.rollbackUserDBTransaction(connection);
String errorMessage = "Error while updating groups to the role: %s in the tenantDomain: %s";
throw new IdentityRoleManagementServerException(UNEXPECTED_SERVER_ERROR.getCode(), String.format(errorMessage, roleName, tenantDomain), e);
}
} catch (SQLException e) {
String errorMessage = "Error while updating groups to the role: %s in the tenantDomain: %s";
throw new IdentityRoleManagementServerException(UNEXPECTED_SERVER_ERROR.getCode(), String.format(errorMessage, roleName, tenantDomain), e);
}
clearUserRolesCacheByTenant(tenantId);
return new RoleBasicInfo(roleID, roleName);
}
Aggregations