From e6d74ac9b422d75b96a15bfd6b6f5be110a5f73d Mon Sep 17 00:00:00 2001 From: prabathabey Date: Sun, 29 Mar 2015 13:01:07 +0530 Subject: [PATCH] Cleaning up app manager connector implementation --- .../app/mgt/AppManagementServiceImpl.java | 51 +++++++ .../mgt/core/app/mgt/AppManagerConnector.java | 71 +++++++++ ...java => AppManagerConnectorException.java} | 12 +- .../app/mgt/AppManagerConnectorFactory.java | 29 ++++ .../mgt/core/app/mgt/AppManagerImplHttp.java | 132 ----------------- .../app/mgt/RemoteAppManagerConnector.java | 140 ++++++++++++++++++ .../AppManagementConfigurationManager.java | 7 +- .../app/mgt/oauth/ServiceAuthenticator.java | 59 +++----- .../internal/DeviceManagementDataHolder.java | 8 +- .../DeviceManagementServiceComponent.java | 15 +- .../service/AppManagementServiceImpl.java | 48 ------ .../device/mgt/core/service/AppManager.java | 69 --------- 12 files changed, 331 insertions(+), 310 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagementServiceImpl.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagerConnector.java rename components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/{AppManagementException.java => AppManagerConnectorException.java} (77%) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagerConnectorFactory.java delete 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/RemoteAppManagerConnector.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/AppManagementServiceImpl.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/AppManager.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagementServiceImpl.java new file mode 100644 index 0000000000..e6a17fa5b7 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagementServiceImpl.java @@ -0,0 +1,51 @@ +/* +* 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.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.internal.DeviceManagementDataHolder; + +public class AppManagementServiceImpl implements AppManagerConnector { + + @Override + public Application[] getApplicationList(String domain, int pageNumber, + int size) throws AppManagerConnectorException { + return DeviceManagementDataHolder.getInstance().getAppManager() + .getApplicationList(domain, pageNumber, size); + } + + @Override + public void updateApplicationStatus( + DeviceIdentifier deviceId, Application application, String status) throws AppManagerConnectorException { + DeviceManagementDataHolder.getInstance().getAppManager().updateApplicationStatus(deviceId, application, status); + + } + + @Override + public String getApplicationStatus(DeviceIdentifier deviceId, + Application application) throws AppManagerConnectorException { + return null; + } + + @Override + public Credential getClientCredentials() throws AppManagerConnectorException { + 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/app/mgt/AppManagerConnector.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagerConnector.java new file mode 100644 index 0000000000..df40342059 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagerConnector.java @@ -0,0 +1,71 @@ +/* +* 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.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; + +/** + * This will handle the Application management side of MDM by acting a bridge between + * MDM and App manager product. + */ +public interface AppManagerConnector { + + /** + * 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 AppManagerConnectorException + */ + + Application[] getApplicationList(String domain, int pageNumber, int size) throws AppManagerConnectorException; + + + /** + * 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 updateApplicationStatus(DeviceIdentifier deviceId, Application application, + String status) throws AppManagerConnectorException; + + /** + * 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 getApplicationStatus(DeviceIdentifier deviceId, Application application) throws AppManagerConnectorException; + + /** + * Create a new application and return client Id and secret. + * + * @return consumer Id and consumer key. + * * @throws AppManagerConnectorException + */ + Credential getClientCredentials() throws AppManagerConnectorException; + +} 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/AppManagerConnectorException.java similarity index 77% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagementException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagerConnectorException.java index 6eb3bc499f..3965d7570b 100644 --- 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/AppManagerConnectorException.java @@ -21,7 +21,7 @@ package org.wso2.carbon.device.mgt.core.app.mgt; /** * Handles the exceptions related to Application management. */ -public class AppManagementException extends Exception { +public class AppManagerConnectorException extends Exception { private static final long serialVersionUID = -8933142342423122660L; private String errorMessage; @@ -34,26 +34,26 @@ public class AppManagementException extends Exception { this.errorMessage = errorMessage; } - public AppManagementException(String msg, Exception nestedEx) { + public AppManagerConnectorException(String msg, Exception nestedEx) { super(msg, nestedEx); setErrorMessage(msg); } - public AppManagementException(String message, Throwable cause) { + public AppManagerConnectorException(String message, Throwable cause) { super(message, cause); setErrorMessage(message); } - public AppManagementException(String msg) { + public AppManagerConnectorException(String msg) { super(msg); setErrorMessage(msg); } - public AppManagementException() { + public AppManagerConnectorException() { super(); } - public AppManagementException(Throwable cause) { + public AppManagerConnectorException(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/AppManagerConnectorFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagerConnectorFactory.java new file mode 100644 index 0000000000..755c7f3148 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagerConnectorFactory.java @@ -0,0 +1,29 @@ +/* + * 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.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig; + +public class AppManagerConnectorFactory { + + public static AppManagerConnector getConnector(AppManagementConfig config) { + return new RemoteAppManagerConnector(config); + } + +} 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 deleted file mode 100644 index 94818f7fd9..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/AppManagerImplHttp.java +++ /dev/null @@ -1,132 +0,0 @@ -/* -* 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/RemoteAppManagerConnector.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/RemoteAppManagerConnector.java new file mode 100644 index 0000000000..c1446c09c6 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/RemoteAppManagerConnector.java @@ -0,0 +1,140 @@ +/* +* 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.config.AppManagementConfig; +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.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.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 AppManagerConnector interface + */ +public class RemoteAppManagerConnector implements AppManagerConnector { + + private ConfigurationContext configCtx; + private ServiceAuthenticator authenticator; + private AppManagementConfig appManagementConfig; + private IdentityConfigurations identityConfig; + private String oAuthAdminServiceUrl; + + private static final String GET_APP_LIST_URL = "store/apis/assets/mobileapp?domain=carbon.super&page=1"; + + private static final Log log = LogFactory.getLog(RemoteAppManagerConnector.class); + + public RemoteAppManagerConnector(AppManagementConfig appManagementConfig) { + this.appManagementConfig = appManagementConfig; + this.authenticator = + new ServiceAuthenticator(identityConfig.getAdminUsername(), identityConfig.getAdminPassword()); + this.identityConfig = + DeviceConfigurationManager.getInstance().getDeviceManagementConfig(). + getDeviceManagementConfigRepository().getIdentityConfigurations(); + this.oAuthAdminServiceUrl = + identityConfig.getServerUrl() + DeviceManagementConstants.AppManagement.OAUTH_ADMIN_SERVICE; + try { + this.configCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null); + } catch (AxisFault e) { + throw new IllegalArgumentException("Error occurred while initializing Axis2 Configuration Context. " + + "Please check if an appropriate axis2.xml is provided", e); + } + } + + @Override + public Application[] getApplicationList(String domain, int pageNumber, + int size) throws AppManagerConnectorException { + return new Application[0]; + } + + @Override + public void updateApplicationStatus(DeviceIdentifier deviceId, Application application, + String status) throws AppManagerConnectorException{ + + } + + @Override + public String getApplicationStatus(DeviceIdentifier deviceId, + Application application) throws AppManagerConnectorException { + return null; + } + + @Override + public Credential getClientCredentials() throws AppManagerConnectorException { + OAuthConsumerAppDTO appInfo = this.getAppInfo(); + + Credential credential = new Credential(); + credential.setConsumerKey(appInfo.getOauthConsumerKey()); + credential.setConsumerSecret(appInfo.getOauthConsumerSecret()); + return credential; + } + + private OAuthConsumerAppDTO getAppInfo() throws AppManagerConnectorException { + OAuthConsumerAppDTO appInfo = null; + try { + OAuthAdminServiceStub oAuthAdminServiceStub = + new OAuthAdminServiceStub(configCtx, oAuthAdminServiceUrl); + authenticator.authenticate(oAuthAdminServiceStub._getServiceClient()); + + try { + appInfo = 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(this.getRequestDTO()); + appInfo = oAuthAdminServiceStub.getOAuthApplicationDataByAppName( + DeviceManagementConstants.AppManagement.OAUTH_APPLICATION_NAME); + } + } catch (RemoteException e) { + handleException("Error occurred while retrieving app info", e); + } catch (OAuthAdminServiceException e) { + handleException("Error occurred while invoking OAuth admin service stub", e); + } + return appInfo; + } + + private OAuthConsumerAppDTO getRequestDTO() { + 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); + return appDTO; + } + + private void handleException(String msg, Exception e) throws AppManagerConnectorException { + log.error(msg, e); + throw new AppManagerConnectorException(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/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 index e4cda1a494..a2168cb343 100644 --- 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 @@ -19,7 +19,8 @@ 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.app.mgt.AppManagerConnectorException; +import org.wso2.carbon.device.mgt.core.app.mgt.AppManagerConnectorException; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import org.wso2.carbon.utils.CarbonUtils; @@ -47,7 +48,7 @@ public class AppManagementConfigurationManager { return appManagementConfigManager; } - public synchronized void initConfig() throws AppManagementException { + public synchronized void initConfig() throws AppManagerConnectorException { try { File appManagementConfig = new File(AppManagementConfigurationManager.APP_MANAGER_CONFIG_PATH); @@ -60,7 +61,7 @@ public class AppManagementConfigurationManager { } catch (Exception e) { /* Catches generic exception as there's no specific task to be carried out catching a particular exception */ - throw new AppManagementException( + throw new AppManagerConnectorException( "Error occurred while initializing application management Configurations", e); } } 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 index 879850c976..cacf5d8f81 100644 --- 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 @@ -21,53 +21,30 @@ 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; +import org.wso2.carbon.device.mgt.core.app.mgt.AppManagerConnectorException; /** * 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; - } + private String username; + private String password; + + public ServiceAuthenticator(String username, String password) { + this.username = username; + this.password = password; + } + + public void authenticate(ServiceClient client) throws AppManagerConnectorException { + Options option = client.getOptions(); + HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator(); + auth.setUsername(username); + auth.setPassword(password); + auth.setPreemptiveAuthentication(true); + option.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth); + option.setManageSession(true); + } } 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 60abb695b9..59bf153b06 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,9 +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.AppManagerConnector; 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; @@ -38,7 +38,7 @@ public class DeviceManagementDataHolder { private RegistryService registryService; private LicenseConfig licenseConfig; private APIPublisherService apiPublisherService; - private AppManager appManager; + private AppManagerConnector appManager; private AppManagementConfig appManagerConfig; private static DeviceManagementDataHolder thisInstance = new DeviceManagementDataHolder(); @@ -110,11 +110,11 @@ public class DeviceManagementDataHolder { this.apiPublisherService = apiPublisherService; } - public AppManager getAppManager() { + public AppManagerConnector getAppManager() { return appManager; } - public void setAppManager(AppManager appManager) { + public void setAppManager(AppManagerConnector appManager) { this.appManager = appManager; } 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 d26d4b332f..92f1a92d99 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,8 +34,9 @@ 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.AppManagementException; -import org.wso2.carbon.device.mgt.core.app.mgt.AppManagerImplHttp; +import org.wso2.carbon.device.mgt.core.app.mgt.AppManagerConnectorException; +import org.wso2.carbon.device.mgt.core.app.mgt.RemoteAppManagerConnector; +import org.wso2.carbon.device.mgt.core.app.mgt.RemoteAppManagerConnector; 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; @@ -46,8 +47,8 @@ import org.wso2.carbon.device.mgt.core.config.license.LicenseConfigurationManage 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.app.mgt.AppManagementServiceImpl; +import org.wso2.carbon.device.mgt.core.app.mgt.AppManagerConnector; 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; @@ -165,12 +166,12 @@ public class DeviceManagementServiceComponent { DeviceManagementDataHolder.getInstance().setLicenseConfig(licenseConfig); } - private void initAppManagerConnector() throws AppManagementException { + private void initAppManagerConnector() throws AppManagerConnectorException { AppManagementConfigurationManager.getInstance().initConfig(); AppManagementConfig appConfig = AppManagementConfigurationManager.getInstance().getAppManagementConfig(); DeviceManagementDataHolder.getInstance().setAppManagerConfig(appConfig); - AppManagerImplHttp appManager = new AppManagerImplHttp(appConfig); + RemoteAppManagerConnector appManager = new RemoteAppManagerConnector(appConfig); DeviceManagementDataHolder.getInstance().setAppManager(appManager); } @@ -194,7 +195,7 @@ public class DeviceManagementServiceComponent { bundleContext.registerService(ServerStartupObserver.class, new APIRegistrationStartupObserver(), null); /* Registering App Management service */ - bundleContext.registerService(AppManager.class.getName(), new AppManagementServiceImpl(), null); + bundleContext.registerService(AppManagerConnector.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 deleted file mode 100644 index 488617561b..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/AppManagementServiceImpl.java +++ /dev/null @@ -1,48 +0,0 @@ -/* -* 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 deleted file mode 100644 index 886690ca19..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/AppManager.java +++ /dev/null @@ -1,69 +0,0 @@ -/* -* 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; -}