Search in sources :

Example 41 with Device

use of org.wso2.carbon.device.mgt.common.Device in project product-iots by wso2.

the class SampleFunctionalityTest method setUp.

@BeforeClass(alwaysRun = true)
public void setUp() throws XPathExpressionException, XMLStreamException, IOException {
    super.init();
    driverDevice = BrowserManager.getWebDriver();
    driverServer = BrowserManager.getWebDriver();
    LoginUtils.login(driverServer, automationContext, getWebAppURL());
    driverServer.get(getWebAppURL() + Constants.IOT_DEVICES_URL);
    DevicesPage devicesPage = new DevicesPage(driverServer);
    deviceViewPage = devicesPage.viewDevice(Constants.IOT_CONNECTED_CUP_NAME);
    // Opens the connected cup device interface in the browser.
    driverDevice.get(deviceViewPage.getDeviceLink());
    sampleViewPage = new ConnectedCupDeviceInterface(driverDevice);
}
Also used : DevicesPage(org.wso2.iot.integration.ui.pages.devices.DevicesPage) ConnectedCupDeviceInterface(org.wso2.iot.integration.ui.pages.samples.ConnectedCupDeviceInterface) BeforeClass(org.testng.annotations.BeforeClass)

Example 42 with Device

use of org.wso2.carbon.device.mgt.common.Device in project product-iots by wso2.

the class PolicyOperations method createPasscodePolicy.

public static boolean createPasscodePolicy(String policyName, String deviceType) {
    HashMap<String, String> headers = new HashMap<String, String>();
    String policyEndpoint = EMMQSGConfig.getInstance().getEmmHost() + "/api/device-mgt/v1.0/policies";
    // Set the policy payload
    JSONObject policyData = new JSONObject();
    policyData.put("policyName", policyName);
    policyData.put("description", "Passcode Policy");
    policyData.put("compliance", "enforce");
    policyData.put("ownershipType", "ANY");
    policyData.put("active", false);
    JSONObject profile = new JSONObject();
    profile.put("profileName", "passcode");
    profile.put("deviceType", deviceType);
    JSONArray featureList = new JSONArray();
    JSONObject feature = new JSONObject();
    feature.put("featureCode", "PASSCODE_POLICY");
    feature.put("deviceType", deviceType);
    JSONObject featureContent = new JSONObject();
    featureContent.put("allowSimple", false);
    featureContent.put("requireAlphanumeric", true);
    featureContent.put("minLength", "5");
    featureContent.put("minComplexChars", "2");
    featureContent.put("maxPINAgeInDays", 7);
    featureContent.put("pinHistory", 7);
    featureContent.put("maxFailedAttempts", null);
    feature.put("content", featureContent);
    featureList.add(feature);
    profile.put("profileFeaturesList", featureList);
    JSONArray roles = new JSONArray();
    roles.add(Constants.EMM_USER_ROLE);
    policyData.put("profile", profile);
    policyData.put("roles", roles);
    // Set the headers
    headers.put(Constants.Header.CONTENT_TYPE, Constants.ContentType.APPLICATION_JSON);
    HTTPResponse httpResponse = HTTPInvoker.sendHTTPPostWithOAuthSecurity(policyEndpoint, policyData.toJSONString(), headers);
    if (httpResponse.getResponseCode() == Constants.HTTPStatus.CREATED) {
        return true;
    }
    return false;
}
Also used : JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) HTTPResponse(org.wso2.mdm.qsg.dto.HTTPResponse) JSONArray(org.json.simple.JSONArray)

Example 43 with Device

use of org.wso2.carbon.device.mgt.common.Device in project product-iots by wso2.

the class UserOperations method changePassword.

public static boolean changePassword(String username, String pwd) {
    HashMap<String, String> headers = new HashMap<String, String>();
    String pwdEndpoint = EMMQSGConfig.getInstance().getEmmHost() + "/api/device-mgt/v1.0/admin/users/" + username + "/credentials";
    // Set the password payload
    JSONObject pwdData = new JSONObject();
    pwdData.put("newPassword", pwd);
    // Set the headers
    headers.put(Constants.Header.CONTENT_TYPE, Constants.ContentType.APPLICATION_JSON);
    HTTPResponse httpResponse = HTTPInvoker.sendHTTPPostWithOAuthSecurity(pwdEndpoint, pwdData.toJSONString(), headers);
    if (httpResponse.getResponseCode() == Constants.HTTPStatus.OK) {
        return true;
    }
    return false;
}
Also used : JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) HTTPResponse(org.wso2.mdm.qsg.dto.HTTPResponse)

