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");
}
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);
}
}
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);
}
}
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());
}
}
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);
}
}
Aggregations