Search in sources :

Example 61 with IdentityRoleManagementException

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

the class RoleDAOImpl method isExistingRoleID.

@Override
public boolean isExistingRoleID(String roleID, String tenantDomain) throws IdentityRoleManagementException {
    boolean isExist = false;
    int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
    try (Connection connection = IdentityDatabaseUtil.getDBConnection(false)) {
        try (NamedPreparedStatement statement = new NamedPreparedStatement(connection, IS_ROLE_ID_EXIST_SQL)) {
            statement.setInt(RoleConstants.RoleTableColumns.TENANT_ID, tenantId);
            statement.setString(RoleConstants.RoleTableColumns.ATTR_NAME, RoleConstants.ID_URI);
            statement.setString(RoleConstants.RoleTableColumns.ATTR_VALUE, roleID);
            try (ResultSet resultSet = statement.executeQuery()) {
                if (resultSet.next()) {
                    isExist = resultSet.getInt(1) > 0;
                }
            }
        }
    } catch (SQLException e) {
        String errorMessage = "Error while checking is existing role for role id: %s in the tenantDomain: %s";
        throw new IdentityRoleManagementServerException(UNEXPECTED_SERVER_ERROR.getCode(), String.format(errorMessage, roleID, tenantDomain), e);
    }
    if (log.isDebugEnabled()) {
        log.debug("Is roleID: " + roleID + " Exist: " + isExist + " in the tenantDomain: " + tenantDomain);
    }
    return isExist;
}
Also used : NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement) SQLException(java.sql.SQLException) IdentityRoleManagementServerException(org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementServerException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet)

Example 62 with IdentityRoleManagementException

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

the class IdentityProviderManager method validateOutboundProvisioningRoles.

/**
 * Validate whether the outbound provisioning roles does exist.
 *
 * @param identityProvider IdentityProvider.
 * @param tenantDomain     Tenant Domain.
 * @throws IdentityProviderManagementException If an error occurred while checking for role existence.
 */
private void validateOutboundProvisioningRoles(IdentityProvider identityProvider, String tenantDomain) throws IdentityProviderManagementException {
    String provisioningRole = identityProvider.getProvisioningRole();
    if (StringUtils.isBlank(provisioningRole)) {
        return;
    }
    String[] outboundProvisioningRoles = StringUtils.split(provisioningRole, ",");
    try {
        RoleManagementService roleManagementService = IdpMgtServiceComponentHolder.getInstance().getRoleManagementService();
        for (String roleName : outboundProvisioningRoles) {
            try {
                if (!roleManagementService.isExistingRoleName(roleName, tenantDomain)) {
                    throw IdPManagementUtil.handleClientException(IdPManagementConstants.ErrorMessage.ERROR_CODE_NOT_EXISTING_OUTBOUND_PROVISIONING_ROLE, null);
                }
            } catch (NotImplementedException e) {
                if (log.isDebugEnabled()) {
                    log.debug("isExistingRoleName is not implemented in the RoleManagementService. " + "Therefore, proceeding without validating outbound provisioning role existence.");
                }
            }
        }
    } catch (IdentityRoleManagementException e) {
        throw IdPManagementUtil.handleServerException(IdPManagementConstants.ErrorMessage.ERROR_CODE_VALIDATING_OUTBOUND_PROVISIONING_ROLES, null, e);
    }
}
Also used : RoleManagementService(org.wso2.carbon.identity.role.mgt.core.RoleManagementService) NotImplementedException(org.apache.commons.lang.NotImplementedException) IdentityRoleManagementException(org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException)

Example 63 with IdentityRoleManagementException

use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException 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 64 with IdentityRoleManagementException

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

the class SCIMRoleManagerTest method testListRolesWithGETUnExpectedServerError.

@Test(dataProvider = "dataProviderForListRolesWithGETUnExpectedServerError")
public void testListRolesWithGETUnExpectedServerError(String nodeType, String tenantDomain, String sError) throws IdentityRoleManagementException {
    Node rootNode = generateNodeBasedOnNodeType(nodeType, "name");
    when(mockRoleManagementService.getRoles(anyInt(), anyInt(), anyString(), anyString(), anyString())).thenThrow(unExpectedErrorThrower(tenantDomain, sError, "Error while listing roles in tenantDomain: "));
    when(mockRoleManagementService.getRoles(anyString(), anyInt(), anyInt(), anyString(), anyString(), anyString())).thenThrow(unExpectedErrorThrower(tenantDomain, sError, "Error while listing roles in tenantDomain: "));
    SCIMRoleManager roleManager = new SCIMRoleManager(mockRoleManagementService, tenantDomain);
    assertThrows(CharonException.class, () -> roleManager.listRolesWithGET(rootNode, 2, 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) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 65 with IdentityRoleManagementException

use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException 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)

Aggregations

IdentityRoleManagementClientException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException)29 IdentityRoleManagementServerException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementServerException)23 RoleBasicInfo (org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo)22 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)20 Test (org.testng.annotations.Test)20 NamedPreparedStatement (org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement)20 Connection (java.sql.Connection)19 SQLException (java.sql.SQLException)19 Matchers.anyString (org.mockito.Matchers.anyString)14 IdentityRoleManagementException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException)14 Role (org.wso2.charon3.core.objects.Role)13 ResultSet (java.sql.ResultSet)12 RoleManagementEventPublisherProxy (org.wso2.carbon.identity.role.mgt.core.RoleManagementEventPublisherProxy)11 ArrayList (java.util.ArrayList)9 CharonException (org.wso2.charon3.core.exceptions.CharonException)8 ExpressionNode (org.wso2.charon3.core.utils.codeutils.ExpressionNode)8 Node (org.wso2.charon3.core.utils.codeutils.Node)8 OperationNode (org.wso2.charon3.core.utils.codeutils.OperationNode)8 UserStoreException (org.wso2.carbon.user.api.UserStoreException)6 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)6