From 2384755a97664f7c312c983a800f62aefd6ef566 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Wed, 8 Mar 2017 03:14:51 +0530 Subject: [PATCH 1/2] added claimable property and fixed unsecured endpoint bug --- .../webapp/publisher/APIPublisherUtil.java | 3 +- .../lifecycle/util/AnnotationProcessor.java | 2 +- .../type/deployer/config/Claimable.java | 104 ++++++++++++++++++ .../config/DeviceTypeConfiguration.java | 23 ++++ .../deployer/template/DeviceTypeManager.java | 8 +- .../src/test/resources/sample.xml | 2 + 6 files changed, 139 insertions(+), 3 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/Claimable.java 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 839658ec2a1..a3f8608de4d 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 52dc1477903..dfc8dd74540 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/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 00000000000..7c9a97d0eaf --- /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) 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.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 2a43797e9d9..a367e06e029 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 @@ -56,6 +56,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) @@ -119,6 +121,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/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 eba2f18721a..98c5ef28708 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/test/resources/sample.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/test/resources/sample.xml index 6542d9629b2..414bcaa8ddf 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 From b1b0b03ce1b58d7e1730d88f11a5c86ac8242b7d Mon Sep 17 00:00:00 2001 From: ayyoob Date: Mon, 13 Mar 2017 18:01:41 +0530 Subject: [PATCH 2/2] changed license year --- .../mgt/extensions/device/type/deployer/config/Claimable.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 7c9a97d0eaf..661778e62d0 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/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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * 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