Search in sources :

Example 11 with RoleBasicInfo

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

the class RoleManagementServiceImpl method getRoles.

@Override
public List<RoleBasicInfo> getRoles(String filter, Integer limit, Integer offset, String sortBy, String sortOrder, String tenantDomain) throws IdentityRoleManagementException {
    RoleManagementEventPublisherProxy roleManagementEventPublisherProxy = RoleManagementEventPublisherProxy.getInstance();
    roleManagementEventPublisherProxy.publishPreGetRoles(filter, limit, offset, sortBy, sortOrder, tenantDomain);
    List<RoleBasicInfo> roleBasicInfoList = roleDAO.getRoles(filter, limit, offset, sortBy, sortOrder, tenantDomain);
    roleManagementEventPublisherProxy.publishPostGetRoles(filter, limit, offset, sortBy, sortOrder, tenantDomain);
    if (log.isDebugEnabled()) {
        log.debug(String.format("%s get filtered roles successfully.", getUser(tenantDomain)));
    }
    return roleBasicInfoList;
}
Also used : RoleManagementEventPublisherProxy(org.wso2.carbon.identity.role.mgt.core.RoleManagementEventPublisherProxy) RoleBasicInfo(org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo)

Example 12 with RoleBasicInfo

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

the class SCIMRoleManagerTest method testCreateRolePositive.

@Test(dataProvider = "dataProviderForCreateRolePositive")
public void testCreateRolePositive(String roleId, String roleDisplayName, String tenantDomain) throws IdentityRoleManagementException, BadRequestException, CharonException, ConflictException {
    Role role = getDummyRole(roleId, roleDisplayName);
    when(mockRoleManagementService.addRole(anyString(), anyListOf(String.class), anyListOf(String.class), anyListOf(String.class), anyString())).thenReturn(new RoleBasicInfo(roleId, roleDisplayName));
    SCIMRoleManager scimRoleManager = new SCIMRoleManager(mockRoleManagementService, tenantDomain);
    Role createdRole = scimRoleManager.createRole(role);
    assertEquals(createdRole.getDisplayName(), roleDisplayName);
    assertEquals(createdRole.getId(), roleId);
}
Also used : Role(org.wso2.charon3.core.objects.Role) Matchers.anyString(org.mockito.Matchers.anyString) RoleBasicInfo(org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 13 with RoleBasicInfo

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

the class SCIMRoleManagerTest method testUpdateRoleUpdateGroupListOfRoleThrowingErrors.

@Test(dataProvider = "dataProviderForUpdateRoleUpdateGroupListOfRoleThrowingErrors", expectedExceptions = { BadRequestException.class, CharonException.class })
public void testUpdateRoleUpdateGroupListOfRoleThrowingErrors(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.updateGroupListOfRole(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;
    });
    when(mockRoleManagementService.updateUserListOfRole(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)

Example 14 with RoleBasicInfo

use of org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo 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]);
}
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)

Example 15 with RoleBasicInfo

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

the class SCIMRoleManagerTest method testListRolesWithPOSTPositive.

@Test(dataProvider = "dataProviderForListRolesWithPOSTPositive")
public void testListRolesWithPOSTPositive(String nodeType, 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.listRolesWithPost(getDummySearchRequest(rootNode, 2, 3, null, null));
    assertTrue(true, "listRolesWIthPost run successfully");
}
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) RoleBasicInfo(org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

RoleBasicInfo (org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo)34 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)17 Test (org.testng.annotations.Test)17 Connection (java.sql.Connection)15 ArrayList (java.util.ArrayList)8 IdentityRoleManagementClientException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException)8 Matchers.anyString (org.mockito.Matchers.anyString)7 RealmConfiguration (org.wso2.carbon.user.api.RealmConfiguration)7 Role (org.wso2.charon3.core.objects.Role)7 IdentityRoleManagementServerException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementServerException)6 RoleManagementEventPublisherProxy (org.wso2.carbon.identity.role.mgt.core.RoleManagementEventPublisherProxy)6 SQLException (java.sql.SQLException)5 IdentityRoleManagementException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException)5 NamedPreparedStatement (org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement)3 CharonException (org.wso2.charon3.core.exceptions.CharonException)3 GroupBasicInfo (org.wso2.carbon.identity.role.mgt.core.GroupBasicInfo)2 UserBasicInfo (org.wso2.carbon.identity.role.mgt.core.UserBasicInfo)2 AuthorizationManager (org.wso2.carbon.user.api.AuthorizationManager)2 JDBCAuthorizationManager (org.wso2.carbon.user.core.authorization.JDBCAuthorizationManager)2 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)2