From 274d9ec37e50140c6f624b002380441797fe3768 Mon Sep 17 00:00:00 2001 From: Geeth Munasinghe Date: Fri, 12 Dec 2014 14:45:24 +0530 Subject: [PATCH 1/2] Adding the feature management service and android application to webapps --- .../carbon/policy/mgt/common/Feature.java | 9 ++ .../mgt/common/impl/PolicyManagement.java | 15 ++ .../mgt/common/spi/FeatureManagerService.java | 38 +++++ .../mgt/common/spi/PolicyManagerService.java | 23 ++- product/modules/distribution/pom.xml | 6 +- .../modules/distribution/src/assembly/bin.xml | 149 +++++++----------- 6 files changed, 142 insertions(+), 98 deletions(-) create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/spi/FeatureManagerService.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Feature.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Feature.java index cbe7e55ae56..9183c810be9 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Feature.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Feature.java @@ -20,10 +20,19 @@ package org.wso2.carbon.policy.mgt.common; public class Feature { + private int id; private String code; private String name; private Object attribute; + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + public String getCode() { return code; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/impl/PolicyManagement.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/impl/PolicyManagement.java index db14d8e1fc7..6b2a9ee33f7 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/impl/PolicyManagement.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/impl/PolicyManagement.java @@ -63,4 +63,19 @@ public class PolicyManagement implements PolicyManagerService { public Policy getPolicyOfRole(String roleName) throws FeatureManagementException, PolicyManagementException { return null; } + + @Override + public boolean isPolicyAvailableForDevice(String deviceId, String deviceType) throws PolicyManagementException { + return false; + } + + @Override + public boolean isPolicyUsed(String deviceId, String deviceType) throws PolicyManagementException { + return false; + } + + @Override + public void setPolicyUsed(String deviceId, String deviceType, Policy policy) throws PolicyManagementException { + + } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/spi/FeatureManagerService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/spi/FeatureManagerService.java new file mode 100644 index 00000000000..6ed982cd2ec --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/spi/FeatureManagerService.java @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2014 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.policy.mgt.common.spi; + +import org.wso2.carbon.policy.mgt.common.Feature; +import org.wso2.carbon.policy.mgt.common.FeatureManagementException; + +import java.util.List; + +public interface FeatureManagerService { + + void addFeature(Feature feature) throws FeatureManagementException; + + void editFeature(Feature feature) throws FeatureManagementException; + + void removeFeature(int featureId) throws FeatureManagementException; + + List getFeatures() throws FeatureManagementException; + + List getFeaturesOfPolicy(int policyId) throws FeatureManagementException; +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/spi/PolicyManagerService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/spi/PolicyManagerService.java index 063ac757c9a..ae55266618c 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/spi/PolicyManagerService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/spi/PolicyManagerService.java @@ -30,6 +30,7 @@ public interface PolicyManagerService { /** * This method adds a policy to the platform + * * @param policy * @return primary key (generated key) */ @@ -38,6 +39,7 @@ public interface PolicyManagerService { /** * This method adds a policy per device which should be implemented by the related plugins. + * * @param deviceId * @param deviceType * @param policy @@ -48,15 +50,17 @@ public interface PolicyManagerService { /** * This method adds a policy to device type by the related device type plugins. + * * @param deviceType * @param policy * @return primary key (generated key) */ - int addPolicyToDeviceType(String deviceType,Policy policy) throws FeatureManagementException, PolicyManagementException; + int addPolicyToDeviceType(String deviceType, Policy policy) throws FeatureManagementException, PolicyManagementException; /** * This method adds the policy to specific role. + * * @param roleName * @param policy * @return primary key (generated key) @@ -65,30 +69,34 @@ public interface PolicyManagerService { /** * This method returns the policy of whole platform + * * @return */ - Policy getPolicy(); + Policy getPolicy(); /** * This method gives the device specific policy. + * * @param deviceId * @param deviceType - * @return Policy + * @return Policy */ Policy getPolicyOfDevice(String deviceId, String deviceType) throws FeatureManagementException, PolicyManagementException; /** * This method returns the device type specific policy. + * * @param deviceType - * @return Policy + * @return Policy */ Policy getPolicyOfDeviceType(String deviceType) throws FeatureManagementException, PolicyManagementException; /** * This method returns the role specific policy. + * * @param roleName * @return */ @@ -96,4 +104,11 @@ public interface PolicyManagerService { Policy getPolicyOfRole(String roleName) throws FeatureManagementException, PolicyManagementException; + boolean isPolicyAvailableForDevice(String deviceId, String deviceType) throws PolicyManagementException; + + + boolean isPolicyUsed(String deviceId, String deviceType) throws PolicyManagementException; + + + void setPolicyUsed(String deviceId, String deviceType, Policy policy) throws PolicyManagementException; } diff --git a/product/modules/distribution/pom.xml b/product/modules/distribution/pom.xml index ba6de3b91e5..ab110a0ff26 100644 --- a/product/modules/distribution/pom.xml +++ b/product/modules/distribution/pom.xml @@ -105,6 +105,8 @@ + + @@ -137,7 +139,7 @@ og4j.logger.net.sf.ehcache=ERROR - + @@ -147,6 +149,8 @@ package + + @@ -98,11 +89,11 @@ 755 - - src/repository/resources/stratos_root - wso2cdm-${project.version}/repository/deployment/server/webapps/STRATOS_ROOT - 755 - + ../p2-profile-gen/target/wso2carbon-core-${carbon.kernel.version}/modules ${pom.artifactId}-${project.version}/modules/ @@ -110,50 +101,14 @@ */** - - - - src/repository/conf wso2cdm-${project.version}/repository/conf **/api-manager.xml **/sso-idp-config.xml - + @@ -239,35 +194,42 @@ - + 755 + + src/repository/conf/tomcat/context.xml wso2cdm-${project.version}/repository/conf/tomcat true 644 - + INSTALL.txt @@ -307,18 +269,14 @@ - + + - - target/wso2carbon-core-${carbon.kernel.version}/repository/conf/log4j.properties - wso2cdm-${project.version}/repository/conf/ - true - src/repository/conf/multitenancy/cloud-services-desc.xml wso2cdm-${project.version}/repository/conf/multitenancy/ @@ -354,15 +312,18 @@ - ../p2-profile-gen/target/wso2carbon-core-${carbon.kernel.version}/repository/conf/tomcat/webapp-classloading.xml + + ../p2-profile-gen/target/wso2carbon-core-${carbon.kernel.version}/repository/conf/tomcat/webapp-classloading.xml + ${pom.artifactId}-${pom.version}/repository/conf/tomcat true 644 - + - ../p2-profile-gen/target/wso2carbon-core-${carbon.kernel.version}/repository/conf/cdm-config.xml + ../p2-profile-gen/target/wso2carbon-core-${carbon.kernel.version}/repository/conf/cdm-config.xml + ${pom.artifactId}-${pom.version}/repository/conf true 644 @@ -370,19 +331,21 @@ - ../p2-profile-gen/target/wso2carbon-core-${carbon.kernel.version}/repository/conf/tomcat/webapp-classloading-environments.xml + + ../p2-profile-gen/target/wso2carbon-core-${carbon.kernel.version}/repository/conf/tomcat/webapp-classloading-environments.xml + ${pom.artifactId}-${pom.version}/repository/conf/tomcat true 644 - + From 608e552c07d0c0ea563a1b0e041476765520b2c7 Mon Sep 17 00:00:00 2001 From: Asok Date: Fri, 12 Dec 2014 17:15:07 +0530 Subject: [PATCH 2/2] removing java.nio --- .../windows/impl/DiscoveryServiceImpl.java | 22 ++++++++++++------ .../windows/impl/EnrolmentServiceImpl.java | 23 +++++++++++-------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/impl/DiscoveryServiceImpl.java b/product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/impl/DiscoveryServiceImpl.java index 01ef564609c..59de66ae0f9 100644 --- a/product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/impl/DiscoveryServiceImpl.java +++ b/product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/impl/DiscoveryServiceImpl.java @@ -21,24 +21,35 @@ package cdm.api.windows.impl; import cdm.api.windows.DiscoveryService; import javax.ws.rs.core.Response; +import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Paths; + import org.apache.log4j.Logger; public class DiscoveryServiceImpl implements DiscoveryService { private Logger LOGGER = Logger.getLogger(DiscoveryServiceImpl.class); - private String discoveryServiceFileName; public Response getDiscoveryResponse(InputStream discoveryRequest) { LOGGER.info("Received Discovery Service POST Request [{}]"); String response = null; + File file = null; + FileInputStream fis = null; + byte[] data = null; + try { - response = new String(Files.readAllBytes(Paths.get(discoveryServiceFileName))); + + file = new File("./conf/discover-service.xml"); + fis = new FileInputStream(file); + data = new byte[(int) file.length()]; + fis.read(data); + fis.close(); + response = new String(data, "UTF-8"); + } catch (IOException e) { LOGGER.error("An Unexpected Error has occurred while processing the request ", e); } @@ -57,8 +68,5 @@ public class DiscoveryServiceImpl implements DiscoveryService { return Response.ok().build(); } - public void setDiscoveryServiceFileName(String discoveryServiceFileName) { - this.discoveryServiceFileName = discoveryServiceFileName; - } } diff --git a/product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/impl/EnrolmentServiceImpl.java b/product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/impl/EnrolmentServiceImpl.java index 71b797efeca..c3acde83871 100644 --- a/product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/impl/EnrolmentServiceImpl.java +++ b/product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/impl/EnrolmentServiceImpl.java @@ -40,11 +40,10 @@ import javax.xml.transform.stream.StreamResult; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathFactory; +import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.StringWriter; -import java.nio.file.Files; -import java.nio.file.Paths; import java.security.KeyFactory; import java.security.PrivateKey; import java.security.Security; @@ -65,8 +64,6 @@ public class EnrolmentServiceImpl implements EnrolmentService { private String enrollmentResponseFile; - private String responseFile; - private String wapProvisioningXmlFile; private String privatePemKeyFilePath; @@ -156,9 +153,21 @@ public class EnrolmentServiceImpl implements EnrolmentService { public Response getPolicies(Document request) { LOGGER.info("Received Get Policies Request"); + String response = null; + File file = null; + FileInputStream fis = null; + byte[] data = null; + try { - response = new String(Files.readAllBytes(Paths.get(responseFile))); + + file = new File("./conf/policy-service.xml"); + fis = new FileInputStream(file); + data = new byte[(int) file.length()]; + fis.read(data); + fis.close(); + response = new String(data, "UTF-8"); + } catch (IOException e) { LOGGER.error("An Unexpected Error has occurred while processing the request ", e); } @@ -250,10 +259,6 @@ public class EnrolmentServiceImpl implements EnrolmentService { this.enrollmentResponseFile = enrollmentResponseFile; } - public void setResponseFile(String responseFile) { - this.responseFile = responseFile; - } - public void setWapProvisioningXmlFile(String wapProvisioningXmlFile) { this.wapProvisioningXmlFile = wapProvisioningXmlFile; }