|
|
@ -35,7 +35,6 @@ import io.entgra.device.mgt.core.device.mgt.core.dao.GroupManagementDAOFactory;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.netbeans.lib.cvsclient.commandLine.command.status;
|
|
|
|
|
|
|
|
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.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
@ -46,14 +45,13 @@ import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementEx
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceNotFoundException;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceNotFoundException;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.GroupPaginationRequest;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.GroupPaginationRequest;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.PaginationResult;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.PaginationResult;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.exceptions.TrackerAlreadyExistException;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.event.config.GroupAssignmentEventOperationExecutor;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.event.config.GroupAssignmentEventOperationExecutor;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.geo.task.GeoFenceEventOperationManager;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.geo.task.GeoFenceEventOperationManager;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.internal.DeviceManagementDataHolder;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.internal.DeviceManagementDataHolder;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.OperationMgtConstants;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.OperationMgtConstants;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.util.DeviceManagerUtil;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.util.DeviceManagerUtil;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.util.HttpReportingUtil;
|
|
|
|
import org.wso2.carbon.user.api.AuthorizationManager;
|
|
|
|
import org.wso2.carbon.user.api.UserRealm;
|
|
|
|
import org.wso2.carbon.user.api.UserRealm;
|
|
|
|
import org.wso2.carbon.user.api.UserStoreException;
|
|
|
|
import org.wso2.carbon.user.api.UserStoreException;
|
|
|
|
import org.wso2.carbon.user.api.UserStoreManager;
|
|
|
|
import org.wso2.carbon.user.api.UserStoreManager;
|
|
|
@ -148,7 +146,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void createGroupWithRoles(DeviceGroupRoleWrapper groups, String defaultRole, String[] defaultPermissions) throws GroupManagementException {
|
|
|
|
public void createGroupWithRoles(DeviceGroupRoleWrapper groups, String defaultRole, String[] defaultPermissions) throws GroupAlreadyExistException, GroupManagementException {
|
|
|
|
if (groups == null) {
|
|
|
|
if (groups == null) {
|
|
|
|
String msg = "Received incomplete data for createGroup";
|
|
|
|
String msg = "Received incomplete data for createGroup";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
@ -181,7 +179,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GroupManagementDAOFactory.commitTransaction();
|
|
|
|
GroupManagementDAOFactory.commitTransaction();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw new GroupManagementException("Group exist with name " + groups.getName());
|
|
|
|
throw new GroupAlreadyExistException("Group already exists with name : " + groups.getName() + " Try with another group name.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (GroupManagementDAOException e) {
|
|
|
|
} catch (GroupManagementDAOException e) {
|
|
|
|
GroupManagementDAOFactory.rollbackTransaction();
|
|
|
|
GroupManagementDAOFactory.rollbackTransaction();
|
|
|
@ -312,6 +310,13 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|
|
|
newParentPath = DeviceGroupConstants.HierarchicalGroup.SEPERATOR;
|
|
|
|
newParentPath = DeviceGroupConstants.HierarchicalGroup.SEPERATOR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
childrenGroup.setParentPath(newParentPath);
|
|
|
|
childrenGroup.setParentPath(newParentPath);
|
|
|
|
|
|
|
|
if (!newParentPath.equals(DeviceGroupConstants.HierarchicalGroup.SEPERATOR)) {
|
|
|
|
|
|
|
|
String[] groupIds = newParentPath.split(DeviceGroupConstants.HierarchicalGroup.SEPERATOR);
|
|
|
|
|
|
|
|
int latestGroupId = Integer.parseInt(groupIds[groupIds.length - 1]);
|
|
|
|
|
|
|
|
childrenGroup.setParentGroupId(latestGroupId);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
childrenGroup.setParentGroupId(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -352,6 +357,40 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* {@inheritDoc}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void deleteRoleAndRoleGroupMapping(String roleName, String roleToDelete, int tenantId, UserStoreManager userStoreManager, AuthorizationManager authorizationManager) throws GroupManagementException {
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Delete roles");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
GroupManagementDAOFactory.beginTransaction();
|
|
|
|
|
|
|
|
groupDAO.deleteGroupsMapping(roleToDelete, tenantId);
|
|
|
|
|
|
|
|
userStoreManager.deleteRole(roleName);
|
|
|
|
|
|
|
|
// Delete all authorizations for the current role before deleting
|
|
|
|
|
|
|
|
authorizationManager.clearRoleAuthorization(roleName);
|
|
|
|
|
|
|
|
GroupManagementDAOFactory.commitTransaction();
|
|
|
|
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
|
|
|
|
GroupManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
|
|
|
String msg = "Error occurred while deleting the role '" + roleName + "'";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new GroupManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while initiating transaction.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new GroupManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (GroupManagementDAOException e) {
|
|
|
|
|
|
|
|
GroupManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
|
|
|
String msg = "Error occurred while deleting the role";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new GroupManagementException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
GroupManagementDAOFactory.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -518,7 +557,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public PaginationResult getGroupsWithHierarchy(String username, GroupPaginationRequest request,
|
|
|
|
public PaginationResult getGroupsWithHierarchy(String username, GroupPaginationRequest request,
|
|
|
|
boolean requireGroupProps) throws GroupManagementException {
|
|
|
|
boolean requireGroupProps) throws GroupManagementException {
|
|
|
|
if (request == null) {
|
|
|
|
if (request == null) {
|
|
|
|
String msg = "Received incomplete data for retrieve groups with hierarchy";
|
|
|
|
String msg = "Received incomplete data for retrieve groups with hierarchy";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
@ -527,6 +566,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Get groups with hierarchy " + request.toString());
|
|
|
|
log.debug("Get groups with hierarchy " + request.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean isWithParentPath = false;
|
|
|
|
DeviceManagerUtil.validateGroupListPageSize(request);
|
|
|
|
DeviceManagerUtil.validateGroupListPageSize(request);
|
|
|
|
List<DeviceGroup> rootGroups;
|
|
|
|
List<DeviceGroup> rootGroups;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -538,7 +578,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
List<Integer> allDeviceGroupIdsOfUser = getGroupIds(username);
|
|
|
|
List<Integer> allDeviceGroupIdsOfUser = getGroupIds(username);
|
|
|
|
GroupManagementDAOFactory.openConnection();
|
|
|
|
GroupManagementDAOFactory.openConnection();
|
|
|
|
rootGroups = this.groupDAO.getGroups(request, allDeviceGroupIdsOfUser, tenantId);
|
|
|
|
rootGroups = this.groupDAO.getGroups(request, allDeviceGroupIdsOfUser, tenantId, isWithParentPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String parentPath;
|
|
|
|
String parentPath;
|
|
|
|
List<DeviceGroup> childrenGroups;
|
|
|
|
List<DeviceGroup> childrenGroups;
|
|
|
@ -1359,7 +1399,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|
|
|
* @throws GroupManagementDAOException on error during population of group properties.
|
|
|
|
* @throws GroupManagementDAOException on error during population of group properties.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void createGroupWithChildren(DeviceGroup parentGroup, List<DeviceGroup> childrenGroups,
|
|
|
|
private void createGroupWithChildren(DeviceGroup parentGroup, List<DeviceGroup> childrenGroups,
|
|
|
|
boolean requireGroupProps, int tenantId, int depth, int counter) throws GroupManagementDAOException {
|
|
|
|
boolean requireGroupProps, int tenantId, int depth, int counter) throws GroupManagementDAOException {
|
|
|
|
if (childrenGroups.isEmpty() || depth == counter) {
|
|
|
|
if (childrenGroups.isEmpty() || depth == counter) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|