From 4a061e7be22c3a1ea74ef8676963976c3d63c53a Mon Sep 17 00:00:00 2001 From: inosh-perera Date: Wed, 25 Mar 2015 20:03:06 +0530 Subject: [PATCH] adding App management integeration related code --- .../org.wso2.carbon.device.mgt.core/pom.xml | 8 +- .../mgt/core/DeviceManagementConstants.java | 11 ++ .../api/mgt/config/APIPublisherConfig.java | 2 +- .../core/app/mgt/AppManagementException.java | 60 ++++++++ .../mgt/core/app/mgt/AppManagerImplHttp.java | 132 ++++++++++++++++++ .../app/mgt/config/AppManagementConfig.java | 68 +++++++++ .../AppManagementConfigurationManager.java | 72 ++++++++++ .../app/mgt/oauth/ServiceAuthenticator.java | 74 ++++++++++ .../core/app/mgt/oauth/dto/Credential.java | 43 ++++++ .../DeviceManagementConfigRepository.java | 33 +++-- .../identity/IdentityConfigurations.java | 59 ++++++++ .../device/mgt/core/dto/Application.java | 101 ++++++++++++++ .../internal/DeviceManagementDataHolder.java | 20 +++ .../DeviceManagementServiceComponent.java | 17 +++ .../service/AppManagementServiceImpl.java | 48 +++++++ .../device/mgt/core/service/AppManager.java | 69 +++++++++ .../pom.xml | 2 + .../resources/conf/app-management-config.xml | 23 +++ .../src/main/resources/conf/cdm-config.xml | 5 + pom.xml | 7 + 20 files changed, 841 insertions(+), 13 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagementException.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagerImplHttp.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/config/AppManagementConfig.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/config/AppManagementConfigurationManager.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/oauth/ServiceAuthenticator.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/oauth/dto/Credential.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/identity/IdentityConfigurations.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Application.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/AppManagementServiceImpl.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/AppManager.java create mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/app-management-config.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index 32dc928532..e66aebc504 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -78,7 +78,9 @@ org.wso2.carbon.governance.api.generic.dataobjects, org.wso2.carbon.apimgt.api, org.wso2.carbon.apimgt.api.model, - org.wso2.carbon.apimgt.impl + org.wso2.carbon.apimgt.impl, + org.wso2.carbon.identity.oauth.stub, + org.wso2.carbon.identity.oauth.stub.dto !org.wso2.carbon.device.mgt.core.internal, @@ -195,6 +197,10 @@ org.apache.axis2.wso2 axis2 + + org.wso2.carbon.identity + org.wso2.carbon.identity.oauth.stub + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java index 62be056434..71891e3f7f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java @@ -28,4 +28,15 @@ public final class DeviceManagementConstants { public static final String DEFAULT_LICENSE_CONFIG_XML_NAME = "license-config.xml"; } + public static final class AppManagement { + private AppManagement() { + throw new AssertionError(); + } + + public static final String OAUTH_APPLICATION_NAME = "app_management_application"; + public static final String OAUTH2_GRANT_TYPE_CLIENT_CREDENTIALS = "client_credentials"; + public final static String OAUTH_VERSION_2 = "oauth-2.0"; + public final static String OAUTH_ADMIN_SERVICE = "/services/OAuthAdminService"; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/config/APIPublisherConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/config/APIPublisherConfig.java index 96f220fc70..a781770c6a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/config/APIPublisherConfig.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/config/APIPublisherConfig.java @@ -77,7 +77,7 @@ public class APIPublisherConfig { Document doc = DeviceManagerUtil.convertToDocument(publisherConfig); /* Un-marshaling Device Management configuration */ - JAXBContext ctx = JAXBContext.newInstance(DeviceManagementConfig.class); + JAXBContext ctx = JAXBContext.newInstance(APIPublisherConfig.class); Unmarshaller unmarshaller = ctx.createUnmarshaller(); config = (APIPublisherConfig) unmarshaller.unmarshal(doc); } catch (JAXBException e) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagementException.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagementException.java new file mode 100644 index 0000000000..6eb3bc499f --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagementException.java @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +package org.wso2.carbon.device.mgt.core.app.mgt; + +/** + * Handles the exceptions related to Application management. + */ +public class AppManagementException extends Exception { + + private static final long serialVersionUID = -8933142342423122660L; + private String errorMessage; + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public AppManagementException(String msg, Exception nestedEx) { + super(msg, nestedEx); + setErrorMessage(msg); + } + + public AppManagementException(String message, Throwable cause) { + super(message, cause); + setErrorMessage(message); + } + + public AppManagementException(String msg) { + super(msg); + setErrorMessage(msg); + } + + public AppManagementException() { + super(); + } + + public AppManagementException(Throwable cause) { + super(cause); + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagerImplHttp.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagerImplHttp.java new file mode 100644 index 0000000000..94818f7fd9 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagerImplHttp.java @@ -0,0 +1,132 @@ +/* +* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +package org.wso2.carbon.device.mgt.core.app.mgt; + +import org.apache.axis2.AxisFault; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.context.ConfigurationContextFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; +import org.wso2.carbon.device.mgt.core.app.mgt.oauth.ServiceAuthenticator; +import org.wso2.carbon.device.mgt.core.app.mgt.oauth.dto.Credential; +import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig; +import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; +import org.wso2.carbon.device.mgt.core.config.identity.IdentityConfigurations; +import org.wso2.carbon.device.mgt.core.dto.Application; +import org.wso2.carbon.device.mgt.core.service.AppManager; +import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceException; +import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub; +import org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO; + +import java.rmi.RemoteException; + +/** + * Implements AppManager interface + */ +public class AppManagerImplHttp implements AppManager { + + private static Log log = LogFactory.getLog(AppManagerImplHttp.class); + private static AppManagementConfig appManagementConfig; + private static final String GET_APP_LIST_URL = + "store/apis/assets/mobileapp?domain=carbon.super&page=1"; + private static String appManagerUrl; + private static String consumerKey; + private static String consumerSecret; + + public AppManagerImplHttp(AppManagementConfig appManagementConfig) { + this.appManagementConfig = appManagementConfig; + this.appManagerUrl = appManagementConfig.getAppManagerUrl(); + this.consumerKey = appManagementConfig.getConsumerKey(); + this.consumerSecret = appManagementConfig.getConsumerSecret(); + } + + @Override + public Application[] getApplicationList(String domain, int pageNumber, int size) + throws AppManagementException { + return new Application[0]; + } + + @Override public void updateApplicationStatusOnDevice(DeviceIdentifier deviceId, + Application application, String status) { + + } + + @Override public String getApplicationStatusOnDevice(DeviceIdentifier deviceId, + Application application) { + return null; + } + + @Override public Credential getClientCredentials() throws AppManagementException { + OAuthAdminServiceStub oAuthAdminServiceStub; + OAuthConsumerAppDTO appDTO = new OAuthConsumerAppDTO(); + appDTO.setApplicationName(DeviceManagementConstants.AppManagement.OAUTH_APPLICATION_NAME); + appDTO.setGrantTypes( + DeviceManagementConstants.AppManagement.OAUTH2_GRANT_TYPE_CLIENT_CREDENTIALS); + appDTO.setOAuthVersion(DeviceManagementConstants.AppManagement.OAUTH_VERSION_2); + IdentityConfigurations identityConfigurations = + DeviceConfigurationManager.getInstance().getDeviceManagementConfig() + .getDeviceManagementConfigRepository() + .getIdentityConfigurations(); + String serverUrl = identityConfigurations.getServerUrl(); + String username = identityConfigurations.getAdminUsername(); + String password = identityConfigurations.getAdminPassword(); + String oauthAdminServiceUrl = serverUrl + + DeviceManagementConstants.AppManagement.OAUTH_ADMIN_SERVICE; + + try { + ConfigurationContext configContext = ConfigurationContextFactory + .createConfigurationContextFromFileSystem(null, null); + oAuthAdminServiceStub = new OAuthAdminServiceStub(configContext, oauthAdminServiceUrl); + + ServiceAuthenticator authenticator = ServiceAuthenticator.getInstance(); + authenticator.setAccessUsername(username); + authenticator.setAccessPassword(password); + authenticator.authenticate(oAuthAdminServiceStub._getServiceClient()); + + OAuthConsumerAppDTO createdAppData = null; + try { + createdAppData = oAuthAdminServiceStub.getOAuthApplicationDataByAppName( + DeviceManagementConstants.AppManagement.OAUTH_APPLICATION_NAME); + } + //application doesn't exist. Due to the way getOAuthApplicationDataByAppName has been + //implemented, it throws an AxisFault if the App doesn't exist. Hence the catch. + catch (AxisFault fault) { + oAuthAdminServiceStub.registerOAuthApplicationData(appDTO); + createdAppData = oAuthAdminServiceStub.getOAuthApplicationDataByAppName( + DeviceManagementConstants.AppManagement.OAUTH_APPLICATION_NAME); + } + + Credential credential = new Credential(); + credential.setConsumerKey(createdAppData.getOauthConsumerKey()); + credential.setConsumerSecret(createdAppData.getOauthConsumerSecret()); + return credential; + } catch (RemoteException e) { + String msg = "Error while registering a new application."; + log.error(msg, e); + throw new AppManagementException(msg, e); + } catch (OAuthAdminServiceException e) { + String msg = "Error while working with oauth admin services stub."; + log.error(msg, e); + throw new AppManagementException(msg, e); + } + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/config/AppManagementConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/config/AppManagementConfig.java new file mode 100644 index 0000000000..c6fe92e125 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/config/AppManagementConfig.java @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +package org.wso2.carbon.device.mgt.core.app.mgt.config; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "AppManagementConfig") +public class AppManagementConfig { + + private boolean enabled; + private String appManagerUrl; + private String consumerKey; + private String consumerSecret; + + @XmlElement(name = "ConsumerKey", required = true) + public String getConsumerKey() { + return consumerKey; + } + + public void setConsumerKey(String consumerKey) { + this.consumerKey = consumerKey; + } + + @XmlElement(name = "ConsumerSecret", required = true) + public String getConsumerSecret() { + return consumerSecret; + } + + public void setConsumerSecret(String consumerSecret) { + this.consumerSecret = consumerSecret; + } + + @XmlElement(name = "Enabled", required = true) + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + @XmlElement(name = "AppManagerUrl", required = false) + public String getAppManagerUrl() { + return appManagerUrl; + } + + public void setAppManagerUrl(String appManagerUrl) { + this.appManagerUrl = appManagerUrl; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/config/AppManagementConfigurationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/config/AppManagementConfigurationManager.java new file mode 100644 index 0000000000..e4cda1a494 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/config/AppManagementConfigurationManager.java @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +package org.wso2.carbon.device.mgt.core.app.mgt.config; + +import org.w3c.dom.Document; +import org.wso2.carbon.device.mgt.core.app.mgt.AppManagementException; +import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; +import org.wso2.carbon.utils.CarbonUtils; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; +import java.io.File; + +public class AppManagementConfigurationManager { + + private AppManagementConfig appManagementConfig; + private static AppManagementConfigurationManager appManagementConfigManager; + + private static final String APP_MANAGER_CONFIG_FILE = "app-management-config.xml"; + private static final String APP_MANAGER_CONFIG_PATH = + CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + APP_MANAGER_CONFIG_FILE; + + public static AppManagementConfigurationManager getInstance() { + if (appManagementConfigManager == null) { + synchronized (AppManagementConfigurationManager.class) { + if (appManagementConfigManager == null) { + appManagementConfigManager = new AppManagementConfigurationManager(); + } + } + } + return appManagementConfigManager; + } + + public synchronized void initConfig() throws AppManagementException { + try { + File appManagementConfig = + new File(AppManagementConfigurationManager.APP_MANAGER_CONFIG_PATH); + Document doc = DeviceManagerUtil.convertToDocument(appManagementConfig); + + /* Un-marshaling App Management configuration */ + JAXBContext cdmContext = JAXBContext.newInstance(AppManagementConfig.class); + Unmarshaller unmarshaller = cdmContext.createUnmarshaller(); + this.appManagementConfig = (AppManagementConfig) unmarshaller.unmarshal(doc); + } catch (Exception e) { + /* Catches generic exception as there's no specific task to be carried out catching a particular + exception */ + throw new AppManagementException( + "Error occurred while initializing application management Configurations", e); + } + } + + public AppManagementConfig getAppManagementConfig() { + return appManagementConfig; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/oauth/ServiceAuthenticator.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/oauth/ServiceAuthenticator.java new file mode 100644 index 0000000000..879850c976 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/oauth/ServiceAuthenticator.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.carbon.device.mgt.core.app.mgt.oauth; + + +import org.apache.axis2.client.Options; +import org.apache.axis2.client.ServiceClient; +import org.apache.axis2.transport.http.HttpTransportProperties; +import org.wso2.carbon.device.mgt.core.app.mgt.AppManagementException; + +/** + * Authenticate a given service client. + */ +public class ServiceAuthenticator { + + private static ServiceAuthenticator instance = null; + private String accessUsername = null; + private String accessPassword = null; + + private ServiceAuthenticator() { + } + + public static ServiceAuthenticator getInstance() { + + if (instance != null) { + return instance; + } else { + instance = new ServiceAuthenticator(); + return instance; + } + } + + public void authenticate(ServiceClient client) throws AppManagementException { + + if (accessUsername != null && accessPassword != null) { + Options option = client.getOptions(); + HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator(); + auth.setUsername(accessUsername); + auth.setPassword(accessPassword); + auth.setPreemptiveAuthentication(true); + option.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth); + option.setManageSession(true); + + } else { + throw new AppManagementException("Authentication username or password not set"); + } + } + + public void setAccessUsername(String accessUsername) { + this.accessUsername = accessUsername; + } + + public void setAccessPassword(String accessPassword) { + this.accessPassword = accessPassword; + } + +} + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/oauth/dto/Credential.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/oauth/dto/Credential.java new file mode 100644 index 0000000000..1cf07326d7 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/oauth/dto/Credential.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.carbon.device.mgt.core.app.mgt.oauth.dto; + +/** + * DTO of the consumer key and secret + */ +public class Credential { + String consumerKey; + String consumerSecret; + + public String getConsumerKey() { + return consumerKey; + } + + public void setConsumerKey(String consumerKey) { + this.consumerKey = consumerKey; + } + + public String getConsumerSecret() { + return consumerSecret; + } + + public void setConsumerSecret(String consumerSecret) { + this.consumerSecret = consumerSecret; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfigRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfigRepository.java index 640f8ec2b7..2867b08014 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfigRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfigRepository.java @@ -19,6 +19,7 @@ package org.wso2.carbon.device.mgt.core.config; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.config.email.EmailConfigurations; +import org.wso2.carbon.device.mgt.core.config.identity.IdentityConfigurations; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @@ -29,8 +30,9 @@ import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement(name = "ManagementRepository") public class DeviceManagementConfigRepository { - private DataSourceConfig dataSourceConfig; - private EmailConfigurations emailConfigurations; + private DataSourceConfig dataSourceConfig; + private EmailConfigurations emailConfigurations; + private IdentityConfigurations identityConfigurations; @XmlElement(name = "DataSourceConfiguration", required = true) public DataSourceConfig getDataSourceConfig() { @@ -40,13 +42,22 @@ public class DeviceManagementConfigRepository { public void setDataSourceConfig(DataSourceConfig dataSourceConfig) { this.dataSourceConfig = dataSourceConfig; } - - @XmlElement(name = "EmailClientConfiguration", required = true) - public EmailConfigurations getEmailConfigurations() { - return emailConfigurations; - } - - public void setEmailConfigurations(EmailConfigurations emailConfigurations) { - this.emailConfigurations = emailConfigurations; - } + + @XmlElement(name = "EmailClientConfiguration", required = true) + public EmailConfigurations getEmailConfigurations() { + return emailConfigurations; + } + + public void setEmailConfigurations(EmailConfigurations emailConfigurations) { + this.emailConfigurations = emailConfigurations; + } + + @XmlElement(name = "IdentityConfiguration", required = true) + public IdentityConfigurations getIdentityConfigurations() { + return identityConfigurations; + } + + public void setIdentityConfigurations(IdentityConfigurations identityConfigurations) { + this.identityConfigurations = identityConfigurations; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/identity/IdentityConfigurations.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/identity/IdentityConfigurations.java new file mode 100644 index 0000000000..fe7a7c7ae6 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/identity/IdentityConfigurations.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.carbon.device.mgt.core.config.identity; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * Configurations related to identity management. + */ +@XmlRootElement(name = "IdentityConfiguration") +public class IdentityConfigurations { + private String serverUrl; + private String adminUsername; + private String adminPassword; + + @XmlElement(name = "AdminUsername", required = true) + public String getAdminUsername() { + return adminUsername; + } + + public void setAdminUsername(String adminUsername) { + this.adminUsername = adminUsername; + } + + @XmlElement(name = "AdminPassword", required = true) + public String getAdminPassword() { + return adminPassword; + } + + public void setAdminPassword(String adminPassword) { + this.adminPassword = adminPassword; + } + + @XmlElement(name = "ServerUrl", required = true) + public String getServerUrl() { + return serverUrl; + } + + public void setServerUrl(String serverUrl) { + this.serverUrl = serverUrl; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Application.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Application.java new file mode 100644 index 0000000000..61129c7c1f --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Application.java @@ -0,0 +1,101 @@ +/* +* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +package org.wso2.carbon.device.mgt.core.dto; + +import java.io.Serializable; + +/** + * Holds data about an application that can be installed on a device. + */ +public class Application implements Serializable { + private static final long serialVersionUID = -81011063453453455L; + String id; + String name; + String packageName; + String platform; + String fileUrl; + String applicationType; + String category; + + public String getApplicationType() { + return applicationType; + } + + public void setApplicationType(String applicationType) { + this.applicationType = applicationType; + } + + public String getCategory() { + return category; + } + + public void setCategory(String category) { + this.category = category; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPackageName() { + return packageName; + } + + public void setPackageName(String packageName) { + this.packageName = packageName; + } + + public String getPlatform() { + return platform; + } + + public void setPlatform(String platform) { + this.platform = platform; + } + + public String getFileUrl() { + return fileUrl; + } + + public void setFileUrl(String fileUrl) { + this.fileUrl = fileUrl; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + String type; +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java index 813a3e5a7a..60abb695b9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java @@ -21,7 +21,9 @@ package org.wso2.carbon.device.mgt.core.internal; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherService; +import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig; import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig; +import org.wso2.carbon.device.mgt.core.service.AppManager; import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.user.core.service.RealmService; @@ -36,6 +38,8 @@ public class DeviceManagementDataHolder { private RegistryService registryService; private LicenseConfig licenseConfig; private APIPublisherService apiPublisherService; + private AppManager appManager; + private AppManagementConfig appManagerConfig; private static DeviceManagementDataHolder thisInstance = new DeviceManagementDataHolder(); @@ -106,4 +110,20 @@ public class DeviceManagementDataHolder { this.apiPublisherService = apiPublisherService; } + public AppManager getAppManager() { + return appManager; + } + + public void setAppManager(AppManager appManager) { + this.appManager = appManager; + } + + public AppManagementConfig getAppManagerConfig() { + return appManagerConfig; + } + + public void setAppManagerConfig(AppManagementConfig appManagerConfig) { + this.appManagerConfig = appManagerConfig; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index 1a83004c29..06c3a71326 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -34,14 +34,19 @@ import org.wso2.carbon.device.mgt.core.DeviceManagementServiceProviderImpl; import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherService; import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherServiceImpl; import org.wso2.carbon.device.mgt.core.api.mgt.APIRegistrationStartupObserver; +import org.wso2.carbon.device.mgt.core.app.mgt.AppManagerImplHttp; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; +import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig; +import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfigurationManager; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig; import org.wso2.carbon.device.mgt.core.config.license.LicenseConfigurationManager; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagerImpl; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; +import org.wso2.carbon.device.mgt.core.service.AppManagementServiceImpl; +import org.wso2.carbon.device.mgt.core.service.AppManager; import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementServiceImpl; import org.wso2.carbon.device.mgt.core.util.DeviceManagementSchemaInitializer; @@ -106,6 +111,13 @@ public class DeviceManagementServiceComponent { DeviceManagementDataHolder.getInstance().setLicenseManager(licenseManager); DeviceManagementDataHolder.getInstance().setLicenseConfig(licenseConfig); + AppManagementConfigurationManager.getInstance().initConfig(); + AppManagementConfig appConfig = + AppManagementConfigurationManager.getInstance().getAppManagementConfig(); + DeviceManagementDataHolder.getInstance().setAppManagerConfig(appConfig); + AppManagerImplHttp appManager = new AppManagerImplHttp(appConfig); + DeviceManagementDataHolder.getInstance().setAppManager(appManager); + OperationManagementDAOFactory.init(dsConfig); /* If -Dsetup option enabled then create device management database schema */ @@ -146,6 +158,11 @@ public class DeviceManagementServiceComponent { bundleContext.registerService(APIPublisherService.class, publisher, null); bundleContext.registerService(ServerStartupObserver.class, new APIRegistrationStartupObserver(), null); + + + /* Registering App Management service */ + bundleContext.registerService(AppManager.class.getName(), + new AppManagementServiceImpl(), null); } private void setupDeviceManagementSchema(DataSourceConfig config) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/AppManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/AppManagementServiceImpl.java new file mode 100644 index 0000000000..488617561b --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/AppManagementServiceImpl.java @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +package org.wso2.carbon.device.mgt.core.service; + +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.core.app.mgt.AppManagementException; +import org.wso2.carbon.device.mgt.core.app.mgt.oauth.dto.Credential; +import org.wso2.carbon.device.mgt.core.dto.Application; +import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; + +public class AppManagementServiceImpl implements AppManager { + @Override public Application[] getApplicationList(String domain, int pageNumber, int size) + throws AppManagementException { + return DeviceManagementDataHolder.getInstance().getAppManager() + .getApplicationList(domain, pageNumber, size); + } + + @Override public void updateApplicationStatusOnDevice(DeviceIdentifier deviceId, + Application application, String status) { + DeviceManagementDataHolder.getInstance().getAppManager() + .updateApplicationStatusOnDevice(deviceId, application, status); + + } + + @Override public String getApplicationStatusOnDevice(DeviceIdentifier deviceId, + Application application) { + return null; + } + + @Override public Credential getClientCredentials() throws AppManagementException{ + return DeviceManagementDataHolder.getInstance().getAppManager().getClientCredentials(); + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/AppManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/AppManager.java new file mode 100644 index 0000000000..886690ca19 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/AppManager.java @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +package org.wso2.carbon.device.mgt.core.service; + +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.core.app.mgt.oauth.dto.Credential; +import org.wso2.carbon.device.mgt.core.dto.Application; +import org.wso2.carbon.device.mgt.core.app.mgt.AppManagementException; + +/** + * This will handle the Application management side of MDM by acting a bridge between + * MDM and App manager product. + */ +public interface AppManager { + + /** + * This will communicate with App manager and retrieve the list of apps in the store, when + * the domain is given. The list is broken down into pages and retrieved. + * @param domain Tenant domain of the app list to be retrieved. + * @param pageNumber Page number of the list. + * @param size Number of items in one page. + * @return The list of applications belongs to a domain. + * @throws AppManagementException + */ + + Application [] getApplicationList(String domain, int pageNumber, int size) + throws AppManagementException; + + + /** + * Updates the application, install/uninstall status of the a certain application, on a device. + * @param deviceId Device id of the device that the status belongs to. + * @param application Application details of the app being updated. + * @param status Installed/Uninstalled + */ + void updateApplicationStatusOnDevice(DeviceIdentifier deviceId, Application application, + String status); + + /** + * Retrieve the status of an application on a device. Whether it is installed or not. + * @param deviceId Device id of the device that the status belongs to. + * @param application Application details of the app being searched. + * @return Status of the application on the device. + */ + String getApplicationStatusOnDevice(DeviceIdentifier deviceId, Application application); + + /** + * Create a new application and return client Id and secret. + * @return consumer Id and consumer key. + * * @throws AppManagementException + */ + Credential getClientCredentials() throws AppManagementException; +} diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml index e248b3af86..2b5c29a425 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml @@ -105,6 +105,8 @@ org.wso2.carbon.commons:org.wso2.carbon.email.verification + org.wso2.carbon.identity:org.wso2.carbon.identity.oauth.stub:${carbon.identity.version} + org.wso2.carbon.core.server:${carbon.kernel.version} diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/app-management-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/app-management-config.xml new file mode 100644 index 0000000000..ef7a146cdd --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/app-management-config.xml @@ -0,0 +1,23 @@ + + + + + true + http:/www.google.com + diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml index 0991207a54..a6646f863a 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml @@ -30,6 +30,11 @@ 20 1000 + + https://localhost:9443 + admin + admin + diff --git a/pom.xml b/pom.xml index 0f70a3b211..eea7b87859 100644 --- a/pom.xml +++ b/pom.xml @@ -154,6 +154,12 @@ org.wso2.carbon.device.mgt.user.common ${carbon.device.mgt.version} + + + org.wso2.carbon.identity + org.wso2.carbon.identity.oauth.stub + ${carbon.identity.version} + @@ -1056,6 +1062,7 @@ 4.3.3 + 4.3.3