From 77823e2839c67db35b1163ed9884f7e74899307e Mon Sep 17 00:00:00 2001 From: pramilaniroshan Date: Fri, 6 Oct 2023 08:04:38 +0530 Subject: [PATCH 1/4] Modify get Geofence API to get total count --- .../impl/GeoLocationBasedServiceImpl.java | 8 ++++++ .../service/GeoLocationProviderService.java | 7 +++++ .../core/device/mgt/core/dao/GeofenceDAO.java | 8 ++++++ .../dao/impl/AbstractGeofenceDAOImpl.java | 24 +++++++++++++++++ .../GeoLocationProviderServiceImpl.java | 26 +++++++++++++++++++ 5 files changed, 73 insertions(+) diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/GeoLocationBasedServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/GeoLocationBasedServiceImpl.java index b45725c5c1..837e9ea9e7 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/GeoLocationBasedServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/GeoLocationBasedServiceImpl.java @@ -870,6 +870,14 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { PaginationResult paginationResult = new PaginationResult(); paginationResult.setData(geofenceList); paginationResult.setRecordsTotal(geofenceList.size()); + try { + GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService(); + paginationResult.setTotalDeviceCount(geoService.getGeoFenceCount()); + } catch (GeoLocationBasedServiceException e) { + String msg = "Failed to retrieve geofence data"; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } return Response.status(Response.Status.OK).entity(paginationResult).build(); } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/geo/service/GeoLocationProviderService.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/geo/service/GeoLocationProviderService.java index 920cdac80e..c214971604 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/geo/service/GeoLocationProviderService.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/geo/service/GeoLocationProviderService.java @@ -171,4 +171,11 @@ public interface GeoLocationProviderService { * @throws GeoLocationBasedServiceException any errors occurred while reading event records to geofence */ List getEventsOfGeoFence(int geoFenceId) throws GeoLocationBasedServiceException; + + /** + * Get geo fence count by tenant id + * @return returns the geofence count of tenant. + * @throws GeoLocationBasedServiceException any errors occurred while reading event records to geofence + */ + int getGeoFenceCount() throws GeoLocationBasedServiceException; } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/GeofenceDAO.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/GeofenceDAO.java index a6fcf172e5..1546d4034e 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/GeofenceDAO.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/GeofenceDAO.java @@ -174,4 +174,12 @@ public interface GeofenceDAO { * @throws DeviceManagementDAOException */ GeofenceData getGeofence(int fenceId, boolean requireGroupData) throws DeviceManagementDAOException; + + /** + * This method is used to get the geofence count by tenant id. + * @param tenantId tenant id. + * @return returns the geofence count of tenant. + * @throws DeviceManagementDAOException + */ + int getGeofenceCount(int tenantId) throws DeviceManagementDAOException; } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGeofenceDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGeofenceDAOImpl.java index c575ea60dc..393a11bf20 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGeofenceDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGeofenceDAOImpl.java @@ -644,4 +644,28 @@ public abstract class AbstractGeofenceDAOImpl implements GeofenceDAO { throw new DeviceManagementDAOException(msg, e); } } + + @Override + public int getGeofenceCount(int tenantId) throws DeviceManagementDAOException { + try { + Connection conn = this.getConnection(); + String sql = "SELECT COUNT(*) AS geofence_count " + + "FROM DM_GEOFENCE " + + "WHERE TENANT_ID = ?"; + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setInt(1, tenantId); + try (ResultSet rst = stmt.executeQuery()) { + if (rst.next()) { + return rst.getInt("geofence_count"); + } + } + } + return 0; // Return 0 if no records found for the given tenantId. + } catch (SQLException e) { + String msg = "Error occurred while retrieving Geofence count of the tenant " + tenantId; + log.error(msg, e); + throw new DeviceManagementDAOException(msg, e); + } + } + } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java index ac5c6fac5b..edac4eaa09 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java @@ -1747,6 +1747,32 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic } } + @Override + public int getGeoFenceCount() throws GeoLocationBasedServiceException { + int tenantId; + try { + tenantId = DeviceManagementDAOUtil.getTenantId(); + } catch (DeviceManagementDAOException e) { + String msg = "Error occurred while retrieving tenant id while get geofence data"; + log.error(msg, e); + throw new GeoLocationBasedServiceException(msg, e); + } + try { + EventManagementDAOFactory.openConnection(); + return geofenceDAO.getGeofenceCount(tenantId); + } catch (DeviceManagementDAOException e) { + String msg = "Error occurred while retrieving geofence data for the tenant " + tenantId; + log.error(msg, e); + throw new GeoLocationBasedServiceException(msg, e); + } catch (SQLException e) { + String msg = "Failed to open the DB connection to retrieve Geofence"; + log.error(msg, e); + throw new GeoLocationBasedServiceException(msg, e); + } finally { + EventManagementDAOFactory.closeConnection(); + } + } + /** * Delete events of geofence * From 22b9897a4bdac688f2ff3963dacda0ca3567b8e3 Mon Sep 17 00:00:00 2001 From: akeela_azhar Date: Mon, 16 Oct 2023 08:00:42 +0530 Subject: [PATCH 2/4] Add permission updating logic --- .../webapp/publisher/APIPublisherService.java | 2 +- .../publisher/APIPublisherServiceImpl.java | 105 +++++++++++------- .../device/mgt/api/jaxrs/beans/RoleInfo.java | 8 ++ .../impl/RoleManagementServiceImpl.java | 11 +- 4 files changed, 78 insertions(+), 48 deletions(-) diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherService.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherService.java index 94eae16cb8..2dc95d4f37 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherService.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherService.java @@ -38,6 +38,6 @@ public interface APIPublisherService { void addDefaultScopesIfNotExist(); - void updateScopeRoleMapping(String roleName, String[] permissions) throws APIManagerPublisherException; + void updateScopeRoleMapping(String roleName, String[] permissions, String[] removedPermissions) throws APIManagerPublisherException; } diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java index be4def9da6..6d037525ae 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java @@ -626,7 +626,7 @@ public class APIPublisherServiceImpl implements APIPublisherService { } @Override - public void updateScopeRoleMapping(String roleName, String[] permissions) throws APIManagerPublisherException { + public void updateScopeRoleMapping(String roleName, String[] permissions, String[] removedPermissions) throws APIManagerPublisherException { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); APIApplicationKey apiApplicationKey; AccessTokenInfo accessTokenInfo; @@ -643,49 +643,14 @@ public class APIPublisherServiceImpl implements APIPublisherService { try { PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServicesImpl(); JSONObject scopeObject = publisherRESTAPIServices.getScopes(apiApplicationKey, accessTokenInfo); - Map permScopeMap = APIPublisherDataHolder.getInstance().getPermScopeMapping(); - for (String permission : permissions) { - String scopeValue = permScopeMap.get(permission); - if (scopeValue == null) { - String msg = "Found invalid permission: " + permission + ". Hence aborting the scope role " + - "mapping process"; - log.error(msg); - throw new APIManagerPublisherException(msg); - } - - JSONArray scopeList = (JSONArray) scopeObject.get("list"); - for (int i = 0; i < scopeList.length(); i++) { - JSONObject scopeObj = scopeList.getJSONObject(i); - if (scopeObj.getString("name").equals(scopeValue)) { - Scope scope = new Scope(); - scope.setName(scopeObj.getString("name")); - scope.setKey(scopeObj.getString("name")); - scope.setDescription(scopeObj.getString("description")); - scope.setId(scopeObj.getString("id")); - - // Including already existing roles - JSONArray existingRolesArray = (JSONArray) scopeObj.get("bindings"); - List existingRoleList = new ArrayList(); - - for (int j = 0; j < existingRolesArray.length(); j++) { - existingRoleList.add((String) existingRolesArray.get(j)); - } - if (!existingRoleList.contains(roleName)) { - existingRoleList.add(roleName); - } - scope.setRoles(String.join(",", existingRoleList)); - - if (publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo, scope.getKey())) { - publisherRESTAPIServices.updateSharedScope(apiApplicationKey, accessTokenInfo, scope); - } else { - // todo: come to this level means, that scope is removed from API, but haven't removed from the scope-role-permission-mappings list - log.warn(scope.getKey() + " not available as shared scope"); - } - break; - } - } + if (permissions.length != 0) { + updateScopes(roleName, publisherRESTAPIServices, apiApplicationKey, accessTokenInfo, scopeObject, permissions, permScopeMap, false); + } + if (removedPermissions.length != 0) { + updateScopes(roleName, publisherRESTAPIServices, apiApplicationKey, accessTokenInfo, scopeObject, removedPermissions, permScopeMap, true); } + try { updatePermissions(roleName, Arrays.asList(permissions)); } catch (UserStoreException e) { @@ -708,6 +673,62 @@ public class APIPublisherServiceImpl implements APIPublisherService { } } + private void updateScopes (String roleName, PublisherRESTAPIServices publisherRESTAPIServices, + APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, + JSONObject scopeObject, String[] permissions, Map permScopeMap, boolean removingPermissions ) + throws APIManagerPublisherException { + for (String permission : permissions) { + String scopeValue = permScopeMap.get(permission); + if (scopeValue == null) { + String msg = "Found invalid permission: " + permission + ". Hence aborting the scope role " + + "mapping process"; + log.error(msg); + throw new APIManagerPublisherException(msg); + } + + JSONArray scopeList = (JSONArray) scopeObject.get("list"); + for (int i = 0; i < scopeList.length(); i++) { + JSONObject scopeObj = scopeList.getJSONObject(i); + if (scopeObj.getString("name").equals(scopeValue)) { + Scope scope = new Scope(); + scope.setName(scopeObj.getString("name")); + scope.setKey(scopeObj.getString("name")); + scope.setDescription(scopeObj.getString("description")); + scope.setId(scopeObj.getString("id")); + + // Including already existing roles + JSONArray existingRolesArray = (JSONArray) scopeObj.get("bindings"); + List existingRoleList = new ArrayList(); + + for (int j = 0; j < existingRolesArray.length(); j++) { + existingRoleList.add((String) existingRolesArray.get(j)); + } + + if (removingPermissions) { + existingRoleList.remove(roleName); + } else { + if (!existingRoleList.contains(roleName)) { + existingRoleList.add(roleName); + } + } + scope.setRoles(String.join(",", existingRoleList)); + + try { + if (publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo, scope.getKey())) { + publisherRESTAPIServices.updateSharedScope(apiApplicationKey, accessTokenInfo, scope); + } else { + // todo: come to this level means, that scope is removed from API, but haven't removed from the scope-role-permission-mappings list + log.warn(scope.getKey() + " not available as shared scope"); + } + } catch (APIServicesException | BadRequestException | UnexpectedResponseException e) { + log.error("Error occurred while updating role scope mapping via APIM REST endpoint.", e); + } + break; + } + } + } + } + private void updatePermissions(String role, List permissions) throws UserStoreException { AuthorizationManager authorizationManager = APIPublisherDataHolder.getInstance().getUserRealm() .getAuthorizationManager(); diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/beans/RoleInfo.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/beans/RoleInfo.java index 3ad90c07a6..374efeb6e0 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/beans/RoleInfo.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/beans/RoleInfo.java @@ -33,6 +33,11 @@ public class RoleInfo { @ApiModelProperty(name = "permissions", value = "Lists out all the permissions associated with roles.", required = true, dataType = "List[java.lang.String]") private String[] permissions; + + @ApiModelProperty(name = "removedPermissions", value = "Lists out all the permissions unassociated with roles.", + required = true, dataType = "List[java.lang.String]") + private String[] removedPermissions; + @ApiModelProperty(name = "users", value = "The list of users assigned to the selected role.", required = true, dataType = "List[java.lang.String]") private String[] users; @@ -76,4 +81,7 @@ public class RoleInfo { this.permissionList = permissionList; } + public String[] getRemovedPermissions() { return removedPermissions; } + + public void setRemovedPermissions(String[] removedPermissions) { this.removedPermissions = removedPermissions; } } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/RoleManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/RoleManagementServiceImpl.java index a9ea688d05..63a6a71d12 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/RoleManagementServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/RoleManagementServiceImpl.java @@ -403,8 +403,8 @@ public class RoleManagementServiceImpl implements RoleManagementService { try { if (roleInfo.getPermissions() != null && roleInfo.getPermissions().length > 0) { String[] roleName = roleInfo.getRoleName().split("/"); - addPermissions(roleName[roleName.length - 1], roleInfo.getPermissions(), - DeviceMgtAPIUtils.getUserRealm()); + roleInfo.setRemovedPermissions(new String[0]); + updatePermissions(roleName[roleName.length - 1], roleInfo, DeviceMgtAPIUtils.getUserRealm()); } } catch (UserStoreException e) { String msg = "Error occurred while loading the user store."; @@ -546,7 +546,7 @@ public class RoleManagementServiceImpl implements RoleManagementService { if (roleInfo.getPermissions() != null) { String[] roleDetails = roleName.split("/"); - addPermissions(roleDetails[roleDetails.length - 1], roleInfo.getPermissions(), userRealm); + updatePermissions(roleDetails[roleDetails.length - 1], roleInfo, userRealm); } //TODO: Need to send the updated role information in the entity back to the client return Response.status(Response.Status.OK).entity("Role '" + roleInfo.getRoleName() + "' has " + @@ -697,7 +697,7 @@ public class RoleManagementServiceImpl implements RoleManagementService { return rolePermissions; } - private void addPermissions(String roleName, String[] permissions, UserRealm userRealm) { + private void updatePermissions(String roleName, RoleInfo roleInfo, UserRealm userRealm) { String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true); Thread thread = new Thread(new Runnable() { @Override @@ -707,7 +707,8 @@ public class RoleManagementServiceImpl implements RoleManagementService { PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true); DeviceMgtAPIUtils.getApiPublisher().updateScopeRoleMapping(roleName, RoleManagementServiceImpl.this.getPlatformUIPermissions(roleName, userRealm, - permissions)); + roleInfo.getPermissions()), RoleManagementServiceImpl.this.getPlatformUIPermissions(roleName, userRealm, + roleInfo.getRemovedPermissions())); } catch (APIManagerPublisherException | UserAdminException e) { log.error("Error Occurred while updating role scope mapping. ", e); } finally { From 1b0ad156b2f8476cbeb91bc6ba9e2181af085ba6 Mon Sep 17 00:00:00 2001 From: tcdlpds Date: Mon, 16 Oct 2023 10:30:03 +0530 Subject: [PATCH 3/4] Add Java Doc comments --- .../webapp/publisher/APIPublisherService.java | 13 ++++++++++ .../publisher/APIPublisherServiceImpl.java | 13 ++++++++++ .../impl/RoleManagementServiceImpl.java | 24 +++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherService.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherService.java index 2dc95d4f37..eec6cfcab7 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherService.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherService.java @@ -36,8 +36,21 @@ public interface APIPublisherService { void updateScopeRoleMapping() throws APIManagerPublisherException; + /** + * Add default scopes defined in the cdm-config.xml + */ void addDefaultScopesIfNotExist(); + /** + * If the permissions are in the permission list, identify the relevant scopes of the supplied permission list + * and put the role there; if the permissions are in the removedPermission list, update the relevant scopes by + * deleting the role from those scopes. + * + * @param roleName Role Name + * @param permissions List of adding permissions + * @param removedPermissions List of removing permissions + * @throws APIManagerPublisherException If error occurred while updating the scope role mapping + */ void updateScopeRoleMapping(String roleName, String[] permissions, String[] removedPermissions) throws APIManagerPublisherException; } diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java index 6d037525ae..69f20fa020 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java @@ -673,6 +673,19 @@ public class APIPublisherServiceImpl implements APIPublisherService { } } + /** + * Update Scopes + * + * @param roleName Role Name + * @param publisherRESTAPIServices {@link PublisherRESTAPIServices} + * @param apiApplicationKey {@link APIApplicationKey} + * @param accessTokenInfo {@link AccessTokenInfo} + * @param scopeObject scope object returning from APIM + * @param permissions List of permissions + * @param permScopeMap Permission Scope map + * @param removingPermissions if list of permissions has to be removed from the role send true, otherwise sends false. + * @throws APIManagerPublisherException If the method receives invalid permission to update. + */ private void updateScopes (String roleName, PublisherRESTAPIServices publisherRESTAPIServices, APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, JSONObject scopeObject, String[] permissions, Map permScopeMap, boolean removingPermissions ) diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/RoleManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/RoleManagementServiceImpl.java index 63a6a71d12..bca483f6c0 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/RoleManagementServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/RoleManagementServiceImpl.java @@ -279,6 +279,14 @@ public class RoleManagementServiceImpl implements RoleManagementService { } } + /** + * Retrieve filtered permissions by analyzing all the permission paths. + * + * @param rolePermissions All the permission paths + * @param permissionPaths Permission paths that needs to filter + * @param permissions List of filtered permissions + * @return {@link List} + */ private List processAndFilterPermissions(UIPermissionNode[] rolePermissions, List permissionPaths, List permissions) { for (UIPermissionNode rolePermission : rolePermissions) { @@ -299,6 +307,15 @@ public class RoleManagementServiceImpl implements RoleManagementService { return permissions; } + /** + * Getting platform permissions + * + * @param roleName Role Name + * @param userRealm {@link UserRealm} + * @param permissions list of permissions + * @return {@link List} + * @throws UserAdminException if error occurred when getting {@link UIPermissionNode} + */ private String[] getPlatformUIPermissions(String roleName, UserRealm userRealm, String[] permissions) throws UserAdminException { UIPermissionNode uiPermissionNode = getUIPermissionNode(roleName, userRealm); @@ -697,6 +714,13 @@ public class RoleManagementServiceImpl implements RoleManagementService { return rolePermissions; } + /** + * Update the role's permissions. This will function in the fire and forget pattern and run on a new thread. + * + * @param roleName Role Name + * @param roleInfo {@link RoleInfo} + * @param userRealm {@link UserRealm} + */ private void updatePermissions(String roleName, RoleInfo roleInfo, UserRealm userRealm) { String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true); Thread thread = new Thread(new Runnable() { From c3cc4fe6d42599c9302d849c6e9955cd5afe4e0f Mon Sep 17 00:00:00 2001 From: Oshani Silva Date: Mon, 16 Oct 2023 05:21:44 +0000 Subject: [PATCH 4/4] Add fix for search operation (#251) fixes https://roadmap.entgra.net/issues/10279 Co-authored-by: osh Reviewed-on: https://repository.entgra.net/community/device-mgt-core/pulls/251 Co-authored-by: Oshani Silva Co-committed-by: Oshani Silva --- .../device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java | 4 ++-- .../mgt/core/service/DeviceManagementProviderServiceImpl.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java index 32bffa5af4..fcb1799568 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java @@ -94,7 +94,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { "t.NAME AS DEVICE_TYPE "; //Filter by serial number or any Custom Property in DM_DEVICE_INFO - if (serial != null || !request.getCustomProperty().isEmpty()) { + if ((serial != null) || (request.getCustomProperty() != null && !request.getCustomProperty().isEmpty())) { sql = sql + "FROM DM_DEVICE d " + "INNER JOIN DM_DEVICE_TYPE t ON d.DEVICE_TYPE_ID = t.ID " + @@ -170,7 +170,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { if (isSerialProvided) { stmt.setString(paramIdx++, "%" + serial + "%"); } - if (!request.getCustomProperty().isEmpty()) { + if (request.getCustomProperty() != null && !request.getCustomProperty().isEmpty()) { for (Map.Entry entry : request.getCustomProperty().entrySet()) { stmt.setString(paramIdx++, "%" + entry.getValue() + "%"); } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 8413b1499f..344325ae10 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -652,7 +652,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv Map deviceManagerMap = new HashMap<>(); List deviceCacheKeyList = new ArrayList<>(); List existingDevices; - List validDevices = new ArrayList<>();; + List validDevices = new ArrayList<>(); int tenantId = this.getTenantId(); try {