From 1b5bae3e46789cb99faa1a67855aecf237b1554c Mon Sep 17 00:00:00 2001 From: Hasunie Date: Thu, 1 Dec 2016 08:59:19 +0530 Subject: [PATCH] adding required authorization property --- .../config/DeviceAuthorizationConfig.java | 68 +++++++++ .../config/DeviceTypeConfiguration.java | 141 +++++++++--------- .../deployer/template/DeviceTypeManager.java | 27 ++-- .../src/test/resources/sample.xml | 4 + 4 files changed, 155 insertions(+), 85 deletions(-) create mode 100644 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/DeviceAuthorizationConfig.java 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/DeviceAuthorizationConfig.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/DeviceAuthorizationConfig.java new file mode 100644 index 0000000000..833719ba2a --- /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/DeviceAuthorizationConfig.java @@ -0,0 +1,68 @@ +/* + * 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.extensions.device.type.deployer.config; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; + +/** + *

Java class for Device type authorization requirement. + *

+ *

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

+ *

+ * <complexType name="DeviceAuthorizationConfig">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="authorizationRequired" type="{http://www.w3.org/2001/XMLSchema}boolean"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "DeviceAuthorizationConfig", propOrder = { + "authorizationRequired" +}) +public class DeviceAuthorizationConfig { + + @XmlElement(name = "authorizationRequired") + protected boolean authorizationRequired; + + /** + * Gets the value of the sharedWithAllTenants property. + */ + public boolean isAuthorizationRequired() { + return authorizationRequired; + } + + /** + * Sets the value of the sharedWithAllTenants property. + */ + public void setAuthorizationRequired(boolean authorizationRequired) { + this.authorizationRequired = authorizationRequired; + } + +} + 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 4e8cfc4a88..51d603347f 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 @@ -27,9 +27,9 @@ import javax.xml.bind.annotation.XmlRootElement; /** *

Java class for DeviceTypeConfiguration complex type. - * + *

*

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

*

  * <complexType name="DeviceTypeConfiguration">
  *   <complexContent>
@@ -41,14 +41,13 @@ import javax.xml.bind.annotation.XmlRootElement;
  *         <element name="PushNotificationProvider" type="{}PushNotificationProvider"/>
  *         <element name="License" type="{}License"/>
  *         <element name="DataSource" type="{}DataSource"/>
+ *         <element name="DeviceAuthorizationConfig" type="{}DeviceAuthorizationConfig"/>
  *       </sequence>
  *       <attribute name="name" type="{http://www.w3.org/2001/XMLSchema}string" />
  *     </restriction>
  *   </complexContent>
  * </complexType>
  * 
- * - * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "DeviceTypeConfiguration") @@ -66,16 +65,16 @@ public class DeviceTypeConfiguration { protected License license; @XmlElement(name = "DataSource", required = true) protected DataSource dataSource; + @XmlElement(name = "DeviceAuthorizationConfig", required = true) + protected DeviceAuthorizationConfig deviceAuthorizationConfig; @XmlAttribute(name = "name") protected String name; /** * Gets the value of the deviceDetails property. - * - * @return - * possible object is - * {@link DeviceDetails } - * + * + * @return possible object is + * {@link DeviceDetails } */ public DeviceDetails getDeviceDetails() { return deviceDetails; @@ -83,11 +82,9 @@ public class DeviceTypeConfiguration { /** * Sets the value of the deviceDetails property. - * - * @param value - * allowed object is - * {@link DeviceDetails } - * + * + * @param value allowed object is + * {@link DeviceDetails } */ public void setDeviceDetails(DeviceDetails value) { this.deviceDetails = value; @@ -95,11 +92,9 @@ public class DeviceTypeConfiguration { /** * Gets the value of the features property. - * - * @return - * possible object is - * {@link Features } - * + * + * @return possible object is + * {@link Features } */ public Features getFeatures() { return features; @@ -107,11 +102,9 @@ public class DeviceTypeConfiguration { /** * Sets the value of the features property. - * - * @param value - * allowed object is - * {@link Features } - * + * + * @param value allowed object is + * {@link Features } */ public void setFeatures(Features value) { this.features = value; @@ -119,11 +112,9 @@ public class DeviceTypeConfiguration { /** * Gets the value of the provisioningConfig property. - * - * @return - * possible object is - * {@link ProvisioningConfig } - * + * + * @return possible object is + * {@link ProvisioningConfig } */ public ProvisioningConfig getProvisioningConfig() { return provisioningConfig; @@ -131,11 +122,9 @@ public class DeviceTypeConfiguration { /** * Sets the value of the provisioningConfig property. - * - * @param value - * allowed object is - * {@link ProvisioningConfig } - * + * + * @param value allowed object is + * {@link ProvisioningConfig } */ public void setProvisioningConfig(ProvisioningConfig value) { this.provisioningConfig = value; @@ -143,11 +132,9 @@ public class DeviceTypeConfiguration { /** * Gets the value of the pushNotificationProvider property. - * - * @return - * possible object is - * {@link PushNotificationProvider } - * + * + * @return possible object is + * {@link PushNotificationProvider } */ public PushNotificationProvider getPushNotificationProvider() { return pushNotificationProvider; @@ -155,11 +142,9 @@ public class DeviceTypeConfiguration { /** * Sets the value of the pushNotificationProvider property. - * - * @param value - * allowed object is - * {@link PushNotificationProvider } - * + * + * @param value allowed object is + * {@link PushNotificationProvider } */ public void setPushNotificationProvider(PushNotificationProvider value) { this.pushNotificationProvider = value; @@ -167,11 +152,9 @@ public class DeviceTypeConfiguration { /** * Gets the value of the license property. - * - * @return - * possible object is - * {@link License } - * + * + * @return possible object is + * {@link License } */ public License getLicense() { return license; @@ -179,11 +162,9 @@ public class DeviceTypeConfiguration { /** * Sets the value of the license property. - * - * @param value - * allowed object is - * {@link License } - * + * + * @param value allowed object is + * {@link License } */ public void setLicense(License value) { this.license = value; @@ -191,11 +172,9 @@ public class DeviceTypeConfiguration { /** * Gets the value of the dataSource property. - * - * @return - * possible object is - * {@link DataSource } - * + * + * @return possible object is + * {@link DataSource } */ public DataSource getDataSource() { return dataSource; @@ -203,11 +182,9 @@ public class DeviceTypeConfiguration { /** * Sets the value of the dataSource property. - * - * @param value - * allowed object is - * {@link DataSource } - * + * + * @param value allowed object is + * {@link DataSource } */ public void setDataSource(DataSource value) { this.dataSource = value; @@ -215,11 +192,9 @@ public class DeviceTypeConfiguration { /** * Gets the value of the name property. - * - * @return - * possible object is - * {@link String } - * + * + * @return possible object is + * {@link String } */ public String getName() { return name; @@ -227,14 +202,32 @@ public class DeviceTypeConfiguration { /** * Sets the value of the name property. - * - * @param value - * allowed object is - * {@link String } - * + * + * @param value allowed object is + * {@link String } */ public void setName(String value) { this.name = value; } + /** + * Gets the value of the authorizationRequired property. + * + * @return possible object is + * {@link DeviceAuthorizationConfig } + */ + public DeviceAuthorizationConfig getDeviceAuthorizationConfig() { + return deviceAuthorizationConfig; + } + + /** + * Sets the value of the provisioningConfig property. + * + * @param value allowed object is + * {@link DeviceAuthorizationConfig } + */ + public void setDeviceAuthorizationConfig(DeviceAuthorizationConfig value) { + this.deviceAuthorizationConfig = value; + } + } 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 e0f2d45f10..8a9bcd7ed5 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 @@ -30,11 +30,8 @@ import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; -import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.DeviceDetails; -import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.DeviceTypeConfiguration; -import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.Table; +import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.*; import org.wso2.carbon.device.mgt.extensions.device.type.deployer.util.DeviceTypePluginConstants; -import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.Feature; import org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception.DeviceTypeDeployerFileException; import org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception.DeviceTypeMgtPluginException; import org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.dao.DeviceDAODefinition; @@ -65,18 +62,26 @@ public class DeviceTypeManager implements DeviceManager { private DeviceTypePluginDAOManager deviceTypePluginDAOManager; private LicenseManager licenseManager; private boolean propertiesExist; + private boolean requiredDeviceTypeAuthorization; private FeatureManager featureManager; + public DeviceTypeManager(DeviceTypeConfigIdentifier deviceTypeConfigIdentifier, - DeviceTypeConfiguration deviceTypeConfiguration) { + DeviceTypeConfiguration deviceTypeConfiguration) { deviceType = deviceTypeConfigIdentifier.getDeviceType(); - if (deviceTypeConfiguration.getFeatures() != null && deviceTypeConfiguration.getFeatures().getFeature() != null ) { + if (deviceTypeConfiguration.getFeatures() != null && deviceTypeConfiguration.getFeatures(). + getFeature() != null) { List features = deviceTypeConfiguration.getFeatures().getFeature(); if (features != null) { featureManager = new ConfigurationBasedFeatureManager(features); } } - + if (deviceTypeConfiguration.getDeviceAuthorizationConfig() != null) { + requiredDeviceTypeAuthorization = deviceTypeConfiguration.getDeviceAuthorizationConfig(). + isAuthorizationRequired(); + } else { + requiredDeviceTypeAuthorization = true; + } //add license to registry. this.licenseManager = new RegistryBasedLicenseManager(); try { @@ -120,11 +125,11 @@ public class DeviceTypeManager implements DeviceManager { if (setupOption != null) { if (log.isDebugEnabled()) { log.debug("-Dsetup is enabled. Device management repository schema initialization is about " + - "to begin"); + "to begin"); } try { DeviceTypeUtils.setupDeviceManagementSchema(datasourceName, deviceType, - deviceDAODefinition.getDeviceTableName()); + deviceDAODefinition.getDeviceTableName()); } catch (DeviceTypeMgtPluginException e) { log.error("Exception occurred while initializing device management database schema", e); } @@ -346,7 +351,7 @@ public class DeviceTypeManager implements DeviceManager { @Override public boolean requireDeviceAuthorization() { - return true; + return requiredDeviceTypeAuthorization; } @Override @@ -370,7 +375,7 @@ public class DeviceTypeManager implements DeviceManager { deviceTypePluginDAOManager.getDeviceTypeDAOHandler().rollbackTransaction(); } catch (DeviceTypeMgtPluginException e1) { log.warn("Error occurred while roll back the update device info transaction : '" + - device.toString() + "'", e1); + device.toString() + "'", e1); } throw new DeviceManagementException( "Error occurred while updating the " + deviceType + " device: '" + 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 1f0584227c..ac2d059aea 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 @@ -63,6 +63,10 @@ false + + true + + true