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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations