|
|
@ -22,7 +22,12 @@ import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.wso2.carbon.CarbonConstants;
|
|
|
|
import org.wso2.carbon.CarbonConstants;
|
|
|
|
import org.wso2.carbon.context.CarbonContext;
|
|
|
|
import org.wso2.carbon.context.CarbonContext;
|
|
|
|
import org.wso2.carbon.device.mgt.common.*;
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
|
|
|
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
|
|
|
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.group.mgt.GroupUser;
|
|
|
|
import org.wso2.carbon.device.mgt.common.group.mgt.GroupUser;
|
|
|
@ -38,18 +43,21 @@ import org.wso2.carbon.user.api.UserStoreManager;
|
|
|
|
import org.wso2.carbon.user.core.util.UserCoreUtil;
|
|
|
|
import org.wso2.carbon.user.core.util.UserCoreUtil;
|
|
|
|
|
|
|
|
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
public class GroupManagementServiceProviderImpl implements GroupManagementServiceProvider {
|
|
|
|
public class GroupManagementProviderServiceImpl implements GroupManagementProviderService {
|
|
|
|
|
|
|
|
|
|
|
|
private static Log log = LogFactory.getLog(GroupManagementServiceProviderImpl.class);
|
|
|
|
private static Log log = LogFactory.getLog(GroupManagementProviderServiceImpl.class);
|
|
|
|
|
|
|
|
|
|
|
|
private GroupDAO groupDAO;
|
|
|
|
private GroupDAO groupDAO;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Set groupDAO from GroupManagementDAOFactory when class instantiate.
|
|
|
|
* Set groupDAO from GroupManagementDAOFactory when class instantiate.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public GroupManagementServiceProviderImpl() {
|
|
|
|
public GroupManagementProviderServiceImpl() {
|
|
|
|
this.groupDAO = GroupManagementDAOFactory.getGroupDAO();
|
|
|
|
this.groupDAO = GroupManagementDAOFactory.getGroupDAO();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -71,6 +79,10 @@ public class GroupManagementServiceProviderImpl implements GroupManagementServic
|
|
|
|
if (!nameIsExists) {
|
|
|
|
if (!nameIsExists) {
|
|
|
|
groupId = this.groupDAO.addGroup(groupBroker, tenantId);
|
|
|
|
groupId = this.groupDAO.addGroup(groupBroker, tenantId);
|
|
|
|
GroupManagementDAOFactory.commitTransaction();
|
|
|
|
GroupManagementDAOFactory.commitTransaction();
|
|
|
|
|
|
|
|
if (groupId < 0) {
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
groupBroker.setId(groupId);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return -2;
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -83,10 +95,8 @@ public class GroupManagementServiceProviderImpl implements GroupManagementServic
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
GroupManagementDAOFactory.closeConnection();
|
|
|
|
GroupManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (groupId == -1) {
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
addGroupSharingRole(groupBroker.getOwner(), groupId, defaultRole, defaultPermissions);
|
|
|
|
}
|
|
|
|
|
|
|
|
addGroupSharingRole(groupBroker.getOwner(), deviceGroup.getName(), defaultRole, defaultPermissions);
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("DeviceGroup added: " + groupBroker.getName());
|
|
|
|
log.debug("DeviceGroup added: " + groupBroker.getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -120,30 +130,22 @@ public class GroupManagementServiceProviderImpl implements GroupManagementServic
|
|
|
|
* {@inheritDoc}
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean deleteGroup(String groupName) throws GroupManagementException {
|
|
|
|
public boolean deleteGroup(int groupId) throws GroupManagementException {
|
|
|
|
String roleName;
|
|
|
|
String roleName;
|
|
|
|
DeviceGroup deviceGroup = getGroup(groupName);
|
|
|
|
DeviceGroup deviceGroup = getGroup(groupId);
|
|
|
|
if (deviceGroup == null) {
|
|
|
|
if (deviceGroup == null) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<String> groupRoles = getRoles(groupName);
|
|
|
|
List<String> groupRoles = getRoles(groupId);
|
|
|
|
for (String role : groupRoles) {
|
|
|
|
for (String role : groupRoles) {
|
|
|
|
if (role != null) {
|
|
|
|
if (role != null) {
|
|
|
|
roleName = role.replace("Internal/group-" + groupName + "-", "");
|
|
|
|
roleName = role.replace("Internal/group-" + groupId + "-", "");
|
|
|
|
removeGroupSharingRole(groupName, roleName);
|
|
|
|
removeGroupSharingRole(groupId, roleName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<Device> groupDevices = getDevices(groupName);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
for (Device device : groupDevices) {
|
|
|
|
|
|
|
|
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().modifyEnrollment(device);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
throw new GroupManagementException("Error occurred while removing device from group.", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
GroupManagementDAOFactory.beginTransaction();
|
|
|
|
GroupManagementDAOFactory.beginTransaction();
|
|
|
|
this.groupDAO.deleteGroup(groupName, CarbonContext.getThreadLocalCarbonContext().getTenantId());
|
|
|
|
this.groupDAO.deleteGroup(groupId, CarbonContext.getThreadLocalCarbonContext().getTenantId());
|
|
|
|
GroupManagementDAOFactory.commitTransaction();
|
|
|
|
GroupManagementDAOFactory.commitTransaction();
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("DeviceGroup " + deviceGroup.getName() + " removed.");
|
|
|
|
log.debug("DeviceGroup " + deviceGroup.getName() + " removed.");
|
|
|
@ -152,7 +154,7 @@ public class GroupManagementServiceProviderImpl implements GroupManagementServic
|
|
|
|
} catch (GroupManagementDAOException e) {
|
|
|
|
} catch (GroupManagementDAOException e) {
|
|
|
|
GroupManagementDAOFactory.rollbackTransaction();
|
|
|
|
GroupManagementDAOFactory.rollbackTransaction();
|
|
|
|
throw new GroupManagementException("Error occurred while removing group " +
|
|
|
|
throw new GroupManagementException("Error occurred while removing group " +
|
|
|
|
"'" + groupName + "' data.", e);
|
|
|
|
"'" + groupId + "' data.", e);
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
throw new GroupManagementException("Error occurred while initiating transaction.", e);
|
|
|
|
throw new GroupManagementException("Error occurred while initiating transaction.", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
@ -164,21 +166,21 @@ public class GroupManagementServiceProviderImpl implements GroupManagementServic
|
|
|
|
* {@inheritDoc}
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public DeviceGroup getGroup(String groupName) throws GroupManagementException {
|
|
|
|
public DeviceGroup getGroup(int groupId) throws GroupManagementException {
|
|
|
|
DeviceGroupBuilder groupBroker;
|
|
|
|
DeviceGroupBuilder groupBroker;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
GroupManagementDAOFactory.openConnection();
|
|
|
|
GroupManagementDAOFactory.openConnection();
|
|
|
|
groupBroker = this.groupDAO.getGroup(groupName, CarbonContext.getThreadLocalCarbonContext().getTenantId());
|
|
|
|
groupBroker = this.groupDAO.getGroup(groupId, CarbonContext.getThreadLocalCarbonContext().getTenantId());
|
|
|
|
} catch (GroupManagementDAOException e) {
|
|
|
|
} catch (GroupManagementDAOException e) {
|
|
|
|
throw new GroupManagementException("Error occurred while obtaining group " + groupName, e);
|
|
|
|
throw new GroupManagementException("Error occurred while obtaining group " + groupId, e);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new GroupManagementException("Error occurred while opening a connection to the data source.", e);
|
|
|
|
throw new GroupManagementException("Error occurred while opening a connection to the data source.", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
GroupManagementDAOFactory.closeConnection();
|
|
|
|
GroupManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (groupBroker != null) {
|
|
|
|
if (groupBroker != null) {
|
|
|
|
groupBroker.setUsers(this.getUsers(groupName));
|
|
|
|
groupBroker.setUsers(this.getUsers(groupId));
|
|
|
|
groupBroker.setRoles(this.getRoles(groupName));
|
|
|
|
groupBroker.setRoles(this.getRoles(groupId));
|
|
|
|
return groupBroker.getGroup();
|
|
|
|
return groupBroker.getGroup();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
@ -189,12 +191,12 @@ public class GroupManagementServiceProviderImpl implements GroupManagementServic
|
|
|
|
* {@inheritDoc}
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<DeviceGroup> findGroups(String groupName, String owner) throws GroupManagementException {
|
|
|
|
public List<DeviceGroup> findInGroups(String groupName, String owner) throws GroupManagementException {
|
|
|
|
List<DeviceGroupBuilder> deviceGroups = new ArrayList<>();
|
|
|
|
List<DeviceGroupBuilder> deviceGroups = new ArrayList<>();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
GroupManagementDAOFactory.openConnection();
|
|
|
|
GroupManagementDAOFactory.openConnection();
|
|
|
|
deviceGroups = this.groupDAO.getGroups(groupName, tenantId);
|
|
|
|
deviceGroups = this.groupDAO.findInGroups(groupName, tenantId);
|
|
|
|
} catch (GroupManagementDAOException e) {
|
|
|
|
} catch (GroupManagementDAOException e) {
|
|
|
|
throw new GroupManagementException("Error occurred while finding group " + groupName, e);
|
|
|
|
throw new GroupManagementException("Error occurred while finding group " + groupName, e);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
@ -204,8 +206,8 @@ public class GroupManagementServiceProviderImpl implements GroupManagementServic
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<DeviceGroup> groupsWithData = new ArrayList<>();
|
|
|
|
List<DeviceGroup> groupsWithData = new ArrayList<>();
|
|
|
|
for (DeviceGroupBuilder groupBroker : deviceGroups) {
|
|
|
|
for (DeviceGroupBuilder groupBroker : deviceGroups) {
|
|
|
|
groupBroker.setUsers(this.getUsers(groupBroker.getName()));
|
|
|
|
groupBroker.setUsers(this.getUsers(groupBroker.getId()));
|
|
|
|
groupBroker.setRoles(this.getRoles(groupBroker.getName()));
|
|
|
|
groupBroker.setRoles(this.getRoles(groupBroker.getId()));
|
|
|
|
groupsWithData.add(groupBroker.getGroup());
|
|
|
|
groupsWithData.add(groupBroker.getGroup());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return groupsWithData;
|
|
|
|
return groupsWithData;
|
|
|
@ -222,13 +224,12 @@ public class GroupManagementServiceProviderImpl implements GroupManagementServic
|
|
|
|
userStoreManager = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId)
|
|
|
|
userStoreManager = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId)
|
|
|
|
.getUserStoreManager();
|
|
|
|
.getUserStoreManager();
|
|
|
|
String[] roleList = userStoreManager.getRoleListOfUser(username);
|
|
|
|
String[] roleList = userStoreManager.getRoleListOfUser(username);
|
|
|
|
Map<String, DeviceGroup> groups = new HashMap<>();
|
|
|
|
Map<Integer, DeviceGroup> groups = new HashMap<>();
|
|
|
|
for (String role : roleList) {
|
|
|
|
for (String role : roleList) {
|
|
|
|
if (role != null && role.contains("Internal/group-")) {
|
|
|
|
if (role != null && role.contains("Internal/group-")) {
|
|
|
|
String groupName = role.split("-")[1];
|
|
|
|
DeviceGroup deviceGroup = extractNewGroupFromRole(groups, role);
|
|
|
|
if (!groups.containsKey(groupName)) {
|
|
|
|
if (deviceGroup != null) {
|
|
|
|
DeviceGroup deviceGroup = getGroup(groupName);
|
|
|
|
groups.put(deviceGroup.getId(), deviceGroup);
|
|
|
|
groups.put(groupName, deviceGroup);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -250,66 +251,39 @@ public class GroupManagementServiceProviderImpl implements GroupManagementServic
|
|
|
|
* {@inheritDoc}
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean shareGroup(String username, String groupName, String sharingRole)
|
|
|
|
public boolean shareGroup(String username, int groupId, String sharingRole)
|
|
|
|
throws GroupManagementException {
|
|
|
|
throws GroupManagementException {
|
|
|
|
return modifyGroupShare(username, groupName, sharingRole, true);
|
|
|
|
return modifyGroupShare(username, groupId, sharingRole, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean unshareGroup(String username, String groupName, String sharingRole)
|
|
|
|
public boolean unshareGroup(String username, int groupId, String sharingRole)
|
|
|
|
throws GroupManagementException {
|
|
|
|
throws GroupManagementException {
|
|
|
|
return modifyGroupShare(username, groupName, sharingRole, false);
|
|
|
|
return modifyGroupShare(username, groupId, sharingRole, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean modifyGroupShare(String username, String groupName, String sharingRole,
|
|
|
|
|
|
|
|
boolean isAddNew)
|
|
|
|
|
|
|
|
throws GroupManagementException {
|
|
|
|
|
|
|
|
UserStoreManager userStoreManager;
|
|
|
|
|
|
|
|
String[] roles = new String[1];
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
DeviceGroup deviceGroup = getGroup(groupName);
|
|
|
|
|
|
|
|
if (deviceGroup == null) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
userStoreManager =
|
|
|
|
|
|
|
|
DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(
|
|
|
|
|
|
|
|
tenantId).getUserStoreManager();
|
|
|
|
|
|
|
|
roles[0] = "Internal/group-" + groupName + "-" + sharingRole;
|
|
|
|
|
|
|
|
if (isAddNew) {
|
|
|
|
|
|
|
|
userStoreManager.updateRoleListOfUser(username, null, roles);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
userStoreManager.updateRoleListOfUser(username, roles, null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
|
|
|
|
throw new GroupManagementException("User store error in adding user " + username + " to group name:" +
|
|
|
|
|
|
|
|
groupName, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean addGroupSharingRole(String username, String groupName, String roleName,
|
|
|
|
public boolean addGroupSharingRole(String username, int groupId, String roleName,
|
|
|
|
String[] permissions)
|
|
|
|
String[] permissions)
|
|
|
|
throws GroupManagementException {
|
|
|
|
throws GroupManagementException {
|
|
|
|
UserStoreManager userStoreManager;
|
|
|
|
UserStoreManager userStoreManager;
|
|
|
|
String role;
|
|
|
|
String role;
|
|
|
|
String[] userNames = new String[1];
|
|
|
|
String[] userNames = new String[1];
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
DeviceGroup deviceGroup = getGroup(groupName);
|
|
|
|
DeviceGroup deviceGroup = getGroup(groupId);
|
|
|
|
if (deviceGroup == null) {
|
|
|
|
if (deviceGroup == null) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
userStoreManager = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId)
|
|
|
|
userStoreManager = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId)
|
|
|
|
.getUserStoreManager();
|
|
|
|
.getUserStoreManager();
|
|
|
|
role = "Internal/group-" + groupName + "-" + roleName;
|
|
|
|
role = "Internal/group-" + groupId + "-" + roleName;
|
|
|
|
userNames[0] = username;
|
|
|
|
userNames[0] = username;
|
|
|
|
Permission[] carbonPermissions = new Permission[permissions.length];
|
|
|
|
Permission[] carbonPermissions = new Permission[permissions.length];
|
|
|
|
for (int i = 0; i < permissions.length; i++) {
|
|
|
|
for (int i = 0; i < permissions.length; i++) {
|
|
|
@ -318,8 +292,7 @@ public class GroupManagementServiceProviderImpl implements GroupManagementServic
|
|
|
|
userStoreManager.addRole(role, userNames, carbonPermissions);
|
|
|
|
userStoreManager.addRole(role, userNames, carbonPermissions);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
String errorMsg = "User store error in adding role to group id:" + groupName;
|
|
|
|
String errorMsg = "User store error in adding role to group id:" + groupId;
|
|
|
|
log.error(errorMsg, e);
|
|
|
|
|
|
|
|
throw new GroupManagementException(errorMsg, e);
|
|
|
|
throw new GroupManagementException(errorMsg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -328,23 +301,23 @@ public class GroupManagementServiceProviderImpl implements GroupManagementServic
|
|
|
|
* {@inheritDoc}
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean removeGroupSharingRole(String groupName, String roleName)
|
|
|
|
public boolean removeGroupSharingRole(int groupId, String roleName)
|
|
|
|
throws GroupManagementException {
|
|
|
|
throws GroupManagementException {
|
|
|
|
UserStoreManager userStoreManager;
|
|
|
|
UserStoreManager userStoreManager;
|
|
|
|
String role;
|
|
|
|
String role;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
DeviceGroup deviceGroup = getGroup(groupName);
|
|
|
|
DeviceGroup deviceGroup = getGroup(groupId);
|
|
|
|
if (deviceGroup == null) {
|
|
|
|
if (deviceGroup == null) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
userStoreManager = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId)
|
|
|
|
userStoreManager = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId)
|
|
|
|
.getUserStoreManager();
|
|
|
|
.getUserStoreManager();
|
|
|
|
role = "Internal/group-" + groupName + "-" + roleName;
|
|
|
|
role = "Internal/group-" + groupId + "-" + roleName;
|
|
|
|
userStoreManager.deleteRole(role);
|
|
|
|
userStoreManager.deleteRole(role);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
} catch (UserStoreException userStoreEx) {
|
|
|
|
} catch (UserStoreException userStoreEx) {
|
|
|
|
String errorMsg = "User store error in adding role to group id:" + groupName;
|
|
|
|
String errorMsg = "User store error in adding role to group id:" + groupId;
|
|
|
|
log.error(errorMsg, userStoreEx);
|
|
|
|
log.error(errorMsg, userStoreEx);
|
|
|
|
throw new GroupManagementException(errorMsg, userStoreEx);
|
|
|
|
throw new GroupManagementException(errorMsg, userStoreEx);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -354,7 +327,7 @@ public class GroupManagementServiceProviderImpl implements GroupManagementServic
|
|
|
|
* {@inheritDoc}
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<String> getRoles(String groupName) throws GroupManagementException {
|
|
|
|
public List<String> getRoles(int groupId) throws GroupManagementException {
|
|
|
|
UserStoreManager userStoreManager;
|
|
|
|
UserStoreManager userStoreManager;
|
|
|
|
String[] roles;
|
|
|
|
String[] roles;
|
|
|
|
List<String> groupRoles;
|
|
|
|
List<String> groupRoles;
|
|
|
@ -365,13 +338,13 @@ public class GroupManagementServiceProviderImpl implements GroupManagementServic
|
|
|
|
roles = userStoreManager.getRoleNames();
|
|
|
|
roles = userStoreManager.getRoleNames();
|
|
|
|
groupRoles = new ArrayList<>();
|
|
|
|
groupRoles = new ArrayList<>();
|
|
|
|
for (String r : roles) {
|
|
|
|
for (String r : roles) {
|
|
|
|
if (r != null && r.contains("Internal/group-" + groupName + "-")) {
|
|
|
|
if (r != null && r.contains("Internal/group-" + groupId + "-")) {
|
|
|
|
groupRoles.add(r.replace("Internal/group-" + groupName + "-", ""));
|
|
|
|
groupRoles.add(r.replace("Internal/group-" + groupId + "-", ""));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return groupRoles;
|
|
|
|
return groupRoles;
|
|
|
|
} catch (UserStoreException userStoreEx) {
|
|
|
|
} catch (UserStoreException userStoreEx) {
|
|
|
|
String errorMsg = "User store error in adding role to group id:" + groupName;
|
|
|
|
String errorMsg = "User store error in adding role to group id:" + groupId;
|
|
|
|
log.error(errorMsg, userStoreEx);
|
|
|
|
log.error(errorMsg, userStoreEx);
|
|
|
|
throw new GroupManagementException(errorMsg, userStoreEx);
|
|
|
|
throw new GroupManagementException(errorMsg, userStoreEx);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -381,7 +354,7 @@ public class GroupManagementServiceProviderImpl implements GroupManagementServic
|
|
|
|
* {@inheritDoc}
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<String> getRoles(String username, String groupName) throws GroupManagementException {
|
|
|
|
public List<String> getRoles(String username, int groupId) throws GroupManagementException {
|
|
|
|
UserStoreManager userStoreManager;
|
|
|
|
UserStoreManager userStoreManager;
|
|
|
|
List<String> groupRoleList = new ArrayList<>();
|
|
|
|
List<String> groupRoleList = new ArrayList<>();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -390,8 +363,8 @@ public class GroupManagementServiceProviderImpl implements GroupManagementServic
|
|
|
|
.getUserStoreManager();
|
|
|
|
.getUserStoreManager();
|
|
|
|
String[] roleList = userStoreManager.getRoleListOfUser(username);
|
|
|
|
String[] roleList = userStoreManager.getRoleListOfUser(username);
|
|
|
|
for (String role : roleList) {
|
|
|
|
for (String role : roleList) {
|
|
|
|
if (role != null && role.contains("Internal/group-" + groupName)) {
|
|
|
|
if (role != null && role.contains("Internal/group-" + groupId)) {
|
|
|
|
String roleName = role.replace("Internal/group-" + groupName + "-", "");
|
|
|
|
String roleName = role.replace("Internal/group-" + groupId + "-", "");
|
|
|
|
groupRoleList.add(roleName);
|
|
|
|
groupRoleList.add(roleName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -405,16 +378,16 @@ public class GroupManagementServiceProviderImpl implements GroupManagementServic
|
|
|
|
* {@inheritDoc}
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<GroupUser> getUsers(String groupName) throws GroupManagementException {
|
|
|
|
public List<GroupUser> getUsers(int groupId) throws GroupManagementException {
|
|
|
|
UserStoreManager userStoreManager;
|
|
|
|
UserStoreManager userStoreManager;
|
|
|
|
Map<String, GroupUser> groupUserHashMap = new HashMap<>();
|
|
|
|
Map<String, GroupUser> groupUserHashMap = new HashMap<>();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
userStoreManager = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId)
|
|
|
|
userStoreManager = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId)
|
|
|
|
.getUserStoreManager();
|
|
|
|
.getUserStoreManager();
|
|
|
|
List<String> rolesForGroup = this.getRoles(groupName);
|
|
|
|
List<String> rolesForGroup = this.getRoles(groupId);
|
|
|
|
for (String role : rolesForGroup) {
|
|
|
|
for (String role : rolesForGroup) {
|
|
|
|
String[] users = userStoreManager.getUserListOfRole("Internal/group-" + groupName + "-" + role);
|
|
|
|
String[] users = userStoreManager.getUserListOfRole("Internal/group-" + groupId + "-" + role);
|
|
|
|
for (String user : users) {
|
|
|
|
for (String user : users) {
|
|
|
|
GroupUser groupUser;
|
|
|
|
GroupUser groupUser;
|
|
|
|
if (groupUserHashMap.containsKey(user)) {
|
|
|
|
if (groupUserHashMap.containsKey(user)) {
|
|
|
@ -431,7 +404,7 @@ public class GroupManagementServiceProviderImpl implements GroupManagementServic
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new ArrayList<>(groupUserHashMap.values());
|
|
|
|
return new ArrayList<>(groupUserHashMap.values());
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
String errorMsg = "User store error in fetching user list for group id:" + groupName;
|
|
|
|
String errorMsg = "User store error in fetching user list for group id:" + groupId;
|
|
|
|
log.error(errorMsg, e);
|
|
|
|
log.error(errorMsg, e);
|
|
|
|
throw new GroupManagementException(errorMsg, e);
|
|
|
|
throw new GroupManagementException(errorMsg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -441,53 +414,45 @@ public class GroupManagementServiceProviderImpl implements GroupManagementServic
|
|
|
|
* {@inheritDoc}
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Device> getDevices(String groupName) throws GroupManagementException {
|
|
|
|
public List<Device> getDevices(int groupId) throws GroupManagementException {
|
|
|
|
return Collections.emptyList();
|
|
|
|
try {
|
|
|
|
//TODO: Add a method that returns a collection of devices in a particular group to GroupDAO
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
// try {
|
|
|
|
return this.groupDAO.getDevices(groupId, tenantId);
|
|
|
|
// return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevices(groupName);
|
|
|
|
} catch (GroupManagementDAOException e) {
|
|
|
|
// } catch (DeviceManagementException e) {
|
|
|
|
throw new GroupManagementException("Error occurred while getting devices in group.", e);
|
|
|
|
// throw new GroupManagementException("Error occurred while getting devices in group.", e);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public PaginationResult getDevices(String groupName, PaginationRequest request)
|
|
|
|
public PaginationResult getDevices(int groupId, PaginationRequest request)
|
|
|
|
throws GroupManagementException {
|
|
|
|
throws GroupManagementException {
|
|
|
|
return null;
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
//TODO: Add a method that returns a collection of devices in a particular group to GroupDAO
|
|
|
|
try {
|
|
|
|
// try {
|
|
|
|
return this.groupDAO.getDevices(groupId, request, tenantId);
|
|
|
|
// return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevices(groupName);
|
|
|
|
} catch (GroupManagementDAOException e) {
|
|
|
|
// } catch (DeviceManagementException e) {
|
|
|
|
throw new GroupManagementException("Error occurred while getting devices in group.", e);
|
|
|
|
// throw new GroupManagementException("Error occurred while getting devices in group.", e);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
|
|
|
// return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevices(groupName,
|
|
|
|
|
|
|
|
// request);
|
|
|
|
|
|
|
|
// } catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
// throw new GroupManagementException("Error occurred while getting devices in group.", e);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int getDeviceCount(String groupName) throws GroupManagementException {
|
|
|
|
public int getDeviceCount(int groupId) throws GroupManagementException {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
int count;
|
|
|
|
int count;
|
|
|
|
GroupManagementDAOFactory.beginTransaction();
|
|
|
|
GroupManagementDAOFactory.beginTransaction();
|
|
|
|
count = groupDAO.getDeviceCount(groupName,
|
|
|
|
count = groupDAO.getDeviceCount(groupId,
|
|
|
|
CarbonContext.getThreadLocalCarbonContext().getTenantId());
|
|
|
|
CarbonContext.getThreadLocalCarbonContext().getTenantId());
|
|
|
|
GroupManagementDAOFactory.commitTransaction();
|
|
|
|
GroupManagementDAOFactory.commitTransaction();
|
|
|
|
return count;
|
|
|
|
return count;
|
|
|
|
} catch (GroupManagementDAOException e) {
|
|
|
|
} catch (GroupManagementDAOException e) {
|
|
|
|
GroupManagementDAOFactory.rollbackTransaction();
|
|
|
|
GroupManagementDAOFactory.rollbackTransaction();
|
|
|
|
throw new GroupManagementException("Error occurred while retrieving device count of group " +
|
|
|
|
throw new GroupManagementException("Error occurred while retrieving device count of group " +
|
|
|
|
"'" + groupName + "'.", e);
|
|
|
|
"'" + groupId + "'.", e);
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
throw new GroupManagementException("Error occurred while initiating transaction.", e);
|
|
|
|
throw new GroupManagementException("Error occurred while initiating transaction.", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
@ -499,19 +464,22 @@ public class GroupManagementServiceProviderImpl implements GroupManagementServic
|
|
|
|
* {@inheritDoc}
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean addDevice(DeviceIdentifier deviceId, String groupName)
|
|
|
|
public boolean addDevice(DeviceIdentifier deviceIdentifier, int groupId)
|
|
|
|
throws GroupManagementException {
|
|
|
|
throws GroupManagementException {
|
|
|
|
Device device;
|
|
|
|
Device device;
|
|
|
|
DeviceGroup deviceGroup;
|
|
|
|
DeviceGroup deviceGroup;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceId);
|
|
|
|
device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceIdentifier);
|
|
|
|
deviceGroup = this.getGroup(groupName);
|
|
|
|
deviceGroup = this.getGroup(groupId);
|
|
|
|
if (device == null || deviceGroup == null) {
|
|
|
|
if (device == null || deviceGroup == null) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().modifyEnrollment(device);
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
this.groupDAO.addDevice(groupId, device.getId(), tenantId);
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
throw new GroupManagementException("Error occurred while adding device in to deviceGroup.", e);
|
|
|
|
throw new GroupManagementException("Error occurred while retrieving device.", e);
|
|
|
|
|
|
|
|
} catch (GroupManagementDAOException e) {
|
|
|
|
|
|
|
|
throw new GroupManagementException("Error occurred while adding device to group '" + groupId + "'.", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -520,19 +488,22 @@ public class GroupManagementServiceProviderImpl implements GroupManagementServic
|
|
|
|
* {@inheritDoc}
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean removeDevice(DeviceIdentifier deviceId, String groupName)
|
|
|
|
public boolean removeDevice(DeviceIdentifier deviceIdentifier, int groupId)
|
|
|
|
throws GroupManagementException {
|
|
|
|
throws GroupManagementException {
|
|
|
|
Device device;
|
|
|
|
Device device;
|
|
|
|
DeviceGroup deviceGroup;
|
|
|
|
DeviceGroup deviceGroup;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceId);
|
|
|
|
device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceIdentifier);
|
|
|
|
deviceGroup = this.getGroup(groupName);
|
|
|
|
deviceGroup = this.getGroup(groupId);
|
|
|
|
if (device == null || deviceGroup == null) {
|
|
|
|
if (device == null || deviceGroup == null) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().modifyEnrollment(device);
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
this.groupDAO.removeDevice(groupId, device.getId(), tenantId);
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
throw new GroupManagementException("Error occurred while removing device from deviceGroup.", e);
|
|
|
|
throw new GroupManagementException("Error occurred while retrieving device.", e);
|
|
|
|
|
|
|
|
} catch (GroupManagementDAOException e) {
|
|
|
|
|
|
|
|
throw new GroupManagementException("Error occurred while adding device to group '" + groupId + "'.", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -541,9 +512,9 @@ public class GroupManagementServiceProviderImpl implements GroupManagementServic
|
|
|
|
* {@inheritDoc}
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String[] getPermissions(String username, String groupName) throws GroupManagementException {
|
|
|
|
public String[] getPermissions(String username, int groupId) throws GroupManagementException {
|
|
|
|
UserRealm userRealm;
|
|
|
|
UserRealm userRealm;
|
|
|
|
List<String> roles = getRoles(username, groupName);
|
|
|
|
List<String> roles = getRoles(username, groupId);
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
userRealm = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId);
|
|
|
|
userRealm = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId);
|
|
|
@ -553,7 +524,7 @@ public class GroupManagementServiceProviderImpl implements GroupManagementServic
|
|
|
|
for (String resourceId : resourceIds) {
|
|
|
|
for (String resourceId : resourceIds) {
|
|
|
|
for (String roleName : roles) {
|
|
|
|
for (String roleName : roles) {
|
|
|
|
if (userRealm.getAuthorizationManager().
|
|
|
|
if (userRealm.getAuthorizationManager().
|
|
|
|
isRoleAuthorized("Internal/group-" + groupName + "-" + roleName, resourceId,
|
|
|
|
isRoleAuthorized("Internal/group-" + groupId + "-" + roleName, resourceId,
|
|
|
|
CarbonConstants.UI_PERMISSION_ACTION)) {
|
|
|
|
CarbonConstants.UI_PERMISSION_ACTION)) {
|
|
|
|
lstPermissions.add(resourceId);
|
|
|
|
lstPermissions.add(resourceId);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -575,17 +546,16 @@ public class GroupManagementServiceProviderImpl implements GroupManagementServic
|
|
|
|
throws GroupManagementException {
|
|
|
|
throws GroupManagementException {
|
|
|
|
UserRealm userRealm;
|
|
|
|
UserRealm userRealm;
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
Map<String, DeviceGroup> groups = new HashMap<>();
|
|
|
|
Map<Integer, DeviceGroup> groups = new HashMap<>();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
userRealm = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId);
|
|
|
|
userRealm = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId);
|
|
|
|
String[] roles = userRealm.getUserStoreManager().getRoleListOfUser(username);
|
|
|
|
String[] roles = userRealm.getUserStoreManager().getRoleListOfUser(username);
|
|
|
|
for (String role : roles) {
|
|
|
|
for (String role : roles) {
|
|
|
|
if (role != null && role.contains("Internal/group-") && userRealm.getAuthorizationManager()
|
|
|
|
if (role != null && role.contains("Internal/group-") && userRealm.getAuthorizationManager()
|
|
|
|
.isRoleAuthorized(role, permission, CarbonConstants.UI_PERMISSION_ACTION)) {
|
|
|
|
.isRoleAuthorized(role, permission, CarbonConstants.UI_PERMISSION_ACTION)) {
|
|
|
|
String groupName = role.split("-")[1];
|
|
|
|
DeviceGroup deviceGroup = extractNewGroupFromRole(groups, role);
|
|
|
|
if (!groups.containsKey(groupName)) {
|
|
|
|
if (deviceGroup != null) {
|
|
|
|
DeviceGroup deviceGroup = getGroup(groupName);
|
|
|
|
groups.put(deviceGroup.getId(), deviceGroup);
|
|
|
|
groups.put(groupName, deviceGroup);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -599,16 +569,16 @@ public class GroupManagementServiceProviderImpl implements GroupManagementServic
|
|
|
|
* {@inheritDoc}
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean isAuthorized(String username, String groupName, String permission)
|
|
|
|
public boolean isAuthorized(String username, int groupId, String permission)
|
|
|
|
throws GroupManagementException {
|
|
|
|
throws GroupManagementException {
|
|
|
|
UserRealm userRealm;
|
|
|
|
UserRealm userRealm;
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
userRealm = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId);
|
|
|
|
userRealm = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId);
|
|
|
|
List<String> roles = this.getRoles(username, groupName);
|
|
|
|
List<String> roles = this.getRoles(username, groupId);
|
|
|
|
for (String role : roles) {
|
|
|
|
for (String role : roles) {
|
|
|
|
if (userRealm.getAuthorizationManager()
|
|
|
|
if (userRealm.getAuthorizationManager()
|
|
|
|
.isRoleAuthorized("Internal/group-" + groupName + "-" + role, permission,
|
|
|
|
.isRoleAuthorized("Internal/group-" + groupId + "-" + role, permission,
|
|
|
|
CarbonConstants.UI_PERMISSION_ACTION)) {
|
|
|
|
CarbonConstants.UI_PERMISSION_ACTION)) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -619,4 +589,44 @@ public class GroupManagementServiceProviderImpl implements GroupManagementServic
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean modifyGroupShare(String username, int groupId, String sharingRole,
|
|
|
|
|
|
|
|
boolean isAddNew)
|
|
|
|
|
|
|
|
throws GroupManagementException {
|
|
|
|
|
|
|
|
UserStoreManager userStoreManager;
|
|
|
|
|
|
|
|
String[] roles = new String[1];
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
DeviceGroup deviceGroup = getGroup(groupId);
|
|
|
|
|
|
|
|
if (deviceGroup == null) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
userStoreManager =
|
|
|
|
|
|
|
|
DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(
|
|
|
|
|
|
|
|
tenantId).getUserStoreManager();
|
|
|
|
|
|
|
|
roles[0] = "Internal/group-" + groupId + "-" + sharingRole;
|
|
|
|
|
|
|
|
if (isAddNew) {
|
|
|
|
|
|
|
|
userStoreManager.updateRoleListOfUser(username, null, roles);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
userStoreManager.updateRoleListOfUser(username, roles, null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
|
|
|
|
throw new GroupManagementException("User store error in adding user " + username + " to group name:" +
|
|
|
|
|
|
|
|
groupId, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private DeviceGroup extractNewGroupFromRole(Map<Integer, DeviceGroup> groups, String role)
|
|
|
|
|
|
|
|
throws GroupManagementException {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
int groupId = Integer.parseInt(role.split("-")[1]);
|
|
|
|
|
|
|
|
if (!groups.containsKey(groupId)) {
|
|
|
|
|
|
|
|
return getGroup(groupId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
|
|
|
log.error("Unable to extract groupId from role " + role, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|