diff --git a/README.md b/README.md index 5ff98b8ff5..e07bdc3705 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # carbon-device-mgt + + WSO2 CONNECTED DEVICE MANAGEMENT COMPONENTS WSO2 Connected Device Manager (WSO2 CDM) is a comprehensive platform that helps solve mobile computing challenges enterprises face today when dealing with both corporate owned, personally enabled (COPE) devices and employee owned devices as part of a bring your own device (BYOD) program. diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml index 8174536bd2..59dac71956 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml @@ -22,13 +22,13 @@ apimgt-extensions org.wso2.carbon.devicemgt - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.apimgt.annotations - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT bundle WSO2 Carbon - API Management Annotations WSO2 Carbon - API Management Custom Annotation Module diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml index 4894c6a3ba..d4639c7ac6 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml @@ -21,12 +21,12 @@ apimgt-extensions org.wso2.carbon.devicemgt - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT ../pom.xml 4.0.0 - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT org.wso2.carbon.apimgt.application.extension.api war WSO2 Carbon - API Application Management API diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml index c72fcb0b8e..f9eec4c064 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml @@ -22,12 +22,12 @@ apimgt-extensions org.wso2.carbon.devicemgt - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT ../pom.xml 4.0.0 - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT org.wso2.carbon.apimgt.application.extension bundle WSO2 Carbon - API Application Management diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/pom.xml index 272d0c5e34..60a240a4a7 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/pom.xml @@ -21,13 +21,13 @@ apimgt-extensions org.wso2.carbon.devicemgt - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.apimgt.handlers - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT bundle WSO2 Carbon - API Security Handler Component WSO2 Carbon - API Management Security Handler Module diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/pom.xml index 8756c25905..600a37c095 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/pom.xml @@ -8,19 +8,18 @@ License for the ~ specific language governing permissions and limitations ~ under the License. --> - + apimgt-extensions org.wso2.carbon.devicemgt - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.apimgt.integration.client - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT bundle WSO2 Carbon - API Management Integration Client WSO2 Carbon - API Management Integration Client diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.generated.client/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.generated.client/pom.xml index aa6c82acf8..45c73d2839 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.generated.client/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.generated.client/pom.xml @@ -8,21 +8,20 @@ License for the ~ specific language governing permissions and limitations ~ under the License. --> - + apimgt-extensions org.wso2.carbon.devicemgt - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.apimgt.integration.generated.client - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT bundle - WSO2 Carbon - API Management Integration Client + WSO2 Carbon - API Management Integration Generated Client WSO2 Carbon - API Management Integration Client http://wso2.org @@ -201,5 +200,7 @@ jackson-datatype-joda - + + true + diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml index 040588814c..b5c7204eb7 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml @@ -22,13 +22,13 @@ apimgt-extensions org.wso2.carbon.devicemgt - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.apimgt.webapp.publisher - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT bundle WSO2 Carbon - API Management Webapp Publisher WSO2 Carbon - API Management Webapp Publisher diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java index 839658ec2a..a3f8608de4 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java @@ -218,7 +218,7 @@ public class APIPublisherUtil { JsonObject httpVerb = new JsonObject(); httpVerb.add("responses", response); - httpVerb.addProperty("x-auth-type", "Application%20%26%20Application%20User"); + httpVerb.addProperty("x-auth-type", uriTemplate.getAuthType()); httpVerb.addProperty("x-throttling-tier", "Unlimited"); if (uriTemplate.getScope() != null) { httpVerb.addProperty("x-scope", uriTemplate.getScope().getKey()); @@ -289,5 +289,6 @@ public class APIPublisherUtil { } } } + apiConfig.setUriTemplates(templates); } } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java index 52dc147790..dfc8dd7454 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java @@ -53,7 +53,7 @@ public class AnnotationProcessor { private static final Log log = LogFactory.getLog(AnnotationProcessor.class); - private static final String AUTH_TYPE = "Any"; + private static final String AUTH_TYPE = "Application & Application User"; private static final String STRING_ARR = "string_arr"; private static final String STRING = "string"; private static final String PACKAGE_ORG_APACHE = "org.apache"; diff --git a/components/apimgt-extensions/pom.xml b/components/apimgt-extensions/pom.xml index 747dc0d394..6d23a37141 100644 --- a/components/apimgt-extensions/pom.xml +++ b/components/apimgt-extensions/pom.xml @@ -22,13 +22,13 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT ../../pom.xml 4.0.0 apimgt-extensions - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT pom WSO2 Carbon - API Management Extensions Component http://wso2.org diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml index 948ba6691b..b567e83cd7 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml @@ -22,7 +22,7 @@ certificate-mgt org.wso2.carbon.devicemgt - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT ../pom.xml diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml index 955bb55fa2..992199ec4d 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml @@ -22,7 +22,7 @@ certificate-mgt org.wso2.carbon.devicemgt - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT ../pom.xml diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml index 764f381934..a74d2b8810 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml @@ -21,13 +21,13 @@ org.wso2.carbon.devicemgt certificate-mgt - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.certificate.mgt.core - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT bundle WSO2 Carbon - Certificate Management Core WSO2 Carbon - Certificate Management Core diff --git a/components/certificate-mgt/pom.xml b/components/certificate-mgt/pom.xml index 44988a66b4..1c48533dd6 100644 --- a/components/certificate-mgt/pom.xml +++ b/components/certificate-mgt/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT ../../pom.xml 4.0.0 org.wso2.carbon.devicemgt certificate-mgt - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT pom WSO2 Carbon - Certificate Management Component http://wso2.org diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml index 435730554e..9f667e301e 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/Claimable.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/Claimable.java new file mode 100644 index 0000000000..661778e62d --- /dev/null +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/Claimable.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. 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 org.wso2.carbon.device.mgt.extensions.device.type.deployer.config; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.XmlValue; + + +/** + *

