use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException in project identity-inbound-provisioning-scim2 by wso2-extensions.
the class SCIMRoleManagerTest method testListRolesWithGETPositive.
@Test(dataProvider = "dataProviderForListRolesWithGETPositive")
public void testListRolesWithGETPositive(String nodeType, Object count, String operation) throws CharonException, IdentityRoleManagementException, NotImplementedException, BadRequestException {
Node rootNode = generateNodeBasedOnNodeType(nodeType, "name", operation);
List<RoleBasicInfo> roleList = getDummyRoleBasicInfoList();
when(mockRoleManagementService.getRoles(anyInt(), anyInt(), anyString(), anyString(), anyString())).thenAnswer(invocationOnMock -> roleList);
when(mockRoleManagementService.getRoles(anyString(), anyInt(), anyInt(), anyString(), anyString(), anyString())).thenAnswer(invocationOnMock -> roleList);
SCIMRoleManager roleManager = new SCIMRoleManager(mockRoleManagementService, SAMPLE_TENANT_DOMAIN);
roleManager.listRolesWithGET(rootNode, 2, (Integer) count, null, null);
assertTrue(true, "list roles works as expected");
}
use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException in project identity-inbound-provisioning-scim2 by wso2-extensions.
the class SCIMRoleManager method doUpdateUsers.
private void doUpdateUsers(Role oldRole, Role newRole) throws CharonException, BadRequestException {
if (log.isDebugEnabled()) {
log.debug("Updating users of role: " + oldRole.getDisplayName());
}
Set<String> userIDsInOldRole = new HashSet<>(oldRole.getUsers());
Set<String> userIDsInNewRole = new HashSet<>(newRole.getUsers());
// Check for deleted users.
Set<String> deletedUserIDList = getRemovedIDList(userIDsInOldRole, userIDsInNewRole);
// Check for added users.
Set<String> newUserIDList = getAddedIDList(userIDsInOldRole, userIDsInNewRole);
// Update the role with added users and deleted users.
if (isNotEmpty(newUserIDList) || isNotEmpty(deletedUserIDList)) {
try {
roleManagementService.updateUserListOfRole(oldRole.getId(), new ArrayList<>(newUserIDList), new ArrayList<>(deletedUserIDList), tenantDomain);
} catch (IdentityRoleManagementException e) {
if (StringUtils.equals(INVALID_REQUEST.getCode(), e.getErrorCode()) || StringUtils.equals(OPERATION_FORBIDDEN.getCode(), e.getErrorCode())) {
throw new BadRequestException(e.getMessage());
}
throw new CharonException(String.format("Error occurred while updating users in the role: %s", newRole.getDisplayName()), e);
}
}
}
use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException in project identity-inbound-provisioning-scim2 by wso2-extensions.
the class SCIMRoleManager method doUpdatePermissions.
private void doUpdatePermissions(Role oldRole, Role newRole) throws BadRequestException, CharonException {
if (log.isDebugEnabled()) {
log.debug("Updating permissions of role: " + oldRole.getDisplayName());
}
List<String> oldRolePermissions = oldRole.getPermissions();
List<String> newRolePermissions = newRole.getPermissions();
// Update the role with specified permissions.
if (hasPermissionsChanged(oldRolePermissions, newRolePermissions)) {
if (log.isDebugEnabled()) {
log.debug("Permissions have changed. Updating permissions of role: " + oldRole.getDisplayName());
}
try {
roleManagementService.setPermissionsForRole(oldRole.getId(), newRolePermissions, tenantDomain);
} catch (IdentityRoleManagementException e) {
if (StringUtils.equals(INVALID_REQUEST.getCode(), e.getErrorCode())) {
throw new BadRequestException(e.getMessage());
} else if (StringUtils.equals(OPERATION_FORBIDDEN.getCode(), e.getErrorCode())) {
throw new BadRequestException(e.getMessage());
}
throw new CharonException(String.format("Error occurred while updating permissions for role: %s", newRole.getDisplayName()), e);
}
}
}
use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException in project identity-inbound-provisioning-scim2 by wso2-extensions.
the class SCIMRoleManager method createRole.
@Override
public Role createRole(Role role) throws CharonException, ConflictException, BadRequestException {
if (log.isDebugEnabled()) {
log.debug("Creating role: " + role.getDisplayName());
}
try {
// Check if the role already exists.
if (roleManagementService.isExistingRole(role.getId(), tenantDomain)) {
String error = "Role with name: " + role.getDisplayName() + " already exists in the tenantDomain: " + tenantDomain;
throw new ConflictException(error);
}
RoleBasicInfo roleBasicInfo = roleManagementService.addRole(role.getDisplayName(), role.getUsers(), role.getGroups(), role.getPermissions(), tenantDomain);
Role createdRole = new Role();
createdRole.setId(roleBasicInfo.getId());
String locationURI = SCIMCommonUtils.getSCIMRoleURL(roleBasicInfo.getId());
createdRole.setLocation(locationURI);
createdRole.setDisplayName(roleBasicInfo.getName());
createdRole.setSchemas();
return createdRole;
} catch (IdentityRoleManagementException e) {
if (StringUtils.equals(ROLE_ALREADY_EXISTS.getCode(), e.getErrorCode())) {
throw new ConflictException(e.getMessage());
} else if (StringUtils.equals(INVALID_REQUEST.getCode(), e.getErrorCode())) {
throw new BadRequestException(e.getMessage());
}
throw new CharonException(String.format("Error occurred while adding a new role: %s", role.getDisplayName()), e);
}
}
use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException in project identity-inbound-provisioning-scim2 by wso2-extensions.
the class SCIMRoleManager method doUpdateRoleName.
private void doUpdateRoleName(Role oldRole, Role newRole) throws CharonException, ConflictException, NotFoundException, BadRequestException {
if (log.isDebugEnabled()) {
log.debug(String.format("Updating name of role %s to %s.", oldRole.getDisplayName(), newRole.getDisplayName()));
}
// Update name if it is changed.
String oldRoleDisplayName = oldRole.getDisplayName();
String newRoleDisplayName = newRole.getDisplayName();
if (!StringUtils.equals(oldRoleDisplayName, newRoleDisplayName)) {
// Update role name.
try {
roleManagementService.updateRoleName(oldRole.getId(), newRoleDisplayName, tenantDomain);
} catch (IdentityRoleManagementException e) {
if (StringUtils.equals(ROLE_NOT_FOUND.getCode(), e.getErrorCode())) {
throw new NotFoundException(e.getMessage());
} else if (StringUtils.equals(ROLE_ALREADY_EXISTS.getCode(), e.getErrorCode())) {
throw new ConflictException(e.getMessage());
} else if (StringUtils.equals(OPERATION_FORBIDDEN.getCode(), e.getErrorCode())) {
throw new BadRequestException(e.getMessage());
}
throw new CharonException(String.format("Error occurred while updating role name from: %s to %s", oldRoleDisplayName, newRoleDisplayName), e);
}
}
}
Aggregations