diff --git a/README.md b/README.md index 3a1819b659..d692947a53 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,4 @@ WSO2 CONNECTED DEVICE MANAGER 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. -Whether it is device provisioning, device configuration management, policy enforcement, mobile application management, device data security, or compliance monitoring, WSO2 EMM offers a single enterprise-grade platform. \ No newline at end of file +Whether it is device provisioning, device configuration management, policy enforcement, mobile application management, device data security, or compliance monitoring, WSO2 CDM offers a single enterprise-grade platform to develop extensions for IOT related device types. \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java index 9802fe30fe..76c541d337 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java @@ -43,4 +43,10 @@ public final class DeviceManagementConstants { public final static String MOBILE_DEVICE_TYPE_WINDOWS = "windows"; } + public static final class LanguageCodes{ + private LanguageCodes() { throw new AssertionError();} + public final static String LANGUAGE_CODE_ENGLISH_US = "en-us"; + public final static String LANGUAGE_CODE_ENGLISH_UK = "en-uk"; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementException.java index 48c409b894..4d261973e7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementException.java @@ -15,7 +15,6 @@ */ package org.wso2.carbon.device.mgt.common; -@SuppressWarnings("unused") public class DeviceManagementException extends Exception { private static final long serialVersionUID = -3151279311929070297L; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/LicenseManagementException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/LicenseManagementException.java new file mode 100644 index 0000000000..1b39a74981 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/LicenseManagementException.java @@ -0,0 +1,62 @@ +/* + * + * Copyright (c) 2015, 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; + +public class LicenseManagementException extends Exception{ + + private static final long serialVersionUID = 8606378077242945475L; + private String errorMessage; + + public static long getSerialVersionUID() { + return serialVersionUID; + } + + public LicenseManagementException(String msg, Exception nestedEx) { + super(msg, nestedEx); + setErrorMessage(msg); + } + + public LicenseManagementException(String message, Throwable cause) { + super(message, cause); + setErrorMessage(message); + } + + public LicenseManagementException(String msg) { + super(msg); + setErrorMessage(msg); + } + + public LicenseManagementException() { + super(); + } + + public LicenseManagementException(Throwable cause) { + super(cause); + } + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } +} 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 8690a2e3fd..fece8a1afb 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 @@ -121,6 +121,10 @@ org.wso2.carbon org.wso2.carbon.user.api + + org.wso2.carbon + org.wso2.carbon.governance.api + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java index 726c43c343..8f8f24328b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java @@ -17,6 +17,8 @@ */ package org.wso2.carbon.device.mgt.core; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; @@ -35,6 +37,7 @@ import java.util.List; public class DeviceManagerImpl implements DeviceManager { + private static Log log = LogFactory.getLog(DeviceManagerImpl.class); private DeviceDAO deviceDAO; private DeviceTypeDAO deviceTypeDAO; private DeviceManagementConfig config; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManager.java index 0275a1bc20..35c846ac2e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManager.java @@ -1,30 +1,27 @@ /* * - * * 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. - * / + * Copyright (c) 2015, 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.core; -import org.wso2.carbon.device.mgt.core.dto.DeviceType; - -public class LicenseManager { - -/* public void addLicense(DeviceType deviceType,String langCode, String - );*/ +import org.wso2.carbon.device.mgt.common.*; +public interface LicenseManager { + public License getLicense(String deviceType,String languageCodes) throws LicenseManagementException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManagerImpl.java new file mode 100644 index 0000000000..d00936e3fa --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManagerImpl.java @@ -0,0 +1,119 @@ +/* + * + * Copyright (c) 2015, 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.core; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.base.MultitenantConstants; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.context.RegistryType; +import org.wso2.carbon.device.mgt.common.License; +import org.wso2.carbon.device.mgt.common.LicenseManagementException; +import org.wso2.carbon.governance.api.exception.GovernanceException; +import org.wso2.carbon.governance.api.generic.GenericArtifactFilter; +import org.wso2.carbon.governance.api.generic.GenericArtifactManager; +import org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact; +import org.wso2.carbon.governance.api.util.GovernanceUtils; +import org.wso2.carbon.registry.core.Registry; +import org.wso2.carbon.registry.core.exceptions.RegistryException; +import org.wso2.carbon.registry.core.session.UserRegistry; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + + +public class LicenseManagerImpl implements LicenseManager { + + private static Log log = LogFactory.getLog(DeviceManagerImpl.class); + + @Override + public License getLicense(final String deviceType, + final String languageCodes) throws LicenseManagementException { + + if (log.isDebugEnabled()){ + log.debug("entered get License in license manager impl"); + } + // TODO: After completes JAX-RX user login, this need to be change to CarbonContext + PrivilegedCarbonContext.getThreadLocalCarbonContext().startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername("admin"); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); + + Registry registry = (UserRegistry) PrivilegedCarbonContext.getThreadLocalCarbonContext().getRegistry( + RegistryType.USER_GOVERNANCE); + + GenericArtifact[] filteredArtifacts; + License license = new License(); + + try { + GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry); + GenericArtifactManager artifactManager = new GenericArtifactManager(registry, "license"); + + filteredArtifacts = artifactManager.findGenericArtifacts( + new GenericArtifactFilter() { + public boolean matches(GenericArtifact artifact) throws GovernanceException { + String attributeNameVal = artifact.getAttribute("overview_name"); + String attributeLangVal = artifact.getAttribute("overview_language"); + return (attributeNameVal != null && attributeLangVal != null && attributeNameVal.equals + (deviceType) && attributeLangVal.equals(languageCodes)); + } + }); + String validFrom; + String validTo; + DateFormat format; + Date fromDate; + Date toDate; + + for (GenericArtifact artifact : filteredArtifacts) { + if (log.isDebugEnabled()){ + log.debug("Overview name:"+artifact.getAttribute("overview_name")); + log.debug("Overview provider:"+artifact.getAttribute("overview_provider")); + log.debug("Overview Language:"+artifact.getAttribute("overview_language")); + log.debug("overview_validityFrom:"+artifact.getAttribute("overview_validityFrom")); + log.debug("overview_validityTo:"+artifact.getAttribute("overview_validityTo")); + } + validFrom = artifact.getAttribute("overview_validityFrom"); + validTo = artifact.getAttribute("overview_validityTo"); + format = new SimpleDateFormat("dd-mm-yyyy", Locale.ENGLISH); + try { + fromDate = format.parse(validFrom); + toDate = format.parse(validTo); + if (fromDate.getTime()<= new Date().getTime() && new Date().getTime() <= toDate.getTime()){ + license.setLicenseText(artifact.getAttribute("overview_license")); + } + } catch (ParseException e) { + log.error("validFrom:"+ validFrom); + log.error("validTo:"+validTo); + log.error("Valid date parse error:",e); + } + } + } catch (RegistryException regEx) { + log.error("registry exception:",regEx); + throw new LicenseManagementException(); + }finally { + PrivilegedCarbonContext.endTenantFlow(); + } + + return license; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index 311e59d961..96a591ef75 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -50,7 +50,6 @@ import org.wso2.carbon.user.core.service.RealmService; * bind="setDeviceManagerService" * unbind="unsetDeviceManagerService" */ -@SuppressWarnings("unused") public class DeviceManagementServiceComponent { private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/LicenseManagementDataHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/LicenseManagementDataHolder.java new file mode 100644 index 0000000000..1d81f8f10c --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/LicenseManagementDataHolder.java @@ -0,0 +1,63 @@ +/* + * + * Copyright (c) 2015, 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.core.internal; + +import org.wso2.carbon.device.mgt.core.LicenseManager; +import org.wso2.carbon.user.core.service.RealmService; +import org.wso2.carbon.user.core.tenant.TenantManager; + +public class LicenseManagementDataHolder { + + private RealmService realmService; + private TenantManager tenantManager; + private LicenseManager licenseManager; + private static LicenseManagementDataHolder thisInstance = new LicenseManagementDataHolder(); + + public RealmService getRealmService() { + return realmService; + } + + public void setRealmService(RealmService realmService) { + this.realmService = realmService; + } + + public TenantManager getTenantManager() { + return tenantManager; + } + + public void setTenantManager(TenantManager tenantManager) { + this.tenantManager = tenantManager; + } + + private LicenseManagementDataHolder() { + } + + public static LicenseManagementDataHolder getInstance() { + return thisInstance; + } + public LicenseManager getLicenseManager() { + return licenseManager; + } + + public void setLicenseManager(LicenseManager licenseManager) { + this.licenseManager = licenseManager; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/LicenseManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/LicenseManagementServiceComponent.java new file mode 100644 index 0000000000..b1316eff5c --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/LicenseManagementServiceComponent.java @@ -0,0 +1,82 @@ +/* + * + * Copyright (c) 2015, 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.core.internal; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.framework.BundleContext; +import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.device.mgt.core.LicenseManager; +import org.wso2.carbon.device.mgt.core.LicenseManagerImpl; +import org.wso2.carbon.device.mgt.core.service.LicenseManagementService; +import org.wso2.carbon.user.core.service.RealmService; + +/** + * @scr.component name="org.wso2.carbon.license.manager" immediate="true" + * @scr.reference name="user.realmservice.default" + * interface="org.wso2.carbon.user.core.service.RealmService" + * cardinality="1..1" + * policy="dynamic" + * bind="setRealmService" + * unbind="unsetRealmService" + */ +public class LicenseManagementServiceComponent { + + private static Log log = LogFactory.getLog(LicenseManagementServiceComponent.class); + + protected void activate(ComponentContext componentContext) { + + if (log.isDebugEnabled()) { + log.debug("Initializing license management core bundle"); + } + LicenseManager licenseManager = new LicenseManagerImpl(); + LicenseManagementDataHolder.getInstance().setLicenseManager(licenseManager); + + if (log.isDebugEnabled()) { + log.debug("Registering OSGi service LicenseManagementService"); + } + BundleContext bundleContext = componentContext.getBundleContext(); + bundleContext.registerService(LicenseManagementService.class.getName(), new LicenseManagementService(), null); + if (log.isDebugEnabled()) { + log.debug("License management core bundle has been successfully initialized"); + } + } + + /** + * Sets Realm Service. + * @param realmService An instance of RealmService + */ + protected void setRealmService(RealmService realmService) { + if (log.isDebugEnabled()) { + log.debug("Setting Realm Service in license management"); + } + LicenseManagementDataHolder.getInstance().setRealmService(realmService); + } + + /** + * Unsets Realm Service. + * @param realmService An instance of RealmService + */ + protected void unsetRealmService(RealmService realmService) { + if (log.isDebugEnabled()) { + log.debug("Un setting Realm Service in license management"); + } + LicenseManagementDataHolder.getInstance().setRealmService(null); + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/LicenseManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/LicenseManagementService.java new file mode 100644 index 0000000000..bccbcea3c7 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/LicenseManagementService.java @@ -0,0 +1,34 @@ +/* + * + * Copyright (c) 2015, 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.core.service; + +import org.wso2.carbon.device.mgt.common.License; +import org.wso2.carbon.device.mgt.common.LicenseManagementException; +import org.wso2.carbon.device.mgt.core.LicenseManager; +import org.wso2.carbon.device.mgt.core.internal.LicenseManagementDataHolder; + +public class LicenseManagementService implements LicenseManager { + + @Override + public License getLicense(String deviceType, String languageCode) throws LicenseManagementException { + return LicenseManagementDataHolder.getInstance().getLicenseManager().getLicense(deviceType, languageCode); + } +} diff --git a/pom.xml b/pom.xml index e4618c0556..cc71985697 100644 --- a/pom.xml +++ b/pom.xml @@ -120,8 +120,11 @@ org.wso2.carbon.policy.mgt.core ${project.version} - - + + org.wso2.carbon + org.wso2.carbon.governance.api + ${carbon.platform.version} + org.eclipse.osgi @@ -201,6 +204,7 @@ ${project.version} + diff --git a/product/modules/distribution/src/repository/resources/rxts/license.rxt b/product/modules/distribution/src/repository/resources/rxts/license.rxt index 72f5c2618a..2fc84c6db9 100644 --- a/product/modules/distribution/src/repository/resources/rxts/license.rxt +++ b/product/modules/distribution/src/repository/resources/rxts/license.rxt @@ -1,16 +1,19 @@ - /license/@{overview_provider}/@{overview_name}/@{overview_version} + /license/@{overview_provider}/@{overview_name}/@{overview_language}/@{overview_version} overview_name - + + + + @@ -24,11 +27,17 @@ Name + + Language + Version - Createdtime + Validity From + + + Validity To License