Java class for DeviceDetails complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="DeviceDetails">
+ *   <simpleContent>
+ *     <extension base="<http://www.w3.org/2001/XMLSchema>string">
+ *       <attribute name="table-id" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *     </extension>
+ *   </simpleContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "Claimable", propOrder = { + "value" +}) +public class Claimable { + + @XmlValue + protected String value; + @XmlAttribute(name = "enabled") + protected boolean enabled; + + /** + * Gets the value of the value property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getValue() { + return value; + } + + /** + * Sets the value of the value property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setValue(String value) { + this.value = value; + } + + /** + * Gets the value of the enabled property. + * + * @return + * possible object is + * {@link String } + * + */ + public boolean isEnabled() { + return enabled; + } + + /** + * Sets the value of the enabled property. + * + * @param enabled + * allowed object is + * {@link String } + * + */ + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + +} diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/DeviceTypeConfiguration.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/DeviceTypeConfiguration.java index 2a43797e9d..00d20b4ebe 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/DeviceTypeConfiguration.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/DeviceTypeConfiguration.java @@ -18,11 +18,8 @@ */ package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.*; +import java.util.List; /** @@ -56,6 +53,8 @@ public class DeviceTypeConfiguration { @XmlElement(name = "DeviceDetails", required = true) protected DeviceDetails deviceDetails; + @XmlElement(name = "Claimable", required = true) + protected Claimable claimable; @XmlElement(name = "Features", required = true) protected Features features; @XmlElement(name = "ProvisioningConfig", required = true) @@ -74,6 +73,21 @@ public class DeviceTypeConfiguration { protected String name; @XmlElement(name = "PolicyMonitoring", required = true) protected PolicyMonitoring policyMonitoring; + @XmlElementWrapper(name = "InitialOperationConfig") + @XmlElement(name = "Operation", required = true) + protected List operations; + + public List getOperations() { + return operations; + } + + public void setOperations(List operations) { + this.operations = operations; + } + + + + /** * Gets the value of the taskConfiguration property. @@ -119,6 +133,27 @@ public class DeviceTypeConfiguration { this.deviceDetails = value; } + /** + * Gets the value of the Claimable property. + * + * @return possible object is + * {@link DeviceDetails } + */ + public Claimable getClaimable() { + return claimable; + } + + /** + * Sets the value of the deviceDetails property. + * + * @param value allowed object is + * {@link DeviceDetails } + */ + public void setClaimable(Claimable value) { + this.claimable = value; + } + + /** * Gets the value of the policyMonitoring property. * diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/InitialOperationConfig.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/InitialOperationConfig.java new file mode 100644 index 0000000000..e172d7b009 --- /dev/null +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/InitialOperationConfig.java @@ -0,0 +1,39 @@ +package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config; + +import javax.xml.bind.annotation.*; +import java.util.List; + +/** + *

Java class for InitialOperationConfig complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="InitialOperationConfig">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="Operations" type="{http://www.w3.org/2001/XMLSchema}list"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlRootElement(name = "InitialOperationConfig") +public class InitialOperationConfig { + + private List operations; + + @XmlElementWrapper(name = "Operations", required = true) + @XmlElement(name = "Operation", required = true) + public List getOperations() { + return operations; + } + + public void setOperationsll(List operations) { + this.operations = operations; + } +} diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeManager.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeManager.java index eba2f18721..98c5ef2870 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeManager.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeManager.java @@ -65,6 +65,7 @@ public class DeviceTypeManager implements DeviceManager { private LicenseManager licenseManager; private boolean propertiesExist; private boolean requiredDeviceTypeAuthorization; + private boolean claimable; private FeatureManager featureManager; @@ -101,8 +102,13 @@ public class DeviceTypeManager implements DeviceManager { String msg = "Error occurred while adding default license for " + deviceType + " devices"; throw new DeviceTypeDeployerFileException(msg, e); } + claimable = false; + if (deviceTypeConfiguration.getClaimable() != null ) { + claimable = deviceTypeConfiguration.getClaimable().isEnabled(); + } DeviceDetails deviceDetails = deviceTypeConfiguration.getDeviceDetails(); + if (deviceDetails != null) { //Check whether device dao definition exist. @@ -341,7 +347,7 @@ public class DeviceTypeManager implements DeviceManager { @Override public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { - return false; + return claimable; } @Override diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeManagerService.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeManagerService.java index c7720093a6..64398d3715 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeManagerService.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeManagerService.java @@ -20,11 +20,7 @@ package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.DeviceManager; -import org.wso2.carbon.device.mgt.common.MonitoringOperation; -import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; -import org.wso2.carbon.device.mgt.common.ProvisioningConfig; +import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; @@ -57,6 +53,8 @@ public class DeviceTypeManagerService implements DeviceManagementService { private OperationMonitoringTaskConfig operationMonitoringConfigs; private List monitoringOperations; private PolicyMonitoringManager policyMonitoringManager; + private InitialOperationConfig initialOperationConfig; + private List operations; public DeviceTypeManagerService(DeviceTypeConfigIdentifier deviceTypeConfigIdentifier, DeviceTypeConfiguration deviceTypeConfiguration) { @@ -66,6 +64,7 @@ public class DeviceTypeManagerService implements DeviceManagementService { this.populatePushNotificationConfig(deviceTypeConfiguration.getPushNotificationProvider()); this.operationMonitoringConfigs = new OperationMonitoringTaskConfig(); this.setOperationMonitoringConfig(deviceTypeConfiguration); + this.setInitialOperationConfig(deviceTypeConfiguration); if (deviceTypeConfiguration.getPolicyMonitoring() != null && deviceTypeConfiguration.getPolicyMonitoring() .isEnabled()) { this.policyMonitoringManager = new DefaultPolicyMonitoringManager(); @@ -157,6 +156,11 @@ public class DeviceTypeManagerService implements DeviceManagementService { return policyMonitoringManager; } + @Override + public InitialOperationConfig getInitialOperationConfig() { + return initialOperationConfig; + } + private void setProvisioningConfig(String tenantDomain, DeviceTypeConfiguration deviceTypeConfiguration) { if (deviceTypeConfiguration.getProvisioningConfig() != null) { boolean sharedWithAllTenants = deviceTypeConfiguration.getProvisioningConfig().isSharedWithAllTenants(); @@ -166,6 +170,15 @@ public class DeviceTypeManagerService implements DeviceManagementService { } } + protected void setInitialOperationConfig(DeviceTypeConfiguration deviceTypeConfiguration) { + if (deviceTypeConfiguration.getOperations() != null) { + List ops = deviceTypeConfiguration.getOperations(); + if (ops != null && !ops.isEmpty()) { + initialOperationConfig.setOperations(ops); + } + } + } + private void setType(String type) { this.type = type; } diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/test/resources/sample.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/test/resources/sample.xml index 6542d9629b..414bcaa8dd 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/test/resources/sample.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/test/resources/sample.xml @@ -36,6 +36,8 @@ + + temperature sensor fitted diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml similarity index 94% rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/pom.xml rename to components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml index e4af0cccb0..995df87a58 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml @@ -22,15 +22,15 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT ../pom.xml 4.0.0 - org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm + org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm bundle - WSO2 Carbon - GCM Based Push Notification Provider Implementation - WSO2 Carbon - GCM Based Push Notification Provider Implementation + WSO2 Carbon - FCM Based Push Notification Provider Implementation + WSO2 Carbon - FCM Based Push Notification Provider Implementation http://wso2.org @@ -128,10 +128,10 @@ ${project.artifactId} ${project.artifactId} ${carbon.device.mgt.version} - GCM Based Push Notification Provider Bundle + FCM Based Push Notification Provider Bundle - !org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.internal, - org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.* + !org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.internal, + org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.* com.google.gson, diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/GCMBasedPushNotificationProvider.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/FCMBasedPushNotificationProvider.java similarity index 84% rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/GCMBasedPushNotificationProvider.java rename to components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/FCMBasedPushNotificationProvider.java index 5168e25e25..30affceb27 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/GCMBasedPushNotificationProvider.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/FCMBasedPushNotificationProvider.java @@ -16,24 +16,24 @@ * under the License. * */ -package org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm; +package org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm; import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationProvider; -public class GCMBasedPushNotificationProvider implements PushNotificationProvider { +public class FCMBasedPushNotificationProvider implements PushNotificationProvider { - private static final String PS_PROVIDER_GCM = "GCM"; + private static final String PS_PROVIDER_FCM = "FCM"; @Override public String getType() { - return PS_PROVIDER_GCM; + return PS_PROVIDER_FCM; } @Override public NotificationStrategy getNotificationStrategy(PushNotificationConfig config) { - return new GCMNotificationStrategy(config); + return new FCMNotificationStrategy(config); } } diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/GCMNotificationStrategy.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/FCMNotificationStrategy.java similarity index 76% rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/GCMNotificationStrategy.java rename to components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/FCMNotificationStrategy.java index af93b692a4..6dd66f0836 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/GCMNotificationStrategy.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/FCMNotificationStrategy.java @@ -16,7 +16,7 @@ * under the License. * */ -package org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm; +package org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm; import com.google.gson.JsonArray; import com.google.gson.JsonObject; @@ -27,7 +27,7 @@ import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext; import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException; -import org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.internal.GCMDataHolder; +import org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.internal.FCMDataHolder; import java.io.IOException; import java.io.OutputStream; @@ -35,16 +35,16 @@ import java.net.HttpURLConnection; import java.net.URL; import java.util.List; -public class GCMNotificationStrategy implements NotificationStrategy { +public class FCMNotificationStrategy implements NotificationStrategy { - private static final String GCM_TOKEN = "GCM_TOKEN"; - private final static String GCM_ENDPOINT = "https://fcm.googleapis.com/fcm/send"; - private static final String GCM_API_KEY = "gcmAPIKey"; + private static final String FCM_TOKEN = "FCM_TOKEN"; + private static final String FCM_ENDPOINT = "https://fcm.googleapis.com/fcm/send"; + private static final String FCM_API_KEY = "fcmAPIKey"; private static final int TIME_TO_LIVE = 60; private static final int HTTP_STATUS_CODE_OK = 200; private PushNotificationConfig config; - public GCMNotificationStrategy(PushNotificationConfig config) { + public FCMNotificationStrategy(PushNotificationConfig config) { this.config = config; } @@ -57,7 +57,7 @@ public class GCMNotificationStrategy implements NotificationStrategy { public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException { try { Device device = - GCMDataHolder.getInstance().getDeviceManagementProviderService().getDevice(ctx.getDeviceId()); + FCMDataHolder.getInstance().getDeviceManagementProviderService().getDevice(ctx.getDeviceId()); this.sendWakeUpCall(ctx.getOperation().getCode(), device); } catch (DeviceManagementException e) { throw new PushNotificationExecutionFailedException("Error occurred while retrieving device information", e); @@ -79,13 +79,13 @@ public class GCMNotificationStrategy implements NotificationStrategy { private void sendWakeUpCall(String message, Device device) throws IOException, PushNotificationExecutionFailedException { OutputStream os = null; - byte[] bytes = getGCMRequest(message, getGCMToken(device.getProperties())).getBytes(); + byte[] bytes = getFCMRequest(message, getFCMToken(device.getProperties())).getBytes(); HttpURLConnection conn = null; try { - conn = (HttpURLConnection) new URL(GCM_ENDPOINT).openConnection(); + conn = (HttpURLConnection) new URL(FCM_ENDPOINT).openConnection(); conn.setRequestProperty("Content-Type", "application/json"); - conn.setRequestProperty("Authorization", "key=" + config.getProperty(GCM_API_KEY)); + conn.setRequestProperty("Authorization", "key=" + config.getProperty(FCM_API_KEY)); conn.setRequestMethod("POST"); conn.setDoOutput(true); os = conn.getOutputStream(); @@ -102,35 +102,35 @@ public class GCMNotificationStrategy implements NotificationStrategy { } } - private static String getGCMRequest(String message, String registrationId) { - JsonObject gcmRequest = new JsonObject(); - gcmRequest.addProperty("delay_while_idle", false); - gcmRequest.addProperty("time_to_live", TIME_TO_LIVE); + private static String getFCMRequest(String message, String registrationId) { + JsonObject fcmRequest = new JsonObject(); + fcmRequest.addProperty("delay_while_idle", false); + fcmRequest.addProperty("time_to_live", TIME_TO_LIVE); - //Add message to GCM request + //Add message to FCM request JsonObject data = new JsonObject(); if (message != null && !message.isEmpty()) { data.addProperty("data", message); - gcmRequest.add("data", data); + fcmRequest.add("data", data); } //Set device reg-id JsonArray regIds = new JsonArray(); regIds.add(new JsonPrimitive(registrationId)); - gcmRequest.add("registration_ids", regIds); - return gcmRequest.toString(); + fcmRequest.add("registration_ids", regIds); + return fcmRequest.toString(); } - private static String getGCMToken(List properties) { - String gcmToken = null; + private static String getFCMToken(List properties) { + String fcmToken = null; for (Device.Property property : properties) { - if (GCM_TOKEN.equals(property.getName())) { - gcmToken = property.getValue(); + if (FCM_TOKEN.equals(property.getName())) { + fcmToken = property.getValue(); break; } } - return gcmToken; + return fcmToken; } } diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/internal/GCMDataHolder.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/internal/FCMDataHolder.java similarity index 88% rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/internal/GCMDataHolder.java rename to components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/internal/FCMDataHolder.java index 67b44109af..64569d7fb6 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/internal/GCMDataHolder.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/internal/FCMDataHolder.java @@ -16,16 +16,16 @@ * under the License. * */ -package org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.internal; +package org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.internal; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; -public class GCMDataHolder { +public class FCMDataHolder { private DeviceManagementProviderService deviceManagementProviderService; - private static GCMDataHolder thisInstance = new GCMDataHolder(); + private static FCMDataHolder thisInstance = new FCMDataHolder(); - public static GCMDataHolder getInstance() { + public static FCMDataHolder getInstance() { return thisInstance; } diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/internal/GCMPushNotificationServiceComponent.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/internal/FCMPushNotificationServiceComponent.java similarity index 78% rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/internal/GCMPushNotificationServiceComponent.java rename to components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/internal/FCMPushNotificationServiceComponent.java index 6e5171ec4b..8993e6928a 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/internal/GCMPushNotificationServiceComponent.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/internal/FCMPushNotificationServiceComponent.java @@ -16,7 +16,7 @@ * under the License. * */ -package org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.internal; +package org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.internal; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -24,7 +24,7 @@ import org.osgi.service.component.ComponentContext; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; /** - * @scr.component name="org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.internal.GCMPushNotificationServiceComponent" immediate="true" + * @scr.component name="org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.internal.FCMPushNotificationServiceComponent" immediate="true" * @scr.reference name="carbon.device.mgt.provider" * interface="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService" * cardinality="1..1" @@ -32,23 +32,20 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; * bind="setDeviceManagementProviderService" * unbind="unsetDeviceManagementProviderService" */ -public class GCMPushNotificationServiceComponent { +public class FCMPushNotificationServiceComponent { - private static final Log log = LogFactory.getLog(GCMPushNotificationServiceComponent.class); + private static final Log log = LogFactory.getLog(FCMPushNotificationServiceComponent.class); @SuppressWarnings("unused") protected void activate(ComponentContext componentContext) { try { - if (log.isDebugEnabled()) { - log.debug("Initializing GCM based push notification provider implementation bundle"); - } //Do nothing if (log.isDebugEnabled()) { - log.debug("GCM based push notification provider implementation bundle has been successfully " + + log.debug("FCM based push notification provider implementation bundle has been successfully " + "initialized"); } } catch (Throwable e) { - log.error("Error occurred while initializing GCM based push notification provider " + + log.error("Error occurred while initializing FCM based push notification provider " + "implementation bundle", e); } } @@ -59,12 +56,12 @@ public class GCMPushNotificationServiceComponent { protected void setDeviceManagementProviderService( DeviceManagementProviderService deviceManagementProviderService) { - GCMDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService); + FCMDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService); } protected void unsetDeviceManagementProviderService( DeviceManagementProviderService deviceManagementProviderService) { - GCMDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService); + FCMDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService); } } diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml index 01626d2475..113938c4c8 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml index 47cd64f41e..75f8bf70db 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/internal/XMPPPushNotificationServiceComponent.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/internal/XMPPPushNotificationServiceComponent.java index 7085191dc8..71dada3b66 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/internal/XMPPPushNotificationServiceComponent.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/internal/XMPPPushNotificationServiceComponent.java @@ -25,7 +25,7 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService; /** - * @scr.component name="org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.internal.XMPPPushNotificationServiceComponent" immediate="true" + * @scr.component name="org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.internal.XMPPPushNotificationServiceComponent" immediate="true" * @scr.reference name="carbon.device.mgt.provider" * interface="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService" * cardinality="1..1" diff --git a/components/device-mgt-extensions/pom.xml b/components/device-mgt-extensions/pom.xml index f1a3bc5edd..79cf359322 100644 --- a/components/device-mgt-extensions/pom.xml +++ b/components/device-mgt-extensions/pom.xml @@ -22,7 +22,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT ../../pom.xml @@ -34,7 +34,7 @@ http://wso2.org - org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm + org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp org.wso2.carbon.device.mgt.extensions.device.type.deployer diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml index 8bd503dc20..5e27ea4773 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml @@ -3,7 +3,7 @@ org.wso2.carbon.devicemgt device-mgt - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml index 7a35748c11..d97af674a9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml index 56d1b5b78b..a99a720874 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml @@ -22,7 +22,7 @@ device-mgt org.wso2.carbon.devicemgt - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT ../pom.xml @@ -291,6 +291,13 @@ org.wso2.carbon.identity.jwt.client.extension provided + + org.wso2.carbon.identity.framework + org.wso2.carbon.identity.user.store.count + ${carbon.identity.framework.version} + provided + +
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/BasePaginatedResult.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/BasePaginatedResult.java index 8d1c82d8d7..5c2936a1a3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/BasePaginatedResult.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/BasePaginatedResult.java @@ -30,13 +30,13 @@ public class BasePaginatedResult { value = "Number of total resources.", example = "1") @JsonProperty("count") - private int count; + private long count; - public int getCount() { + public long getCount() { return count; } - public void setCount(int count) { + public void setCount(long count) { this.count = count; } } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java index 82aa78e1f9..ddbdfcdc08 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java @@ -32,6 +32,7 @@ import io.swagger.annotations.Tag; import org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; @@ -48,6 +49,7 @@ import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.HeaderParam; import javax.ws.rs.POST; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -134,7 +136,13 @@ import javax.ws.rs.core.Response; description = "Getting Policy Compliance Details of a Device", key = "perm:devices:compliance-data", permissions = {"/device-mgt/devices/owning-device/view"} - ) + ), + @Scope( + name = "Change device status.", + description = "Change device status.", + key = "perm:devices:change-status", + permissions = {"/device-mgt/devices/change-status"} + ), } ) @Path("/devices") @@ -1150,4 +1158,79 @@ public interface DeviceManagementService { @PathParam("id") @Size(max = 45) String id); + + @PUT + @Path("/{type}/{id}/changestatus") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + consumes = MediaType.APPLICATION_JSON, + httpMethod = "PUT", + value = "Change device status by device id.", + notes = "Returns the status of the changed device operation.", + tags = "Device Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:change-status") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully changed the device status.", + response = Device.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 304, + message = "Not Modified. Empty body because the client already has the latest " + + "version of the requested resource."), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error.", + response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "Not Found. \n No device is found under the provided type and id.", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while retrieving information requested device.", + response = ErrorResponse.class) + }) + Response changeDeviceStatus( + @ApiParam( + name = "type", + value = "The device type, such as ios, android or windows.", + required = true) + @PathParam("type") + @Size(max = 45) + String type, + @ApiParam( + name = "id", + value = "Device id", + required = true) + @PathParam("id") + @Size(max = 45) + String id, + @ApiParam( + name = "newStatus", + value = "New status of the device.", + required = true) + @QueryParam("newStatus") + EnrolmentInfo.Status newStatus); + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java index e4da6a1ed6..3f3185a30d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -23,7 +23,14 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; 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.EnrolmentInfo; +import org.wso2.carbon.device.mgt.common.Feature; +import org.wso2.carbon.device.mgt.common.FeatureManager; +import org.wso2.carbon.device.mgt.common.PaginationRequest; +import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException; @@ -53,7 +60,16 @@ import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import javax.validation.constraints.Size; -import javax.ws.rs.*; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.text.ParseException; @@ -553,4 +569,36 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { } } + /** + * Change device status. + * + * @param type Device type + * @param id Device id + * @param newsStatus Device new status + * @return {@link Response} object + */ + @PUT + @Path("/{type}/{id}/changestatus") + public Response changeDeviceStatus(@PathParam("type") @Size(max = 45) String type, + @PathParam("id") @Size(max = 45) String id, + @QueryParam("newStatus") EnrolmentInfo.Status newsStatus) { + RequestValidationUtil.validateDeviceIdentifier(type, id); + DeviceManagementProviderService deviceManagementProviderService = + DeviceMgtAPIUtils.getDeviceManagementService(); + try { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(id, type); + Device persistedDevice = deviceManagementProviderService.getDevice(deviceIdentifier); + if (persistedDevice == null) { + return Response.status(Response.Status.NOT_FOUND).build(); + } + boolean response = deviceManagementProviderService.changeDeviceStatus(deviceIdentifier, newsStatus); + return Response.status(Response.Status.OK).entity(response).build(); + } catch (DeviceManagementException e) { + String msg = "Error occurred while changing device status of type : " + type + " and " + + "device id : " + id; + log.error(msg); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + } + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java index 2b5a2e8d45..ca1ad45d1d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java @@ -38,6 +38,8 @@ import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import org.wso2.carbon.device.mgt.jaxrs.util.CredentialManagementResponseBuilder; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; +import org.wso2.carbon.identity.user.store.count.UserStoreCountRetriever; +import org.wso2.carbon.identity.user.store.count.exception.UserStoreCounterException; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreManager; import org.wso2.carbon.utils.CarbonUtils; @@ -395,6 +397,30 @@ public class UserManagementServiceImpl implements UserManagementService { @Path("/count") @Override public Response getUserCount() { + try { + UserStoreCountRetriever userStoreCountRetrieverService = DeviceMgtAPIUtils.getUserStoreCountRetrieverService(); + if (userStoreCountRetrieverService != null) { + long count = userStoreCountRetrieverService.countUsers(""); + if (count != -1) { + BasicUserInfoList result = new BasicUserInfoList(); + result.setCount(count); + return Response.status(Response.Status.OK).entity(result).build(); + } + } + } catch (UserStoreCounterException e) { + String msg = + "Error occurred while retrieving the count of users that exist within the current tenant"; + log.error(msg, e); + } + return getUserCountViaUserStoreManager(); + } + + /** + * This method returns the count of users using UserStoreManager. + * + * @return user count + */ + private Response getUserCountViaUserStoreManager() { if (log.isDebugEnabled()) { log.debug("Getting the user count"); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java index 87d055c34f..888b1c42ee 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java @@ -37,14 +37,21 @@ import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.InputValidationException; import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService; +import org.wso2.carbon.identity.user.store.count.AbstractCountRetrieverFactory; +import org.wso2.carbon.identity.user.store.count.UserStoreCountRetriever; +import org.wso2.carbon.identity.user.store.count.exception.UserStoreCounterException; +import org.wso2.carbon.identity.user.store.count.jdbc.JDBCCountRetrieverFactory; +import org.wso2.carbon.identity.user.store.count.jdbc.internal.InternalCountRetrieverFactory; import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException; import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService; import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.user.api.AuthorizationManager; +import org.wso2.carbon.user.api.RealmConfiguration; import org.wso2.carbon.user.api.UserRealm; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreManager; +import org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager; import org.wso2.carbon.user.core.service.RealmService; import javax.ws.rs.core.MediaType; @@ -106,6 +113,32 @@ public class DeviceMgtAPIUtils { return deviceManagementProviderService; } + public static UserStoreCountRetriever getUserStoreCountRetrieverService() + throws UserStoreCounterException { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + List countRetrieverFactories = ctx.getOSGiServices(AbstractCountRetrieverFactory.class, null); + RealmService realmService = (RealmService) ctx.getOSGiService(RealmService.class, null); + RealmConfiguration realmConfiguration = realmService.getBootstrapRealmConfiguration(); + String userStoreType; + //Ignoring Sonar warning as getUserStoreClass() returning string name of the class. So cannot use 'instanceof'. + if (JDBCUserStoreManager.class.getName().equals(realmConfiguration.getUserStoreClass())) { + userStoreType = JDBCCountRetrieverFactory.JDBC; + } else { + userStoreType = InternalCountRetrieverFactory.INTERNAL; + } + AbstractCountRetrieverFactory countRetrieverFactory = null; + for (Object countRetrieverFactoryObj : countRetrieverFactories) { + countRetrieverFactory = (AbstractCountRetrieverFactory) countRetrieverFactoryObj; + if (userStoreType.equals(countRetrieverFactory.getCounterType())) { + break; + } + } + if (countRetrieverFactory == null) { + return null; + } + return countRetrieverFactory.buildCountRetriever(realmConfiguration); + } + public static DeviceAccessAuthorizationService getDeviceAccessAuthorizationService() { PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); DeviceAccessAuthorizationService deviceAccessAuthorizationService = diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml index 0067817575..d44753056a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml @@ -21,7 +21,7 @@ device-mgt org.wso2.carbon.devicemgt - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/InitialOperationConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/InitialOperationConfig.java new file mode 100644 index 0000000000..758ba549f2 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/InitialOperationConfig.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. 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 org.wso2.carbon.device.mgt.common; + +import java.util.List; + +public class InitialOperationConfig { + private List operations; + + public List getOperations() { + return operations; + } + + public void setOperations(List operations) { + this.operations = operations; + } + + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/Condition.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/Condition.java index 2007a3f121..8483788e9d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/Condition.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/Condition.java @@ -25,7 +25,7 @@ import io.swagger.annotations.ApiModelProperty; @ApiModel(value = "Condition", description = "Contains the advance search parameters.") public class Condition { - @ApiModelProperty(name = "conditions", value = "Provide the operation code. You can assign the following operation " + + @ApiModelProperty(name = "key", value = "Provide the operation code. You can assign the following operation " + "codes:\n" + "DEVICE_MODEL : The model of the device.\n" + "VENDOR : The name of the device vendor.\n" + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java index 197275600e..7e6f730337 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java @@ -18,10 +18,7 @@ */ package org.wso2.carbon.device.mgt.common.spi; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.DeviceManager; -import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; -import org.wso2.carbon.device.mgt.common.ProvisioningConfig; +import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; @@ -48,4 +45,8 @@ public interface DeviceManagementService { PolicyMonitoringManager getPolicyMonitoringManager(); + InitialOperationConfig getInitialOperationConfig(); + + + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index f2b7a661a4..4f57a513d4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java index a634fe93b6..1eb39fc502 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java @@ -420,12 +420,5 @@ public interface DeviceDAO { */ List getEnrolmentsByStatus(List deviceIds, Status status, int tenantId) throws DeviceManagementDAOException; - - /** - * Retrieving the tenants which are have device enrolled. - * @return - * @throws DeviceManagementDAOException - */ - List getDeviceEnrolledTenants() throws DeviceManagementDAOException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java index 09557518c4..4e37aca000 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java @@ -1063,26 +1063,4 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { return devices; } - public List getDeviceEnrolledTenants() throws DeviceManagementDAOException { - Connection conn; - PreparedStatement stmt = null; - ResultSet rs = null; - List tenants = new ArrayList<>(); - try { - conn = this.getConnection(); - String sql = "SELECT distinct(TENANT_ID) FROM DM_DEVICE"; - stmt = conn.prepareStatement(sql); - rs = stmt.executeQuery(); - while (rs.next()) { - tenants.add(rs.getInt("TENANT_ID")); - } - } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while retrieving tenants which have " + - "device registered.", e); - } finally { - DeviceManagementDAOUtil.cleanupResources(stmt, rs); - } - return tenants; - } - } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java index 7de2928065..f7e8e0a177 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java @@ -62,11 +62,6 @@ public class DeviceManagementDataHolder { private Map map = new HashMap<>(); - - public void addToMap(OperationMonitoringTaskConfig taskConfig) { - this.map.put("aa", taskConfig); - } - public Map getMap(){ return this.map; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/QueryBuilderImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/QueryBuilderImpl.java index 6291f9cb16..253e95fdd0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/QueryBuilderImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/QueryBuilderImpl.java @@ -35,6 +35,7 @@ public class QueryBuilderImpl implements QueryBuilder { private static final Log log = LogFactory.getLog(QueryBuilderImpl.class); private final String WILDCARD_OPERATOR = "%"; + private final String OR_OPERATOR = "OR"; private String current_username; private boolean isDeviceAdminUser; @@ -131,7 +132,7 @@ public class QueryBuilderImpl implements QueryBuilder { for (Condition con : conditions) { if (Utils.checkDeviceDetailsColumns(con.getKey())) { if (con.operator.equals(WILDCARD_OPERATOR)) { - querySuffix = querySuffix + " OR DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) + querySuffix = querySuffix + " AND DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) + " LIKE ? "; ValueType type = new ValueType(); type.setColumnType(ValueType.columnType.STRING); @@ -215,6 +216,11 @@ public class QueryBuilderImpl implements QueryBuilder { } catch (Exception e) { throw new InvalidOperatorException("Error occurred while building the sql", e); } + if (!querySuffix.isEmpty()) { + //Replacing the first OR operator as it's unnecessary + querySuffix = querySuffix.replaceFirst(OR_OPERATOR, ""); + querySuffix = " AND (" + querySuffix + ")"; + } return querySuffix; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index bef274e572..a48cb423c8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -307,6 +307,14 @@ public interface DeviceManagementProviderService { PolicyMonitoringManager getPolicyMonitoringManager(String deviceType); - List getDeviceEnrolledTenants() throws DeviceManagementException; - + /** + * Change device status. + * + * @param deviceIdentifier {@link DeviceIdentifier} object + * @param newStatus New status of the device + * @return Whether status is changed or not + * @throws DeviceManagementException on errors while trying to change device status + */ + boolean changeDeviceStatus(DeviceIdentifier deviceIdentifier, EnrolmentInfo.Status newStatus) + throws DeviceManagementException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 8bde4d8e06..f7d268642f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -23,20 +23,7 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; -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.DeviceManager; -import org.wso2.carbon.device.mgt.common.DeviceNotFoundException; -import org.wso2.carbon.device.mgt.common.DeviceTypeIdentifier; -import org.wso2.carbon.device.mgt.common.EnrolmentInfo; -import org.wso2.carbon.device.mgt.common.FeatureManager; -import org.wso2.carbon.device.mgt.common.InvalidDeviceException; -import org.wso2.carbon.device.mgt.common.MonitoringOperation; -import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; -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.*; import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo; @@ -66,6 +53,7 @@ import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent; import org.wso2.carbon.device.mgt.core.internal.PluginInitializationListener; +import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import org.wso2.carbon.email.sender.core.ContentProviderInfo; import org.wso2.carbon.email.sender.core.EmailContext; @@ -257,6 +245,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv if (status) { addDeviceToGroups(deviceIdentifier, device.getEnrolmentInfo().getOwnership()); + addInitialOperations(deviceIdentifier, device.getType()); + } return status; } @@ -1279,21 +1269,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv return dms.getPolicyMonitoringManager(); } - @Override - public List getDeviceEnrolledTenants() throws DeviceManagementException { - try { - DeviceManagementDAOFactory.openConnection(); - return deviceDAO.getDeviceEnrolledTenants(); - } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while retrieving the tenants " + - "which have device enrolled.", e); - } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); - } finally { - DeviceManagementDAOFactory.closeConnection(); - } - } - @Override public List getDevicesOfUser(String username) throws DeviceManagementException { List devices = new ArrayList<>(); @@ -1981,6 +1956,68 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv return false; } + /** + * Change device status. + * + * @param deviceIdentifier {@link DeviceIdentifier} object + * @param newStatus New status of the device + * @return Whether status is changed or not + * @throws DeviceManagementException on errors while trying to change device status + */ + @Override + public boolean changeDeviceStatus(DeviceIdentifier deviceIdentifier, EnrolmentInfo.Status newStatus) + throws DeviceManagementException { + boolean isDeviceUpdated = false; + Device device = getDevice(deviceIdentifier); + int deviceId = device.getId(); + EnrolmentInfo enrolmentInfo = device.getEnrolmentInfo(); + enrolmentInfo.setStatus(newStatus); + int tenantId = this.getTenantId(); + switch (newStatus) { + case ACTIVE: + isDeviceUpdated = updateEnrollment(deviceId, enrolmentInfo, tenantId); + break; + case INACTIVE: + isDeviceUpdated = updateEnrollment(deviceId, enrolmentInfo, tenantId); + break; + case REMOVED: + isDeviceUpdated = disenrollDevice(deviceIdentifier); + break; + default: + throw new DeviceManagementException("Invalid status retrieved. Status : " + newStatus); + } + return isDeviceUpdated; + } + + private boolean updateEnrollment(int deviceId, EnrolmentInfo enrolmentInfo, int tenantId) + throws DeviceManagementException { + boolean isUpdatedEnrollment = false; + boolean isAutoCommit = true; + try { + DeviceManagementDAOFactory.openConnection(); + isAutoCommit = DeviceManagementDAOFactory.getConnection().getAutoCommit(); + DeviceManagementDAOFactory.getConnection().setAutoCommit(true); + int updatedRows = enrollmentDAO.updateEnrollment(deviceId, enrolmentInfo, tenantId); + if (updatedRows > 0) { + isUpdatedEnrollment = true; + } + } catch (SQLException e) { + throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + } catch (DeviceManagementDAOException e) { + throw new DeviceManagementException("Error occurred while updating the enrollment information device for" + + "id '" + deviceId + "' ." , e); + } finally { + try { + DeviceManagementDAOFactory.getConnection().setAutoCommit(isAutoCommit); + } catch (SQLException e) { + log.error("Exception occurred while setting auto commit."); + } + DeviceManagementDAOFactory.closeConnection(); + } + return isUpdatedEnrollment; + } + + private int getTenantId() { return CarbonContext.getThreadLocalCarbonContext().getTenantId(); } @@ -2037,6 +2074,37 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } } + private void addInitialOperations(DeviceIdentifier deviceIdentifier, String deviceType) throws DeviceManagementException { + DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder.getInstance(). + getDeviceManagementProvider(); + DeviceManagementService deviceManagementService = + pluginRepository.getDeviceManagementService(deviceType, this.getTenantId()); + InitialOperationConfig init = deviceManagementService.getInitialOperationConfig(); + List deviceIdentifiers = new ArrayList<>(); + deviceIdentifiers.add(deviceIdentifier); + if (init != null) { + List initialOperations = init.getOperations(); + + for (String str : initialOperations) { + CommandOperation operation = new CommandOperation(); + operation.setEnabled(true); + operation.setType(Operation.Type.COMMAND); + operation.setCode(str); + try { + deviceManagementProviderService. + addOperation(deviceType, + operation, deviceIdentifiers); + } catch (OperationManagementException e) { + throw new DeviceManagementException("Unable to find the device with the id: '" + deviceIdentifier.getId(), + e); + } catch (InvalidDeviceException e) { + throw new DeviceManagementException("Unable to find the device with the id: '" + deviceIdentifier.getId(), + e); + } + } + } + } + /** * Checks for the default group existence and create group based on device ownership * diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java index 9040af6654..6d1228563c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java @@ -22,25 +22,17 @@ package org.wso2.carbon.device.mgt.core.task.impl; import com.google.gson.Gson; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; -import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException; import org.wso2.carbon.device.mgt.core.task.DeviceTaskManager; import org.wso2.carbon.ntask.core.Task; -import org.wso2.carbon.user.api.Tenant; -import org.wso2.carbon.user.api.UserStoreException; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import java.util.List; -import java.util.List; import java.util.Map; public class DeviceDetailsRetrieverTask implements Task { private static Log log = LogFactory.getLog(DeviceDetailsRetrieverTask.class); - // private DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(); +// private DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(); private String deviceType; private String oppConfig; private OperationMonitoringTaskConfig operationMonitoringTaskConfig; @@ -65,41 +57,18 @@ public class DeviceDetailsRetrieverTask implements Task { if (log.isDebugEnabled()) { log.debug("Device details retrieving task started to run."); } - try { -// Tenant tenants[] = DeviceManagementDataHolder.getInstance(). -// getRealmService().getTenantManager().getAllTenants(); - List tenants = DeviceManagementDataHolder.getInstance(). - getDeviceManagementProvider().getDeviceEnrolledTenants(); - for (Integer tenant : tenants) { - String tenantDomain = DeviceManagementDataHolder.getInstance(). - getRealmService().getTenantManager().getDomain(tenant); - try { - PrivilegedCarbonContext.startTenantFlow(); - PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain); - PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant); - DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType, - operationMonitoringTaskConfig); - //pass the configurations also from here, monitoring tasks - try { - deviceTaskManager.addOperations(); - } catch (DeviceMgtTaskException e) { - log.error("Error occurred while trying to add the operations to " + - "device to retrieve device details.", e); - } - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - } catch (UserStoreException e) { - log.error("Error occurred while trying to get the available tenants", e); - } catch (DeviceManagementException e) { - log.error("Error occurred while trying to get the available tenants " + - "from device manager provider service.", e); + DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType, + operationMonitoringTaskConfig); + //pass the configurations also from here, monitoring tasks + try { + deviceTaskManager.addOperations(); + } catch (DeviceMgtTaskException e) { + log.error( + "Error occurred while trying to add the operations to device to retrieve device details.", + e); } - } } - diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java index e30cdf4389..d425133ce5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java @@ -17,10 +17,7 @@ */ package org.wso2.carbon.device.mgt.core; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.DeviceManager; -import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; -import org.wso2.carbon.device.mgt.common.ProvisioningConfig; +import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; @@ -75,4 +72,9 @@ public class TestDeviceManagementService implements DeviceManagementService { return null; } + @Override + public InitialOperationConfig getInitialOperationConfig() { + return null; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml index 6b799048d0..f1518f1e98 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml @@ -22,7 +22,7 @@ device-mgt org.wso2.carbon.devicemgt - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.ui/pom.xml index 8476e6b962..ed5305f49d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/pom.xml @@ -22,7 +22,7 @@ device-mgt org.wso2.carbon.devicemgt - 2.0.16-SNAPSHOT + 2.0.36-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json index 0a1d5bc659..5caf20f31f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json @@ -1,6 +1,6 @@ { "appContext": "/devicemgt/", - "isCloud": true, + "isCloud": false, "httpsURL": "https://%iot.gateway.host%:%iot.gateway.https.port%", "httpURL": "http://%iot.gateway.host%:%iot.gateway.http.port", "wssURL": "https://%iot.analytics.host%:%iot.analytics.https.port%", @@ -182,4 +182,4 @@ "backendRestEndpoints": { "deviceMgt": "/api/device-mgt/v1.0" } -} \ No newline at end of file +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js index e9c07ee0ba..dd200cdfbe 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js @@ -81,21 +81,11 @@ var operationModule = function () { publicMethods.getControlOperations = function (deviceType) { var operations = privateMethods.getOperationsFromFeatures(deviceType, "operation"); - var features = utility.getDeviceTypeConfig(deviceType).deviceType.features; for (var op in operations) { var iconIdentifier = operations[op].operation; - if (features && features[iconIdentifier]) { - var icon = features[iconIdentifier].icon; - if (icon) { - operations[op]["iconFont"] = icon; - } else if (iconPath) { - var iconPath = utility.getOperationIcon(deviceType, iconIdentifier); - operations[op]["icon"] = iconPath; - } - var formParams = features[iconIdentifier].formParams; - if (formParams) { - operations[op]["uiParams"] = formParams; - } + var icon = utility.getOperationIcon(deviceType, iconIdentifier); + if (icon) { + operations[op]["icon"] = icon; } } return operations; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js index 96f4d280bc..e85f46c347 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js @@ -174,7 +174,7 @@ var userModule = function () { } try { utility.startTenantFlow(carbonUser); - var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users?offset=0&limit=1"; + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/count"; return serviceInvokers.XMLHttp.get( url, function (responsePayload) { return parse(responsePayload["responseText"])["count"]; @@ -609,6 +609,9 @@ var userModule = function () { if (publicMethods.isAuthorized("/permission/admin/device-mgt/platform-configs/view")) { permissions["TENANT_CONFIGURATION"] = true; } + if (publicMethods.isAuthorized("/permission/admin/device-mgt/devices/change-status")) { + permissions["CHANGE_DEVICE_STATUS"] = true; + } return permissions; }; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js index beaa90c56b..f6ee8587ec 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js @@ -33,12 +33,14 @@ var permissions = { "/permission/admin/device-mgt/device/api/subscribe": ["ui.execute"], "/permission/admin/device-mgt/devices/enroll": ["ui.execute"], "/permission/admin/device-mgt/devices/disenroll": ["ui.execute"], - "/permission/admin/device-mgt/devices/owning-device/view": ["ui.execute"] + "/permission/admin/device-mgt/devices/owning-device/view": ["ui.execute"], + "/permission/admin/manage/portal": ["ui.execute"] }; var adminPermissions = { "/permission/admin/device-mgt": ["ui.execute"], - "/permission/admin/manage/api": ["ui.execute"] + "/permission/admin/manage/api": ["ui.execute"], + "/permission/admin/manage/portal": ["ui.execute"] }; //On Startup, admin user will get both roles: devicemgt-admin and devicemgt-user diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handlers.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handlers.js index 22da928495..0fa1fbb0dc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handlers.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handlers.js @@ -40,7 +40,7 @@ var handlers = function () { "as input - setupTokenPairByPasswordGrantType(x, y)"); } else { privateMethods.setUpEncodedTenantBasedClientAppCredentials(username); - //privateMethods.setUpEncodedTenantBasedWebSocketClientAppCredentials(username); + privateMethods.setUpEncodedTenantBasedWebSocketClientAppCredentials(username); var encodedClientAppCredentials = session.get(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS"]); if (!encodedClientAppCredentials) { throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up access token pair by " + @@ -84,7 +84,7 @@ var handlers = function () { "as input - setupTokenPairBySamlGrantType(x, y)"); } else { privateMethods.setUpEncodedTenantBasedClientAppCredentials(username); - //privateMethods.setUpEncodedTenantBasedWebSocketClientAppCredentials(username); + privateMethods.setUpEncodedTenantBasedWebSocketClientAppCredentials(username); var encodedClientAppCredentials = session.get(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS"]); if (!encodedClientAppCredentials) { throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up access token pair " + @@ -129,7 +129,7 @@ var handlers = function () { "as input - setupTokenPairBySamlGrantType(x, y)"); } else { privateMethods.setUpEncodedTenantBasedClientAppCredentials(username); - //privateMethods.setUpEncodedTenantBasedWebSocketClientAppCredentials(username); + privateMethods.setUpEncodedTenantBasedWebSocketClientAppCredentials(username); var encodedClientAppCredentials = session.get(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS"]); if (!encodedClientAppCredentials) { throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up access token pair " + @@ -158,13 +158,13 @@ var handlers = function () { // setting up access token pair into session context as a string session.put(constants["TOKEN_PAIR"], stringify(tokenPair)); - var scopes = tokenData.scopes.split(" "); - // adding allowed scopes to the session - session.put(constants["ALLOWED_SCOPES"], scopes); - } - } - } - }; + var scopes = tokenData.scopes.split(" "); + // adding allowed scopes to the session + session.put(constants["ALLOWED_SCOPES"], scopes); + } + } + } + }; publicMethods["refreshTokenPair"] = function () { var currentTokenPair = parse(session.get(constants["TOKEN_PAIR"])); @@ -224,44 +224,44 @@ var handlers = function () { } }; -// privateMethods["setUpEncodedTenantBasedWebSocketClientAppCredentials"] = function (username) { -// if (!username) { -// throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up encoded tenant based " + -// "client credentials to session context. No username of logged in user is found as " + -// "input - setUpEncodedTenantBasedWebSocketClientAppCredentials(x)"); -// } else { -// if (devicemgtProps["gatewayEnabled"]) { -// var tenantBasedWebSocketClientAppCredentials -// = tokenUtil.getTenantBasedWebSocketClientAppCredentials(username); -// if (!tenantBasedWebSocketClientAppCredentials) { -// throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up encoded tenant " + -// "based client credentials to session context as the server is unable " + -// "to obtain such credentials - setUpEncodedTenantBasedWebSocketClientAppCredentials(x)"); -// } else { -// var encodedTenantBasedWebSocketClientAppCredentials = -// tokenUtil.encode(tenantBasedWebSocketClientAppCredentials["clientId"] + ":" + -// tenantBasedWebSocketClientAppCredentials["clientSecret"]); -// // setting up encoded tenant based client credentials to session context. -// session.put(constants["ENCODED_TENANT_BASED_WEB_SOCKET_CLIENT_CREDENTIALS"], -// encodedTenantBasedWebSocketClientAppCredentials); -// } -// } else { -// var dynamicClientAppCredentials = tokenUtil.getDynamicClientAppCredentials(); -// if (!dynamicClientAppCredentials) { -// throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up encoded tenant based " + -// "client credentials to session context as the server is unable to obtain " + -// "dynamic client credentials - setUpEncodedTenantBasedWebSocketClientAppCredentials(x)"); -// } -// var encodedTenantBasedWebSocketClientAppCredentials = -// tokenUtil.encode(dynamicClientAppCredentials["clientId"] + ":" + -// dynamicClientAppCredentials["clientSecret"]); -// // setting up encoded tenant based client credentials to session context. -// session.put(constants["ENCODED_TENANT_BASED_WEB_SOCKET_CLIENT_CREDENTIALS"], -// encodedTenantBasedWebSocketClientAppCredentials); -// } + privateMethods["setUpEncodedTenantBasedWebSocketClientAppCredentials"] = function (username) { + if (!username) { + throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up encoded tenant based " + + "client credentials to session context. No username of logged in user is found as " + + "input - setUpEncodedTenantBasedWebSocketClientAppCredentials(x)"); + } else { + if (devicemgtProps["gatewayEnabled"]) { + var tenantBasedWebSocketClientAppCredentials + = tokenUtil.getTenantBasedWebSocketClientAppCredentials(username); + if (!tenantBasedWebSocketClientAppCredentials) { + throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up encoded tenant " + + "based client credentials to session context as the server is unable " + + "to obtain such credentials - setUpEncodedTenantBasedWebSocketClientAppCredentials(x)"); + } else { + var encodedTenantBasedWebSocketClientAppCredentials = + tokenUtil.encode(tenantBasedWebSocketClientAppCredentials["clientId"] + ":" + + tenantBasedWebSocketClientAppCredentials["clientSecret"]); + // setting up encoded tenant based client credentials to session context. + session.put(constants["ENCODED_TENANT_BASED_WEB_SOCKET_CLIENT_CREDENTIALS"], + encodedTenantBasedWebSocketClientAppCredentials); + } + } else { + var dynamicClientAppCredentials = tokenUtil.getDynamicClientAppCredentials(); + if (!dynamicClientAppCredentials) { + throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up encoded tenant based " + + "client credentials to session context as the server is unable to obtain " + + "dynamic client credentials - setUpEncodedTenantBasedWebSocketClientAppCredentials(x)"); + } + var encodedTenantBasedWebSocketClientAppCredentials = + tokenUtil.encode(dynamicClientAppCredentials["clientId"] + ":" + + dynamicClientAppCredentials["clientSecret"]); + // setting up encoded tenant based client credentials to session context. + session.put(constants["ENCODED_TENANT_BASED_WEB_SOCKET_CLIENT_CREDENTIALS"], + encodedTenantBasedWebSocketClientAppCredentials); + } -// } -// }; + } + }; return publicMethods; }(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/public/js/bottomJs.js index 68a4292ea8..66c1719052 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/public/js/bottomJs.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/public/js/bottomJs.js @@ -44,7 +44,7 @@ var dynamicForm = '
+ **/ + tpl: '', + /** + Placeholder attribute of input. Shown when input is empty. + + @property placeholder + @type string + @default null + **/ + placeholder: null, + + /** + Whether to show `clear` button + + @property clear + @type boolean + @default true + **/ + clear: true + }); + + $.fn.editabletypes.text = Text; + +}(window.jQuery)); + +/** +Textarea input + +@class textarea +@extends abstractinput +@final +@example +awesome comment! + +**/ +(function ($) { + "use strict"; + + var Textarea = function (options) { + this.init('textarea', options, Textarea.defaults); + }; + + $.fn.editableutils.inherit(Textarea, $.fn.editabletypes.abstractinput); + + $.extend(Textarea.prototype, { + render: function () { + this.setClass(); + this.setAttr('placeholder'); + this.setAttr('rows'); + + //ctrl + enter + this.$input.keydown(function (e) { + if (e.ctrlKey && e.which === 13) { + $(this).closest('form').submit(); + } + }); + }, + + //using `white-space: pre-wrap` solves \n <--> BR conversion very elegant! + /* + value2html: function(value, element) { + var html = '', lines; + if(value) { + lines = value.split("\n"); + for (var i = 0; i < lines.length; i++) { + lines[i] = $('
').text(lines[i]).html(); + } + html = lines.join('
'); + } + $(element).html(html); + }, + + html2value: function(html) { + if(!html) { + return ''; + } + + var regex = new RegExp(String.fromCharCode(10), 'g'); + var lines = html.split(//i); + for (var i = 0; i < lines.length; i++) { + var text = $('
').html(lines[i]).text(); + + // Remove newline characters (\n) to avoid them being converted by value2html() method + // thus adding extra
tags + text = text.replace(regex, ''); + + lines[i] = text; + } + return lines.join("\n"); + }, + */ + activate: function() { + $.fn.editabletypes.text.prototype.activate.call(this); + } + }); + + Textarea.defaults = $.extend({}, $.fn.editabletypes.abstractinput.defaults, { + /** + @property tpl + @default + **/ + tpl:'', + /** + @property inputclass + @default input-large + **/ + inputclass: 'input-large', + /** + Placeholder attribute of input. Shown when input is empty. + + @property placeholder + @type string + @default null + **/ + placeholder: null, + /** + Number of rows in textarea + + @property rows + @type integer + @default 7 + **/ + rows: 7 + }); + + $.fn.editabletypes.textarea = Textarea; + +}(window.jQuery)); + +/** +Select (dropdown) + +@class select +@extends list +@final +@example + + +**/ +(function ($) { + "use strict"; + + var Select = function (options) { + this.init('select', options, Select.defaults); + }; + + $.fn.editableutils.inherit(Select, $.fn.editabletypes.list); + + $.extend(Select.prototype, { + renderList: function() { + this.$input.empty(); + + var fillItems = function($el, data) { + var attr; + if($.isArray(data)) { + for(var i=0; i', attr), data[i].children)); + } else { + attr.value = data[i].value; + if(data[i].disabled) { + attr.disabled = true; + } + $el.append($('