Search in sources :

Example 26 with IdentityRoleManagementClientException

use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException in project carbon-identity-framework by wso2.

the class GroupIDResolver method getIDByName.

@Override
public String getIDByName(String name, String tenantDomain) throws IdentityRoleManagementException {
    GroupDAO groupDAO = RoleMgtDAOFactory.getInstance().getGroupDAO();
    String groupName = groupDAO.getGroupIDByName(name, tenantDomain);
    if (groupName == null) {
        String errorMessage = "A group doesn't exist with name: " + name + " in the tenantDomain: " + tenantDomain;
        throw new IdentityRoleManagementClientException(INVALID_REQUEST.getCode(), errorMessage);
    }
    return groupName;
}
Also used : GroupDAO(org.wso2.carbon.identity.role.mgt.core.dao.GroupDAO) IdentityRoleManagementClientException(org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException)

Example 27 with IdentityRoleManagementClientException

use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SCIMRoleManagerTest method testCreateRoleAddRoleInvalidRoleName.

@Test
public void testCreateRoleAddRoleInvalidRoleName() throws BadRequestException, CharonException, IdentityRoleManagementException {
    Role role = getDummyRole(SAMPLE_VALID_ROLE_ID, SAMPLE_INVALID_ROLE_NAME);
    when(mockRoleManagementService.addRole(anyString(), anyListOf(String.class), anyListOf(String.class), anyListOf(String.class), anyString())).thenThrow(new IdentityRoleManagementClientException(INVALID_REQUEST.getCode(), String.format("Invalid role name: %s. Role names with the prefix: %s, is not allowed" + " to be created from externally in the system.", SAMPLE_INVALID_ROLE_NAME, UserCoreConstants.INTERNAL_SYSTEM_ROLE_PREFIX)));
    SCIMRoleManager scimRoleManager = new SCIMRoleManager(mockRoleManagementService, SAMPLE_TENANT_DOMAIN);
    assertThrows(BadRequestException.class, () -> scimRoleManager.createRole(role));
}
Also used : Role(org.wso2.charon3.core.objects.Role) Matchers.anyString(org.mockito.Matchers.anyString) IdentityRoleManagementClientException(org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 28 with IdentityRoleManagementClientException

use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SCIMRoleManagerTest method testListRolesWithPOSTInvalidOffset.

@Test(dataProvider = "dataProviderForListRolesWithPOSTInvalidOffset")
public void testListRolesWithPOSTInvalidOffset(String nodeType, Integer startIndex) throws IdentityRoleManagementException {
    Node rootNode = generateNodeBasedOnNodeType(nodeType, "name");
    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 limit requested. Limit value should be greater than or equal to zero. limit: " + 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 limit requested. Limit value should be greater than or equal to zero. limit: " + startIndexArg;
            throw new IdentityRoleManagementClientException(INVALID_LIMIT.getCode(), errorMessage);
        }
        return null;
    });
    SCIMRoleManager roleManager = new SCIMRoleManager(mockRoleManagementService, SAMPLE_TENANT_DOMAIN);
    assertThrows(CharonException.class, () -> roleManager.listRolesWithPost(getDummySearchRequest(rootNode, startIndex, 2, null, null)));
}
Also used : OperationNode(org.wso2.charon3.core.utils.codeutils.OperationNode) ExpressionNode(org.wso2.charon3.core.utils.codeutils.ExpressionNode) Node(org.wso2.charon3.core.utils.codeutils.Node) Matchers.anyString(org.mockito.Matchers.anyString) IdentityRoleManagementClientException(org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 29 with IdentityRoleManagementClientException

use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SCIMRoleManagerTest method testRoleUpdatePermissionListOfRoleThrowingErrors.

@Test(dataProvider = "dataProviderForRoleUpdatePermissionListOfRoleThrowingErrors", expectedExceptions = { BadRequestException.class, CharonException.class })
public void testRoleUpdatePermissionListOfRoleThrowingErrors(String roleId, String oldRoleName, String newRoleName, String tenantDomain, String permissionType, String sError) throws IdentityRoleManagementException, BadRequestException, CharonException, ConflictException, NotFoundException {
    RoleBasicInfo roleBasicInfo = new RoleBasicInfo(roleId, newRoleName);
    Role[] oldAndNewRoles = getOldAndNewRoleDummies(roleId, oldRoleName, newRoleName, permissionType);
    when(mockRoleManagementService.updateRoleName(anyString(), anyString(), anyString())).thenReturn(roleBasicInfo);
    when(mockRoleManagementService.setPermissionsForRole(anyString(), anyListOf(String.class), anyString())).thenAnswer(invocationOnMock -> {
        String roleIdArg = invocationOnMock.getArgumentAt(0, String.class);
        String tenantDomainArg = invocationOnMock.getArgumentAt(2, 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);
        }
        if (SYSTEM_ROLES.contains(oldRoleName)) {
            throw new IdentityRoleManagementClientException(RoleConstants.Error.OPERATION_FORBIDDEN.getCode(), "Invalid operation. Permissions cannot be modified in the role: " + oldRoleName + " since it's a read only system role.");
        }
        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;
    });
    when(mockRoleManagementService.updateUserListOfRole(eq(roleId), anyListOf(String.class), anyListOf(String.class), anyString())).thenReturn(roleBasicInfo);
    when(mockRoleManagementService.updateGroupListOfRole(eq(roleId), anyListOf(String.class), anyListOf(String.class), anyString())).thenReturn(roleBasicInfo);
    SCIMRoleManager scimRoleManager = new SCIMRoleManager(mockRoleManagementService, tenantDomain);
    scimRoleManager.updateRole(oldAndNewRoles[0], oldAndNewRoles[1]);
}
Also used : Role(org.wso2.charon3.core.objects.Role) Matchers.anyString(org.mockito.Matchers.anyString) RoleBasicInfo(org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo) IdentityRoleManagementClientException(org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

IdentityRoleManagementClientException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException)29 IdentityRoleManagementServerException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementServerException)13 NamedPreparedStatement (org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement)12 Connection (java.sql.Connection)11 SQLException (java.sql.SQLException)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 Test (org.testng.annotations.Test)10 ResultSet (java.sql.ResultSet)9 Matchers.anyString (org.mockito.Matchers.anyString)9 RoleBasicInfo (org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo)8 UserRealm (org.wso2.carbon.user.api.UserRealm)5 UserStoreException (org.wso2.carbon.user.api.UserStoreException)5 Role (org.wso2.charon3.core.objects.Role)5 ArrayList (java.util.ArrayList)4 ExpressionNode (org.wso2.charon3.core.utils.codeutils.ExpressionNode)4 Node (org.wso2.charon3.core.utils.codeutils.Node)4 OperationNode (org.wso2.charon3.core.utils.codeutils.OperationNode)4 HashMap (java.util.HashMap)3 IdentityRoleManagementException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException)3 AbstractUserStoreManager (org.wso2.carbon.user.core.common.AbstractUserStoreManager)3