├── features └── device-mgt │ ├── org.wso2.carbon.device.mgt.mobile.feature │ ├── src │ │ └── main │ │ │ └── resources │ │ │ ├── build.properties │ │ │ ├── p2.inf │ │ │ ├── dbscripts │ │ │ └── plugins │ │ │ │ ├── android │ │ │ │ ├── mssql.sql │ │ │ │ ├── postgresql.sql │ │ │ │ ├── h2.sql │ │ │ │ ├── mysql.sql │ │ │ │ └── oracle.sql │ │ │ │ ├── windows │ │ │ │ ├── mssql.sql │ │ │ │ ├── postgresql.sql │ │ │ │ ├── h2.sql │ │ │ │ ├── mysql.sql │ │ │ │ └── oracle.sql │ │ │ │ └── ios │ │ │ │ ├── mssql.sql │ │ │ │ ├── h2.sql │ │ │ │ ├── postgresql.sql │ │ │ │ ├── mysql.sql │ │ │ │ └── oracle.sql │ │ │ └── conf │ │ │ └── mobile-config.xml │ └── pom.xml │ └── pom.xml ├── .gitignore ├── README.md └── components ├── device-mgt ├── org.wso2.carbon.device.mgt.mobile.impl │ └── src │ │ ├── main │ │ └── java │ │ │ └── org │ │ │ └── wso2 │ │ │ └── carbon │ │ │ └── device │ │ │ └── mgt │ │ │ └── mobile │ │ │ ├── DataSourceListener.java │ │ │ ├── dao │ │ │ ├── MobileDeviceManagementDAOFactory.java │ │ │ ├── MobileDeviceManagementDAOException.java │ │ │ ├── MobileDeviceDAO.java │ │ │ ├── MobileFeatureDAO.java │ │ │ ├── AbstractMobileDeviceManagementDAOFactory.java │ │ │ └── util │ │ │ │ └── MobileDeviceManagementDAOUtil.java │ │ │ ├── impl │ │ │ ├── android │ │ │ │ ├── util │ │ │ │ │ ├── AndroidUtils.java │ │ │ │ │ ├── AndroidPluginConstants.java │ │ │ │ │ └── AndroidPluginUtils.java │ │ │ │ ├── gcm │ │ │ │ │ ├── GCMResult.java │ │ │ │ │ └── GCMService.java │ │ │ │ ├── dao │ │ │ │ │ ├── AndroidFeatureManagementDAOException.java │ │ │ │ │ └── AndroidDAOFactory.java │ │ │ │ ├── AndroidDeviceManagementService.java │ │ │ │ └── AndroidPolicyMonitoringService.java │ │ │ └── windows │ │ │ │ ├── util │ │ │ │ ├── WindowsUtils.java │ │ │ │ ├── WindowsPluginConstants.java │ │ │ │ └── WindowsPluginUtils.java │ │ │ │ ├── dao │ │ │ │ ├── WindowsFeatureManagementDAOException.java │ │ │ │ └── WindowsDAOFactory.java │ │ │ │ ├── WindowsPolicyMonitoringService.java │ │ │ │ └── WindowsDeviceManagementService.java │ │ │ ├── common │ │ │ ├── MobilePluginConstants.java │ │ │ └── MobileDeviceMgtPluginException.java │ │ │ ├── dto │ │ │ ├── MobileFeatureProperty.java │ │ │ ├── MobileOperationProperty.java │ │ │ ├── MobileOperation.java │ │ │ ├── MobileFeature.java │ │ │ ├── MobileDeviceOperationMapping.java │ │ │ └── MobileDevice.java │ │ │ ├── AbstractMobileOperationManager.java │ │ │ ├── config │ │ │ ├── MobileDeviceManagementConfig.java │ │ │ ├── datasource │ │ │ │ ├── MobileDataSourceConfigurations.java │ │ │ │ ├── MobileDataSourceConfig.java │ │ │ │ ├── JNDILookupDefinition.java │ │ │ │ └── DataSourceConfigAdapter.java │ │ │ ├── MobileDeviceManagementRepository.java │ │ │ └── MobileDeviceConfigurationManager.java │ │ │ ├── DataSourceNotAvailableException.java │ │ │ ├── internal │ │ │ └── MobileDeviceManagementDataHolder.java │ │ │ └── util │ │ │ └── MobileDeviceManagementSchemaInitializer.java │ │ └── test │ │ ├── java │ │ └── org │ │ │ └── wso2 │ │ │ └── carbon │ │ │ └── device │ │ │ └── mgt │ │ │ └── mobile │ │ │ └── impl │ │ │ ├── common │ │ │ ├── DBTypes.java │ │ │ ├── TestDBConfigurations.java │ │ │ └── TestDBConfiguration.java │ │ │ ├── dao │ │ │ └── util │ │ │ │ └── MobileDatabaseUtils.java │ │ │ └── MobileDeviceManagementConfigTests.java │ │ └── resources │ │ ├── testdbconfig.xml │ │ ├── testng.xml │ │ ├── log4j.properties │ │ ├── config │ │ ├── malformed-mobile-config-no-apis-config.xml │ │ ├── malformed-mobile-config-no-ds-config.xml │ │ ├── malformed-mobile-config-no-jndi-config.xml │ │ ├── malformed-mobile-config-no-mgt-repo.xml │ │ ├── malformed-mobile-config-no-api-publisher-config.xml │ │ ├── malformed-mobile-config-no-api-config.xml │ │ └── schema │ │ │ └── MobileDeviceManagementConfigSchema.xsd │ │ └── sql │ │ └── h2.sql ├── org.wso2.carbon.device.mgt.mobile.url.printer │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── org │ │ │ └── wso2 │ │ │ └── carbon │ │ │ └── device │ │ │ └── mgt │ │ │ └── mobile │ │ │ └── url │ │ │ └── printer │ │ │ ├── internal │ │ │ ├── URLPrinterDataHolder.java │ │ │ └── URLPrinterStartupHandlerServiceComponent.java │ │ │ └── URLPrinterStartupHandler.java │ └── pom.xml └── pom.xml └── key-mgt ├── org.wso2.carbon.key.mgt.handler.valve ├── src │ └── main │ │ └── java │ │ └── org │ │ └── wso2 │ │ └── carbon │ │ └── key │ │ └── mgt │ │ └── handler │ │ └── valve │ │ ├── HandlerConstants.java │ │ ├── APIFaultException.java │ │ ├── OAuthTokenValidatorValve.java │ │ └── HandlerUtil.java └── pom.xml └── pom.xml /features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/build.properties: -------------------------------------------------------------------------------- 1 | custom = true 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | target 3 | .classpath 4 | .settings 5 | .project 6 | *.iml 7 | *.iws 8 | *.ipr 9 | .idea 10 | 11 | # Mac crap 12 | .DS_Store 13 | *.class 14 | 15 | # Mobile Tools for Java (J2ME) 16 | .mtj.tmp/ 17 | 18 | # Package Files # 19 | *.jar 20 | *.war 21 | *.ear 22 | 23 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 24 | hs_err_pid* 25 | -------------------------------------------------------------------------------- /features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/p2.inf: -------------------------------------------------------------------------------- 1 | instructions.configure = \ 2 | org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile_${feature.version}/conf/mobile-config.xml,target:${installFolder}/../../conf/mobile-config.xml,overwrite:true);\ 3 | org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile_${feature.version}/dbscripts/plugins/,target:${installFolder}/../../../dbscripts/cdm/plugins,overwrite:true);\ 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #carbon-device-mgt-plugins 2 | 3 | WSO2 MOBILE DEVICE MANAGER 4 | 5 | WSO2 Mobile Device Manager (WSO2 MDM) 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. 6 | 7 | Whether it is device provisioning, device configuration management, policy enforcement, mobile application management, device data security, or compliance monitoring, WSO2 MDM offers a single enterprise-grade platform. 8 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/DataSourceListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile; 20 | 21 | public interface DataSourceListener { 22 | 23 | void notifyObserver(); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.dao; 20 | 21 | public interface MobileDeviceManagementDAOFactory { 22 | 23 | MobileDeviceDAO getMobileDeviceDAO(); 24 | 25 | MobileFeatureDAO getMobileFeatureDAO(); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/common/DBTypes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.impl.common; 20 | 21 | 22 | public enum DBTypes { 23 | Oracle("Oracle"),H2("H2"),MySql("MySql"); 24 | 25 | String dbName ; 26 | DBTypes(String dbStrName) { 27 | dbName = dbStrName; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/testdbconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | 19 | jdbc:h2:mem:cdm-mobile-test-db;DB_CLOSE_DELAY=-1 20 | org.h2.Driver 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /components/key-mgt/org.wso2.carbon.key.mgt.handler.valve/src/main/java/org/wso2/carbon/key/mgt/handler/valve/HandlerConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.key.mgt.handler.valve; 20 | 21 | public class HandlerConstants { 22 | 23 | public static final String HEADER_AUTHORIZATION = "Authorization"; 24 | public static final String TOKEN_NAME_BEARER = "Bearer"; 25 | 26 | public static final String NO_MATCHING_AUTH_SCHEME = "noMatchedAuthScheme"; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.impl.android.util; 20 | 21 | import java.util.Map; 22 | 23 | /** 24 | * Contains utility methods used by Android plugin. 25 | */ 26 | public class AndroidUtils { 27 | 28 | public static String getDeviceProperty(Map deviceProperties, String property) { 29 | return deviceProperties.get(property); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/mssql.sql: -------------------------------------------------------------------------------- 1 | -- ----------------------------------------------------- 2 | -- Table `AD_DEVICE` 3 | -- ----------------------------------------------------- 4 | CREATE TABLE AD_DEVICE ( 5 | DEVICE_ID VARCHAR(45) NOT NULL, 6 | GCM_TOKEN VARCHAR(1000) NULL DEFAULT NULL, 7 | DEVICE_INFO VARCHAR(8000) NULL DEFAULT NULL, 8 | IMEI VARCHAR(45) NULL DEFAULT NULL, 9 | IMSI VARCHAR(45) NULL DEFAULT NULL, 10 | OS_VERSION VARCHAR(45) NULL DEFAULT NULL, 11 | DEVICE_MODEL VARCHAR(45) NULL DEFAULT NULL, 12 | VENDOR VARCHAR(45) NULL DEFAULT NULL, 13 | LATITUDE VARCHAR(45) NULL DEFAULT NULL, 14 | LONGITUDE VARCHAR(45) NULL DEFAULT NULL, 15 | SERIAL VARCHAR(45) NULL DEFAULT NULL, 16 | MAC_ADDRESS VARCHAR(45) NULL DEFAULT NULL, 17 | DEVICE_NAME VARCHAR(100) NULL DEFAULT NULL, 18 | PRIMARY KEY (DEVICE_ID)); 19 | 20 | -- ----------------------------------------------------- 21 | -- Table `AD_FEATURE` 22 | -- ----------------------------------------------------- 23 | CREATE TABLE AD_FEATURE ( 24 | ID INT NOT NULL IDENTITY, 25 | CODE VARCHAR(45) NOT NULL, 26 | NAME VARCHAR(100) NULL, 27 | DESCRIPTION VARCHAR(200) NULL, 28 | PRIMARY KEY (ID) 29 | ); 30 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/testng.xml: -------------------------------------------------------------------------------- 1 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/postgresql.sql: -------------------------------------------------------------------------------- 1 | -- ----------------------------------------------------- 2 | -- Table AD_DEVICE 3 | -- ----------------------------------------------------- 4 | CREATE TABLE IF NOT EXISTS AD_DEVICE ( 5 | DEVICE_ID VARCHAR(45) NOT NULL , 6 | DEVICE_INFO TEXT NULL DEFAULT NULL, 7 | GCM_TOKEN VARCHAR(1000) NULL DEFAULT NULL, 8 | IMEI VARCHAR(45) NULL DEFAULT NULL, 9 | IMSI VARCHAR(45) NULL DEFAULT NULL, 10 | OS_VERSION VARCHAR(45) NULL DEFAULT NULL, 11 | DEVICE_MODEL VARCHAR(45) NULL DEFAULT NULL, 12 | VENDOR VARCHAR(45) NULL DEFAULT NULL, 13 | LATITUDE VARCHAR(45) NULL DEFAULT NULL, 14 | LONGITUDE VARCHAR(45) NULL DEFAULT NULL, 15 | SERIAL VARCHAR(45) NULL DEFAULT NULL, 16 | MAC_ADDRESS VARCHAR(45) NULL DEFAULT NULL, 17 | DEVICE_NAME VARCHAR(100) NULL DEFAULT NULL, 18 | PRIMARY KEY (DEVICE_ID) 19 | ); 20 | 21 | -- ----------------------------------------------------- 22 | -- Table AD_FEATURE 23 | -- ----------------------------------------------------- 24 | CREATE TABLE IF NOT EXISTS AD_FEATURE ( 25 | ID BIGSERIAL NOT NULL PRIMARY KEY, 26 | CODE VARCHAR(45) NOT NULL, 27 | NAME VARCHAR(100) NULL, 28 | DESCRIPTION VARCHAR(200) NULL 29 | ); 30 | -------------------------------------------------------------------------------- /features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/mssql.sql: -------------------------------------------------------------------------------- 1 | -- ----------------------------------------------------- 2 | -- Table `WINDOWS_FEATURE` 3 | -- ----------------------------------------------------- 4 | CREATE TABLE WIN_FEATURE ( 5 | ID INT NOT NULL IDENTITY, 6 | CODE VARCHAR(45) NOT NULL, 7 | NAME VARCHAR(100) NULL, 8 | DESCRIPTION VARCHAR(200) NULL, 9 | PRIMARY KEY (ID) 10 | ); 11 | 12 | -- ----------------------------------------------------- 13 | -- Table `WINDOWS_DEVICE` 14 | -- ----------------------------------------------------- 15 | CREATE TABLE WIN_DEVICE ( 16 | DEVICE_ID VARCHAR(45) NOT NULL, 17 | CHANNEL_URI VARCHAR(100) NULL DEFAULT NULL, 18 | DEVICE_INFO TEXT NULL DEFAULT NULL, 19 | IMEI VARCHAR(45) NULL DEFAULT NULL, 20 | IMSI VARCHAR(45) NULL DEFAULT NULL, 21 | OS_VERSION VARCHAR(45) NULL DEFAULT NULL, 22 | DEVICE_MODEL VARCHAR(45) NULL DEFAULT NULL, 23 | VENDOR VARCHAR(45) NULL DEFAULT NULL, 24 | LATITUDE VARCHAR(45) NULL DEFAULT NULL, 25 | LONGITUDE VARCHAR(45) NULL DEFAULT NULL, 26 | SERIAL VARCHAR(45) NULL DEFAULT NULL, 27 | MAC_ADDRESS VARCHAR(45) NULL DEFAULT NULL, 28 | DEVICE_NAME VARCHAR(100) NULL DEFAULT NULL, 29 | PRIMARY KEY (DEVICE_ID) 30 | ); 31 | -------------------------------------------------------------------------------- /features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/postgresql.sql: -------------------------------------------------------------------------------- 1 | -- ----------------------------------------------------- 2 | -- Table WIN_DEVICE 3 | -- ----------------------------------------------------- 4 | CREATE TABLE IF NOT EXISTS WIN_DEVICE ( 5 | DEVICE_ID VARCHAR(45) NOT NULL, 6 | CHANNEL_URI VARCHAR(100) NULL DEFAULT NULL, 7 | DEVICE_INFO TEXT NULL DEFAULT NULL, 8 | IMEI VARCHAR(45) NULL DEFAULT NULL, 9 | IMSI VARCHAR(45) NULL DEFAULT NULL, 10 | OS_VERSION VARCHAR(45) NULL DEFAULT NULL, 11 | DEVICE_MODEL VARCHAR(45) NULL DEFAULT NULL, 12 | VENDOR VARCHAR(45) NULL DEFAULT NULL, 13 | LATITUDE VARCHAR(45) NULL DEFAULT NULL, 14 | LONGITUDE VARCHAR(45) NULL DEFAULT NULL, 15 | SERIAL VARCHAR(45) NULL DEFAULT NULL, 16 | MAC_ADDRESS VARCHAR(45) NULL DEFAULT NULL, 17 | DEVICE_NAME VARCHAR(100) NULL DEFAULT NULL, 18 | PRIMARY KEY (DEVICE_ID) 19 | ); 20 | 21 | -- ----------------------------------------------------- 22 | -- Table WIN_FEATURE 23 | -- ----------------------------------------------------- 24 | CREATE TABLE IF NOT EXISTS WIN_FEATURE ( 25 | ID SERIAL NOT NULL, 26 | CODE VARCHAR(45) NULL, 27 | NAME VARCHAR(100) NULL, 28 | DESCRIPTION VARCHAR(200) NULL, 29 | PRIMARY KEY (ID) 30 | ); 31 | 32 | -------------------------------------------------------------------------------- /features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/h2.sql: -------------------------------------------------------------------------------- 1 | -- ----------------------------------------------------- 2 | -- Table `WIN_DEVICE` 3 | -- ----------------------------------------------------- 4 | CREATE TABLE IF NOT EXISTS `WIN_DEVICE` ( 5 | `DEVICE_ID` VARCHAR(45) NOT NULL, 6 | `CHANNEL_URI` VARCHAR(100) NULL DEFAULT NULL, 7 | `DEVICE_INFO` TEXT NULL DEFAULT NULL, 8 | `IMEI` VARCHAR(45) NULL DEFAULT NULL, 9 | `IMSI` VARCHAR(45) NULL DEFAULT NULL, 10 | `OS_VERSION` VARCHAR(45) NULL DEFAULT NULL, 11 | `DEVICE_MODEL` VARCHAR(45) NULL DEFAULT NULL, 12 | `VENDOR` VARCHAR(45) NULL DEFAULT NULL, 13 | `LATITUDE` VARCHAR(45) NULL DEFAULT NULL, 14 | `LONGITUDE` VARCHAR(45) NULL DEFAULT NULL, 15 | `SERIAL` VARCHAR(45) NULL DEFAULT NULL, 16 | `MAC_ADDRESS` VARCHAR(45) NULL DEFAULT NULL, 17 | `DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL, 18 | PRIMARY KEY (`DEVICE_ID`) 19 | ); 20 | 21 | -- ----------------------------------------------------- 22 | -- Table `WIN_FEATURE` 23 | -- ----------------------------------------------------- 24 | CREATE TABLE IF NOT EXISTS `WIN_FEATURE` ( 25 | `ID` INT NOT NULL AUTO_INCREMENT, 26 | `CODE` VARCHAR(45) NOT NULL, 27 | `NAME` VARCHAR(100) NULL, 28 | `DESCRIPTION` VARCHAR(200) NULL, 29 | PRIMARY KEY (`ID`) 30 | ); 31 | -------------------------------------------------------------------------------- /features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/h2.sql: -------------------------------------------------------------------------------- 1 | 2 | -- ----------------------------------------------------- 3 | -- Table `AD_DEVICE` 4 | -- ----------------------------------------------------- 5 | CREATE TABLE IF NOT EXISTS `AD_DEVICE` ( 6 | `DEVICE_ID` VARCHAR(45) NOT NULL, 7 | `GCM_TOKEN` VARCHAR(1000) NULL DEFAULT NULL, 8 | `DEVICE_INFO` VARCHAR(8000) NULL DEFAULT NULL, 9 | `IMEI` VARCHAR(45) NULL DEFAULT NULL, 10 | `IMSI` VARCHAR(45) NULL DEFAULT NULL, 11 | `OS_VERSION` VARCHAR(45) NULL DEFAULT NULL, 12 | `DEVICE_MODEL` VARCHAR(45) NULL DEFAULT NULL, 13 | `VENDOR` VARCHAR(45) NULL DEFAULT NULL, 14 | `LATITUDE` VARCHAR(45) NULL DEFAULT NULL, 15 | `LONGITUDE` VARCHAR(45) NULL DEFAULT NULL, 16 | `SERIAL` VARCHAR(45) NULL DEFAULT NULL, 17 | `MAC_ADDRESS` VARCHAR(45) NULL DEFAULT NULL, 18 | `DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL, 19 | PRIMARY KEY (`DEVICE_ID`)); 20 | 21 | -- ----------------------------------------------------- 22 | -- Table `AD_FEATURE` 23 | -- ----------------------------------------------------- 24 | CREATE TABLE IF NOT EXISTS `AD_FEATURE` ( 25 | `ID` INT NOT NULL AUTO_INCREMENT, 26 | `CODE` VARCHAR(45) NOT NULL, 27 | `NAME` VARCHAR(100) NULL, 28 | `DESCRIPTION` VARCHAR(200) NULL, 29 | PRIMARY KEY (`ID`)); 30 | 31 | -------------------------------------------------------------------------------- /features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/mysql.sql: -------------------------------------------------------------------------------- 1 | -- ----------------------------------------------------- 2 | -- Table `AD_DEVICE` 3 | -- ----------------------------------------------------- 4 | CREATE TABLE IF NOT EXISTS `AD_DEVICE` ( 5 | `DEVICE_ID` VARCHAR(45) NOT NULL, 6 | `GCM_TOKEN` VARCHAR(1000) NULL DEFAULT NULL, 7 | `DEVICE_INFO` VARCHAR(8000) NULL DEFAULT NULL, 8 | `IMEI` VARCHAR(45) NULL DEFAULT NULL, 9 | `IMSI` VARCHAR(45) NULL DEFAULT NULL, 10 | `OS_VERSION` VARCHAR(45) NULL DEFAULT NULL, 11 | `DEVICE_MODEL` VARCHAR(45) NULL DEFAULT NULL, 12 | `VENDOR` VARCHAR(45) NULL DEFAULT NULL, 13 | `LATITUDE` VARCHAR(45) NULL DEFAULT NULL, 14 | `LONGITUDE` VARCHAR(45) NULL DEFAULT NULL, 15 | `SERIAL` VARCHAR(45) NULL DEFAULT NULL, 16 | `MAC_ADDRESS` VARCHAR(45) NULL DEFAULT NULL, 17 | `DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL, 18 | PRIMARY KEY (`DEVICE_ID`)) 19 | ENGINE = InnoDB; 20 | 21 | -- ----------------------------------------------------- 22 | -- Table `AD_FEATURE` 23 | -- ----------------------------------------------------- 24 | CREATE TABLE IF NOT EXISTS `AD_FEATURE` ( 25 | `ID` INT NOT NULL AUTO_INCREMENT, 26 | `CODE` VARCHAR(45) NOT NULL, 27 | `NAME` VARCHAR(100) NULL, 28 | `DESCRIPTION` VARCHAR(200) NULL, 29 | PRIMARY KEY (`ID`) 30 | ) ENGINE = InnoDB; 31 | 32 | -------------------------------------------------------------------------------- /features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/mysql.sql: -------------------------------------------------------------------------------- 1 | -- ----------------------------------------------------- 2 | -- Table `WIN_DEVICE` 3 | -- ----------------------------------------------------- 4 | CREATE TABLE IF NOT EXISTS `WIN_DEVICE` ( 5 | `DEVICE_ID` VARCHAR(45) NOT NULL, 6 | `CHANNEL_URI` VARCHAR(100) NULL DEFAULT NULL, 7 | `DEVICE_INFO` TEXT NULL DEFAULT NULL, 8 | `IMEI` VARCHAR(45) NULL DEFAULT NULL, 9 | `IMSI` VARCHAR(45) NULL DEFAULT NULL, 10 | `OS_VERSION` VARCHAR(45) NULL DEFAULT NULL, 11 | `DEVICE_MODEL` VARCHAR(45) NULL DEFAULT NULL, 12 | `VENDOR` VARCHAR(45) NULL DEFAULT NULL, 13 | `LATITUDE` VARCHAR(45) NULL DEFAULT NULL, 14 | `LONGITUDE` VARCHAR(45) NULL DEFAULT NULL, 15 | `SERIAL` VARCHAR(45) NULL DEFAULT NULL, 16 | `MAC_ADDRESS` VARCHAR(45) NULL DEFAULT NULL, 17 | `DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL, 18 | PRIMARY KEY (`DEVICE_ID`)) 19 | ENGINE = InnoDB; 20 | 21 | 22 | -- ----------------------------------------------------- 23 | -- Table `WIN_FEATURE` 24 | -- ----------------------------------------------------- 25 | CREATE TABLE IF NOT EXISTS `WIN_FEATURE` ( 26 | `ID` INT NOT NULL AUTO_INCREMENT, 27 | `CODE` VARCHAR(45) NULL, 28 | `NAME` VARCHAR(100) NULL, 29 | `DESCRIPTION` VARCHAR(200) NULL, 30 | PRIMARY KEY (`ID`)) 31 | ENGINE = InnoDB; 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.impl.windows.util; 20 | 21 | import java.util.Map; 22 | 23 | /** 24 | * Contains utility methods used by Windows plugin. 25 | */ 26 | public class WindowsUtils { 27 | public static String getDeviceProperty(Map deviceProperties, String property) { 28 | 29 | String deviceProperty = deviceProperties.get(property); 30 | if (deviceProperty == null) { 31 | return null; 32 | } 33 | return deviceProperty; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/common/MobilePluginConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | package org.wso2.carbon.device.mgt.mobile.common; 19 | 20 | public class MobilePluginConstants { 21 | public static final String MOBILE_DB_SCRIPTS_FOLDER = "cdm"; 22 | public static final String MOBILE_CONFIG_REGISTRY_ROOT = "/_system/config"; 23 | 24 | public static final String MEDIA_TYPE_XML = "application/xml"; 25 | public static final String CHARSET_UTF8 = "UTF8"; 26 | public static final String LANGUAGE_CODE_ENGLISH_US = "en_US"; 27 | public static final String LANGUAGE_CODE_ENGLISH_UK = "en_UK"; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/mssql.sql: -------------------------------------------------------------------------------- 1 | -- ----------------------------------------------------- 2 | -- Table `IOS_FEATURE` 3 | -- ----------------------------------------------------- 4 | CREATE TABLE IOS_FEATURE ( 5 | ID INT NOT NULL IDENTITY, 6 | CODE VARCHAR(45) NOT NULL, 7 | NAME VARCHAR(100) NULL, 8 | DESCRIPTION VARCHAR(200) NULL, 9 | PRIMARY KEY (ID) 10 | ); 11 | 12 | -- ----------------------------------------------------- 13 | -- Table `IOS_DEVICE` 14 | -- ----------------------------------------------------- 15 | CREATE TABLE IOS_DEVICE ( 16 | MOBILE_DEVICE_ID VARCHAR(45) NOT NULL, 17 | APNS_PUSH_TOKEN VARCHAR(100) NULL DEFAULT NULL, 18 | MAGIC_TOKEN VARCHAR(100) NULL DEFAULT NULL, 19 | MDM_TOKEN VARCHAR(100) NULL DEFAULT NULL, 20 | UNLOCK_TOKEN VARCHAR(2000) NULL DEFAULT NULL, 21 | CHALLENGE_TOKEN VARCHAR(45) NULL DEFAULT NULL, 22 | DEVICE_INFO VARCHAR(8000) NULL DEFAULT NULL, 23 | SERIAL VARCHAR(45) NULL DEFAULT NULL, 24 | PRODUCT VARCHAR(45) NULL DEFAULT NULL, 25 | IMEI VARCHAR(45) NULL DEFAULT NULL, 26 | VERSION VARCHAR(45) NULL DEFAULT NULL, 27 | MAC_ADDRESS VARCHAR(45) NULL DEFAULT NULL, 28 | DEVICE_NAME VARCHAR(100) NULL DEFAULT NULL, 29 | ICCID VARCHAR(45) NULL DEFAULT NULL, 30 | LATITUDE VARCHAR(45) NULL DEFAULT NULL, 31 | LONGITUDE VARCHAR(45) NULL DEFAULT NULL, 32 | PRIMARY KEY (MOBILE_DEVICE_ID) 33 | ); 34 | -------------------------------------------------------------------------------- /features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/h2.sql: -------------------------------------------------------------------------------- 1 | -- ----------------------------------------------------- 2 | -- Table `IOS_DEVICE` 3 | -- ----------------------------------------------------- 4 | CREATE TABLE IF NOT EXISTS `IOS_DEVICE` ( 5 | `MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL, 6 | `APNS_PUSH_TOKEN` VARCHAR(100) DEFAULT NULL, 7 | `MAGIC_TOKEN` VARCHAR(100) DEFAULT NULL, 8 | `MDM_TOKEN` VARCHAR(100) DEFAULT NULL, 9 | `UNLOCK_TOKEN` VARCHAR(2000) DEFAULT NULL, 10 | `CHALLENGE_TOKEN` VARCHAR(45) DEFAULT NULL, 11 | `DEVICE_INFO` VARCHAR(8000) DEFAULT NULL, 12 | `SERIAL` VARCHAR(45) DEFAULT NULL, 13 | `PRODUCT` VARCHAR(45) DEFAULT NULL, 14 | `IMEI` VARCHAR(45) DEFAULT NULL, 15 | `VERSION` VARCHAR(45) DEFAULT NULL, 16 | `MAC_ADDRESS` VARCHAR(45) DEFAULT NULL, 17 | `DEVICE_NAME` VARCHAR(100) DEFAULT NULL, 18 | `ICCID` VARCHAR(45) DEFAULT NULL, 19 | `LATITUDE` VARCHAR(45) DEFAULT NULL, 20 | `LONGITUDE` VARCHAR(45) DEFAULT NULL, 21 | PRIMARY KEY (`MOBILE_DEVICE_ID`) 22 | ); 23 | 24 | -- ----------------------------------------------------- 25 | -- Table `IOS_FEATURE` 26 | -- ----------------------------------------------------- 27 | CREATE TABLE IF NOT EXISTS `IOS_FEATURE` ( 28 | `FEATURE_ID` INT NOT NULL AUTO_INCREMENT, 29 | `CODE` VARCHAR(45) NOT NULL, 30 | `NAME` VARCHAR(100) NULL, 31 | `DESCRIPTION` VARCHAR(200) NULL, 32 | PRIMARY KEY (`FEATURE_ID`) 33 | ); 34 | -------------------------------------------------------------------------------- /features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/postgresql.sql: -------------------------------------------------------------------------------- 1 | -- ----------------------------------------------------- 2 | -- Table IOS_FEATURE 3 | -- ----------------------------------------------------- 4 | CREATE TABLE IF NOT EXISTS IOS_FEATURE ( 5 | ID SERIAL NOT NULL, 6 | CODE VARCHAR(45) NOT NULL, 7 | NAME VARCHAR(100) NULL, 8 | DESCRIPTION VARCHAR(200) NULL, 9 | PRIMARY KEY (ID) 10 | ); 11 | 12 | -- ----------------------------------------------------- 13 | -- Table IOS_DEVICE 14 | -- ----------------------------------------------------- 15 | CREATE TABLE IF NOT EXISTS IOS_DEVICE ( 16 | MOBILE_DEVICE_ID VARCHAR(45) NOT NULL, 17 | APNS_PUSH_TOKEN VARCHAR(100) NULL DEFAULT NULL, 18 | MAGIC_TOKEN VARCHAR(100) NULL DEFAULT NULL, 19 | MDM_TOKEN VARCHAR(100) NULL DEFAULT NULL, 20 | UNLOCK_TOKEN VARCHAR(2000) NULL DEFAULT NULL, 21 | CHALLENGE_TOKEN VARCHAR(45) NULL DEFAULT NULL, 22 | DEVICE_INFO VARCHAR(8000) NULL DEFAULT NULL, 23 | SERIAL VARCHAR(45) NULL DEFAULT NULL, 24 | PRODUCT VARCHAR(45) NULL DEFAULT NULL, 25 | IMEI VARCHAR(45) NULL DEFAULT NULL, 26 | VERSION VARCHAR(45) NULL DEFAULT NULL, 27 | MAC_ADDRESS VARCHAR(45) NULL DEFAULT NULL, 28 | DEVICE_NAME VARCHAR(100) NULL DEFAULT NULL, 29 | ICCID VARCHAR(45) NULL DEFAULT NULL, 30 | LATITUDE VARCHAR(45) NULL DEFAULT NULL, 31 | LONGITUDE VARCHAR(45) NULL DEFAULT NULL, 32 | PRIMARY KEY (MOBILE_DEVICE_ID) 33 | ); 34 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015 WSO2, Inc. (http://wso2.com) 3 | # 4 | # WSO2 Inc. licenses this file to you under the Apache License, 5 | # version 2.0 (the "License"); you may not use this file except 6 | # in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | # 19 | # This is the log4j configuration file used by WSO2 Carbon 20 | # 21 | # IMPORTANT : Please do not remove or change the names of any 22 | # of the Appenders defined here. The layout pattern & log file 23 | # can be changed using the WSO2 Carbon Management Console, and those 24 | # settings will override the settings in this file. 25 | # 26 | 27 | log4j.rootLogger=DEBUG, STD_OUT 28 | 29 | # Redirect log messages to console 30 | log4j.appender.STD_OUT=org.apache.log4j.ConsoleAppender 31 | log4j.appender.STD_OUT.Target=System.out 32 | log4j.appender.STD_OUT.layout=org.apache.log4j.PatternLayout 33 | log4j.appender.STD_OUT.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 34 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileFeatureProperty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.dto; 20 | 21 | /** 22 | * DTO of Mobile feature property. Represents a property of a mobile feature. 23 | */ 24 | public class MobileFeatureProperty { 25 | 26 | private String property; 27 | private Integer featureID; 28 | 29 | public Integer getFeatureID() { 30 | return featureID; 31 | } 32 | 33 | public void setFeatureID(Integer featureID) { 34 | this.featureID = featureID; 35 | } 36 | 37 | public String getProperty() { 38 | return property; 39 | } 40 | 41 | public void setProperty(String property) { 42 | this.property = property; 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /components/key-mgt/org.wso2.carbon.key.mgt.handler.valve/src/main/java/org/wso2/carbon/key/mgt/handler/valve/APIFaultException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.key.mgt.handler.valve; 20 | 21 | public class APIFaultException extends Exception { 22 | 23 | private static final long serialVersionUID = 1L; 24 | private int errorCode; 25 | 26 | public APIFaultException(int errorCode, String message) { 27 | super(message); 28 | this.errorCode = errorCode; 29 | } 30 | 31 | public APIFaultException(int errorCode, String message, Throwable cause) { 32 | super(message, cause); 33 | this.errorCode = errorCode; 34 | } 35 | 36 | public int getErrorCode() { 37 | return errorCode; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/common/TestDBConfigurations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.impl.common; 20 | 21 | import javax.xml.bind.annotation.XmlElement; 22 | import javax.xml.bind.annotation.XmlRootElement; 23 | import java.util.List; 24 | 25 | @XmlRootElement(name = "TestDataSourceConfigurations") 26 | public class TestDBConfigurations { 27 | 28 | private List dbTypesList; 29 | 30 | @XmlElement(name = "Type") 31 | public List getDbTypesList() { 32 | return dbTypesList; 33 | } 34 | 35 | public void setDbTypesList(List dbTypesList) { 36 | this.dbTypesList = dbTypesList; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/mysql.sql: -------------------------------------------------------------------------------- 1 | -- ----------------------------------------------------- 2 | -- Table `IOS_DEVICE` 3 | -- ----------------------------------------------------- 4 | CREATE TABLE IF NOT EXISTS `IOS_DEVICE` ( 5 | `MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL, 6 | `APNS_PUSH_TOKEN` VARCHAR(100) NULL DEFAULT NULL, 7 | `MAGIC_TOKEN` VARCHAR(100) NULL DEFAULT NULL, 8 | `MDM_TOKEN` VARCHAR(100) NULL DEFAULT NULL, 9 | `UNLOCK_TOKEN` VARCHAR(2000) NULL DEFAULT NULL, 10 | `CHALLENGE_TOKEN` VARCHAR(45) NULL DEFAULT NULL, 11 | `DEVICE_INFO` VARCHAR(8000) NULL DEFAULT NULL, 12 | `SERIAL` VARCHAR(45) NULL DEFAULT NULL, 13 | `PRODUCT` VARCHAR(45) NULL DEFAULT NULL, 14 | `IMEI` VARCHAR(45) NULL DEFAULT NULL, 15 | `VERSION` VARCHAR(45) NULL DEFAULT NULL, 16 | `MAC_ADDRESS` VARCHAR(45) NULL DEFAULT NULL, 17 | `DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL, 18 | `ICCID` VARCHAR(45) NULL DEFAULT NULL, 19 | `LATITUDE` VARCHAR(45) NULL DEFAULT NULL, 20 | `LONGITUDE` VARCHAR(45) NULL DEFAULT NULL, 21 | PRIMARY KEY (`MOBILE_DEVICE_ID`) 22 | ) ENGINE = InnoDB; 23 | 24 | -- ----------------------------------------------------- 25 | -- Table `IOS_FEATURE` 26 | -- ----------------------------------------------------- 27 | CREATE TABLE IF NOT EXISTS `IOS_FEATURE` ( 28 | `FEATURE_ID` INT NOT NULL AUTO_INCREMENT, 29 | `CODE` VARCHAR(45) NOT NULL, 30 | `NAME` VARCHAR(100) NULL, 31 | `DESCRIPTION` VARCHAR(200) NULL, 32 | PRIMARY KEY (`FEATURE_ID`) 33 | ) ENGINE = InnoDB; 34 | -------------------------------------------------------------------------------- /features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/conf/mobile-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | jdbc/MobileAndroidDM_DS 26 | 27 | 28 | 29 | 30 | jdbc/MobileWindowsDM_DS 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileOperationProperty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.dto; 20 | 21 | /** 22 | * DTO of Mobile Operation property. 23 | */ 24 | public class MobileOperationProperty { 25 | 26 | private int operationId; 27 | private String property; 28 | private String value; 29 | 30 | public String getValue() { 31 | return value; 32 | } 33 | 34 | public void setValue(String value) { 35 | this.value = value; 36 | } 37 | 38 | public int getOperationId() { 39 | return operationId; 40 | } 41 | 42 | public void setOperationId(int operationId) { 43 | this.operationId = operationId; 44 | } 45 | 46 | public String getProperty() { 47 | return property; 48 | } 49 | 50 | public void setProperty(String property) { 51 | this.property = property; 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile; 20 | 21 | import org.wso2.carbon.device.mgt.common.*; 22 | import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; 23 | import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; 24 | import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; 25 | 26 | import java.util.List; 27 | 28 | public abstract class AbstractMobileOperationManager implements OperationManager { 29 | 30 | @Override 31 | public List getOperations(DeviceIdentifier deviceIdentifier) throws OperationManagementException { 32 | return null; 33 | } 34 | 35 | @Override 36 | public int addOperation(Operation operation, List devices) throws 37 | OperationManagementException { 38 | return 1; 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.impl.android.gcm; 20 | 21 | /** 22 | * Represents model object for holding GCM response data. 23 | */ 24 | public class GCMResult { 25 | 26 | private String errorMsg; 27 | private String msg; 28 | private int statusCode; 29 | 30 | public String getErrorMsg() { 31 | return errorMsg; 32 | } 33 | 34 | public void setErrorMsg(String errorMsg) { 35 | this.errorMsg = errorMsg; 36 | } 37 | 38 | public String getMsg() { 39 | return msg; 40 | } 41 | 42 | public void setMsg(String msg) { 43 | this.msg = msg; 44 | } 45 | 46 | public int getStatusCode() { 47 | return statusCode; 48 | } 49 | 50 | public void setStatusCode(int statusCode) { 51 | this.statusCode = statusCode; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-apis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | 24 | jdbc/MobileDM_DS 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | enrollment 33 | admin 34 | enrollment 35 | 1.0.0 36 | http://localhost:9763/ 37 | http,https 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-ds-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | 24 | jdbc/MobileDM_DS 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | enrollment 33 | admin 34 | enrollment 35 | 1.0.0 36 | http://localhost:9763/ 37 | http,https 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-jndi-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | 24 | jdbc/MobileDM_DS 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | enrollment 33 | admin 34 | enrollment 35 | 1.0.0 36 | http://localhost:9763/ 37 | http,https 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-mgt-repo.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | 24 | jdbc/MobileDM_DS 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | enrollment 33 | admin 34 | enrollment 35 | 1.0.0 36 | http://localhost:9763/ 37 | http,https 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-api-publisher-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | 24 | jdbc/MobileDM_DS 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | enrollment 33 | admin 34 | enrollment 35 | 1.0.0 36 | http://localhost:9763/ 37 | http,https 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /features/device-mgt/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | org.wso2.carbon.devicemgt-plugins 24 | carbon-device-mgt-plugins-parent 25 | 2.0.4-SNAPSHOT 26 | ../../pom.xml 27 | 28 | 29 | 4.0.0 30 | org.wso2.carbon.devicemgt-plugins 31 | device-mgt-feature 32 | 2.0.4-SNAPSHOT 33 | pom 34 | WSO2 Carbon - Device Management Feature 35 | http://wso2.org 36 | 37 | 38 | org.wso2.carbon.device.mgt.mobile.feature 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceManagementConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.config; 20 | 21 | import javax.xml.bind.annotation.XmlElement; 22 | import javax.xml.bind.annotation.XmlRootElement; 23 | 24 | /** 25 | * Represents Mobile Device Mgt configuration. 26 | */ 27 | @XmlRootElement(name = "MobileDeviceMgtConfiguration") 28 | public final class MobileDeviceManagementConfig { 29 | 30 | private MobileDeviceManagementRepository mobileDeviceMgtRepository; 31 | 32 | @XmlElement(name = "ManagementRepository", nillable = false) 33 | public MobileDeviceManagementRepository getMobileDeviceMgtRepository() { 34 | return mobileDeviceMgtRepository; 35 | } 36 | 37 | public void setMobileDeviceMgtRepository( 38 | MobileDeviceManagementRepository mobileDeviceMgtRepository) { 39 | this.mobileDeviceMgtRepository = mobileDeviceMgtRepository; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.url.printer/src/main/java/org/wso2/carbon/device/mgt/mobile/url/printer/internal/URLPrinterDataHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | * 18 | */ 19 | package org.wso2.carbon.device.mgt.mobile.url.printer.internal; 20 | 21 | import org.wso2.carbon.utils.ConfigurationContextService; 22 | 23 | public class URLPrinterDataHolder { 24 | 25 | private ConfigurationContextService configurationContextService; 26 | private static URLPrinterDataHolder thisInstance = new URLPrinterDataHolder(); 27 | 28 | private URLPrinterDataHolder() {} 29 | 30 | public static URLPrinterDataHolder getInstance() { 31 | return thisInstance; 32 | } 33 | 34 | public ConfigurationContextService getConfigurationContextService() { 35 | return configurationContextService; 36 | } 37 | 38 | public void setConfigurationContextService(ConfigurationContextService configurationContextService) { 39 | this.configurationContextService = configurationContextService; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfigurations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | package org.wso2.carbon.device.mgt.mobile.config.datasource; 19 | 20 | import javax.xml.bind.annotation.XmlAccessType; 21 | import javax.xml.bind.annotation.XmlAccessorType; 22 | import javax.xml.bind.annotation.XmlElement; 23 | import javax.xml.bind.annotation.XmlRootElement; 24 | import java.util.List; 25 | 26 | @XmlRootElement(name = "DataSourceConfigurations") 27 | @XmlAccessorType(XmlAccessType.FIELD) 28 | public class MobileDataSourceConfigurations { 29 | 30 | @XmlElement(name = "DataSourceConfiguration", nillable = true) 31 | private List mobileDataSourceConfigs; 32 | 33 | public List getMobileDataSourceConfigs() { 34 | return mobileDataSourceConfigs; 35 | } 36 | 37 | public void setMobileDataSourceConfigs(List mobileDataSourceConfigs) { 38 | this.mobileDataSourceConfigs = mobileDataSourceConfigs; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-api-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | jdbc/MobileIOSDM_DS 26 | 27 | 28 | 29 | 30 | jdbc/MobileAndroidDM_DS 31 | 32 | 33 | 34 | 35 | jdbc/MobileWindowsDM_DS 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/oracle.sql: -------------------------------------------------------------------------------- 1 | -- ----------------------------------------------------- 2 | -- Table `WIN_DEVICE` 3 | -- ----------------------------------------------------- 4 | CREATE TABLE WIN_DEVICE ( 5 | DEVICE_ID VARCHAR(45) NOT NULL, 6 | CHANNEL_URI VARCHAR(100) DEFAULT NULL, 7 | DEVICE_INFO VARCHAR2(4000) DEFAULT NULL, 8 | IMEI VARCHAR(45) DEFAULT NULL, 9 | IMSI VARCHAR(45) DEFAULT NULL, 10 | OS_VERSION VARCHAR(45) DEFAULT NULL, 11 | DEVICE_MODEL VARCHAR(45) DEFAULT NULL, 12 | VENDOR VARCHAR(45) DEFAULT NULL, 13 | LATITUDE VARCHAR(45) DEFAULT NULL, 14 | LONGITUDE VARCHAR(45) DEFAULT NULL, 15 | SERIAL VARCHAR(45) DEFAULT NULL, 16 | MAC_ADDRESS VARCHAR(45) DEFAULT NULL, 17 | DEVICE_NAME VARCHAR(100) DEFAULT NULL, 18 | CONSTRAINT PK_WIN_DEVICE PRIMARY KEY (DEVICE_ID) 19 | ) 20 | / 21 | 22 | -- ----------------------------------------------------- 23 | -- Table `WIN_FEATURE` 24 | -- ----------------------------------------------------- 25 | CREATE TABLE WIN_FEATURE ( 26 | ID INT NOT NULL, 27 | CODE VARCHAR(45) NOT NULL, 28 | NAME VARCHAR(100) NOT NULL, 29 | DESCRIPTION VARCHAR(200) NULL, 30 | PRIMARY KEY (ID) 31 | ) 32 | / 33 | 34 | -- ----------------------------------------------------- 35 | -- Sequence `WIN_FEATURE_ID_INC_SEQ` 36 | -- ----------------------------------------------------- 37 | CREATE SEQUENCE WIN_FEATURE_ID_INC_SEQ START WITH 1 INCREMENT BY 1 NOCACHE 38 | / 39 | 40 | -- ----------------------------------------------------- 41 | -- Trigger `WIN_FEATURE_ID_INC_TRIG` 42 | -- ----------------------------------------------------- 43 | CREATE OR REPLACE TRIGGER WIN_FEATURE_ID_INC_TRIG 44 | BEFORE INSERT 45 | ON WIN_FEATURE 46 | REFERENCING NEW AS NEW 47 | FOR EACH ROW 48 | BEGIN 49 | SELECT WIN_FEATURE_ID_INC_SEQ.NEXTVAL INTO :NEW.ID FROM DUAL; 50 | END; 51 | / -------------------------------------------------------------------------------- /features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/oracle.sql: -------------------------------------------------------------------------------- 1 | -- ----------------------------------------------------- 2 | -- Table `AD_DEVICE` 3 | -- ----------------------------------------------------- 4 | CREATE TABLE AD_DEVICE ( 5 | DEVICE_ID VARCHAR(45) NOT NULL , 6 | DEVICE_INFO VARCHAR(4000) DEFAULT NULL, 7 | GCM_TOKEN VARCHAR(1000) DEFAULT NULL, 8 | IMEI VARCHAR(45) DEFAULT NULL, 9 | IMSI VARCHAR(45) DEFAULT NULL, 10 | OS_VERSION VARCHAR(45) DEFAULT NULL, 11 | DEVICE_MODEL VARCHAR(45) DEFAULT NULL, 12 | VENDOR VARCHAR(45) DEFAULT NULL, 13 | LATITUDE VARCHAR(45) DEFAULT NULL, 14 | LONGITUDE VARCHAR(45) DEFAULT NULL, 15 | SERIAL VARCHAR(45) DEFAULT NULL, 16 | MAC_ADDRESS VARCHAR(45) DEFAULT NULL, 17 | DEVICE_NAME VARCHAR(100) DEFAULT NULL, 18 | CONSTRAINT PK_AD_DEVICE PRIMARY KEY (DEVICE_ID) 19 | ) 20 | / 21 | 22 | -- ----------------------------------------------------- 23 | -- Table `AD_FEATURE` 24 | -- ----------------------------------------------------- 25 | CREATE TABLE AD_FEATURE ( 26 | ID INT NOT NULL, 27 | CODE VARCHAR(45) NOT NULL, 28 | NAME VARCHAR(100) NOT NULL, 29 | DESCRIPTION VARCHAR(200) DEFAULT NULL, 30 | CONSTRAINT AD_FEATURE PRIMARY KEY (ID) 31 | ) 32 | / 33 | 34 | -- ----------------------------------------------------- 35 | -- Sequence `AD_FEATURE_ID_INC_SEQ` 36 | -- ----------------------------------------------------- 37 | CREATE SEQUENCE AD_FEATURE_ID_INC_SEQ START WITH 1 INCREMENT BY 1 NOCACHE 38 | / 39 | -- ----------------------------------------------------- 40 | -- Trigger `AD_FEATURE_ID_INC_TRIG` 41 | -- ----------------------------------------------------- 42 | CREATE OR REPLACE TRIGGER AD_FEATURE_ID_INC_TRIG 43 | BEFORE INSERT 44 | ON AD_FEATURE 45 | REFERENCING NEW AS NEW 46 | FOR EACH ROW 47 | BEGIN 48 | SELECT AD_FEATURE_ID_INC_SEQ.NEXTVAL INTO :NEW.ID FROM DUAL; 49 | END; 50 | / -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.config.datasource; 20 | 21 | import javax.xml.bind.annotation.XmlAttribute; 22 | import javax.xml.bind.annotation.XmlElement; 23 | import javax.xml.bind.annotation.XmlRootElement; 24 | 25 | /** 26 | * Class for holding data source configuration in mobile-config.xml at parsing with JAXB. 27 | */ 28 | @XmlRootElement(name = "DataSourceConfiguration") 29 | public class MobileDataSourceConfig { 30 | 31 | private JNDILookupDefinition jndiLookupDefinition; 32 | private String type; 33 | 34 | @XmlElement(name = "JndiLookupDefinition", nillable = true) 35 | public JNDILookupDefinition getJndiLookupDefinition() { 36 | return jndiLookupDefinition; 37 | } 38 | 39 | public void setJndiLookupDefinition(JNDILookupDefinition jndiLookupDefinition) { 40 | this.jndiLookupDefinition = jndiLookupDefinition; 41 | } 42 | 43 | @XmlAttribute(name = "type") 44 | public String getType() { 45 | return type; 46 | } 47 | 48 | public void setType(String type) { 49 | this.type = type; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.dto; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * DTO of MobileOperation. 25 | */ 26 | public class MobileOperation { 27 | 28 | private int operationId; 29 | private String featureCode; 30 | private long createdDate; 31 | private List properties; 32 | 33 | public int getOperationId() { 34 | return operationId; 35 | } 36 | 37 | public void setOperationId(int operationId) { 38 | this.operationId = operationId; 39 | } 40 | 41 | public List getProperties() { 42 | return properties; 43 | } 44 | 45 | public void setProperties(List properties) { 46 | this.properties = properties; 47 | } 48 | 49 | public String getFeatureCode() { 50 | return featureCode; 51 | } 52 | 53 | public void setFeatureCode(String featureCode) { 54 | this.featureCode = featureCode; 55 | } 56 | 57 | public long getCreatedDate() { 58 | return createdDate; 59 | } 60 | 61 | public void setCreatedDate(long createdDate) { 62 | this.createdDate = createdDate; 63 | } 64 | } -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/DataSourceNotAvailableException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * * 3 | * * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 4 | * * 5 | * * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * * you may not use this file except in compliance with the License. 7 | * * You may obtain a copy of the License at 8 | * * 9 | * * http://www.apache.org/licenses/LICENSE-2.0 10 | * * 11 | * * Unless required by applicable law or agreed to in writing, software 12 | * * distributed under the License is distributed on an "AS IS" BASIS, 13 | * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * * See the License for the specific language governing permissions and 15 | * * limitations under the License. 16 | * 17 | */ 18 | package org.wso2.carbon.device.mgt.mobile; 19 | 20 | public class DataSourceNotAvailableException extends RuntimeException { 21 | 22 | private String message; 23 | private static final long serialVersionUID = 2021891706072918866L; 24 | 25 | public DataSourceNotAvailableException(String message, Exception nestedException) { 26 | super(message, nestedException); 27 | setErrorMessage(message); 28 | } 29 | 30 | public DataSourceNotAvailableException(String message, Throwable cause) { 31 | super(message, cause); 32 | setErrorMessage(message); 33 | } 34 | 35 | public DataSourceNotAvailableException(String message) { 36 | super(message); 37 | setErrorMessage(message); 38 | } 39 | 40 | public DataSourceNotAvailableException(Throwable cause) { 41 | super(cause); 42 | } 43 | 44 | public String getMessage() { 45 | return message; 46 | } 47 | 48 | public void setErrorMessage(String errorMessage) { 49 | this.message = errorMessage; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileFeature.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.dto; 20 | 21 | import java.io.Serializable; 22 | 23 | /** 24 | * DTO of Mobile features. 25 | */ 26 | public class MobileFeature implements Serializable { 27 | 28 | private int id; 29 | private String deviceType; 30 | private String code; 31 | private String name; 32 | private String description; 33 | 34 | public int getId() { 35 | return id; 36 | } 37 | 38 | public void setId(int id) { 39 | this.id = id; 40 | } 41 | 42 | public String getCode() { 43 | return code; 44 | } 45 | 46 | public void setCode(String code) { 47 | this.code = code; 48 | } 49 | 50 | public String getName() { 51 | return name; 52 | } 53 | 54 | public void setName(String name) { 55 | this.name = name; 56 | } 57 | 58 | public String getDescription() { 59 | return description; 60 | } 61 | 62 | public void setDescription(String description) { 63 | this.description = description; 64 | } 65 | 66 | public String getDeviceType() { 67 | return deviceType; 68 | } 69 | 70 | public void setDeviceType(String deviceType) { 71 | this.deviceType = deviceType; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/oracle.sql: -------------------------------------------------------------------------------- 1 | -- ----------------------------------------------------- 2 | -- Table `IOS_DEVICE` 3 | -- ----------------------------------------------------- 4 | CREATE TABLE IOS_DEVICE ( 5 | MOBILE_DEVICE_ID VARCHAR(45) NOT NULL, 6 | APNS_PUSH_TOKEN VARCHAR(100) DEFAULT NULL, 7 | MAGIC_TOKEN VARCHAR(100) DEFAULT NULL, 8 | MDM_TOKEN VARCHAR(100) DEFAULT NULL, 9 | UNLOCK_TOKEN VARCHAR(2000) DEFAULT NULL, 10 | CHALLENGE_TOKEN VARCHAR(45) DEFAULT NULL, 11 | DEVICE_INFO VARCHAR(4000) DEFAULT NULL, 12 | SERIAL VARCHAR(45) DEFAULT NULL, 13 | PRODUCT VARCHAR(45) DEFAULT NULL, 14 | IMEI VARCHAR(45) DEFAULT NULL, 15 | VERSION VARCHAR(45) DEFAULT NULL, 16 | MAC_ADDRESS VARCHAR(45) DEFAULT NULL, 17 | DEVICE_NAME VARCHAR(100) DEFAULT NULL, 18 | ICCID VARCHAR(45) DEFAULT NULL, 19 | LATITUDE VARCHAR(45) DEFAULT NULL, 20 | LONGITUDE VARCHAR(45) DEFAULT NULL, 21 | CONSTRAINT PK_IOS_DEVICE PRIMARY KEY (MOBILE_DEVICE_ID) 22 | ) 23 | / 24 | 25 | -- ----------------------------------------------------- 26 | -- Table `IOS_FEATURE` 27 | -- ----------------------------------------------------- 28 | CREATE TABLE IOS_FEATURE ( 29 | ID INT NOT NULL, 30 | CODE VARCHAR(45) NOT NULL, 31 | NAME VARCHAR(100) NOT NULL, 32 | DESCRIPTION VARCHAR(200) NULL, 33 | CONSTRAINT PK_IOS_FEATURE PRIMARY KEY (ID) 34 | ) 35 | / 36 | 37 | -- Sequence `IOS_FEATURE_ID_INC_SEQ` 38 | -- ----------------------------------------------------- 39 | CREATE SEQUENCE IOS_FEATURE_ID_INC_SEQ START WITH 1 INCREMENT BY 1 NOCACHE 40 | / 41 | 42 | -- ----------------------------------------------------- 43 | -- Trigger `IOS_FEATURE_ID_INC_TRIG` 44 | -- ----------------------------------------------------- 45 | CREATE OR REPLACE TRIGGER IOS_FEATURE_ID_INC_TRIG 46 | BEFORE INSERT 47 | ON IOS_FEATURE 48 | REFERENCING NEW AS NEW 49 | FOR EACH ROW 50 | BEGIN 51 | SELECT IOS_FEATURE_ID_INC_SEQ.NEXTVAL INTO :NEW.ID FROM DUAL; 52 | END; 53 | / -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/common/MobileDeviceMgtPluginException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | package org.wso2.carbon.device.mgt.mobile.common; 19 | 20 | 21 | public class MobileDeviceMgtPluginException extends Exception{ 22 | 23 | private static final long serialVersionUID = -2297311387874900305L; 24 | private String errorMessage; 25 | 26 | public String getErrorMessage() { 27 | return errorMessage; 28 | } 29 | 30 | public void setErrorMessage(String errorMessage) { 31 | this.errorMessage = errorMessage; 32 | } 33 | 34 | public MobileDeviceMgtPluginException(String msg, Exception nestedEx) { 35 | super(msg, nestedEx); 36 | setErrorMessage(msg); 37 | } 38 | 39 | public MobileDeviceMgtPluginException(String message, Throwable cause) { 40 | super(message, cause); 41 | setErrorMessage(message); 42 | } 43 | 44 | public MobileDeviceMgtPluginException(String msg) { 45 | super(msg); 46 | setErrorMessage(msg); 47 | } 48 | 49 | public MobileDeviceMgtPluginException() { 50 | super(); 51 | } 52 | 53 | public MobileDeviceMgtPluginException(Throwable cause) { 54 | super(cause); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidPluginConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.impl.android.util; 20 | 21 | /** 22 | * Defines constants used by android plugin. 23 | */ 24 | public class AndroidPluginConstants { 25 | 26 | //Properties related to AD_DEVICE table 27 | public static final String DEVICE_ID = "DEVICE_ID"; 28 | public static final String GCM_TOKEN = "GCM_TOKEN"; 29 | public static final String DEVICE_INFO = "DEVICE_INFO"; 30 | public static final String SERIAL = "SERIAL"; 31 | public static final String DEVICE_MODEL = "DEVICE_MODEL"; 32 | public static final String DEVICE_NAME = "DEVICE_NAME"; 33 | public static final String LATITUDE = "LATITUDE"; 34 | public static final String LONGITUDE = "LONGITUDE"; 35 | public static final String IMEI = "IMEI"; 36 | public static final String IMSI = "IMSI"; 37 | public static final String VENDOR = "VENDOR"; 38 | public static final String OS_VERSION = "OS_VERSION"; 39 | public static final String MAC_ADDRESS = "MAC_ADDRESS"; 40 | 41 | //Properties related to AD_FEATURE table 42 | public static final String ANDROID_FEATURE_ID = "ID"; 43 | public static final String ANDROID_FEATURE_CODE = "CODE"; 44 | public static final String ANDROID_FEATURE_NAME = "NAME"; 45 | public static final String ANDROID_FEATURE_DESCRIPTION = "DESCRIPTION"; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.impl.windows.util; 20 | 21 | /** 22 | * Define constance used by Windows plugin. 23 | */ 24 | public class WindowsPluginConstants { 25 | 26 | //properties related to database table WINDOWS_DEVICE 27 | public static final String DEVICE_ID = "DEVICE_ID"; 28 | public static final String CHANNEL_URI = "CHANNEL_URI"; 29 | public static final String DEVICE_INFO = "DEVICE_INFO"; 30 | public static final String IMEI = "IMEI"; 31 | public static final String IMSI = "IMSI"; 32 | public static final String OS_VERSION = "OS_VERSION"; 33 | public static final String DEVICE_MODEL = "DEVICE_MODEL"; 34 | public static final String VENDOR = "VENDOR"; 35 | public static final String LATITUDE = "LATITUDE"; 36 | public static final String LONGITUDE = "LONGITUDE"; 37 | public static final String SERIAL = "SERIAL"; 38 | public static final String MAC_ADDRESS = "MAC_ADDRESS"; 39 | public static final String DEVICE_NAME = "DEVICE_NAME"; 40 | 41 | //Properties related to WIN_FEATURE table 42 | public static final String WINDOWS_FEATURE_ID = "ID"; 43 | public static final String WINDOWS_FEATURE_CODE = "CODE"; 44 | public static final String WINDOWS_FEATURE_NAME = "NAME"; 45 | public static final String WINDOWS_FEATURE_DESCRIPTION = "DESCRIPTION"; 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/sql/h2.sql: -------------------------------------------------------------------------------- 1 | 2 | -- ----------------------------------------------------- 3 | -- Table `AD_DEVICE` 4 | -- ----------------------------------------------------- 5 | CREATE TABLE IF NOT EXISTS `AD_DEVICE` ( 6 | `DEVICE_ID` VARCHAR(45) NOT NULL , 7 | `PUSH_TOKEN` VARCHAR(45) NULL DEFAULT NULL , 8 | `IMEI` VARCHAR(45) NULL DEFAULT NULL , 9 | `IMSI` VARCHAR(45) NULL DEFAULT NULL , 10 | `OS_VERSION` VARCHAR(45) NULL DEFAULT NULL , 11 | `DEVICE_MODEL` VARCHAR(45) NULL DEFAULT NULL , 12 | `VENDOR` VARCHAR(45) NULL DEFAULT NULL , 13 | `LATITUDE` VARCHAR(45) NULL DEFAULT NULL, 14 | `LONGITUDE` VARCHAR(45) NULL DEFAULT NULL, 15 | `CHALLENGE` VARCHAR(45) NULL DEFAULT NULL, 16 | `TOKEN` VARCHAR(500) NULL DEFAULT NULL, 17 | `UNLOCK_TOKEN` VARCHAR(500) NULL DEFAULT NULL, 18 | `SERIAL` VARCHAR(45) NULL DEFAULT NULL, 19 | PRIMARY KEY (`DEVICE_ID`) ); 20 | 21 | 22 | -- ----------------------------------------------------- 23 | -- Table `AD_FEATURE` 24 | -- ----------------------------------------------------- 25 | CREATE TABLE IF NOT EXISTS `AD_FEATURE` ( 26 | `ID` INT NOT NULL AUTO_INCREMENT , 27 | `CODE` VARCHAR(45) NOT NULL, 28 | `NAME` VARCHAR(100) NULL , 29 | `DESCRIPTION` VARCHAR(200) NULL , 30 | `DEVICE_TYPE` VARCHAR(50) NULL , 31 | PRIMARY KEY (`ID`) ); 32 | 33 | -- ----------------------------------------------------- 34 | -- Table `AD_OPERATION` 35 | -- ----------------------------------------------------- 36 | CREATE TABLE IF NOT EXISTS `AD_OPERATION` ( 37 | `OPERATION_ID` INT NOT NULL AUTO_INCREMENT , 38 | `FEATURE_CODE` VARCHAR(45) NOT NULL , 39 | `CREATED_DATE` BIGINT NULL , 40 | PRIMARY KEY (`OPERATION_ID`)); 41 | 42 | 43 | -- ----------------------------------------------------- 44 | -- Table `AD_FEATURE_PROPERTY` 45 | -- ----------------------------------------------------- 46 | CREATE TABLE IF NOT EXISTS `AD_FEATURE_PROPERTY` ( 47 | `PROPERTY` VARCHAR(45) NOT NULL , 48 | `FEATURE_ID` INT NOT NULL , 49 | PRIMARY KEY (`PROPERTY`) , 50 | CONSTRAINT `fk_AD_FEATURE_PROPERTY_AD_FEATURE1` 51 | FOREIGN KEY (`FEATURE_ID` ) 52 | REFERENCES `AD_FEATURE` (`ID` ) 53 | ON DELETE NO ACTION 54 | ON UPDATE NO ACTION); 55 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/JNDILookupDefinition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.config.datasource; 20 | 21 | import javax.xml.bind.annotation.*; 22 | import java.util.List; 23 | 24 | /** 25 | * Class for hold JndiLookupDefinition of mobile-config.xml at parsing with JAXB. 26 | */ 27 | @XmlRootElement(name = "JndiLookupDefinition") 28 | public class JNDILookupDefinition { 29 | 30 | private String jndiName; 31 | private List jndiProperties; 32 | 33 | @XmlElement(name = "Name", nillable = false) 34 | public String getJndiName() { 35 | return jndiName; 36 | } 37 | 38 | public void setJndiName(String jndiName) { 39 | this.jndiName = jndiName; 40 | } 41 | 42 | @XmlElementWrapper(name = "Environment", nillable = false) 43 | @XmlElement(name = "Property", nillable = false) 44 | public List getJndiProperties() { 45 | return jndiProperties; 46 | } 47 | 48 | public void setJndiProperties(List jndiProperties) { 49 | this.jndiProperties = jndiProperties; 50 | } 51 | 52 | @XmlRootElement(name = "Property") 53 | public static class JNDIProperty { 54 | 55 | private String name; 56 | 57 | private String value; 58 | 59 | @XmlAttribute(name = "Name") 60 | public String getName() { 61 | return name; 62 | } 63 | 64 | public void setName(String name) { 65 | this.name = name; 66 | } 67 | 68 | @XmlValue 69 | public String getValue() { 70 | return value; 71 | } 72 | 73 | public void setValue(String value) { 74 | this.value = value; 75 | } 76 | } 77 | 78 | } 79 | 80 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/DataSourceConfigAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.config.datasource; 20 | 21 | import javax.xml.bind.annotation.adapters.XmlAdapter; 22 | import java.util.HashMap; 23 | import java.util.List; 24 | import java.util.Map; 25 | 26 | public class DataSourceConfigAdapter 27 | extends XmlAdapter> { 28 | 29 | @Override 30 | public Map unmarshal(MobileDataSourceConfigurations mobileDataSourceConfigurations) 31 | throws Exception { 32 | 33 | Map mobileDataSourceConfigMap = new HashMap(); 34 | for (MobileDataSourceConfig mobileDataSourceConfig : mobileDataSourceConfigurations 35 | .getMobileDataSourceConfigs()) { 36 | mobileDataSourceConfigMap.put(mobileDataSourceConfig.getType(), mobileDataSourceConfig); 37 | } 38 | return mobileDataSourceConfigMap; 39 | } 40 | 41 | @Override 42 | public MobileDataSourceConfigurations marshal(Map mobileDataSourceConfigMap) 43 | throws Exception { 44 | 45 | MobileDataSourceConfigurations mobileDataSourceConfigurations = new MobileDataSourceConfigurations(); 46 | mobileDataSourceConfigurations.setMobileDataSourceConfigs( 47 | (List) mobileDataSourceConfigMap.values()); 48 | 49 | return mobileDataSourceConfigurations; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileDeviceOperationMapping.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.dto; 20 | 21 | /** 22 | * DTO of Mobile Device Operation Mappings. 23 | */ 24 | public class MobileDeviceOperationMapping { 25 | 26 | private String deviceId; 27 | private int operationId; 28 | private long sentDate; 29 | private long receivedDate; 30 | private Status status; 31 | 32 | public enum Status { 33 | NEW, INPROGRESS, COMPLETED 34 | } 35 | 36 | public Status getStatus() { 37 | return status; 38 | } 39 | 40 | public void setStatus(Status status) { 41 | this.status = status; 42 | } 43 | 44 | public void setStatus(String status) { 45 | if(Status.NEW.name().equals(status)){ 46 | this.status = Status.NEW; 47 | }else if(Status.INPROGRESS.name().equals(status)){ 48 | this.status = Status.INPROGRESS; 49 | }else if(Status.COMPLETED.name().equals(status)){ 50 | this.status = Status.COMPLETED; 51 | } 52 | } 53 | 54 | public String getDeviceId() { 55 | return deviceId; 56 | } 57 | 58 | public void setDeviceId(String deviceId) { 59 | this.deviceId = deviceId; 60 | } 61 | 62 | public int getOperationId() { 63 | return operationId; 64 | } 65 | 66 | public void setOperationId(int operationId) { 67 | this.operationId = operationId; 68 | } 69 | 70 | public long getSentDate() { 71 | return sentDate; 72 | } 73 | 74 | public void setSentDate(long sentDate) { 75 | this.sentDate = sentDate; 76 | } 77 | 78 | public long getReceivedDate() { 79 | return receivedDate; 80 | } 81 | 82 | public void setReceivedDate(long receivedDate) { 83 | this.receivedDate = receivedDate; 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceManagementRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.config; 20 | 21 | import org.wso2.carbon.device.mgt.mobile.config.datasource.DataSourceConfigAdapter; 22 | import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig; 23 | 24 | import javax.xml.bind.annotation.XmlElement; 25 | import javax.xml.bind.annotation.XmlRootElement; 26 | import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; 27 | import java.util.List; 28 | import java.util.Map; 29 | 30 | /** 31 | * Class for holding management repository data. 32 | */ 33 | @XmlRootElement(name = "ManagementRepository") 34 | public class MobileDeviceManagementRepository { 35 | 36 | private Map mobileDataSourceConfigMap; 37 | private List mobileDataSourceConfigs; 38 | 39 | public MobileDataSourceConfig getMobileDataSourceConfig(String provider) { 40 | return mobileDataSourceConfigMap.get(provider); 41 | } 42 | 43 | @XmlElement(name = "DataSourceConfigurations") 44 | @XmlJavaTypeAdapter(DataSourceConfigAdapter.class) 45 | public Map getMobileDataSourceConfigMap() { 46 | return mobileDataSourceConfigMap; 47 | } 48 | 49 | public void setMobileDataSourceConfigMap(Map mobileDataSourceConfigMap) { 50 | this.mobileDataSourceConfigMap = mobileDataSourceConfigMap; 51 | } 52 | 53 | public List getMobileDataSourceConfigs() { 54 | return (List) mobileDataSourceConfigMap.values(); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementDataHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.internal; 20 | 21 | import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; 22 | import org.wso2.carbon.device.mgt.mobile.impl.android.gcm.GCMService; 23 | import org.wso2.carbon.registry.core.service.RegistryService; 24 | 25 | /** 26 | * DataHolder class of Mobile plugins component. 27 | */ 28 | public class MobileDeviceManagementDataHolder { 29 | 30 | private RegistryService registryService; 31 | private DeviceManagementService androidDeviceManagementService; 32 | private GCMService gcmService; 33 | 34 | private static MobileDeviceManagementDataHolder thisInstance = new MobileDeviceManagementDataHolder(); 35 | 36 | private MobileDeviceManagementDataHolder() { 37 | } 38 | 39 | public static MobileDeviceManagementDataHolder getInstance() { 40 | return thisInstance; 41 | } 42 | 43 | public RegistryService getRegistryService() { 44 | return registryService; 45 | } 46 | 47 | public void setRegistryService(RegistryService registryService) { 48 | this.registryService = registryService; 49 | } 50 | 51 | public DeviceManagementService getAndroidDeviceManagementService() { 52 | return androidDeviceManagementService; 53 | } 54 | 55 | public void setAndroidDeviceManagementService( 56 | DeviceManagementService androidDeviceManagementService) { 57 | this.androidDeviceManagementService = androidDeviceManagementService; 58 | } 59 | 60 | public GCMService getGCMService() { 61 | return gcmService; 62 | } 63 | 64 | public void setGCMService(GCMService gcmService) { 65 | this.gcmService = gcmService; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /components/key-mgt/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 23 | 24 | 25 | org.wso2.carbon.devicemgt-plugins 26 | carbon-device-mgt-plugins-parent 27 | 1.9.0-SNAPSHOT 28 | ../../pom.xml 29 | 30 | 31 | 4.0.0 32 | org.wso2.carbon.devicemgt-plugins 33 | key-mgt 34 | 1.9.0-SNAPSHOT 35 | pom 36 | WSO2 Carbon - Oauth Key Management Component 37 | http://wso2.org 38 | 39 | 40 | org.wso2.carbon.key.mgt.handler.valve 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.apache.felix 49 | maven-scr-plugin 50 | 1.7.2 51 | 52 | 53 | generate-scr-scrdescriptor 54 | 55 | scr 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /components/device-mgt/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | org.wso2.carbon.devicemgt-plugins 24 | carbon-device-mgt-plugins-parent 25 | 2.0.4-SNAPSHOT 26 | ../../pom.xml 27 | 28 | 29 | 4.0.0 30 | org.wso2.carbon.devicemgt-plugins 31 | device-mgt 32 | 2.0.4-SNAPSHOT 33 | pom 34 | WSO2 Carbon - Mobile Device Management Component 35 | http://wso2.org 36 | 37 | 38 | org.wso2.carbon.device.mgt.mobile.impl 39 | org.wso2.carbon.device.mgt.mobile.url.printer 40 | 41 | 42 | 43 | 44 | 45 | 46 | org.apache.felix 47 | maven-scr-plugin 48 | 1.7.2 49 | 50 | 51 | generate-scr-scrdescriptor 52 | 53 | scr 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementSchemaInitializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.util; 20 | 21 | import org.apache.commons.logging.Log; 22 | import org.apache.commons.logging.LogFactory; 23 | import org.wso2.carbon.device.mgt.mobile.common.MobilePluginConstants; 24 | import org.wso2.carbon.utils.CarbonUtils; 25 | import org.wso2.carbon.utils.dbcreator.DatabaseCreator; 26 | 27 | import javax.sql.DataSource; 28 | import java.io.File; 29 | 30 | /** 31 | * 32 | * Provides methods for initializing the database script. 33 | * 34 | */ 35 | public final class MobileDeviceManagementSchemaInitializer extends DatabaseCreator { 36 | 37 | private static final Log log = LogFactory.getLog(MobileDeviceManagementSchemaInitializer.class); 38 | private static final String setupSQLScriptBaseLocation = 39 | CarbonUtils.getCarbonHome() + File.separator + "dbscripts" + File.separator 40 | + MobilePluginConstants.MOBILE_DB_SCRIPTS_FOLDER + 41 | File.separator + "plugins" + File.separator; 42 | private String pluginType; 43 | 44 | public String getPluginType() { 45 | return pluginType; 46 | } 47 | 48 | public MobileDeviceManagementSchemaInitializer(DataSource dataSource, String pType) { 49 | super(dataSource); 50 | this.pluginType = pType; 51 | } 52 | 53 | protected String getDbScriptLocation(String databaseType) { 54 | String scriptName = databaseType + ".sql"; 55 | String scriptLocation = setupSQLScriptBaseLocation + this.getPluginType() + File.separator + scriptName; 56 | if (log.isDebugEnabled()) { 57 | log.debug("Loading database script from :" + scriptLocation); 58 | } 59 | return scriptLocation; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.impl.android.gcm; 20 | 21 | import org.apache.commons.logging.Log; 22 | import org.apache.commons.logging.LogFactory; 23 | import org.wso2.carbon.device.mgt.common.Device; 24 | 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | 28 | /** 29 | * GCM notification service implementation for Android platform. 30 | */ 31 | public class GCMService { 32 | 33 | private static final Log log = LogFactory.getLog(GCMService.class); 34 | private static final String NOTIFIER_TYPE = "notifierType"; 35 | private static final String GCM_NOTIFIER_CODE = "2"; 36 | 37 | public boolean isGCMEnabled() { 38 | String notifierType = GCMUtil.getConfigurationProperty(NOTIFIER_TYPE); 39 | if (GCM_NOTIFIER_CODE.equals(notifierType)) { 40 | return true; 41 | } 42 | return false; 43 | } 44 | 45 | public void sendNotification(String messageData, Device device) { 46 | List devices = new ArrayList<>(1); 47 | devices.add(device); 48 | GCMResult result = GCMUtil.sendWakeUpCall(messageData, devices); 49 | if (result.getStatusCode() != 200) { 50 | log.error("Exception occurred while sending the GCM notification : " + result.getErrorMsg()); 51 | } 52 | } 53 | 54 | public void sendNotification(String messageData, List devices) { 55 | GCMResult result = GCMUtil.sendWakeUpCall(messageData, devices); 56 | if (result.getStatusCode() != 200) { 57 | log.error("Exception occurred while sending the GCM notification : " + result.getErrorMsg()); 58 | } 59 | } 60 | 61 | public void resetTenantConfigCache() { 62 | GCMUtil.resetTenantConfigCache(); 63 | } 64 | } -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.url.printer/src/main/java/org/wso2/carbon/device/mgt/mobile/url/printer/URLPrinterStartupHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | * 18 | */ 19 | package org.wso2.carbon.device.mgt.mobile.url.printer; 20 | 21 | import org.apache.commons.logging.Log; 22 | import org.apache.commons.logging.LogFactory; 23 | import org.wso2.carbon.core.ServerStartupObserver; 24 | import org.wso2.carbon.device.mgt.mobile.url.printer.internal.URLPrinterDataHolder; 25 | import org.wso2.carbon.utils.CarbonUtils; 26 | import org.wso2.carbon.utils.ConfigurationContextService; 27 | import org.wso2.carbon.utils.NetworkUtils; 28 | 29 | public class URLPrinterStartupHandler implements ServerStartupObserver { 30 | 31 | private static final Log log = LogFactory.getLog(URLPrinterStartupHandler.class); 32 | 33 | @Override 34 | public void completingServerStartup() { 35 | 36 | } 37 | 38 | @Override 39 | public void completedServerStartup() { 40 | log.info("EMM Console URL : " + this.getEmmUrl()); 41 | } 42 | 43 | private String getEmmUrl() { 44 | // Hostname 45 | String hostName = "localhost"; 46 | try { 47 | hostName = NetworkUtils.getMgtHostName(); 48 | } catch (Exception ignored) { 49 | } 50 | // HTTPS port 51 | String mgtConsoleTransport = CarbonUtils.getManagementTransport(); 52 | ConfigurationContextService configContextService = 53 | URLPrinterDataHolder.getInstance().getConfigurationContextService(); 54 | int port = CarbonUtils.getTransportPort(configContextService, mgtConsoleTransport); 55 | int httpsProxyPort = 56 | CarbonUtils.getTransportProxyPort(configContextService.getServerConfigContext(), 57 | mgtConsoleTransport); 58 | if (httpsProxyPort > 0) { 59 | port = httpsProxyPort; 60 | } 61 | return "https://" + hostName + ":" + port + "/emm"; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.dao; 20 | 21 | /** 22 | * Custom exception class for mobile device specific data access related exceptions. 23 | */ 24 | public class MobileDeviceManagementDAOException extends Exception { 25 | 26 | private String message; 27 | private static final long serialVersionUID = 2021891706072918865L; 28 | 29 | /** 30 | * Constructs a new MobileDeviceManagementDAOException with the specified detail message and 31 | * nested exception. 32 | * 33 | * @param message error message 34 | * @param nestedException exception 35 | */ 36 | public MobileDeviceManagementDAOException(String message, Exception nestedException) { 37 | super(message, nestedException); 38 | setErrorMessage(message); 39 | } 40 | 41 | /** 42 | * Constructs a new MobileDeviceManagementDAOException with the specified detail message 43 | * and cause. 44 | * 45 | * @param message the detail message. 46 | * @param cause the cause of this exception. 47 | */ 48 | public MobileDeviceManagementDAOException(String message, Throwable cause) { 49 | super(message, cause); 50 | setErrorMessage(message); 51 | } 52 | 53 | /** 54 | * Constructs a new MobileDeviceManagementDAOException with the specified detail message. 55 | * 56 | * @param message the detail message. 57 | */ 58 | public MobileDeviceManagementDAOException(String message) { 59 | super(message); 60 | setErrorMessage(message); 61 | } 62 | 63 | /** 64 | * Constructs a new MobileDeviceManagementDAOException with the specified and cause. 65 | * 66 | * @param cause the cause of this exception. 67 | */ 68 | public MobileDeviceManagementDAOException(Throwable cause) { 69 | super(cause); 70 | } 71 | 72 | public String getMessage() { 73 | return message; 74 | } 75 | 76 | public void setErrorMessage(String errorMessage) { 77 | this.message = errorMessage; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceDAO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.dao; 20 | 21 | import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice; 22 | import java.util.List; 23 | 24 | /** 25 | * This class represents the key operations associated with persisting mobile-device related 26 | * information. 27 | */ 28 | public interface MobileDeviceDAO { 29 | 30 | /** 31 | * Fetches a MobileDevice from MDM database. 32 | * 33 | * @param mblDeviceId Id of the Mobile-Device. 34 | * @return MobileDevice corresponding to given device-id. 35 | * @throws MobileDeviceManagementDAOException 36 | */ 37 | MobileDevice getMobileDevice(String mblDeviceId) throws MobileDeviceManagementDAOException; 38 | 39 | /** 40 | * Adds a new MobileDevice to the MDM database. 41 | * 42 | * @param mobileDevice MobileDevice to be added. 43 | * @return The status of the operation. 44 | * @throws MobileDeviceManagementDAOException 45 | */ 46 | boolean addMobileDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException; 47 | 48 | /** 49 | * Updates MobileDevice information in MDM database. 50 | * 51 | * @param mobileDevice MobileDevice to be updated. 52 | * @return The status of the operation. 53 | * @throws MobileDeviceManagementDAOException 54 | */ 55 | boolean updateMobileDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException; 56 | 57 | /** 58 | * Deletes a given MobileDevice from MDM database. 59 | * 60 | * @param mblDeviceId Id of MobileDevice to be deleted. 61 | * @return The status of the operation. 62 | * @throws MobileDeviceManagementDAOException 63 | */ 64 | boolean deleteMobileDevice(String mblDeviceId) throws MobileDeviceManagementDAOException; 65 | 66 | /** 67 | * Fetches all MobileDevices from MDM database. 68 | * 69 | * @return List of MobileDevices. 70 | * @throws MobileDeviceManagementDAOException 71 | */ 72 | List getAllMobileDevices() throws MobileDeviceManagementDAOException; 73 | 74 | } 75 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidFeatureManagementDAOException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | * 18 | */ 19 | package org.wso2.carbon.device.mgt.mobile.impl.android.dao; 20 | 21 | import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; 22 | 23 | public class AndroidFeatureManagementDAOException extends MobileDeviceManagementDAOException { 24 | 25 | private String message; 26 | private static final long serialVersionUID = 2021891706072918865L; 27 | 28 | /** 29 | * Constructs a new MobileDeviceManagementDAOException with the specified detail message and 30 | * nested exception. 31 | * 32 | * @param message error message 33 | * @param nestedException exception 34 | */ 35 | public AndroidFeatureManagementDAOException(String message, Exception nestedException) { 36 | super(message, nestedException); 37 | setErrorMessage(message); 38 | } 39 | 40 | /** 41 | * Constructs a new MobileDeviceManagementDAOException with the specified detail message 42 | * and cause. 43 | * 44 | * @param message the detail message. 45 | * @param cause the cause of this exception. 46 | */ 47 | public AndroidFeatureManagementDAOException(String message, Throwable cause) { 48 | super(message, cause); 49 | setErrorMessage(message); 50 | } 51 | 52 | /** 53 | * Constructs a new MobileDeviceManagementDAOException with the specified detail message. 54 | * 55 | * @param message the detail message. 56 | */ 57 | public AndroidFeatureManagementDAOException(String message) { 58 | super(message); 59 | setErrorMessage(message); 60 | } 61 | 62 | /** 63 | * Constructs a new MobileDeviceManagementDAOException with the specified and cause. 64 | * 65 | * @param cause the cause of this exception. 66 | */ 67 | public AndroidFeatureManagementDAOException(Throwable cause) { 68 | super(cause); 69 | } 70 | 71 | public String getMessage() { 72 | return message; 73 | } 74 | 75 | public void setErrorMessage(String errorMessage) { 76 | this.message = errorMessage; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsFeatureManagementDAOException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.impl.windows.dao; 20 | 21 | import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; 22 | 23 | /** 24 | * Implement Exception class for Windows Device Features. 25 | */ 26 | public class WindowsFeatureManagementDAOException extends MobileDeviceManagementDAOException { 27 | 28 | private String message; 29 | private static final long serialVersionUID = 2021891706072918865L; 30 | 31 | /** 32 | * Constructs a new MobileDeviceManagementDAOException with the specified detail message and 33 | * nested exception. 34 | * 35 | * @param message error message 36 | * @param nestedException exception 37 | */ 38 | public WindowsFeatureManagementDAOException(String message, Exception nestedException) { 39 | super(message, nestedException); 40 | } 41 | 42 | /** 43 | * Constructs a new MobileDeviceManagementDAOException with the specified detail message 44 | * and cause. 45 | * 46 | * @param message the detail message. 47 | * @param cause the cause of this exception. 48 | */ 49 | public WindowsFeatureManagementDAOException(String message, Throwable cause) { 50 | super(message, cause); 51 | setErrorMessage(message); 52 | } 53 | 54 | /** 55 | * Constructs a new MobileDeviceManagementDAOException with the specified detail message. 56 | * 57 | * @param message the detail message. 58 | */ 59 | public WindowsFeatureManagementDAOException(String message) { 60 | super(message); 61 | setErrorMessage(message); 62 | } 63 | 64 | /** 65 | * Constructs a new MobileDeviceManagementDAOException with the specified and cause. 66 | * 67 | * @param cause the cause of this exception. 68 | */ 69 | public WindowsFeatureManagementDAOException(Throwable cause) { 70 | super(cause); 71 | } 72 | 73 | public String getMessage() { 74 | return message; 75 | } 76 | 77 | public void setErrorMessage(String errorMessage) { 78 | this.message = errorMessage; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/common/TestDBConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.impl.common; 20 | 21 | import javax.xml.bind.annotation.XmlAttribute; 22 | import javax.xml.bind.annotation.XmlElement; 23 | import javax.xml.bind.annotation.XmlRootElement; 24 | 25 | @XmlRootElement(name = "Type") 26 | public class TestDBConfiguration { 27 | 28 | private String connectionURL; 29 | private String driverClassName; 30 | private String username; 31 | private String password; 32 | 33 | @Override public String toString() { 34 | return "TestDataSourceConfiguration{" + 35 | "ConnectionURL='" + connectionURL + '\'' + 36 | ", DriverClassName='" + driverClassName + '\'' + 37 | ", Username='" + username + '\'' + 38 | ", Password='" + password + '\'' + 39 | ", Type='" + dbType + '\'' + 40 | '}'; 41 | } 42 | 43 | private String dbType; 44 | 45 | @XmlElement(name = "ConnectionURL", nillable = false) 46 | public String getConnectionURL() { 47 | return connectionURL; 48 | } 49 | 50 | public void setConnectionURL(String connectionURL) { 51 | this.connectionURL = connectionURL; 52 | } 53 | 54 | @XmlElement(name = "DriverClassName", nillable = false) 55 | public String getDriverClassName() { 56 | return driverClassName; 57 | } 58 | 59 | public void setDriverClassName(String driverClassName) { 60 | this.driverClassName = driverClassName; 61 | } 62 | 63 | @XmlElement(name = "Username", nillable = false) 64 | public String getUsername() { 65 | return username; 66 | } 67 | 68 | public void setUsername(String username) { 69 | this.username = username; 70 | } 71 | 72 | @XmlElement(name = "Password", nillable = false) 73 | public String getPassword() { 74 | return password; 75 | } 76 | 77 | public void setPassword(String password) { 78 | this.password = password; 79 | } 80 | 81 | @XmlAttribute(name = "name") 82 | public String getType() { 83 | return dbType; 84 | } 85 | 86 | public void setType(String type) { 87 | this.dbType = type; 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsPolicyMonitoringService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.impl.windows; 20 | 21 | import org.apache.commons.logging.Log; 22 | import org.apache.commons.logging.LogFactory; 23 | import org.wso2.carbon.device.mgt.common.Device; 24 | import org.wso2.carbon.device.mgt.common.DeviceIdentifier; 25 | import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; 26 | import org.wso2.carbon.policy.mgt.common.Policy; 27 | import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData; 28 | import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature; 29 | import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException; 30 | import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService; 31 | 32 | import java.util.ArrayList; 33 | import java.util.List; 34 | 35 | public class WindowsPolicyMonitoringService implements PolicyMonitoringService { 36 | 37 | private static Log log = LogFactory.getLog(WindowsPolicyMonitoringService.class); 38 | 39 | @Override 40 | public void notifyDevices(List list) throws PolicyComplianceException { 41 | 42 | } 43 | 44 | @Override 45 | public ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object compliancePayload) 46 | throws PolicyComplianceException { 47 | if (log.isDebugEnabled()) { 48 | log.debug("checking policy compliance status of device '" + deviceIdentifier.getId() + "'"); 49 | } 50 | List complianceFeatures = (List) compliancePayload; 51 | List nonComplianceFeatures = new ArrayList<>(); 52 | ComplianceData complianceData = new ComplianceData(); 53 | 54 | if (policy == null || compliancePayload == null) { 55 | return complianceData; 56 | } 57 | 58 | for (ComplianceFeature complianceFeature : complianceFeatures) { 59 | if (!complianceFeature.isCompliant()) { 60 | complianceData.setStatus(false); 61 | nonComplianceFeatures.add(complianceFeature); 62 | break; 63 | } 64 | } 65 | complianceData.setComplianceFeatures(nonComplianceFeatures); 66 | return complianceData; 67 | } 68 | 69 | @Override 70 | public String getType() { 71 | return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/schema/MobileDeviceManagementConfigSchema.xsd: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | 24 | 26 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 42 | 43 | 44 | 45 | 46 | 47 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.url.printer/src/main/java/org/wso2/carbon/device/mgt/mobile/url/printer/internal/URLPrinterStartupHandlerServiceComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | * 18 | */ 19 | package org.wso2.carbon.device.mgt.mobile.url.printer.internal; 20 | 21 | import org.apache.commons.logging.Log; 22 | import org.apache.commons.logging.LogFactory; 23 | import org.osgi.framework.BundleContext; 24 | import org.osgi.service.component.ComponentContext; 25 | import org.wso2.carbon.core.ServerStartupObserver; 26 | import org.wso2.carbon.device.mgt.mobile.url.printer.URLPrinterStartupHandler; 27 | import org.wso2.carbon.utils.ConfigurationContextService; 28 | 29 | /** 30 | * @scr.component name="org.wso2.carbon.device.mgt.mobile.url.printer.URLPrinterStartupHandlerServiceComponent" 31 | * immediate="true" 32 | * @scr.reference name="config.context.service" 33 | * interface="org.wso2.carbon.utils.ConfigurationContextService" 34 | * cardinality="0..1" 35 | * policy="dynamic" 36 | * bind="setConfigurationContextService" 37 | * unbind="unsetConfigurationContextService" 38 | */ 39 | public class URLPrinterStartupHandlerServiceComponent { 40 | 41 | private static final Log log = LogFactory.getLog(URLPrinterStartupHandlerServiceComponent.class); 42 | 43 | @SuppressWarnings("unused") 44 | protected void activate(ComponentContext componentContext) { 45 | try { 46 | BundleContext bundleContext = componentContext.getBundleContext(); 47 | /* Registering URL printer start-up handler */ 48 | bundleContext.registerService(ServerStartupObserver.class, new URLPrinterStartupHandler(), null); 49 | } catch (Throwable e) { 50 | log.error("Error occurred while activating URL printer server start-up handler service component", e); 51 | } 52 | } 53 | 54 | @SuppressWarnings("unused") 55 | protected void deactivate(ComponentContext componentContext) { 56 | //do nothing 57 | } 58 | 59 | protected void setConfigurationContextService(ConfigurationContextService configurationContextService) { 60 | if (log.isDebugEnabled()) { 61 | log.debug("Setting ConfigurationContextService"); 62 | } 63 | URLPrinterDataHolder.getInstance().setConfigurationContextService(configurationContextService); 64 | } 65 | 66 | protected void unsetConfigurationContextService(ConfigurationContextService configurationContextService) { 67 | if (log.isDebugEnabled()) { 68 | log.debug("Un-setting ConfigurationContextService"); 69 | } 70 | URLPrinterDataHolder.getInstance().setConfigurationContextService(null); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceConfigurationManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.config; 20 | 21 | import org.w3c.dom.Document; 22 | import org.wso2.carbon.device.mgt.common.DeviceManagementException; 23 | import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; 24 | import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig; 25 | import org.wso2.carbon.utils.CarbonUtils; 26 | 27 | import javax.xml.bind.JAXBContext; 28 | import javax.xml.bind.Unmarshaller; 29 | import java.io.File; 30 | 31 | /** 32 | * Class responsible for the mobile device manager configuration initialization. 33 | */ 34 | public class MobileDeviceConfigurationManager { 35 | 36 | private static final String MOBILE_DEVICE_CONFIG_XML_NAME = "mobile-config.xml"; 37 | private static final String MOBILE_DEVICE_PLUGIN_DIRECTORY = "mobile"; 38 | private static final String DEVICE_MGT_PLUGIN_CONFIGS_DIRECTORY = "device-mgt-plugin-configs"; 39 | private MobileDeviceManagementConfig currentMobileDeviceConfig; 40 | private static MobileDeviceConfigurationManager mobileDeviceConfigManager; 41 | 42 | private final String mobileDeviceMgtConfigXMLPath = 43 | CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + 44 | DEVICE_MGT_PLUGIN_CONFIGS_DIRECTORY + 45 | File.separator + 46 | MOBILE_DEVICE_PLUGIN_DIRECTORY + File.separator + MOBILE_DEVICE_CONFIG_XML_NAME; 47 | 48 | public static MobileDeviceConfigurationManager getInstance() { 49 | if (mobileDeviceConfigManager == null) { 50 | synchronized (MobileDeviceConfigurationManager.class) { 51 | if (mobileDeviceConfigManager == null) { 52 | mobileDeviceConfigManager = new MobileDeviceConfigurationManager(); 53 | } 54 | } 55 | } 56 | return mobileDeviceConfigManager; 57 | } 58 | 59 | public synchronized void initConfig() throws DeviceManagementException { 60 | try { 61 | File mobileDeviceMgtConfig = new File(mobileDeviceMgtConfigXMLPath); 62 | Document doc = MobileDeviceManagementUtil.convertToDocument(mobileDeviceMgtConfig); 63 | JAXBContext mobileDeviceMgmtContext = 64 | JAXBContext.newInstance(MobileDeviceManagementConfig.class); 65 | Unmarshaller unmarshaller = mobileDeviceMgmtContext.createUnmarshaller(); 66 | this.currentMobileDeviceConfig = 67 | (MobileDeviceManagementConfig) unmarshaller.unmarshal(doc); 68 | } catch (Exception e) { 69 | throw new DeviceManagementException( 70 | "Error occurred while initializing Mobile Device Management config", e); 71 | } 72 | } 73 | 74 | public MobileDeviceManagementConfig getMobileDeviceManagementConfig() { 75 | return currentMobileDeviceConfig; 76 | } 77 | 78 | 79 | } 80 | -------------------------------------------------------------------------------- /components/key-mgt/org.wso2.carbon.key.mgt.handler.valve/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 22 | 23 | org.wso2.carbon.devicemgt-plugins 24 | key-mgt 25 | 1.9.0-SNAPSHOT 26 | ../pom.xml 27 | 28 | 29 | 4.0.0 30 | org.wso2.carbon.devicemgt-plugins 31 | org.wso2.carbon.key.mgt.handler.valve 32 | 1.9.0-SNAPSHOT 33 | bundle 34 | WSO2 Carbon - Key Management Handler Valve 35 | WSO2 Carbon - Key Management Handler Valve 36 | http://wso2.org 37 | 38 | 39 | 40 | 41 | org.apache.felix 42 | maven-bundle-plugin 43 | true 44 | 45 | 46 | ${project.artifactId} 47 | ${project.artifactId} 48 | org.wso2.carbon.tomcat.patch 49 | 50 | org.wso2.carbon.key.mgt.handler.valve.* 51 | 52 | tomcat 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | org.apache.tomcat.wso2 62 | tomcat 63 | 64 | 65 | org.wso2.carbon 66 | org.wso2.carbon.apimgt.core 67 | 68 | 69 | org.wso2.carbon 70 | org.wso2.carbon.apimgt.impl 71 | 72 | 73 | org.wso2.carbon 74 | org.wso2.carbon.logging 75 | 76 | 77 | org.wso2.carbon 78 | org.wso2.carbon.tomcat.ext 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileDevice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.dto; 20 | 21 | import java.io.Serializable; 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | 25 | /** 26 | * DTO of MobileDevice. 27 | */ 28 | public class MobileDevice implements Serializable { 29 | 30 | private String mobileDeviceId; 31 | private String osVersion; 32 | private String model; 33 | private String vendor; 34 | private String latitude; 35 | private String longitude; 36 | private String imei; 37 | private String imsi; 38 | private String serial; 39 | private Map deviceProperties; 40 | 41 | public MobileDevice() { 42 | this.deviceProperties = new HashMap<>(); 43 | } 44 | 45 | public String getMobileDeviceId() { 46 | return mobileDeviceId; 47 | } 48 | 49 | public void setMobileDeviceId(String mobileDeviceId) { 50 | this.mobileDeviceId = mobileDeviceId; 51 | } 52 | 53 | public String getOsVersion() { 54 | return osVersion; 55 | } 56 | 57 | public void setOsVersion(String osVersion) { 58 | this.osVersion = osVersion; 59 | } 60 | 61 | public String getModel() { 62 | return model; 63 | } 64 | 65 | public void setModel(String model) { 66 | this.model = model; 67 | } 68 | 69 | public String getVendor() { 70 | return vendor; 71 | } 72 | 73 | public void setVendor(String vendor) { 74 | this.vendor = vendor; 75 | } 76 | 77 | public String getLatitude() { 78 | return latitude; 79 | } 80 | 81 | public void setLatitude(String latitude) { 82 | this.latitude = latitude; 83 | } 84 | 85 | public String getLongitude() { 86 | return longitude; 87 | } 88 | 89 | public void setLongitude(String longitude) { 90 | this.longitude = longitude; 91 | } 92 | 93 | public String getImei() { 94 | return imei; 95 | } 96 | 97 | public void setImei(String imei) { 98 | this.imei = imei; 99 | } 100 | 101 | public String getImsi() { 102 | return imsi; 103 | } 104 | 105 | public void setImsi(String imsi) { 106 | this.imsi = imsi; 107 | } 108 | 109 | public String getSerial() { 110 | return serial; 111 | } 112 | 113 | public void setSerial(String serial) { 114 | this.serial = serial; 115 | } 116 | 117 | public Map getDeviceProperties() { 118 | return deviceProperties; 119 | } 120 | 121 | public void setDeviceProperties(Map deviceProperties) { 122 | this.deviceProperties = deviceProperties; 123 | } 124 | 125 | } 126 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagementService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.impl.android; 20 | 21 | import org.wso2.carbon.device.mgt.common.*; 22 | import org.wso2.carbon.device.mgt.common.app.mgt.Application; 23 | import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; 24 | import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; 25 | import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; 26 | import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; 27 | 28 | import java.util.List; 29 | 30 | /** 31 | * This represents the Android implementation of DeviceManagerService. 32 | */ 33 | public class AndroidDeviceManagementService implements DeviceManagementService { 34 | 35 | private DeviceManager deviceManager; 36 | public static final String DEVICE_TYPE_ANDROID = "android"; 37 | 38 | @Override 39 | public String getType() { 40 | return AndroidDeviceManagementService.DEVICE_TYPE_ANDROID; 41 | } 42 | 43 | @Override 44 | public void init() throws DeviceManagementException { 45 | this.deviceManager = new AndroidDeviceManager(); 46 | } 47 | 48 | @Override 49 | public DeviceManager getDeviceManager() { 50 | return deviceManager; 51 | } 52 | 53 | @Override 54 | public ApplicationManager getApplicationManager() { 55 | return null; 56 | } 57 | 58 | @Override 59 | public void notifyOperationToDevices(Operation operation, List deviceIdentifiers) 60 | throws DeviceManagementException { 61 | 62 | } 63 | 64 | @Override 65 | public Application[] getApplications(String s, int i, int i2) throws ApplicationManagementException { 66 | return new Application[0]; 67 | } 68 | 69 | @Override 70 | public void updateApplicationStatus(DeviceIdentifier deviceIdentifier, Application application, 71 | String s) throws ApplicationManagementException { 72 | 73 | } 74 | 75 | @Override 76 | public String getApplicationStatus(DeviceIdentifier deviceIdentifier, 77 | Application application) throws ApplicationManagementException { 78 | return null; 79 | } 80 | 81 | @Override public void installApplicationForDevices(Operation operation, List deviceIdentifiers) 82 | throws ApplicationManagementException { 83 | 84 | } 85 | 86 | @Override public void installApplicationForUsers(Operation operation, List strings) 87 | throws ApplicationManagementException { 88 | 89 | } 90 | 91 | @Override public void installApplicationForUserRoles(Operation operation, List strings) 92 | throws ApplicationManagementException { 93 | 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidPluginUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.impl.android.util; 20 | 21 | import org.wso2.carbon.device.mgt.common.license.mgt.License; 22 | import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManagementService; 23 | 24 | /** 25 | * Contains utility methods used by Android plugin. 26 | */ 27 | public class AndroidPluginUtils { 28 | 29 | public static License getDefaultLicense() { 30 | License license = new License(); 31 | license.setName(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID); 32 | license.setLanguage("en_US"); 33 | license.setVersion("1.0.0"); 34 | license.setText("This End User License Agreement (\"Agreement\") is a legal agreement between you (\"You\") " + 35 | "and WSO2, Inc., regarding the enrollment of Your personal mobile device (\"Device\") in SoR's " + 36 | "mobile device management program, and the loading to and removal from Your Device and Your use " + 37 | "of certain applications and any associated software and user documentation, whether provided in " + 38 | "\"online\" or electronic format, used in connection with the operation of or provision of services " + 39 | "to WSO2, Inc., BY SELECTING \"I ACCEPT\" DURING INSTALLATION, YOU ARE ENROLLING YOUR DEVICE, AND " + 40 | "THEREBY AUTHORIZING SOR OR ITS AGENTS TO INSTALL, UPDATE AND REMOVE THE APPS FROM YOUR DEVICE AS " + 41 | "DESCRIBED IN THIS AGREEMENT. YOU ARE ALSO EXPLICITLY ACKNOWLEDGING AND AGREEING THAT (1) THIS IS " + 42 | "A BINDING CONTRACT AND (2) YOU HAVE READ AND AGREE TO THE TERMS OF THIS AGREEMENT.\n" + 43 | "\n" + 44 | "IF YOU DO NOT ACCEPT THESE TERMS, DO NOT ENROLL YOUR DEVICE AND DO NOT PROCEED ANY FURTHER.\n" + 45 | "\n" + 46 | "You agree that: (1) You understand and agree to be bound by the terms and conditions contained " + 47 | "in this Agreement, and (2) You are at least 21 years old and have the legal capacity to enter " + 48 | "into this Agreement as defined by the laws of Your jurisdiction. SoR shall have the right, " + 49 | "without prior notice, to terminate or suspend (i) this Agreement, (ii) the enrollment of Your " + 50 | "Device, or (iii) the functioning of the Apps in the event of a violation of this Agreement or " + 51 | "the cessation of Your relationship with SoR (including termination of Your employment if You are " + 52 | "an employee or expiration or termination of Your applicable franchise or supply agreement if You " + 53 | "are a franchisee of or supplier to the WSO2 WSO2, Inc., system). SoR expressly reserves all " + 54 | "rights not expressly granted herein."); 55 | return license; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | * / 18 | */ 19 | 20 | package org.wso2.carbon.device.mgt.mobile.impl.windows.util; 21 | 22 | import org.wso2.carbon.device.mgt.common.license.mgt.License; 23 | import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagementService; 24 | 25 | /** 26 | * Contains utility method used by Windows plugin. 27 | */ 28 | public class WindowsPluginUtils { 29 | 30 | public static License getDefaultLicense() { 31 | License license = new License(); 32 | license.setName(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS); 33 | license.setLanguage("en_US"); 34 | license.setVersion("1.0.0"); 35 | license.setText("This End User License Agreement (\"Agreement\") is a legal agreement between you (\"You\") " + 36 | "and WSO2, Inc., regarding the enrollment of Your personal mobile device (\"Device\") in SoR's " + 37 | "mobile device management program, and the loading to and removal from Your Device and Your use " + 38 | "of certain applications and any associated software and user documentation, whether provided in " + 39 | "\"online\" or electronic format, used in connection with the operation of or provision of services " + 40 | "to WSO2, Inc., BY SELECTING \"I ACCEPT\" DURING INSTALLATION, YOU ARE ENROLLING YOUR DEVICE, AND " + 41 | "THEREBY AUTHORIZING SOR OR ITS AGENTS TO INSTALL, UPDATE AND REMOVE THE APPS FROM YOUR DEVICE AS " + 42 | "DESCRIBED IN THIS AGREEMENT. YOU ARE ALSO EXPLICITLY ACKNOWLEDGING AND AGREEING THAT (1) THIS IS " + 43 | "A BINDING CONTRACT AND (2) YOU HAVE READ AND AGREE TO THE TERMS OF THIS AGREEMENT.\n" + 44 | "\n" + 45 | "IF YOU DO NOT ACCEPT THESE TERMS, DO NOT ENROLL YOUR DEVICE AND DO NOT PROCEED ANY FURTHER.\n" + 46 | "\n" + 47 | "You agree that: (1) You understand and agree to be bound by the terms and conditions contained " + 48 | "in this Agreement, and (2) You are at least 21 years old and have the legal capacity to enter " + 49 | "into this Agreement as defined by the laws of Your jurisdiction. SoR shall have the right, " + 50 | "without prior notice, to terminate or suspend (i) this Agreement, (ii) the enrollment of Your " + 51 | "Device, or (iii) the functioning of the Apps in the event of a violation of this Agreement or " + 52 | "the cessation of Your relationship with SoR (including termination of Your employment if You are " + 53 | "an employee or expiration or termination of Your applicable franchise or supply agreement if You " + 54 | "are a franchisee of or supplier to the WSO2 WSO2, Inc., system). SoR expressly reserves all " + 55 | "rights not expressly granted herein."); 56 | return license; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagementService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.impl.windows; 20 | 21 | import org.wso2.carbon.device.mgt.common.DeviceIdentifier; 22 | import org.wso2.carbon.device.mgt.common.DeviceManagementException; 23 | import org.wso2.carbon.device.mgt.common.DeviceManager; 24 | import org.wso2.carbon.device.mgt.common.app.mgt.Application; 25 | import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; 26 | import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; 27 | import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; 28 | import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; 29 | 30 | import java.util.List; 31 | 32 | /** 33 | * This represents the Windows implementation of DeviceManagerService. 34 | */ 35 | public class WindowsDeviceManagementService implements DeviceManagementService { 36 | 37 | private DeviceManager deviceManager; 38 | public static final String DEVICE_TYPE_WINDOWS = "windows"; 39 | 40 | @Override 41 | public String getType() { 42 | return WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS; 43 | } 44 | 45 | @Override 46 | public void init() throws DeviceManagementException { 47 | this.deviceManager = new WindowsDeviceManager(); 48 | } 49 | 50 | @Override 51 | public DeviceManager getDeviceManager() { 52 | return deviceManager; 53 | } 54 | 55 | @Override 56 | public ApplicationManager getApplicationManager() { 57 | return null; 58 | } 59 | 60 | @Override public void notifyOperationToDevices(Operation operation, List deviceIdentifiers) 61 | throws DeviceManagementException { 62 | 63 | } 64 | 65 | @Override 66 | public Application[] getApplications(String s, int i, int i2) throws ApplicationManagementException { 67 | return new Application[0]; 68 | } 69 | 70 | @Override 71 | public void updateApplicationStatus(DeviceIdentifier deviceIdentifier, Application application, 72 | String s) throws ApplicationManagementException { 73 | 74 | } 75 | 76 | @Override 77 | public String getApplicationStatus(DeviceIdentifier deviceIdentifier, 78 | Application application) throws ApplicationManagementException { 79 | return null; 80 | } 81 | 82 | @Override public void installApplicationForDevices(Operation operation, List deviceIdentifiers) 83 | throws ApplicationManagementException { 84 | 85 | } 86 | 87 | @Override public void installApplicationForUsers(Operation operation, List strings) 88 | throws ApplicationManagementException { 89 | 90 | } 91 | 92 | @Override public void installApplicationForUserRoles(Operation operation, List strings) 93 | throws ApplicationManagementException { 94 | 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.url.printer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | device-mgt 5 | org.wso2.carbon.devicemgt-plugins 6 | 2.0.4-SNAPSHOT 7 | ../pom.xml 8 | 9 | 10 | 4.0.0 11 | org.wso2.carbon.devicemgt-plugins 12 | org.wso2.carbon.device.mgt.mobile.url.printer 13 | 2.0.4-SNAPSHOT 14 | bundle 15 | WSO2 Carbon - Startup Handler That Prints MDM End-User Web-App URL 16 | WSO2 Carbon - Startup Handler That Prints MDM End-User Web-App URL 17 | http://wso2.org 18 | 19 | 20 | 21 | 22 | org.apache.felix 23 | maven-scr-plugin 24 | 25 | 26 | org.apache.felix 27 | maven-bundle-plugin 28 | 1.4.0 29 | true 30 | 31 | 32 | ${project.artifactId} 33 | ${project.artifactId} 34 | ${carbon.mobile.device.mgt.version} 35 | Bundle Containing The Startup Handler That Prints MDM End-User Web-App URL 36 | org.wso2.carbon.device.mgt.mobile.url.printer.internal 37 | 38 | org.osgi.framework, 39 | org.osgi.service.component, 40 | org.apache.commons.logging, 41 | org.apache.axis2.*;version="${axis2.osgi.version.range}", 42 | org.wso2.carbon.core, 43 | org.wso2.carbon.utils.*, 44 | 45 | 46 | !org.wso2.carbon.device.mgt.mobile.url.printer.internal, 47 | org.wso2.carbon.device.mgt.mobile.url.printer, 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | org.eclipse.osgi 58 | org.eclipse.osgi 59 | 60 | 61 | org.eclipse.osgi 62 | org.eclipse.osgi.services 63 | 64 | 65 | org.wso2.carbon 66 | org.wso2.carbon.core 67 | 68 | 69 | org.wso2.carbon 70 | org.wso2.carbon.logging 71 | 72 | 73 | org.wso2.carbon 74 | org.wso2.carbon.utils 75 | 76 | 77 | org.apache.axis2.wso2 78 | axis2 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/util/MobileDatabaseUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.impl.dao.util; 20 | 21 | import org.apache.commons.logging.Log; 22 | import org.apache.commons.logging.LogFactory; 23 | import org.w3c.dom.Document; 24 | import org.wso2.carbon.device.mgt.common.DeviceManagementException; 25 | import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; 26 | import org.wso2.carbon.device.mgt.mobile.impl.common.DBTypes; 27 | import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfiguration; 28 | import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfigurations; 29 | import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; 30 | 31 | import javax.xml.bind.JAXBContext; 32 | import javax.xml.bind.JAXBException; 33 | import javax.xml.bind.Unmarshaller; 34 | import java.io.File; 35 | import java.sql.*; 36 | 37 | /** 38 | * This class provides the utility methods needed for DAO related test executions. 39 | */ 40 | public class MobileDatabaseUtils { 41 | 42 | private static final Log log = LogFactory.getLog(MobileDatabaseUtils.class); 43 | public static final String TEST_RESOURCES_DB_CONFIG_FILE = 44 | "src/test/resources/testdbconfig.xml"; 45 | 46 | public static void cleanupResources(Connection conn, Statement stmt, ResultSet rs) { 47 | if (rs != null) { 48 | try { 49 | rs.close(); 50 | } catch (SQLException e) { 51 | log.warn("Error occurred while closing result set", e); 52 | } 53 | } 54 | if (stmt != null) { 55 | try { 56 | stmt.close(); 57 | } catch (SQLException e) { 58 | log.warn("Error occurred while closing prepared statement", e); 59 | } 60 | } 61 | if (conn != null) { 62 | try { 63 | conn.close(); 64 | } catch (SQLException e) { 65 | log.warn("Error occurred while closing database connection", e); 66 | } 67 | } 68 | } 69 | 70 | public static TestDBConfiguration getTestDBConfiguration(DBTypes dbType) throws 71 | MobileDeviceManagementDAOException, 72 | DeviceManagementException { 73 | File deviceMgtConfig = new File(TEST_RESOURCES_DB_CONFIG_FILE); 74 | Document doc; 75 | TestDBConfiguration testDBConfiguration = null; 76 | TestDBConfigurations testDBConfigurations; 77 | 78 | doc = MobileDeviceManagementUtil.convertToDocument(deviceMgtConfig); 79 | JAXBContext testDBContext; 80 | 81 | try { 82 | testDBContext = JAXBContext.newInstance(TestDBConfigurations.class); 83 | Unmarshaller unmarshaller = testDBContext.createUnmarshaller(); 84 | testDBConfigurations = (TestDBConfigurations) unmarshaller.unmarshal(doc); 85 | } catch (JAXBException e) { 86 | throw new MobileDeviceManagementDAOException("Error parsing test db configurations", e); 87 | } 88 | 89 | for (TestDBConfiguration testDBConfiguration1 : testDBConfigurations.getDbTypesList()) { 90 | testDBConfiguration = testDBConfiguration1; 91 | if (testDBConfiguration.getType().equals(dbType.toString())) { 92 | break; 93 | } 94 | } 95 | 96 | return testDBConfiguration; 97 | } 98 | 99 | public static void createH2DB(TestDBConfiguration testDBConf) throws Exception { 100 | Connection conn = null; 101 | Statement stmt = null; 102 | try { 103 | Class.forName(testDBConf.getDriverClassName()); 104 | conn = DriverManager.getConnection(testDBConf.getConnectionURL()); 105 | stmt = conn.createStatement(); 106 | stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql/h2.sql'"); 107 | } finally { 108 | cleanupResources(conn, stmt, null); 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidPolicyMonitoringService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | 20 | package org.wso2.carbon.device.mgt.mobile.impl.android; 21 | 22 | import com.google.gson.Gson; 23 | import com.google.gson.JsonArray; 24 | import com.google.gson.JsonElement; 25 | import com.google.gson.JsonParser; 26 | import org.apache.commons.logging.Log; 27 | import org.apache.commons.logging.LogFactory; 28 | import org.wso2.carbon.device.mgt.common.Device; 29 | import org.wso2.carbon.device.mgt.common.DeviceIdentifier; 30 | import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; 31 | import org.wso2.carbon.device.mgt.mobile.impl.android.gcm.GCMService; 32 | import org.wso2.carbon.device.mgt.mobile.internal.MobileDeviceManagementDataHolder; 33 | import org.wso2.carbon.policy.mgt.common.Policy; 34 | import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData; 35 | import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature; 36 | import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException; 37 | import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService; 38 | 39 | import java.util.ArrayList; 40 | import java.util.List; 41 | 42 | public class AndroidPolicyMonitoringService implements PolicyMonitoringService { 43 | 44 | private static Log log = LogFactory.getLog(AndroidPolicyMonitoringService.class); 45 | 46 | @Override 47 | public void notifyDevices(List list) throws PolicyComplianceException { 48 | GCMService gcmService = MobileDeviceManagementDataHolder.getInstance().getGCMService(); 49 | if (gcmService.isGCMEnabled() && !list.isEmpty()) { 50 | gcmService.sendNotification("POLICY_BUNDLE", list); 51 | } 52 | } 53 | 54 | @Override 55 | public ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, 56 | Object compliancePayload) throws PolicyComplianceException { 57 | if (log.isDebugEnabled()) { 58 | log.debug("Checking policy compliance status of device '" + deviceIdentifier.getId() + "'"); 59 | } 60 | ComplianceData complianceData = new ComplianceData(); 61 | if (compliancePayload == null || policy == null) { 62 | return complianceData; 63 | } 64 | String compliancePayloadString = new Gson().toJson(compliancePayload); 65 | // Parsing json string to get compliance features. 66 | JsonElement jsonElement; 67 | if (compliancePayloadString instanceof String) { 68 | jsonElement = new JsonParser().parse(compliancePayloadString); 69 | } else { 70 | throw new PolicyComplianceException("Invalid policy compliance payload"); 71 | } 72 | 73 | JsonArray jsonArray = jsonElement.getAsJsonArray(); 74 | Gson gson = new Gson(); 75 | ComplianceFeature complianceFeature; 76 | List complianceFeatures = new ArrayList(jsonArray.size()); 77 | List nonComplianceFeatures = new ArrayList<>(); 78 | 79 | for (JsonElement element : jsonArray) { 80 | complianceFeature = gson.fromJson(element, ComplianceFeature.class); 81 | complianceFeatures.add(complianceFeature); 82 | } 83 | 84 | for (ComplianceFeature cf : complianceFeatures) { 85 | if (!cf.isCompliant()) { 86 | complianceData.setStatus(false); 87 | nonComplianceFeatures.add(cf); 88 | break; 89 | } 90 | } 91 | 92 | complianceData.setComplianceFeatures(nonComplianceFeatures); 93 | return complianceData; 94 | } 95 | 96 | @Override 97 | public String getType() { 98 | return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID; 99 | } 100 | } -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeatureDAO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.dao; 20 | 21 | import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * This class represents the key operations associated with persisting mobile feature related 27 | * information. 28 | */ 29 | public interface MobileFeatureDAO { 30 | 31 | /** 32 | * Adds a new MobileFeature to Mobile-Feature table. 33 | * 34 | * @param mobileFeature MobileFeature object that holds data related to the feature to be inserted. 35 | * @return boolean status of the operation. 36 | * @throws MobileDeviceManagementDAOException 37 | */ 38 | boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException; 39 | 40 | /** 41 | * Adda a list of MobileFeatures to Mobile-Feature table. 42 | * 43 | * @param mobileFeatures List of MobileFeature objects. 44 | * @return boolean status of the operation. 45 | * @throws MobileDeviceManagementDAOException 46 | */ 47 | boolean addFeatures(List mobileFeatures) throws MobileDeviceManagementDAOException; 48 | 49 | /** 50 | * Updates a MobileFeature in Mobile-Feature table. 51 | * 52 | * @param mobileFeature MobileFeature object that holds data has to be updated. 53 | * @return The status of the operation. 54 | * @throws MobileDeviceManagementDAOException 55 | */ 56 | boolean updateFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException; 57 | 58 | /** 59 | * Deletes a MobileFeature from Mobile-Feature table when the feature id is given. 60 | * 61 | * @param mblFeatureId MobileFeature id of the MobileFeature to be deleted. 62 | * @return The status of the operation. 63 | * @throws MobileDeviceManagementDAOException 64 | */ 65 | boolean deleteFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException; 66 | 67 | /** 68 | * Deletes a MobileFeature from Mobile-Feature table when the feature code is given. 69 | * 70 | * @param mblFeatureCode MobileFeature code of the feature to be deleted. 71 | * @return The status of the operation. 72 | * @throws MobileDeviceManagementDAOException 73 | */ 74 | boolean deleteFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException; 75 | 76 | /** 77 | * Retrieves a given MobileFeature from Mobile-Feature table when the feature id is given. 78 | * 79 | * @param mblFeatureId Feature id of the feature to be retrieved. 80 | * @return MobileFeature object that holds data of the feature represented by featureId. 81 | * @throws MobileDeviceManagementDAOException 82 | */ 83 | MobileFeature getFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException; 84 | 85 | /** 86 | * Retrieves a given MobileFeature from Mobile-Feature table when the feature code is given. 87 | * 88 | * @param mblFeatureCode Feature code of the feature to be retrieved. 89 | * @return MobileFeature object that holds data of the feature represented by featureCode. 90 | * @throws MobileDeviceManagementDAOException 91 | */ 92 | MobileFeature getFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException; 93 | 94 | /** 95 | * Retrieves all MobileFeatures of a MobileDevice type from Mobile-Feature table. 96 | * 97 | * @param deviceType MobileDevice type of the MobileFeatures to be retrieved 98 | * @return MobileFeature object list. 99 | * @throws MobileDeviceManagementDAOException 100 | */ 101 | List getFeatureByDeviceType(String deviceType) throws MobileDeviceManagementDAOException; 102 | 103 | /** 104 | * Retrieve all the MobileFeatures from Mobile-Feature table. 105 | * 106 | * @return MobileFeature object list. 107 | * @throws MobileDeviceManagementDAOException 108 | */ 109 | List getAllFeatures() throws MobileDeviceManagementDAOException; 110 | } 111 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/AbstractMobileDeviceManagementDAOFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.dao; 20 | 21 | import org.apache.commons.logging.Log; 22 | import org.apache.commons.logging.LogFactory; 23 | import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException; 24 | import org.wso2.carbon.device.mgt.mobile.config.datasource.JNDILookupDefinition; 25 | import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig; 26 | import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; 27 | 28 | import javax.sql.DataSource; 29 | import java.util.HashMap; 30 | import java.util.Hashtable; 31 | import java.util.List; 32 | import java.util.Map; 33 | 34 | /** 35 | * Factory class used to create MobileDeviceManagement related DAO objects. 36 | */ 37 | public abstract class AbstractMobileDeviceManagementDAOFactory implements MobileDeviceManagementDAOFactory { 38 | 39 | private static final Log log = LogFactory.getLog(AbstractMobileDeviceManagementDAOFactory.class); 40 | private static Map dataSourceMap = new HashMap<>(); 41 | private static boolean isInitialized; 42 | 43 | public static void init(Map mobileDataSourceConfigMap) 44 | throws MobileDeviceMgtPluginException { 45 | DataSource dataSource; 46 | for (String pluginType : mobileDataSourceConfigMap.keySet()) { 47 | if (dataSourceMap.get(pluginType) == null) { 48 | dataSource = AbstractMobileDeviceManagementDAOFactory.resolveDataSource(mobileDataSourceConfigMap.get 49 | (pluginType)); 50 | dataSourceMap.put(pluginType, dataSource); 51 | } 52 | } 53 | isInitialized = true; 54 | } 55 | 56 | public static void init(String key, MobileDataSourceConfig mobileDataSourceConfig) throws 57 | MobileDeviceMgtPluginException { 58 | DataSource dataSource = AbstractMobileDeviceManagementDAOFactory.resolveDataSource(mobileDataSourceConfig); 59 | dataSourceMap.put(key, dataSource); 60 | } 61 | 62 | /** 63 | * Resolve data source from the data source definition. 64 | * 65 | * @param config Mobile data source configuration 66 | * @return data source resolved from the data source definition 67 | */ 68 | public static DataSource resolveDataSource(MobileDataSourceConfig config) { 69 | DataSource dataSource = null; 70 | if (config == null) { 71 | throw new RuntimeException("Device Management Repository data source configuration " + 72 | "is null and thus, is not initialized"); 73 | } 74 | JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition(); 75 | if (jndiConfig != null) { 76 | if (log.isDebugEnabled()) { 77 | log.debug("Initializing Device Management Repository data source using the JNDI " + 78 | "Lookup Definition"); 79 | } 80 | List jndiPropertyList = 81 | jndiConfig.getJndiProperties(); 82 | if (jndiPropertyList != null) { 83 | Hashtable jndiProperties = new Hashtable(); 84 | for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) { 85 | jndiProperties.put(prop.getName(), prop.getValue()); 86 | } 87 | dataSource = 88 | MobileDeviceManagementDAOUtil 89 | .lookupDataSource(jndiConfig.getJndiName(), jndiProperties); 90 | } else { 91 | dataSource = MobileDeviceManagementDAOUtil 92 | .lookupDataSource(jndiConfig.getJndiName(), null); 93 | } 94 | } 95 | return dataSource; 96 | } 97 | 98 | public static Map getDataSourceMap() { 99 | return dataSourceMap; 100 | } 101 | 102 | } -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidDAOFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.impl.android.dao; 20 | 21 | import org.apache.commons.logging.Log; 22 | import org.apache.commons.logging.LogFactory; 23 | import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; 24 | import org.wso2.carbon.device.mgt.mobile.dao.*; 25 | import org.wso2.carbon.device.mgt.mobile.impl.android.dao.impl.AndroidDeviceDAOImpl; 26 | import org.wso2.carbon.device.mgt.mobile.impl.android.dao.impl.AndroidFeatureDAOImpl; 27 | 28 | import javax.sql.DataSource; 29 | import java.sql.Connection; 30 | import java.sql.SQLException; 31 | 32 | public class AndroidDAOFactory extends AbstractMobileDeviceManagementDAOFactory { 33 | 34 | private static final Log log = LogFactory.getLog(AndroidDAOFactory.class); 35 | protected static DataSource dataSource; 36 | private static ThreadLocal currentConnection = new ThreadLocal<>(); 37 | 38 | public AndroidDAOFactory() { 39 | this.dataSource = getDataSourceMap().get(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); 40 | } 41 | 42 | @Override 43 | public MobileDeviceDAO getMobileDeviceDAO() { 44 | return new AndroidDeviceDAOImpl(); 45 | } 46 | 47 | public MobileFeatureDAO getMobileFeatureDAO() { 48 | return new AndroidFeatureDAOImpl(); 49 | } 50 | 51 | public static void beginTransaction() throws MobileDeviceManagementDAOException { 52 | try { 53 | Connection conn = dataSource.getConnection(); 54 | conn.setAutoCommit(false); 55 | currentConnection.set(conn); 56 | } catch (SQLException e) { 57 | throw new MobileDeviceManagementDAOException("Error occurred while retrieving datasource connection", e); 58 | } 59 | } 60 | 61 | public static Connection getConnection() throws MobileDeviceManagementDAOException { 62 | if (currentConnection.get() == null) { 63 | try { 64 | currentConnection.set(dataSource.getConnection()); 65 | } catch (SQLException e) { 66 | throw new MobileDeviceManagementDAOException("Error occurred while retrieving data source connection", 67 | e); 68 | } 69 | } 70 | return currentConnection.get(); 71 | } 72 | 73 | public static void commitTransaction() throws MobileDeviceManagementDAOException { 74 | try { 75 | Connection conn = currentConnection.get(); 76 | if (conn != null) { 77 | conn.commit(); 78 | } else { 79 | if (log.isDebugEnabled()) { 80 | log.debug("Datasource connection associated with the current thread is null, hence commit " + 81 | "has not been attempted"); 82 | } 83 | } 84 | } catch (SQLException e) { 85 | throw new MobileDeviceManagementDAOException("Error occurred while committing the transaction", e); 86 | } 87 | } 88 | 89 | public static void closeConnection() throws MobileDeviceManagementDAOException { 90 | Connection conn = currentConnection.get(); 91 | try { 92 | if (conn != null) { 93 | conn.close(); 94 | } 95 | } catch (SQLException e) { 96 | log.error("Error occurred while close the connection"); 97 | } 98 | currentConnection.remove(); 99 | } 100 | 101 | public static void rollbackTransaction() throws MobileDeviceManagementDAOException { 102 | try { 103 | Connection conn = currentConnection.get(); 104 | if (conn != null) { 105 | conn.rollback(); 106 | } else { 107 | if (log.isDebugEnabled()) { 108 | log.debug("Datasource connection associated with the current thread is null, hence rollback " + 109 | "has not been attempted"); 110 | } 111 | } 112 | } catch (SQLException e) { 113 | throw new MobileDeviceManagementDAOException("Error occurred while rollback the transaction", e); 114 | } 115 | } 116 | 117 | } -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.impl.windows.dao; 20 | 21 | import org.apache.commons.logging.Log; 22 | import org.apache.commons.logging.LogFactory; 23 | import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; 24 | import org.wso2.carbon.device.mgt.mobile.dao.AbstractMobileDeviceManagementDAOFactory; 25 | import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceDAO; 26 | import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; 27 | import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO; 28 | import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.impl.WindowsDeviceDAOImpl; 29 | import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.impl.WindowsFeatureDAOImpl; 30 | 31 | import javax.sql.DataSource; 32 | import java.sql.Connection; 33 | import java.sql.SQLException; 34 | 35 | public class WindowsDAOFactory extends AbstractMobileDeviceManagementDAOFactory { 36 | 37 | private static final Log log = LogFactory.getLog(WindowsDAOFactory.class); 38 | protected static DataSource dataSource; 39 | private static ThreadLocal currentConnection = new ThreadLocal<>(); 40 | 41 | public WindowsDAOFactory() { 42 | this.dataSource = getDataSourceMap().get(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); 43 | } 44 | 45 | @Override 46 | public MobileDeviceDAO getMobileDeviceDAO() { 47 | return new WindowsDeviceDAOImpl(); 48 | } 49 | 50 | @Override 51 | public MobileFeatureDAO getMobileFeatureDAO() { 52 | return new WindowsFeatureDAOImpl(); 53 | } 54 | 55 | public static void beginTransaction() throws MobileDeviceManagementDAOException { 56 | try { 57 | Connection conn = dataSource.getConnection(); 58 | conn.setAutoCommit(false); 59 | currentConnection.set(conn); 60 | } catch (SQLException e) { 61 | throw new MobileDeviceManagementDAOException("Error occurred while retrieving datasource connection", e); 62 | } 63 | } 64 | 65 | public static void openConnection() throws MobileDeviceManagementDAOException { 66 | if (currentConnection.get() == null) { 67 | Connection conn; 68 | try { 69 | conn = dataSource.getConnection(); 70 | currentConnection.set(conn); 71 | } catch (SQLException e) { 72 | throw new MobileDeviceManagementDAOException 73 | ("Error occurred while retrieving data source connection", e); 74 | } 75 | } 76 | } 77 | 78 | public static Connection getConnection() throws MobileDeviceManagementDAOException { 79 | if (currentConnection.get() == null) { 80 | try { 81 | currentConnection.set(dataSource.getConnection()); 82 | } catch (SQLException e) { 83 | throw new MobileDeviceManagementDAOException 84 | ("Error occurred while retrieving data source connection", e); 85 | } 86 | } 87 | return currentConnection.get(); 88 | } 89 | 90 | public static void commitTransaction() { 91 | try { 92 | Connection conn = currentConnection.get(); 93 | if (conn != null) { 94 | conn.commit(); 95 | } else { 96 | if (log.isDebugEnabled()) { 97 | log.debug("Datasource connection associated with the current thread is null, hence commit " + 98 | "has not been attempted"); 99 | } 100 | } 101 | } catch (SQLException e) { 102 | log.error("Error occurred while committing the transaction", e); 103 | } 104 | } 105 | 106 | public static void closeConnection() { 107 | Connection con = currentConnection.get(); 108 | try { 109 | con.close(); 110 | } catch (SQLException e) { 111 | log.error("Error occurred while close the connection"); 112 | } 113 | currentConnection.remove(); 114 | } 115 | 116 | public static void rollbackTransaction() { 117 | try { 118 | Connection conn = currentConnection.get(); 119 | if (conn != null) { 120 | conn.rollback(); 121 | } else { 122 | if (log.isDebugEnabled()) { 123 | log.debug("Datasource connection associated with the current thread is null, hence rollback " + 124 | "has not been attempted"); 125 | } 126 | } 127 | } catch (SQLException e) { 128 | log.warn("Error occurred while roll-backing the transaction", e); 129 | } 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/MobileDeviceManagementConfigTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.impl; 20 | 21 | import org.apache.commons.logging.Log; 22 | import org.apache.commons.logging.LogFactory; 23 | import org.testng.Assert; 24 | import org.testng.annotations.BeforeClass; 25 | import org.testng.annotations.Test; 26 | import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceManagementConfig; 27 | import org.xml.sax.SAXException; 28 | import org.xml.sax.SAXParseException; 29 | 30 | import javax.xml.XMLConstants; 31 | import javax.xml.bind.JAXBContext; 32 | import javax.xml.bind.JAXBException; 33 | import javax.xml.bind.Unmarshaller; 34 | import javax.xml.validation.Schema; 35 | import javax.xml.validation.SchemaFactory; 36 | import java.io.File; 37 | 38 | /** 39 | * Class for holding unit-tests related to MobileDeviceManagementConfig class. 40 | */ 41 | 42 | public class MobileDeviceManagementConfigTests { 43 | 44 | private static final Log log = LogFactory.getLog(MobileDeviceManagementConfigTests.class); 45 | private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_MGT_REPOSITORY = 46 | "./src/test/resources/config/malformed-mobile-config-no-mgt-repo.xml"; 47 | private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_DS_CONFIG = 48 | "./src/test/resources/config/malformed-mobile-config-no-ds-config.xml"; 49 | private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_JNDI_CONFIG = 50 | "./src/test/resources/config/malformed-mobile-config-no-jndi-config.xml"; 51 | private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_APIS_CONFIG = 52 | "./src/test/resources/config/malformed-mobile-config-no-apis-config.xml"; 53 | private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_API_CONFIG = 54 | "./src/test/resources/config/malformed-mobile-config-no-api-config.xml"; 55 | private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_API_PUBLISHER_CONFIG = 56 | "./src/test/resources/config/malformed-mobile-config-no-api-publisher-config.xml"; 57 | private static final String TEST_CONFIG_SCHEMA_LOCATION = 58 | "./src/test/resources/config/schema/MobileDeviceManagementConfigSchema.xsd"; 59 | 60 | private Schema schema; 61 | 62 | @BeforeClass 63 | private void initSchema() { 64 | File deviceManagementSchemaConfig = 65 | new File(MobileDeviceManagementConfigTests.TEST_CONFIG_SCHEMA_LOCATION); 66 | SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); 67 | try { 68 | schema = factory.newSchema(deviceManagementSchemaConfig); 69 | } catch (SAXException e) { 70 | Assert.fail("Invalid schema found", e); 71 | } 72 | } 73 | 74 | @Test 75 | public void testMandateManagementRepositoryElement() { 76 | File malformedConfig = 77 | new File( 78 | MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_MGT_REPOSITORY); 79 | this.validateMalformedConfig(malformedConfig); 80 | } 81 | 82 | @Test 83 | public void testMandateDataSourceConfigurationElement() { 84 | File malformedConfig = new File( 85 | MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_DS_CONFIG); 86 | this.validateMalformedConfig(malformedConfig); 87 | } 88 | 89 | @Test 90 | public void testMandateJndiLookupDefinitionElement() { 91 | File malformedConfig = new File( 92 | MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_JNDI_CONFIG); 93 | this.validateMalformedConfig(malformedConfig); 94 | } 95 | 96 | @Test 97 | public void testMandateAPIPublisherElement() { 98 | File malformedConfig = new File( 99 | MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_API_PUBLISHER_CONFIG); 100 | this.validateMalformedConfig(malformedConfig); 101 | } 102 | 103 | @Test 104 | public void testMandateAPIsElement() { 105 | File malformedConfig = new File( 106 | MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_APIS_CONFIG); 107 | this.validateMalformedConfig(malformedConfig); 108 | } 109 | 110 | @Test 111 | public void testMandateAPIElement() { 112 | File malformedConfig = new File( 113 | MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_API_CONFIG); 114 | this.validateMalformedConfig(malformedConfig); 115 | } 116 | 117 | /** 118 | * Validates a given malformed-configuration file. 119 | */ 120 | private void validateMalformedConfig(File malformedConfig) { 121 | try { 122 | JAXBContext ctx = JAXBContext.newInstance(MobileDeviceManagementConfig.class); 123 | Unmarshaller um = ctx.createUnmarshaller(); 124 | um.setSchema(this.getSchema()); 125 | um.unmarshal(malformedConfig); 126 | Assert.assertTrue(false); 127 | } catch (JAXBException e) { 128 | Throwable linkedException = e.getLinkedException(); 129 | if (!(linkedException instanceof SAXParseException)) { 130 | log.error("Unexpected error occurred while unmarshalling mobile device management config", e); 131 | Assert.assertTrue(false); 132 | } 133 | Assert.assertTrue(true); 134 | } 135 | } 136 | 137 | private Schema getSchema() { 138 | return schema; 139 | } 140 | 141 | } 142 | -------------------------------------------------------------------------------- /components/key-mgt/org.wso2.carbon.key.mgt.handler.valve/src/main/java/org/wso2/carbon/key/mgt/handler/valve/OAuthTokenValidatorValve.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.key.mgt.handler.valve; 20 | 21 | import org.apache.catalina.connector.Request; 22 | import org.apache.catalina.connector.Response; 23 | import org.apache.catalina.valves.ValveBase; 24 | import org.apache.commons.logging.Log; 25 | import org.apache.commons.logging.LogFactory; 26 | import org.wso2.carbon.apimgt.api.APIManagementException; 27 | import org.wso2.carbon.apimgt.core.authenticate.APITokenValidator; 28 | import org.wso2.carbon.apimgt.core.gateway.APITokenAuthenticator; 29 | import org.wso2.carbon.apimgt.impl.APIConstants; 30 | import org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO; 31 | import org.wso2.carbon.apimgt.impl.utils.APIUtil; 32 | 33 | import javax.servlet.ServletException; 34 | import java.io.IOException; 35 | import java.util.Enumeration; 36 | 37 | public class OAuthTokenValidatorValve extends ValveBase { 38 | 39 | private static final Log log = LogFactory.getLog(OAuthTokenValidatorValve.class); 40 | 41 | APITokenAuthenticator authenticator; 42 | 43 | public OAuthTokenValidatorValve() { 44 | authenticator = new APITokenAuthenticator(); 45 | } 46 | 47 | @Override 48 | public void invoke(Request request, Response response) throws java.io.IOException, javax.servlet.ServletException { 49 | String context = request.getContextPath(); 50 | if (context == null || context.equals("")) { 51 | //Invoke the next valve in handler chain. 52 | getNext().invoke(request, response); 53 | return; 54 | } 55 | 56 | boolean contextExist; 57 | Boolean contextValueInCache = null; 58 | if (APIUtil.getAPIContextCache().get(context) != null) { 59 | contextValueInCache = Boolean.parseBoolean(APIUtil.getAPIContextCache().get(context).toString()); 60 | } 61 | 62 | if (contextValueInCache != null) { 63 | contextExist = contextValueInCache; 64 | } else { 65 | contextExist = ApiMgtDAO.isContextExist(context); 66 | APIUtil.getAPIContextCache().put(context, contextExist); 67 | } 68 | 69 | if (!contextExist) { 70 | getNext().invoke(request, response); 71 | return; 72 | } 73 | 74 | try { 75 | handleWSDLGetRequest(request, response, context); 76 | } catch (IOException e) { 77 | e.printStackTrace(); 78 | } catch (ServletException e) { 79 | e.printStackTrace(); 80 | } 81 | 82 | String authHeader = request.getHeader(APIConstants.OperationParameter.AUTH_PARAM_NAME); 83 | String accessToken = null; 84 | 85 | /* Authenticate*/ 86 | try { 87 | if (authHeader != null) { 88 | accessToken = HandlerUtil.getAccessToken(authHeader); 89 | } else { 90 | // There can be some API published with None Auth Type 91 | /* 92 | * throw new 93 | * APIFaultException(APIConstants.KeyValidationStatus 94 | * .API_AUTH_INVALID_CREDENTIALS, 95 | * "Invalid format for Authorization header. Expected 'Bearer '" 96 | * ); 97 | */ 98 | } 99 | 100 | String apiVersion = HandlerUtil.getAPIVersion(request); 101 | String domain = request.getHeader(APITokenValidator.getAPIManagerClientDomainHeader()); 102 | String authLevel = authenticator.getResourceAuthenticationScheme(context, 103 | apiVersion, 104 | request.getRequestURI(), 105 | request.getMethod()); 106 | if (HandlerConstants.NO_MATCHING_AUTH_SCHEME.equals(authLevel)) { 107 | HandlerUtil.handleNoMatchAuthSchemeCallForRestService(response, 108 | request.getMethod(), request.getRequestURI(), 109 | apiVersion, context); 110 | return; 111 | } else { 112 | HandlerUtil.doAuthenticate(context, apiVersion, accessToken, authLevel, domain); 113 | } 114 | } catch (APIManagementException e) { 115 | //ignore 116 | } catch (APIFaultException e) { 117 | log.error("Error occurred while key validation", e); 118 | return; 119 | } 120 | 121 | getNext().invoke(request, response); 122 | } 123 | 124 | private void handleWSDLGetRequest(Request request, Response response, 125 | String context) throws IOException, ServletException { 126 | if (request.getMethod().equals("GET")) { 127 | // TODO:Need to get these paths from a config file. 128 | if (request.getRequestURI().matches(context + "/[^/]*/services")) { 129 | getNext().invoke(request, response); 130 | return; 131 | } 132 | Enumeration params = request.getParameterNames(); 133 | String paramName; 134 | while (params.hasMoreElements()) { 135 | paramName = params.nextElement(); 136 | if (paramName.endsWith("wsdl") || paramName.endsWith("wadl")) { 137 | getNext().invoke(request, response); 138 | return; 139 | } 140 | } 141 | } 142 | } 143 | 144 | } 145 | -------------------------------------------------------------------------------- /components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/util/MobileDeviceManagementDAOUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * you may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.device.mgt.mobile.dao.util; 20 | 21 | import org.apache.commons.logging.Log; 22 | import org.apache.commons.logging.LogFactory; 23 | import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException; 24 | import org.wso2.carbon.device.mgt.mobile.config.datasource.JNDILookupDefinition; 25 | import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig; 26 | import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementSchemaInitializer; 27 | 28 | import javax.naming.InitialContext; 29 | import javax.sql.DataSource; 30 | import java.sql.Connection; 31 | import java.sql.PreparedStatement; 32 | import java.sql.ResultSet; 33 | import java.sql.SQLException; 34 | import java.util.Hashtable; 35 | import java.util.List; 36 | 37 | /** 38 | * Utility method required by MobileDeviceManagement DAO classes. 39 | */ 40 | public class MobileDeviceManagementDAOUtil { 41 | 42 | private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOUtil.class); 43 | 44 | public static DataSource lookupDataSource(String dataSourceName, 45 | final Hashtable jndiProperties){ 46 | 47 | try { 48 | if (jndiProperties == null || jndiProperties.isEmpty()) { 49 | return (DataSource) InitialContext.doLookup(dataSourceName); 50 | } 51 | final InitialContext context = new InitialContext(jndiProperties); 52 | return (DataSource) context.lookup(dataSourceName); 53 | } catch (Exception e) { 54 | String msg = "Error in looking up data source: " + e.getMessage(); 55 | log.error(msg, e); 56 | throw new RuntimeException(msg + e.getMessage(), e); 57 | } 58 | } 59 | 60 | public static void cleanupResources(Connection conn, PreparedStatement stmt, ResultSet rs) { 61 | if (rs != null) { 62 | try { 63 | rs.close(); 64 | } catch (SQLException e) { 65 | log.warn("Error occurred while closing result set", e); 66 | } 67 | } 68 | if (stmt != null) { 69 | try { 70 | stmt.close(); 71 | } catch (SQLException e) { 72 | log.warn("Error occurred while closing prepared statement", e); 73 | } 74 | } 75 | if (conn != null) { 76 | try { 77 | conn.close(); 78 | } catch (SQLException e) { 79 | log.warn("Error occurred while closing database connection", e); 80 | } 81 | } 82 | } 83 | 84 | public static void cleanupResources(PreparedStatement stmt, ResultSet rs) { 85 | cleanupResources(null, stmt, rs); 86 | } 87 | 88 | /** 89 | * Creates the mobile device management schema. 90 | * 91 | * @param dataSource Mobile data source 92 | */ 93 | public static void setupMobileDeviceManagementSchema(DataSource dataSource, String pluginType) throws MobileDeviceMgtPluginException { 94 | MobileDeviceManagementSchemaInitializer initializer = 95 | new MobileDeviceManagementSchemaInitializer(dataSource, pluginType); 96 | log.info("Initializing mobile device management repository database schema for : " + pluginType); 97 | try { 98 | initializer.createRegistryDatabase(); 99 | } catch (Exception e) { 100 | throw new MobileDeviceMgtPluginException("Error occurred while initializing Mobile Device " + 101 | "Management database schema", e); 102 | } 103 | } 104 | 105 | 106 | /** 107 | * Resolve data source from the data source definition 108 | * 109 | * @param config data source configuration 110 | * @return data source resolved from the data source definition 111 | */ 112 | private static DataSource resolveDataSource(MobileDataSourceConfig config) { 113 | DataSource dataSource = null; 114 | if (config == null) { 115 | throw new RuntimeException( 116 | "data source configuration " + "is null and " + 117 | "thus, is not initialized"); 118 | } 119 | JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition(); 120 | if (jndiConfig != null) { 121 | if (log.isDebugEnabled()) { 122 | log.debug("Initializing data source using the JNDI " + 123 | "Lookup Definition"); 124 | } 125 | List jndiPropertyList = 126 | jndiConfig.getJndiProperties(); 127 | if (jndiPropertyList != null) { 128 | Hashtable jndiProperties = new Hashtable(); 129 | for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) { 130 | jndiProperties.put(prop.getName(), prop.getValue()); 131 | } 132 | dataSource = MobileDeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties); 133 | } else { 134 | dataSource = MobileDeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null); 135 | } 136 | } 137 | return dataSource; 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | org.wso2.carbon.devicemgt-plugins 24 | device-mgt-feature 25 | 2.0.4-SNAPSHOT 26 | ../pom.xml 27 | 28 | 29 | 4.0.0 30 | org.wso2.carbon.device.mgt.mobile.feature 31 | pom 32 | 2.0.4-SNAPSHOT 33 | WSO2 Carbon - Mobile Device Management Feature 34 | http://wso2.org 35 | This feature contains the core bundles required for Mobile Device Management functionality 36 | 37 | 38 | 39 | 40 | org.wso2.carbon.devicemgt-plugins 41 | org.wso2.carbon.device.mgt.mobile.impl 42 | 43 | 44 | org.wso2.carbon.devicemgt 45 | org.wso2.carbon.device.mgt.common 46 | 47 | 48 | org.wso2.carbon.devicemgt-plugins 49 | org.wso2.carbon.device.mgt.mobile.url.printer 50 | 51 | 52 | org.wso2.carbon.devicemgt 53 | org.wso2.carbon.device.mgt.server.feature 54 | zip 55 | 56 | 57 | org.wso2.carbon.devicemgt 58 | org.wso2.carbon.device.mgt.extensions.feature 59 | zip 60 | 61 | 62 | com.google.code.gson 63 | gson 64 | 65 | 66 | 67 | 68 | 69 | 70 | maven-resources-plugin 71 | 2.6 72 | 73 | 74 | copy-resources 75 | generate-resources 76 | 77 | copy-resources 78 | 79 | 80 | src/main/resources 81 | 82 | 83 | resources 84 | 85 | build.properties 86 | p2.inf 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | org.wso2.maven 96 | carbon-p2-plugin 97 | ${carbon.p2.plugin.version} 98 | 99 | 100 | p2-feature-generation 101 | package 102 | 103 | p2-feature-gen 104 | 105 | 106 | org.wso2.carbon.device.mgt.mobile 107 | ../../../features/etc/feature.properties 108 | 109 | 110 | org.wso2.carbon.p2.category.type:server 111 | org.eclipse.equinox.p2.type.group:false 112 | 113 | 114 | 115 | org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.mobile.impl:${carbon.mobile.device.mgt.version} 116 | org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.mobile.url.printer:${carbon.mobile.device.mgt.version} 117 | 118 | 119 | org.wso2.carbon.core.server:${carbon.kernel.version} 120 | org.wso2.carbon.device.mgt.server:${carbon.device.mgt.version} 121 | org.wso2.carbon.device.mgt.extensions:${carbon.device.mgt.version} 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /components/key-mgt/org.wso2.carbon.key.mgt.handler.valve/src/main/java/org/wso2/carbon/key/mgt/handler/valve/HandlerUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.key.mgt.handler.valve; 20 | 21 | import org.apache.axiom.om.OMAbstractFactory; 22 | import org.apache.axiom.om.OMElement; 23 | import org.apache.axiom.om.OMFactory; 24 | import org.apache.axiom.om.OMNamespace; 25 | import org.apache.catalina.connector.Response; 26 | import org.apache.commons.logging.Log; 27 | import org.apache.commons.logging.LogFactory; 28 | import org.wso2.carbon.apimgt.api.APIManagementException; 29 | import org.wso2.carbon.apimgt.core.APIManagerErrorConstants; 30 | import org.wso2.carbon.apimgt.core.authenticate.APITokenValidator; 31 | import org.wso2.carbon.apimgt.impl.APIConstants; 32 | import org.wso2.carbon.apimgt.impl.dto.APIKeyValidationInfoDTO; 33 | import org.wso2.carbon.context.PrivilegedCarbonContext; 34 | import org.wso2.carbon.identity.base.IdentityException; 35 | import org.wso2.carbon.identity.core.util.IdentityUtil; 36 | 37 | import javax.servlet.http.HttpServletRequest; 38 | import java.io.IOException; 39 | 40 | public class HandlerUtil { 41 | 42 | private static APIKeyValidationInfoDTO apiKeyValidationDTO; 43 | private static final Log log = LogFactory.getLog(HandlerUtil.class); 44 | 45 | /** 46 | * Retrieve bearer token form the HTTP header 47 | * @param bearerToken Bearer Token extracted out of the corresponding HTTP header 48 | */ 49 | public static String getAccessToken(String bearerToken) { 50 | String accessToken = null; 51 | String[] token = bearerToken.split(HandlerConstants.TOKEN_NAME_BEARER); 52 | if (token.length > 1 && token[1] != null) { 53 | accessToken = token[1].trim(); 54 | } 55 | return accessToken; 56 | } 57 | 58 | public static String getAPIVersion(HttpServletRequest request) { 59 | int contextStartsIndex = (request.getRequestURI()).indexOf(request.getContextPath()) + 1; 60 | int length = request.getContextPath().length(); 61 | String afterContext = (request.getRequestURI()).substring(contextStartsIndex + length); 62 | int SlashIndex = afterContext.indexOf(("/")); 63 | 64 | if (SlashIndex != -1) { 65 | return afterContext.substring(0, SlashIndex); 66 | } else { 67 | return afterContext; 68 | } 69 | } 70 | 71 | public static void handleNoMatchAuthSchemeCallForRestService(Response response,String httpVerb, String reqUri, 72 | String version, String context ) { 73 | String errMsg = "Resource is not matched for HTTP Verb " + httpVerb + ". API context " + context + 74 | ",version " + version + ", request " + reqUri; 75 | APIFaultException e = new APIFaultException( APIManagerErrorConstants.API_AUTH_INCORRECT_API_RESOURCE, errMsg); 76 | String faultPayload = getFaultPayload(e, APIManagerErrorConstants.API_SECURITY_NS, 77 | APIManagerErrorConstants.API_SECURITY_NS_PREFIX).toString(); 78 | handleRestFailure(response, faultPayload); 79 | } 80 | 81 | public static boolean doAuthenticate(String context, String version, String accessToken, 82 | String requiredAuthenticationLevel, String clientDomain) 83 | throws APIManagementException, 84 | APIFaultException { 85 | 86 | if (APIConstants.AUTH_NO_AUTHENTICATION.equals(requiredAuthenticationLevel)) { 87 | return true; 88 | } 89 | APITokenValidator tokenValidator = new APITokenValidator(); 90 | apiKeyValidationDTO = tokenValidator.validateKey(context, version, accessToken, 91 | requiredAuthenticationLevel, clientDomain); 92 | if (apiKeyValidationDTO.isAuthorized()) { 93 | String userName = apiKeyValidationDTO.getEndUserName(); 94 | PrivilegedCarbonContext.getThreadLocalCarbonContext() 95 | .setUsername(apiKeyValidationDTO.getEndUserName()); 96 | try { 97 | PrivilegedCarbonContext.getThreadLocalCarbonContext() 98 | .setTenantId(IdentityUtil.getTenantIdOFUser(userName)); 99 | } catch (IdentityException e) { 100 | log.error("Error while retrieving Tenant Id", e); 101 | return false; 102 | } 103 | return true; 104 | } else { 105 | throw new APIFaultException(apiKeyValidationDTO.getValidationStatus(), 106 | "Access failure for API: " + context + ", version: " + 107 | version + " with key: " + accessToken); 108 | } 109 | } 110 | 111 | public static void handleRestFailure(Response response, String payload) { 112 | response.setStatus(403); 113 | response.setContentType("application/xml"); 114 | response.setCharacterEncoding("UTF-8"); 115 | try { 116 | response.getWriter().write(payload); 117 | } catch (IOException e) { 118 | log.error("Error in sending fault response", e); 119 | } 120 | } 121 | 122 | public static OMElement getFaultPayload(APIFaultException exception, String FaultNS, 123 | String FaultNSPrefix) { 124 | OMFactory fac = OMAbstractFactory.getOMFactory(); 125 | OMNamespace ns = fac.createOMNamespace(FaultNS, FaultNSPrefix); 126 | OMElement payload = fac.createOMElement("fault", ns); 127 | 128 | OMElement errorCode = fac.createOMElement("code", ns); 129 | errorCode.setText(String.valueOf(exception.getErrorCode())); 130 | OMElement errorMessage = fac.createOMElement("message", ns); 131 | errorMessage.setText(APIManagerErrorConstants.getFailureMessage(exception.getErrorCode())); 132 | OMElement errorDetail = fac.createOMElement("description", ns); 133 | errorDetail.setText(exception.getMessage()); 134 | 135 | payload.addChild(errorCode); 136 | payload.addChild(errorMessage); 137 | payload.addChild(errorDetail); 138 | return payload; 139 | } 140 | 141 | } 142 | --------------------------------------------------------------------------------