emm renamed to IoTs, some permisiosn issues fixed, names changed to ryan and milan

merge-requests/1/head
susinda 8 years ago
parent 0779e358ed
commit c2891c76e0

@ -37,13 +37,16 @@ import java.util.HashMap;
*/ */
public class AppOperations { public class AppOperations {
private static String appmPublisherMobileBinariesUrl = "/api/appm/publisher/v1.1/apps/mobile/binaries";
private static String appmPublisherResourcesUrl = "/api/appm/publisher/v1.1/apps/static-contents?appType=mobileapp";
private static String appmPublisherAppsUrl = "/api/appm/publisher/v1.1/apps/mobileapp";
public static MobileApplication uploadApplication(String platform, String appName, String appContentType) { public static MobileApplication uploadApplication(String platform, String appName, String appContentType) {
String appUploadEndpoint =
EMMQSGConfig.getInstance().getEmmHost() + "/api/appm/publisher/v1.1/apps/mobile/binaries";
String filePath = "apps" + File.separator + platform + File.separator + appName;
HTTPResponse
httpResponse = HTTPInvoker.uploadFile(appUploadEndpoint, filePath, appContentType);
String appUploadEndpoint = EMMQSGConfig.getInstance().getEmmHost() + appmPublisherMobileBinariesUrl;
String filePath = "apps" + File.separator + platform + File.separator + appName;
HTTPResponse httpResponse = HTTPInvoker.uploadFile(appUploadEndpoint, filePath, appContentType);
if (Constants.HTTPStatus.OK == httpResponse.getResponseCode()) { if (Constants.HTTPStatus.OK == httpResponse.getResponseCode()) {
JSONObject appMeta = null; JSONObject appMeta = null;
MobileApplication application = new MobileApplication(); MobileApplication application = new MobileApplication();
@ -70,8 +73,8 @@ public class AppOperations {
} }
private static String uploadAsset(String path) { private static String uploadAsset(String path) {
String resUploadEndpoint =
EMMQSGConfig.getInstance().getEmmHost() + "/api/appm/publisher/v1.1/apps/static-contents?appType=mobileapp"; String resUploadEndpoint = EMMQSGConfig.getInstance().getEmmHost() + appmPublisherResourcesUrl;
HTTPResponse httpResponse = HTTPInvoker.uploadFile(resUploadEndpoint, path, "image/jpeg"); HTTPResponse httpResponse = HTTPInvoker.uploadFile(resUploadEndpoint, path, "image/jpeg");
if (Constants.HTTPStatus.OK == httpResponse.getResponseCode()) { if (Constants.HTTPStatus.OK == httpResponse.getResponseCode()) {
JSONObject resp = null; JSONObject resp = null;
@ -86,6 +89,7 @@ public class AppOperations {
} }
public static MobileApplication uploadAssets(String platform, MobileApplication application) { public static MobileApplication uploadAssets(String platform, MobileApplication application) {
String assetDir = "apps" + File.separator + platform + File.separator + "images"; String assetDir = "apps" + File.separator + platform + File.separator + "images";
//Upload the icon file //Upload the icon file
String imgFile = assetDir + File.separator + "icon.jpg"; String imgFile = assetDir + File.separator + "icon.jpg";
@ -141,7 +145,8 @@ public class AppOperations {
public static boolean addApplication(String name, MobileApplication mblApp, boolean isEnterpriseApp) { public static boolean addApplication(String name, MobileApplication mblApp, boolean isEnterpriseApp) {
HashMap<String, String> headers = new HashMap<String, String>(); HashMap<String, String> headers = new HashMap<String, String>();
String appEndpoint = EMMQSGConfig.getInstance().getEmmHost() + "/api/appm/publisher/v1.1/apps/mobileapp";
String appEndpoint = EMMQSGConfig.getInstance().getEmmHost() + appmPublisherAppsUrl;
//Set the application payload //Set the application payload
JSONObject application = new JSONObject(); JSONObject application = new JSONObject();
application.put("name", name); application.put("name", name);
@ -160,7 +165,7 @@ public class AppOperations {
application.put("provider", "admin"); application.put("provider", "admin");
application.put("displayName", name); application.put("displayName", name);
application.put("category", "Business"); application.put("category", "Business");
application.put("icon", mblApp.getIcon()); application.put("iconFile", mblApp.getIcon());
application.put("version", mblApp.getVersion()); application.put("version", mblApp.getVersion());
application.put("banner", mblApp.getBanner()); application.put("banner", mblApp.getBanner());
application.put("platform", mblApp.getPlatform()); application.put("platform", mblApp.getPlatform());

@ -30,10 +30,20 @@ import java.util.*;
*/ */
public class QSGExecutor { public class QSGExecutor {
private static String iotAdminUser= "milan";
private static String iotAdminPassword = "milan@IoTS";
private static String iotAdminEmail = "milan@mobx.com";
private static String iotMobileUser = "ryan";
private static String iotMobileUserPassword = "ryan@IoTS";
private static String roleName = "iotMobileUser";
public static void main(String[] args) { public static void main(String[] args) {
boolean status = false; boolean status = false;
Scanner scanner = new Scanner(System.in);
// prompt for the user's name // prompt for the user's name
/*
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your email address and press enter : "); System.out.print("Enter your email address and press enter : ");
String email = scanner.next(); String email = scanner.next();
if (!QSGUtils.isValidEmailAddress(email)) { if (!QSGUtils.isValidEmailAddress(email)) {
@ -42,7 +52,10 @@ public class QSGExecutor {
email = scanner.next(); email = scanner.next();
} while (!QSGUtils.isValidEmailAddress(email)); } while (!QSGUtils.isValidEmailAddress(email));
} }
//Setup the OAuth token */
String email = "ryan@example.com";
//Setup the OAuth token
String token = QSGUtils.getOAuthToken(); String token = QSGUtils.getOAuthToken();
if (token == null) { if (token == null) {
System.out.println("Unable to get the OAuth token. Please check the config.properties file."); System.out.println("Unable to get the OAuth token. Please check the config.properties file.");
@ -50,87 +63,92 @@ public class QSGExecutor {
} }
HTTPInvoker.oAuthToken = token; HTTPInvoker.oAuthToken = token;
//Creates the admin user //Creates the admin user
status = UserOperations.createUser("tom", "tom@mobx.com", true);
status = UserOperations.createUser(iotAdminUser, iotAdminEmail, true);
if (!status) { if (!status) {
System.out.println("Unable to create the admin user. Please check the config.properties file."); System.out.println("Unable to create the admin user. Please check the config.properties file.");
System.exit(0); System.exit(0);
} }
status = UserOperations.changePassword("tom", "tomemm");
status = UserOperations.changePassword(iotAdminUser, iotAdminPassword);
if (!status) { if (!status) {
System.out.println("Unable to change the password of the admin user. Terminating the EMM QSG now."); System.out.println("Unable to change the password of the admin user. Terminating the IoTS QSG now.");
System.exit(0); System.exit(0);
} }
//Creates the emm user //Creates the emm user
status = UserOperations.createUser("kim", email, false);
status = UserOperations.createUser(iotMobileUser, email, false);
if (!status) { if (!status) {
System.out.println("Unable to create the emm user Kim. Terminating the EMM QSG now."); System.out.println("Unable to create the iot user ryan. Terminating the IoTS QSG now.");
System.exit(0); System.exit(0);
} }
status = UserOperations.changePassword("kim", "kimemm");
status = UserOperations.changePassword(iotMobileUser, iotMobileUserPassword);
if (!status) { if (!status) {
System.out.println("Unable to change the password of the emm user. Terminating the EMM QSG now."); System.out.println("Unable to change the password of the iot user. Terminating the IoTS QSG now.");
System.exit(0); System.exit(0);
} }
//Creates the emm-user role //Creates the emm-user role
status = UserOperations.createRole(Constants.EMM_USER_ROLE, new String[] { "kim" }); status = UserOperations.createRole(roleName, new String[] {iotMobileUser});
if (!status) { if (!status) {
System.out.println("Unable to create the emm user role. Terminating the EMM QSG now."); System.out.println("Unable to create the emm user role. Terminating the IoTs QSG now.");
System.exit(0); System.exit(0);
} }
//Add the android policy //Add the android policy
status = PolicyOperations.createPasscodePolicy("android-passcode-policy1", Constants.DeviceType.ANDROID); status = PolicyOperations.createPasscodePolicy("android-passcode-policy1", Constants.DeviceType.ANDROID);
if (!status) { if (!status) {
System.out.println("Unable to create the android passcode policy. Terminating the EMM QSG now."); System.out.println("Unable to create the android passcode policy. Terminating the IoTS QSG now.");
System.exit(0); System.exit(0);
} }
//Add the windows policy //Add the windows policy
status = PolicyOperations.createPasscodePolicy("windows-passcode-policy1", Constants.DeviceType.WINDOWS); status = PolicyOperations.createPasscodePolicy("windows-passcode-policy1", Constants.DeviceType.WINDOWS);
if (!status) { if (!status) {
System.out.println("Unable to create the windows passcode policy. Terminating the EMM QSG now."); System.out.println("Unable to create the windows passcode policy. Terminating the IoTS QSG now.");
System.exit(0); System.exit(0);
} }
//Add the iOS policy //Add the iOS policy
status = PolicyOperations.createPasscodePolicy("ios-passcode-policy1", Constants.DeviceType.IOS); status = PolicyOperations.createPasscodePolicy("ios-passcode-policy1", Constants.DeviceType.IOS);
if (!status) { if (!status) {
System.out.println("Unable to create the ios passcode policy. Terminating the EMM QSG now."); System.out.println("Unable to create the ios passcode policy. Terminating the IoTS QSG now.");
System.exit(0); System.exit(0);
} }
//Upload the android application //Upload the android application
MobileApplication application = AppOperations.uploadApplication(Constants.DeviceType.ANDROID, "catalog.apk", MobileApplication application = AppOperations.uploadApplication(Constants.DeviceType.ANDROID, "catalog.apk",
"application/vnd.android.package-archive"); "application/vnd.android.package-archive");
if (application == null) { if (application == null) {
System.out.println("Unable to upload the sample android application. Terminating the EMM QSG now."); System.out.println("Unable to upload the sample android application. Terminating the IoTS QSG now.");
System.exit(0); System.exit(0);
} }
//Upload the assets //Upload the assets
application = AppOperations.uploadAssets(Constants.DeviceType.ANDROID, application); application = AppOperations.uploadAssets(Constants.DeviceType.ANDROID, application);
if (application == null) { if (application == null) {
System.out.println( System.out.println(
"Unable to upload the assets for sample android application. Terminating the EMM QSG now."); "Unable to upload the assets for sample android application. Terminating the IoTS QSG now.");
System.exit(0); System.exit(0);
} }
//Create application entry in publisher //Create application entry in publisher
status = AppOperations.addApplication("Catalog", application, true); status = AppOperations.addApplication("Catalog", application, true);
if (!status) { if (!status) {
System.out.println("Unable to create the mobile application. Terminating the EMM QSG now."); System.out.println("Unable to create the android mobile application. Terminating the IoTS QSG now.");
System.exit(0); System.exit(0);
} }
//Upload the ios application //Upload the ios application
MobileApplication iOSApplication = AppOperations.uploadApplication(Constants.DeviceType.IOS, "PNDemo.ipa", MobileApplication iOSApplication = AppOperations.uploadApplication(Constants.DeviceType.IOS, "PNDemo.ipa","application/octet-stream");
"application/octet-stream");
iOSApplication.setVersion("1.0.0"); iOSApplication.setVersion("1.0.0");
//Upload the assets //Upload the assets
iOSApplication = AppOperations.uploadAssets(Constants.DeviceType.IOS, iOSApplication); iOSApplication = AppOperations.uploadAssets(Constants.DeviceType.IOS, iOSApplication);
if (iOSApplication == null) { if (iOSApplication == null) {
System.out.println( System.out.println(
"Unable to upload the assets for sample iOS application. Terminating the EMM QSG now."); "Unable to upload the assets for sample iOS application. Terminating the IoTS QSG now.");
System.exit(0); System.exit(0);
} }
//Create application entry in publisher //Create application entry in publisher
status = AppOperations.addApplication("WSO2Con", iOSApplication, true); status = AppOperations.addApplication("WSO2Con", iOSApplication, true);
if (!status) { if (!status) {
System.out.println("Unable to create the mobile application. Terminating the EMM QSG now."); System.out.println("Unable to create the iOS mobile application. Terminating the IoTS QSG now.");
System.exit(0); System.exit(0);
} }
} }

@ -42,11 +42,11 @@ public class UserOperations {
JSONArray roles = new JSONArray(); JSONArray roles = new JSONArray();
if (isAdmin) { if (isAdmin) {
roles.add("admin"); roles.add("admin");
userData.put("firstname", "Tom"); userData.put("firstname", "Milan");
userData.put("lastname", "Admin"); userData.put("lastname", "Admin");
} else { } else {
userData.put("password", "kimemmtrial"); userData.put("password", "kimemmtrial");
userData.put("firstname", "Kim"); userData.put("firstname", "Ryan");
userData.put("lastname", "User"); userData.put("lastname", "User");
} }
userData.put("roles", roles); userData.put("roles", roles);
@ -82,6 +82,8 @@ public class UserOperations {
String permissions = "/permission/admin/device-mgt/certificates/manage," + String permissions = "/permission/admin/device-mgt/certificates/manage," +
"/permission/admin/device-mgt/certificates/view," + "/permission/admin/device-mgt/certificates/view," +
"/permission/admin/device-mgt/configurations/view," + "/permission/admin/device-mgt/configurations/view," +
"/permission/admin/device-mgt/api," +
"/permission/admin/device-mgt/devices/enroll," +
"/permission/admin/device-mgt/devices/enroll/android," + "/permission/admin/device-mgt/devices/enroll/android," +
"/permission/admin/device-mgt/devices/enroll/ios," + "/permission/admin/device-mgt/devices/enroll/ios," +
"/permission/admin/device-mgt/devices/owning-device/view," + "/permission/admin/device-mgt/devices/owning-device/view," +

@ -277,6 +277,7 @@ public class HTTPInvoker {
for (String key : headers.keySet()) { for (String key : headers.keySet()) {
post.setHeader(key, headers.get(key)); post.setHeader(key, headers.get(key));
} }
post.setHeader(Constants.Header.AUTH, OAUTH_BEARER + oAuthToken); post.setHeader(Constants.Header.AUTH, OAUTH_BEARER + oAuthToken);
response = httpclient.execute(post); response = httpclient.execute(post);
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {

Loading…
Cancel
Save