Example 44 with Device

use of org.wso2.carbon.device.mgt.common.Device in project product-iots by wso2.

the class UserOperations method createRole.

public static boolean createRole(String roleName, String[] users) {
    HashMap<String, String> headers = new HashMap<String, String>();
    String roleEndpoint = EMMQSGConfig.getInstance().getEmmHost() + "/api/device-mgt/v1.0/roles";
    // Set the role payload
    JSONObject roleData = new JSONObject();
    roleData.put("roleName", roleName);
    JSONArray perms = new JSONArray();
    String[] permissions = getUserPermissions();
    for (String perm : permissions) {
        perms.add(perm);
    }
    roleData.put("permissions", perms);
    JSONArray usrs = new JSONArray();
    for (String usr : users) {
        usrs.add(usr);
    }
    roleData.put("permissions", perms);
    roleData.put("users", usrs);
    // Set the headers
    headers.put(Constants.Header.CONTENT_TYPE, Constants.ContentType.APPLICATION_JSON);
    HTTPResponse httpResponse = HTTPInvoker.sendHTTPPostWithOAuthSecurity(roleEndpoint, roleData.toJSONString(), headers);
    if (httpResponse.getResponseCode() == Constants.HTTPStatus.CREATED) {
        return true;
    }
    return false;
}
Also used : JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) HTTPResponse(org.wso2.mdm.qsg.dto.HTTPResponse) JSONArray(org.json.simple.JSONArray)

Example 45 with Device

use of org.wso2.carbon.device.mgt.common.Device in project product-iots by wso2.

the class UserOperations method createUser.

public static boolean createUser(String username, String email, boolean isAdmin) {
    HashMap<String, String> headers = new HashMap<String, String>();
    String userEndpoint = EMMQSGConfig.getInstance().getEmmHost() + "/api/device-mgt/v1.0/users";
    // Set the user payload
    JSONObject userData = new JSONObject();
    userData.put("username", username);
    userData.put("emailAddress", email);
    JSONArray roles = new JSONArray();
    if (isAdmin) {
        roles.add("admin");
        userData.put("firstname", "Chris");
        userData.put("lastname", "Admin");
    } else {
        userData.put("password", "kimemmtrial");
        userData.put("firstname", "Alex");
        userData.put("lastname", "User");
    }
    userData.put("roles", roles);
    // Set the headers
    headers.put(Constants.Header.CONTENT_TYPE, Constants.ContentType.APPLICATION_JSON);
    HTTPResponse httpResponse = HTTPInvoker.sendHTTPPostWithOAuthSecurity(userEndpoint, userData.toJSONString(), headers);
    if (httpResponse.getResponseCode() == Constants.HTTPStatus.CREATED) {
        return true;
    }
    return false;
}
Also used : JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) HTTPResponse(org.wso2.mdm.qsg.dto.HTTPResponse) JSONArray(org.json.simple.JSONArray)

Aggregations

Test (org.testng.annotations.Test)20 HttpResponse (org.wso2.carbon.automation.test.utils.http.client.HttpResponse)17 DeviceManagementException (org.wso2.carbon.device.mgt.common.DeviceManagementException)13 DeviceMgtPluginException (org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException)11 JsonParser (com.google.gson.JsonParser)10 SQLException (java.sql.SQLException)8 JsonObject (com.google.gson.JsonObject)7 Connection (java.sql.Connection)7 PreparedStatement (java.sql.PreparedStatement)7 HashMap (java.util.HashMap)6 ConnectedCupDeviceMgtPluginException (org.coffeeking.connectedcup.plugin.exception.ConnectedCupDeviceMgtPluginException)6 Device (org.wso2.carbon.device.mgt.common.Device)6 JsonArray (com.google.gson.JsonArray)5 JsonElement (com.google.gson.JsonElement)4 ResultSet (java.sql.ResultSet)4 ArrayList (java.util.ArrayList)4 Path (javax.ws.rs.Path)4 JSONObject (org.json.simple.JSONObject)4 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)4 DeviceIdentifier (org.wso2.carbon.device.mgt.common.DeviceIdentifier)4