From 2425721744cac3698659def080f5dfa3c94d31c4 Mon Sep 17 00:00:00 2001 From: isuri Date: Sun, 15 Oct 2023 23:57:24 +0530 Subject: [PATCH] permission and web configurations for device organization --- .../pom.xml | 154 ++++++++++++++++-- .../organization/api/ApiOriginFilter.java | 43 +++++ .../api/DeviceOrganizationMgtServiceImpl.java | 11 +- .../src/main/webapp/META-INF/permissions.xml | 76 +++++++++ .../src/main/webapp/WEB-INF/web.xml | 36 +++- 5 files changed, 294 insertions(+), 26 deletions(-) create mode 100644 components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/api/ApiOriginFilter.java diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/pom.xml index 80fb7dc076..3443528ad4 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/pom.xml +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/pom.xml @@ -133,39 +133,75 @@ + + org.testng + testng + test + org.springframework spring-web provided + + org.apache.cxf + cxf-bundle + 3.0.0-milestone2 + test + org.apache.cxf cxf-bundle-jaxrs provided - - commons-codec.wso2 - commons-codec + commons-httpclient.wso2 + commons-httpclient + provided + + + org.wso2.carbon + org.wso2.carbon.utils + provided + + + org.wso2.carbon.identity.framework + org.wso2.carbon.user.mgt + provided - commons-codec - commons-codec + org.slf4j + slf4j-api + + + org.slf4j + jcl-over-slf4j - org.codehaus.jackson - jackson-jaxrs + org.wso2.carbon + org.wso2.carbon.logging + provided + + + org.wso2.carbon.identity.inbound.auth.oauth2 + org.wso2.carbon.identity.oauth.stub + provided + + + org.apache.axis2.wso2 + axis2-client + + - - junit - junit - test + + org.json.wso2 + json - org.wso2.carbon - org.wso2.carbon.logging + commons-codec.wso2 + commons-codec provided @@ -187,13 +223,17 @@ swagger-core - org.wso2.orbit.com.fasterxml.jackson.core - jackson-annotations + com.fasterxml.jackson.module + jackson-module-jaxb-annotations org.slf4j slf4j-api + + org.wso2.orbit.com.fasterxml.jackson.core + jackson-core + @@ -208,13 +248,97 @@ org.slf4j slf4j-api + + org.wso2.orbit.com.fasterxml.jackson.core + jackson-core + + + javax.servlet + javax.servlet-api + provided + io.entgra.device.mgt.core io.entgra.device.mgt.core.apimgt.annotations provided + + org.wso2.orbit.com.fasterxml.jackson.core + jackson-annotations + + + org.hibernate + hibernate-validator + + + javax.ws.rs + javax.ws.rs-api + provided + + + javax.ws.rs + jsr311-api + provided + + + org.wso2.carbon.commons + org.wso2.carbon.application.mgt.stub + provided + + + io.entgra.device.mgt.core + io.entgra.device.mgt.core.identity.jwt.client.extension + provided + + + org.wso2.carbon + org.wso2.carbon.registry.core + provided + + + org.wso2.carbon.registry + org.wso2.carbon.registry.resource + provided + + + org.wso2.carbon.identity.framework + org.wso2.carbon.identity.user.store.count + ${carbon.identity.framework.version} + provided + + + org.powermock + powermock-module-testng + test + + + org.powermock + powermock-api-mockito + test + + + io.entgra.device.mgt.core + io.entgra.device.mgt.core.device.mgt.common + provided + + + io.entgra.device.mgt.core + io.entgra.device.mgt.core.device.mgt.extensions + provided + + + org.wso2.carbon.identity.framework + org.wso2.carbon.identity.claim.metadata.mgt + ${carbon.identity.framework.version} + provided + + + io.entgra.device.mgt.core + io.entgra.device.mgt.core.device.mgt.core + provided + diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/api/ApiOriginFilter.java b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/api/ApiOriginFilter.java new file mode 100644 index 0000000000..1755327573 --- /dev/null +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/api/ApiOriginFilter.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api; + +import javax.servlet.*; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +public class ApiOriginFilter implements Filter { + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + HttpServletResponse res = (HttpServletResponse) response; + res.addHeader("Access-Control-Allow-Origin", "*"); + res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); + res.addHeader("Access-Control-Allow-Headers", "Content-Type"); + chain.doFilter(request, response); + } + + public void destroy() { + //do nothing + } + + public void init(FilterConfig filterConfig) throws ServletException { + //do nothing + } + +} diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/api/DeviceOrganizationMgtServiceImpl.java b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/api/DeviceOrganizationMgtServiceImpl.java index 1176e2f9ee..47174542d0 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/api/DeviceOrganizationMgtServiceImpl.java +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/api/DeviceOrganizationMgtServiceImpl.java @@ -51,11 +51,16 @@ public class DeviceOrganizationMgtServiceImpl implements DeviceOrganizationMgtSe @Override @Path("/add-device-organization") public Response addDeviceOrganization(DeviceOrganization deviceOrganizationRequest) { + if (deviceOrganizationRequest == null) { + String errorMessage = "The payload of the device organization is incorrect."; + return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); + } try { + if (deviceOrganizationRequest.getDeviceId() <= 0 || deviceOrganizationRequest.getParentDeviceId() <= 0) { + String errorMessage = "The payload of the device organization is incorrect."; + return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build(); + } DeviceOrganizationService deviceOrganizationService = new DeviceOrganizationServiceImpl(); -// DeviceOrganization deviceOrganization = new DeviceOrganization(); -// deviceOrganization.setDeviceId(DeviceOrganization.getDeviceId()); -// deviceOrganization.setParentDeviceId(DeviceOrganization.getParentDeviceId()); boolean resp = deviceOrganizationService.addDeviceOrganization(deviceOrganizationRequest); return Response.status(Response.Status.OK).entity(gson.toJson(resp)).build(); } catch (DeviceOrganizationMgtPluginException e) { diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/webapp/META-INF/permissions.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/webapp/META-INF/permissions.xml index addd717eb6..28e415b7af 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/webapp/META-INF/permissions.xml +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/webapp/META-INF/permissions.xml @@ -29,4 +29,80 @@ --> + + + + Create a new Device Organization + /device-mgt/devices/owning/view + /deviceOrganization/add-device-organization + POST + + + View Child Devices + /device-mgt/devices/owning/view + /deviceOrganization/children + GET + + + View Parent Devices + /device-mgt/devices/owning/view + /deviceOrganization/parents + GET + + + View All Device Organizations + /device-mgt/devices/owning/view + /deviceOrganization/all + GET + + + View Device Organization Details + /device-mgt/devices/owning/view + /deviceOrganization/{organizationId} + GET + + + Check Device Organization Existence + /device-mgt/devices/owning/view + /deviceOrganization/exists + GET + + + View Device Organization By Unique key + /device-mgt/devices/owning/view + /deviceOrganization/unique + GET + + + Check Device Organization Existence + /device-mgt/devices/owning/view + /deviceOrganization/device-exists + GET + + + Check Child Device Existence + /device-mgt/devices/owning/view + /deviceOrganization/child-exists + GET + + + Update Device Organization + /device-mgt/devices/owning/view + /deviceOrganization/update + PUT + + + Delete Device Organization By ID + /device-mgt/devices/owning/view + /deviceOrganization/delete/{organizationId} + DELETE + + + Delete Device Organizations Associated with an ID + /device-mgt/devices/owning/view + /deviceOrganization/delete-associations/{deviceId} + DELETE + + + diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/webapp/WEB-INF/web.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/webapp/WEB-INF/web.xml index 7ffe0a5806..1777fa716c 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/webapp/WEB-INF/web.xml +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/webapp/WEB-INF/web.xml @@ -17,9 +17,9 @@ ~ under the License. --> - Grafana-API-Proxy-Webapp + Admin-Webapp - JAX-WS/JAX-RS Grafana API Management Endpoint + JAX-WS/JAX-RS Device Management Endpoint JAX-WS/JAX-RS Servlet CXFServlet @@ -42,17 +42,16 @@ doAuthentication - false - - - basicAuth - false + true nonSecuredEndPoints - /keymgt-test-api/.*, + /api/device-mgt/v1.0/users/validate, + /api/device-mgt/v1.0/whitelabel/.*/favicon, + /api/device-mgt/v1.0/whitelabel/.*/logo, + /api/device-mgt/v1.0/whitelabel/.*/icon, @@ -70,6 +69,22 @@ true + + + + DeviceMgt-Admin + /* + + + CONFIDENTIAL + + + + + ApiOriginFilter + io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.ApiOriginFilter + + HttpHeaderSecurityFilter org.apache.catalina.filters.HttpHeaderSecurityFilter @@ -106,4 +121,9 @@ /* + + ApiOriginFilter + /* + +