Search in sources :

Example 16 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 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");
}
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)

Example 17 with RoleBasicInfo

use of org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo 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);
    }
}
Also used : Role(org.wso2.charon3.core.objects.Role) ConflictException(org.wso2.charon3.core.exceptions.ConflictException) BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException) CharonException(org.wso2.charon3.core.exceptions.CharonException) RoleBasicInfo(org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo) IdentityRoleManagementException(org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException)

Example 18 with RoleBasicInfo

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

the class RoleDAOTest method testGetUserListOfRole.

@Test
public void testGetUserListOfRole() throws Exception {
    try (Connection connection1 = DAOUtils.getConnection(DB_NAME);
        Connection connection2 = DAOUtils.getConnection(DB_NAME);
        Connection connection3 = DAOUtils.getConnection(DB_NAME);
        Connection connection4 = DAOUtils.getConnection(DB_NAME);
        Connection connection5 = DAOUtils.getConnection(DB_NAME);
        Connection connection6 = DAOUtils.getConnection(DB_NAME)) {
        roleDAO = spy(RoleMgtDAOFactory.getInstance().getRoleDAO());
        when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection1);
        when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection2);
        RoleBasicInfo role = addRole("role1");
        doReturn(true).when(roleDAO, "isExistingRoleName", anyString(), anyString());
        doCallRealMethod().when(roleDAO, "updateUserListOfRole", anyString(), anyCollection(), anyCollection(), anyString());
        when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection3);
        when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection4);
        mockStatic(IdentityUtil.class);
        when(IdentityUtil.getPrimaryDomainName()).thenReturn("PRIMARY");
        doReturn(userNamesList).when(roleDAO, "getUserNamesByIDs", eq(userIDsList), anyString());
        roleDAO.updateUserListOfRole(role.getId(), userIDsList, null, SAMPLE_TENANT_DOMAIN);
        mockRealmConfiguration();
        mockStatic(UserCoreUtil.class);
        when(UserCoreUtil.isEveryoneRole(anyString(), any(RealmConfiguration.class))).thenReturn(false);
        when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection5);
        when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection6);
        doCallRealMethod().when(UserCoreUtil.class, "addDomainToName", anyString(), anyString());
        doReturn("userID1").when(roleDAO, "getUserIDByName", eq(userNamesList.get(0)), anyString());
        doReturn("userID2").when(roleDAO, "getUserIDByName", eq(userNamesList.get(1)), anyString());
        List<UserBasicInfo> users = roleDAO.getUserListOfRole(role.getId(), SAMPLE_TENANT_DOMAIN);
        assertEquals(getUserNamesList(users), userNamesList);
    }
}
Also used : RealmConfiguration(org.wso2.carbon.user.api.RealmConfiguration) UserBasicInfo(org.wso2.carbon.identity.role.mgt.core.UserBasicInfo) Connection(java.sql.Connection) RoleBasicInfo(org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 19 with RoleBasicInfo

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

the class RoleDAOTest method testGetRoleIDByName.

@Test
public void testGetRoleIDByName() throws Exception {
    try (Connection connection1 = DAOUtils.getConnection(DB_NAME);
        Connection connection2 = DAOUtils.getConnection(DB_NAME);
        Connection connection3 = DAOUtils.getConnection(DB_NAME)) {
        roleDAO = spy(RoleMgtDAOFactory.getInstance().getRoleDAO());
        when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection1);
        when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection2);
        RoleBasicInfo role = addRole("role1");
        doCallRealMethod().when(roleDAO, "getRoleIDByName", anyString(), anyString());
        when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection3);
        when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection3);
        assertEquals(roleDAO.getRoleIDByName("Internal/role1", SAMPLE_TENANT_DOMAIN), role.getId());
    }
}
Also used : Connection(java.sql.Connection) RoleBasicInfo(org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 20 with RoleBasicInfo

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

the class RoleDAOTest method testGetGroupListOfRole.

@Test
public void testGetGroupListOfRole() throws Exception {
    try (Connection connection1 = DAOUtils.getConnection(DB_NAME);
        Connection connection2 = DAOUtils.getConnection(DB_NAME);
        Connection connection3 = DAOUtils.getConnection(DB_NAME);
        Connection connection4 = DAOUtils.getConnection(DB_NAME);
        Connection connection5 = DAOUtils.getConnection(DB_NAME);
        Connection connection6 = DAOUtils.getConnection(DB_NAME)) {
        roleDAO = spy(RoleMgtDAOFactory.getInstance().getRoleDAO());
        when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection1);
        when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection2);
        RoleBasicInfo role = addRole("role1");
        doReturn(true).when(roleDAO, "isExistingRoleName", anyString(), anyString());
        doCallRealMethod().when(roleDAO, "updateGroupListOfRole", anyString(), anyCollection(), anyCollection(), anyString());
        when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection3);
        when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection4);
        mockStatic(IdentityUtil.class);
        when(IdentityUtil.getPrimaryDomainName()).thenReturn("PRIMARY");
        doReturn(groupNamesMap).when(roleDAO, "getGroupNamesByIDs", eq(groupIDsList), anyString());
        roleDAO.updateGroupListOfRole(role.getId(), groupIDsList, null, SAMPLE_TENANT_DOMAIN);
        mockRealmConfiguration();
        mockStatic(UserCoreUtil.class);
        when(UserCoreUtil.isEveryoneRole(anyString(), any(RealmConfiguration.class))).thenReturn(false);
        when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection5);
        when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection6);
        doCallRealMethod().when(UserCoreUtil.class, "addDomainToName", anyString(), anyString());
        List<GroupBasicInfo> groups = roleDAO.getGroupListOfRole(role.getId(), SAMPLE_TENANT_DOMAIN);
        assertEquals(getGroupNamesList(groups), groupNamesList);
    }
}
Also used : RealmConfiguration(org.wso2.carbon.user.api.RealmConfiguration) GroupBasicInfo(org.wso2.carbon.identity.role.mgt.core.GroupBasicInfo) Connection(java.sql.Connection) 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