Improve APPM MDM configs

4.x.x
lasanthaDLPDS 5 years ago
parent 198bfc11f6
commit 4c79f3f1a8

@ -0,0 +1,40 @@
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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.application.mgt.common.config;
import javax.xml.bind.annotation.XmlElement;
public class MDMConfig {
private String artifactDownloadProtocol;
private String artifactDownloadEndpoint;
@XmlElement(name = "ArtifactDownloadProtocol", required=true)
public String getArtifactDownloadProtocol() { return artifactDownloadProtocol; }
public void setArtifactDownloadProtocol(String artifactDownloadProtocol) {
this.artifactDownloadProtocol = artifactDownloadProtocol;
}
@XmlElement(name = "ArtifactDownloadEndpoint", required=true)
public String getArtifactDownloadEndpoint() { return artifactDownloadEndpoint; }
public void setArtifactDownloadEndpoint(String artifactDownloadEndpoint) {
this.artifactDownloadEndpoint = artifactDownloadEndpoint;
}
}

@ -18,6 +18,7 @@
*/
package org.wso2.carbon.device.application.mgt.core.config;
import org.wso2.carbon.device.application.mgt.common.config.MDMConfig;
import org.wso2.carbon.device.application.mgt.common.config.RatingConfiguration;
import org.wso2.carbon.device.application.mgt.common.config.UIConfiguration;
import org.wso2.carbon.device.application.mgt.common.config.LifecycleState;
@ -37,20 +38,16 @@ public class Configuration {
private List<Extension> extensions;
private Artifacts artifacts;
private PaginationConfiguration paginationConfiguration;
private List<LifecycleState> lifecycleStates;
private UIConfiguration uiConfiguration;
private List<String> appCategories;
private String artifactDownloadEndpoint;
private RatingConfiguration ratingConfiguration;
private MDMConfig mdmConfig;
@XmlElement(name = "DatasourceName", required = true)
public String getDatasourceName() {
return datasourceName;
@ -70,11 +67,6 @@ public class Configuration {
this.extensions = extensions;
}
@XmlElement(name = "PaginationConfiguration", required = true)
public PaginationConfiguration getPaginationConfiguration() {
return paginationConfiguration;
}
@XmlElementWrapper(name = "LifecycleStates")
@XmlElement(name = "LifecycleState")
public List<LifecycleState> getLifecycleStates() {
@ -100,15 +92,6 @@ public class Configuration {
public void setRatingConfiguration(
RatingConfiguration ratingConfiguration) { this.ratingConfiguration = ratingConfiguration; }
@XmlElement(name = "ArtifactDownloadEndpoint", required = true)
public String getArtifactDownloadEndpoint() {
return artifactDownloadEndpoint;
}
public void setArtifactDownloadEndpoint(String artifactDownloadEndpoint) {
this.artifactDownloadEndpoint = artifactDownloadEndpoint;
}
@XmlElementWrapper(name = "AppCategories")
@XmlElement(name = "Category")
public List<String> getAppCategories() {
@ -118,5 +101,12 @@ public class Configuration {
public void setAppCategories(List<String> appCategories) {
this.appCategories = appCategories;
}
@XmlElement(name = "MDMConfig", required = true)
public MDMConfig getMdmConfig() { return mdmConfig; }
public void setMdmConfig(MDMConfig mdmConfig) {
this.mdmConfig = mdmConfig;
}
}

@ -32,6 +32,7 @@ import org.wso2.carbon.device.application.mgt.common.ApplicationInstaller;
import org.wso2.carbon.device.application.mgt.common.DeviceTypes;
import org.wso2.carbon.device.application.mgt.common.LifecycleChanger;
import org.wso2.carbon.device.application.mgt.common.Pagination;
import org.wso2.carbon.device.application.mgt.common.config.MDMConfig;
import org.wso2.carbon.device.application.mgt.common.config.RatingConfiguration;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO;
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
@ -2868,14 +2869,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new NotFoundException(msg);
}
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
String host = System.getProperty(Constants.IOT_HOST_PROPERTY);
String port = System.getProperty(Constants.IOT_PORT_PROPERTY);
String artifactDownloadEndpoint = ConfigurationManager.getInstance().getConfiguration()
.getArtifactDownloadEndpoint();
String artifactDownloadURL =
Constants.ARTIFACT_DOWNLOAD_PROTOCOL + "://" + host + ":" + port + artifactDownloadEndpoint
+ Constants.FORWARD_SLASH + applicationReleaseDTO.getUuid() + Constants.FORWARD_SLASH
+ applicationReleaseDTO.getInstallerName();
String artifactDownloadURL = APIUtil.getArtifactDownloadBaseURL() + applicationReleaseDTO.getUuid()
+ Constants.FORWARD_SLASH + applicationReleaseDTO.getInstallerName();
String plistContent = "&lt;!DOCTYPE plist PUBLIC &quot;-//Apple//DTDPLIST1.0//EN&quot; &quot;" +
"http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt;&lt;plist version=&quot;" +
"1.0&quot;&gt;&lt;dict&gt;&lt;key&gt;items&lt;/key&gt;&lt;array&gt;&lt;dict&gt;&lt;" +

@ -27,6 +27,7 @@ import org.wso2.carbon.device.application.mgt.common.DeviceTypes;
import org.wso2.carbon.device.application.mgt.common.SubAction;
import org.wso2.carbon.device.application.mgt.common.SubsciptionType;
import org.wso2.carbon.device.application.mgt.common.SubscribingDeviceIdHolder;
import org.wso2.carbon.device.application.mgt.common.config.MDMConfig;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO;
import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
@ -480,14 +481,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
} else if (DeviceTypes.IOS.toString().equalsIgnoreCase(deviceType)) {
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
String host = System.getProperty(Constants.IOT_HOST_PROPERTY);
String port = System.getProperty(Constants.IOT_PORT_PROPERTY);
String artifactDownloadEndpoint = ConfigurationManager.getInstance().getConfiguration()
.getArtifactDownloadEndpoint();
String plistDownloadEndpoint =
Constants.ARTIFACT_DOWNLOAD_PROTOCOL + "://" + host + ":" + port + artifactDownloadEndpoint
+ Constants.FORWARD_SLASH + MDMAppConstants.IOSConstants.PLIST
+ Constants.FORWARD_SLASH + application.getApplicationReleases().get(0).getUuid();
String plistDownloadEndpoint = APIUtil.getArtifactDownloadBaseURL()
+ MDMAppConstants.IOSConstants.PLIST + Constants.FORWARD_SLASH
+ application.getApplicationReleases().get(0).getUuid();
mobileApp.setType(mobileAppType);
mobileApp.setLocation(plistDownloadEndpoint);
Properties properties = new Properties();

@ -24,8 +24,10 @@ import org.apache.commons.logging.LogFactory;
import org.apache.commons.validator.routines.UrlValidator;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.application.mgt.common.ApplicationType;
import org.wso2.carbon.device.application.mgt.common.config.MDMConfig;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.response.Application;
import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.common.services.*;
@ -306,8 +308,7 @@ public class APIUtil {
return applicationReleaseDTO;
}
public static Application appDtoToAppResponse(ApplicationDTO applicationDTO)
throws BadRequestException, UnexpectedServerErrorException {
public static Application appDtoToAppResponse(ApplicationDTO applicationDTO) throws ApplicationManagementException {
Application application = new Application();
if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType())) {
@ -326,19 +327,19 @@ public class APIUtil {
application.setTags(applicationDTO.getTags());
application.setUnrestrictedRoles(applicationDTO.getUnrestrictedRoles());
application.setRating(applicationDTO.getAppRating());
List<ApplicationRelease> applicationReleases = applicationDTO.getApplicationReleaseDTOs()
.stream().map(APIUtil::releaseDtoToRelease).collect(Collectors.toList());
List<ApplicationRelease> applicationReleases = new ArrayList<>();
for (ApplicationReleaseDTO applicationReleaseDTO : applicationDTO.getApplicationReleaseDTOs()) {
ApplicationRelease applicationRelease = releaseDtoToRelease(applicationReleaseDTO);
applicationReleases.add(applicationRelease);
}
application.setApplicationReleases(applicationReleases);
return application;
}
public static ApplicationRelease releaseDtoToRelease(ApplicationReleaseDTO applicationReleaseDTO){
String host = System.getProperty(Constants.IOT_HOST_PROPERTY);
String port = System.getProperty(Constants.IOT_PORT_PROPERTY);
String artifactDownloadEndpoint = ConfigurationManager.getInstance().getConfiguration()
.getArtifactDownloadEndpoint();
String basePath = Constants.ARTIFACT_DOWNLOAD_PROTOCOL + "://" + host + ":" + port + artifactDownloadEndpoint
+ Constants.FORWARD_SLASH + applicationReleaseDTO.getUuid() + Constants.FORWARD_SLASH;
public static ApplicationRelease releaseDtoToRelease(ApplicationReleaseDTO applicationReleaseDTO)
throws ApplicationManagementException {
String basePath = getArtifactDownloadBaseURL() + applicationReleaseDTO.getUuid()
+ Constants.FORWARD_SLASH;
List<String> screenshotPaths = new ArrayList<>();
ApplicationRelease applicationRelease = new ApplicationRelease();
@ -391,4 +392,22 @@ public class APIUtil {
return applicationRelease;
}
public static String getArtifactDownloadBaseURL() throws ApplicationManagementException {
String host = System.getProperty(Constants.IOT_HOST_PROPERTY);
MDMConfig mdmConfig = ConfigurationManager.getInstance().getConfiguration().getMdmConfig();
String port;
if (Constants.HTTP_PROTOCOL.equals(mdmConfig.getArtifactDownloadProtocol())){
port = System.getProperty(Constants.IOT_HTTP_PORT_PROPERTY);
} else if( Constants.HTTPS_PROTOCOL.equals(mdmConfig.getArtifactDownloadProtocol())){
port = System.getProperty(Constants.IOT_HTTPS_PORT_PROPERTY);
} else {
String msg = "In order to download application artifacts invalid protocols are defined.";
log.error(msg);
throw new ApplicationManagementException(msg);
}
String artifactDownloadEndpoint = mdmConfig.getArtifactDownloadEndpoint();
return mdmConfig.getArtifactDownloadProtocol() + "://" + host + ":" + port
+ artifactDownloadEndpoint + Constants.FORWARD_SLASH;
}
}

@ -37,8 +37,10 @@ public class Constants {
public static final String CF_BUNDLE_VERSION = "CFBundleVersion";
public static final String APP_EXTENSION = ".app";
public static final String IOT_HOST_PROPERTY = "iot.core.host";
public static final String IOT_PORT_PROPERTY = "iot.core.http.port";
public static final String ARTIFACT_DOWNLOAD_PROTOCOL = "http";
public static final String IOT_HTTP_PORT_PROPERTY = "iot.core.http.port";
public static final String IOT_HTTPS_PORT_PROPERTY = "iot.core.https.port";
public static final String HTTPS_PROTOCOL = "https";
public static final String HTTP_PROTOCOL = "http";
public static final String FORWARD_SLASH = "/";
public static final String ANY = "ANY";

@ -23,17 +23,13 @@ import org.apache.commons.logging.LogFactory;
import org.json.JSONException;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO;
import org.wso2.carbon.device.application.mgt.common.PaginationRequest;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO;
import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO;
import org.wso2.carbon.device.application.mgt.common.dto.ReviewDTO;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
import org.wso2.carbon.device.application.mgt.core.config.Configuration;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
@ -264,21 +260,6 @@ public class DAOUtil {
}
}
public static PaginationRequest validateCommentListPageSize(PaginationRequest paginationRequest) throws
ReviewManagementException {
if (paginationRequest.getLimit() == 0) {
Configuration commentManagementConfig = ConfigurationManager.getInstance().getConfiguration();
if (commentManagementConfig != null) {
paginationRequest.setLimit(
commentManagementConfig.getPaginationConfiguration().getCommentListPageSize());
} else {
throw new ReviewManagementException(
"ApplicationDTO Management configuration has not initialized. Please check the application-mgt.xml file.");
}
}
return paginationRequest;
}
private static ApplicationManager applicationManager;
private static ApplicationStorageManager applicationStorageManager;
private static SubscriptionManager subscriptionManager;

@ -6,6 +6,7 @@ import org.apache.commons.logging.LogFactory;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.carbon.device.application.mgt.core.BaseTestCase;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
import org.wso2.carbon.device.application.mgt.core.dto.ApplicationsDTO;
import org.wso2.carbon.device.application.mgt.core.dto.DeviceTypeCreator;
@ -22,12 +23,12 @@ public class ApplicationManagementDAOTest extends BaseTestCase {
@BeforeClass
public void initialize() throws Exception {
log.info("Initializing ApplicationManagementDAOTest tests");
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
// super.initializeServices();
}
@Test
public void testAddApplication() throws Exception {
ApplicationDAO applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
ConnectionManagerUtil.beginDBTransaction();
applicationDAO.createApplication(ApplicationsDTO.getApp1(), -1234);
@ -52,6 +53,4 @@ public class ApplicationManagementDAOTest extends BaseTestCase {
DeviceManagementDAOFactory.closeConnection();
}
}
}

@ -18,7 +18,7 @@
-->
<ApplicationManagementConfiguration>
<!-- ApplicationDTO Mgt DB schema -->
<!-- Application Mgt DB schema -->
<DatasourceName>jdbc/APPM_DS</DatasourceName>
<Extensions>
@ -135,7 +135,6 @@
<UIConfigs>
<EnableOAuth>true</EnableOAuth>
<EnableSSO>false</EnableSSO>
<EnableSSO>false</EnableSSO>
<AppRegistration>
<Tags>
<Tag>application_management</Tag>
@ -150,13 +149,18 @@
<Scope>perm:app:review:update</Scope>
<Scope>perm:app:publisher:view</Scope>
<Scope>perm:app:publisher:update</Scope>
<Scope>perm:app:store:view</Scope>
<Scope>perm:app:subscription:install</Scope>
<Scope>perm:app:subscription:uninstall</Scope>
<Scope>perm:admin:app:review:update</Scope>
<Scope>perm:admin:app:review:view</Scope>
<Scope>perm:admin:app:publisher:update</Scope>
<Scope>perm:admin:app:review:update</Scope>
</Scopes>
<SSOConfiguration>
<Issuer>app-mgt</Issuer>
</SSOConfiguration>
<LoginResponse>
<SuccessCallback>/application-mgt</SuccessCallback>
<FailureCallback>
<ErrorCallback>
<BadRequest>/pages/error/client-errors/400</BadRequest>
<Unauthorized>/pages/error/client-errors/401</Unauthorized>
<Forbidden>/pages/error/client-errors/403</Forbidden>
@ -166,7 +170,21 @@
<UnsupportedMediaType>/pages/error/client-errors/415</UnsupportedMediaType>
<InternalServerError>/pages/error/server-errors/500</InternalServerError>
<DefaultPage>/pages/error/default</DefaultPage>
</FailureCallback>
</LoginResponse>
</ErrorCallback>
</UIConfigs>
<AppCategories>
<Category>EMM</Category>
<Category>IoT</Category>
</AppCategories>
<RatingConfig>
<MinRatingValue>1</MinRatingValue>
<MaxRatingValue>10</MaxRatingValue>
</RatingConfig>
<MDMConfig>
<ArtifactDownloadProtocol>https</ArtifactDownloadProtocol>
<ArtifactDownloadEndpoint>/api/application-mgt/v1.0/artifact</ArtifactDownloadEndpoint>
</MDMConfig>
</ApplicationManagementConfiguration>

@ -37,7 +37,7 @@
<Extension name="ApplicationStorageManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.ApplicationStorageManagerImpl</ClassName>
<Parameters>
<Parameter name="StoragePath">/tmp/apps/</Parameter>
<Parameter name="StoragePath">repository/resources/apps/</Parameter>
<Parameter name="MaxScreenShotCount">6</Parameter>
</Parameters>
</Extension>
@ -135,7 +135,6 @@
<UIConfigs>
<EnableOAuth>true</EnableOAuth>
<EnableSSO>false</EnableSSO>
<EnableSSO>false</EnableSSO>
<AppRegistration>
<Tags>
<Tag>application_management</Tag>
@ -151,13 +150,17 @@
<Scope>perm:app:publisher:view</Scope>
<Scope>perm:app:publisher:update</Scope>
<Scope>perm:app:store:view</Scope>
<Scope>perm:app:subscription:install</Scope>
<Scope>perm:app:subscription:uninstall</Scope>
<Scope>perm:admin:app:review:update</Scope>
<Scope>perm:admin:app:review:view</Scope>
<Scope>perm:admin:app:publisher:update</Scope>
<Scope>perm:admin:app:review:update</Scope>
</Scopes>
<SSOConfiguration>
<Issuer>app-mgt</Issuer>
</SSOConfiguration>
<LoginResponse>
<SuccessCallback>/apps</SuccessCallback>
<FailureCallback>
<ErrorCallback>
<BadRequest>/pages/error/client-errors/400</BadRequest>
<Unauthorized>/pages/error/client-errors/401</Unauthorized>
<Forbidden>/pages/error/client-errors/403</Forbidden>
@ -167,11 +170,9 @@
<UnsupportedMediaType>/pages/error/client-errors/415</UnsupportedMediaType>
<InternalServerError>/pages/error/server-errors/500</InternalServerError>
<DefaultPage>/pages/error/default</DefaultPage>
</FailureCallback>
</LoginResponse>
</ErrorCallback>
</UIConfigs>
<ArtifactDownloadEndpoint>https://localhost:9443/api/application-mgt/v1.0/artifact</ArtifactDownloadEndpoint>
<AppCategories>
<Category>EMM</Category>
<Category>IoT</Category>
@ -181,4 +182,9 @@
<MinRatingValue>1</MinRatingValue>
<MaxRatingValue>10</MaxRatingValue>
</RatingConfig>
<MDMConfig>
<ArtifactDownloadProtocol>https</ArtifactDownloadProtocol>
<ArtifactDownloadEndpoint>/api/application-mgt/v1.0/artifact</ArtifactDownloadEndpoint>
</MDMConfig>
</ApplicationManagementConfiguration>

@ -173,7 +173,6 @@
</ErrorCallback>
</UIConfigs>
<ArtifactDownloadEndpoint>/api/application-mgt/v1.0/artifact</ArtifactDownloadEndpoint>
<AppCategories>
<Category>EMM</Category>
<Category>IoT</Category>
@ -185,6 +184,7 @@
</RatingConfig>
<MDMConfig>
<Config name="AppDownloadURLHost">https</Config>
<ArtifactDownloadProtocol>https</ArtifactDownloadProtocol>
<ArtifactDownloadEndpoint>/api/application-mgt/v1.0/artifact</ArtifactDownloadEndpoint>
</MDMConfig>
</ApplicationManagementConfiguration>

Loading…
Cancel
Save