use of org.wso2.carbon.identity.role.mgt.core.GroupBasicInfo in project carbon-identity-framework by wso2.
the class RoleDAOImpl method getGroupListOfRole.
@Override
public List<GroupBasicInfo> getGroupListOfRole(String roleID, String tenantDomain) throws IdentityRoleManagementException {
if (!isExistingRoleID(roleID, tenantDomain)) {
throw new IdentityRoleManagementClientException(ROLE_NOT_FOUND.getCode(), "Role id: " + roleID + " does not exist in the system.");
}
String roleName = getRoleNameByID(roleID, tenantDomain);
int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
List<GroupBasicInfo> groupList = new ArrayList<>();
List<String> groupNames = new ArrayList<>();
List<String> disabledDomainName = getDisabledDomainNames();
String primaryDomainName = IdentityUtil.getPrimaryDomainName();
if (primaryDomainName != null) {
primaryDomainName = primaryDomainName.toUpperCase(Locale.ENGLISH);
}
try (Connection connection = IdentityDatabaseUtil.getUserDBConnection(false)) {
try (NamedPreparedStatement statement = new NamedPreparedStatement(connection, GET_GROUP_LIST_OF_ROLE_SQL, RoleTableColumns.UM_ID)) {
statement.setString(RoleTableColumns.UM_ROLE_NAME, roleName);
statement.setInt(RoleTableColumns.UM_TENANT_ID, tenantId);
try (ResultSet resultSet = statement.executeQuery()) {
while (resultSet.next()) {
String name = resultSet.getString(1);
String domain = resultSet.getString(2);
if (!disabledDomainName.contains(domain)) {
if (!StringUtils.equals(primaryDomainName, domain)) {
name = UserCoreUtil.addDomainToName(name, domain);
} else {
name = primaryDomainName + UserCoreConstants.DOMAIN_SEPARATOR + name;
}
groupNames.add(name);
}
}
}
}
} catch (SQLException e) {
String errorMessage = "Error while while getting the group list of role for role name: %s in the " + "tenantDomain: %s";
throw new IdentityRoleManagementServerException(UNEXPECTED_SERVER_ERROR.getCode(), String.format(errorMessage, roleName, tenantDomain), e);
}
Map<String, String> groupNamesToIDs = getGroupIDsByNames(groupNames, tenantDomain);
groupNamesToIDs.forEach((groupName, groupID) -> groupList.add(new GroupBasicInfo(groupID, groupName)));
return groupList;
}
use of org.wso2.carbon.identity.role.mgt.core.GroupBasicInfo in project carbon-identity-framework by wso2.
the class RoleManagementServiceImpl method getGroupListOfRole.
@Override
public List<GroupBasicInfo> getGroupListOfRole(String roleID, String tenantDomain) throws IdentityRoleManagementException {
RoleManagementEventPublisherProxy roleManagementEventPublisherProxy = RoleManagementEventPublisherProxy.getInstance();
roleManagementEventPublisherProxy.publishPreGetUserListOfRole(roleID, tenantDomain);
List<GroupBasicInfo> groupBasicInfoList = roleDAO.getGroupListOfRole(roleID, tenantDomain);
roleManagementEventPublisherProxy.publishPostGetUserListOfRole(roleID, tenantDomain);
if (log.isDebugEnabled()) {
log.debug(String.format("%s get list of groups of role of id : %s successfully.", getUser(tenantDomain), roleID));
}
return groupBasicInfoList;
}
use of org.wso2.carbon.identity.role.mgt.core.GroupBasicInfo in project identity-inbound-provisioning-scim2 by wso2-extensions.
the class SCIMRoleManagerTest method getDummyIdentityRole.
private org.wso2.carbon.identity.role.mgt.core.Role getDummyIdentityRole(String roleId, String roleName, String domain, String tenantDomain) {
org.wso2.carbon.identity.role.mgt.core.Role role = new org.wso2.carbon.identity.role.mgt.core.Role();
role.setId(roleId);
role.setPermissions(Arrays.asList("permission", "usermgt"));
role.setName(roleName);
role.setDomain(domain);
role.setTenantDomain(tenantDomain);
role.setUsers(Arrays.asList(new UserBasicInfo("7646b885-4207-4ca0-bc65-5df82272b6d1", "username1"), new UserBasicInfo("7646b885-4207-4ca0-bc65-5df82272b6d2", "username2")));
GroupBasicInfo groupBasicInfo1 = new GroupBasicInfo();
groupBasicInfo1.setName("groupName1");
groupBasicInfo1.setId("26d3a726-9c00-4f4c-8a4e-f5e310138081");
GroupBasicInfo groupBasicInfo2 = new GroupBasicInfo();
groupBasicInfo2.setName("groupName2");
groupBasicInfo2.setId("26d3a726-9c00-4f4c-8a4e-f5e310138082");
role.setGroups(Arrays.asList(groupBasicInfo1, groupBasicInfo2));
return role;
}
use of org.wso2.carbon.identity.role.mgt.core.GroupBasicInfo in project identity-inbound-provisioning-scim2 by wso2-extensions.
the class SCIMRoleManager method getRole.
@Override
public Role getRole(String roleID, Map<String, Boolean> requiredAttributes) throws BadRequestException, CharonException, NotFoundException {
try {
org.wso2.carbon.identity.role.mgt.core.Role role = roleManagementService.getRole(roleID, tenantDomain);
Role scimRole = new Role();
scimRole.setId(role.getId());
scimRole.setDisplayName(role.getName());
String locationURI = SCIMCommonUtils.getSCIMRoleURL(role.getId());
scimRole.setLocation(locationURI);
scimRole.setPermissions(role.getPermissions());
scimRole.setSchemas();
if (systemRoles.contains(role.getName())) {
scimRole.setSystemRole(true);
}
if (CollectionUtils.isNotEmpty(role.getUsers())) {
for (UserBasicInfo userInfo : role.getUsers()) {
String userLocationURI = SCIMCommonUtils.getSCIMUserURL(userInfo.getId());
User user = new User();
user.setUserName(userInfo.getName());
user.setId(userInfo.getId());
user.setLocation(userLocationURI);
scimRole.setUser(user);
}
}
if (CollectionUtils.isNotEmpty(role.getGroups())) {
for (GroupBasicInfo groupInfo : role.getGroups()) {
String groupLocationURI = SCIMCommonUtils.getSCIMGroupURL(groupInfo.getId());
Group group = new Group();
group.setDisplayName(groupInfo.getName());
group.setId(groupInfo.getId());
group.setLocation(groupLocationURI);
scimRole.setGroup(group);
}
}
return scimRole;
} catch (IdentityRoleManagementException e) {
if (StringUtils.equals(ROLE_NOT_FOUND.getCode(), e.getErrorCode())) {
throw new NotFoundException(e.getMessage());
}
throw new CharonException(String.format("Error occurred while getting the role: %s", roleID), e);
}
}
use of org.wso2.carbon.identity.role.mgt.core.GroupBasicInfo 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