userList;
try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
- String[] users = userStoreManager.listUsers(filter + "*", -1);
- userList = new ArrayList<>(users.length);
+ String[] users = userStoreManager.listUsers(userStoreDomain + "/*", -1);
+ userList = new ArrayList<>();
UserInfo user;
for (String username : users) {
- user = new UserInfo();
- user.setUsername(username);
- user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS));
- user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME));
- user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME));
- userList.add(user);
+ if (username.contains(filter)) {
+ user = new UserInfo();
+ user.setUsername(username);
+ user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS));
+ user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME));
+ user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME));
+ userList.add(user);
+ }
}
-// if (userList.size() <= 0) {
-// return Response.status(Response.Status.NOT_FOUND).entity("No user is available to be retrieved").build();
-// }
return Response.status(Response.Status.OK).entity(userList).build();
} catch (UserStoreException e) {
String msg = "Error occurred while retrieving the list of users using the filter : " + filter;
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/Constants.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/Constants.java
index 451c58b178..d9981ba782 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/Constants.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/Constants.java
@@ -26,6 +26,7 @@ public class Constants {
public static final String USER_CLAIM_EMAIL_ADDRESS = "http://wso2.org/claims/emailaddress";
public static final String USER_CLAIM_FIRST_NAME = "http://wso2.org/claims/givenname";
public static final String USER_CLAIM_LAST_NAME = "http://wso2.org/claims/lastname";
+ public static final String PRIMARY_USER_STORE = "PRIMARY";
public final class ErrorMessages {
private ErrorMessages () { throw new AssertionError(); }
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js
index eb7798a837..67743b3bc0 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js
@@ -187,7 +187,7 @@ var userModule = function () {
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" +
encodeURIComponent(username);
if (domain) {
- url += '?domain=' + domain;
+ url += '?domain=' + encodeURIComponent(domain);
}
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
response["content"] = parse(response.content);
@@ -217,7 +217,7 @@ var userModule = function () {
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" +
encodeURIComponent(username) + "/roles";
if (domain) {
- url += '?domain=' + domain;
+ url += '?domain=' + encodeURIComponent(domain);
}
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
if (response.status == "success") {
@@ -268,7 +268,7 @@ var userModule = function () {
try {
utility.startTenantFlow(carbonUser);
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
- "/roles?offset=0&limit=100";
+ "/roles?offset=0&limit=100&user-store=all";
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
if (response.status == "success") {
response.content = parse(response.content).roles;
@@ -294,7 +294,7 @@ var userModule = function () {
try {
utility.startTenantFlow(carbonUser);
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
- "/roles?offset=0&limit=1";
+ "/roles?offset=0&limit=1&user-store=all";
return serviceInvokers.XMLHttp.get(
url, function (responsePayload) {
return parse(responsePayload["responseText"])["count"];
@@ -328,7 +328,7 @@ var userModule = function () {
try {
utility.startTenantFlow(carbonUser);
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
- "/roles?user-store=" + userStore + "&limit=100";
+ "/roles?user-store=" + encodeURIComponent(userStore) + "&limit=100";
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
if (response.status == "success") {
response.content = parse(response.content).roles;
@@ -374,14 +374,22 @@ var userModule = function () {
publicMethods.getRole = function (roleName) {
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
var utility = require("/app/modules/utility.js")["utility"];
+ var userStore;
if (!carbonUser) {
log.error("User object was not found in the session");
throw constants["ERRORS"]["USER_NOT_FOUND"];
}
try {
utility.startTenantFlow(carbonUser);
+ if (roleName.indexOf('/') > 0) {
+ userStore = roleName.substr(0, roleName.indexOf('/'));
+ roleName = roleName.substr(roleName.indexOf('/') + 1);
+ }
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
"/roles/" + encodeURIComponent(roleName);
+ if (userStore) {
+ url += "?user-store=" + encodeURIComponent(userStore);
+ }
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
if (response.status == "success") {
response.content = parse(response.content);
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/create.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/create.hbs
index d3b2f15329..0bfdfe1d8f 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/create.hbs
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/create.hbs
@@ -94,7 +94,8 @@
data-error-msg="{{roleNameRegExViolationErrorMsg}}" class="form-control" />
{{#if canViewUsers}}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js
index 93f7817db9..2cb8292af7 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js
@@ -32,6 +32,7 @@ var validateInline = {};
var clearInline = {};
var apiBasePath = "/api/device-mgt/v1.0";
+var domain = $("#domain").val();
var enableInlineError = function (inputField, errorMsg, errorSign) {
var fieldIdentifier = "#" + inputField;
@@ -82,7 +83,8 @@ clearInline["role-name"] = function () {
*/
validateInline["role-name"] = function () {
var roleNameInput = $("input#roleName");
- if (inputIsValid( roleNameInput.data("regex"), roleNameInput.val())) {
+ var roleName = roleNameInput.val();
+ if (inputIsValid( roleNameInput.data("regex"), roleName) && roleName.indexOf("@") < 0 && roleName.indexOf("/") < 0) {
disableInlineError("roleNameField", "roleNameEmpty", "roleNameError");
} else {
enableInlineError("roleNameField", "roleNameEmpty", "roleNameError");
@@ -127,7 +129,8 @@ $(document).ready(function () {
data: function (params) {
var postData = {};
postData.requestMethod = "GET";
- postData.requestURL = "/api/device-mgt/v1.0/users/search/usernames?filter=" + params.term;
+ postData.requestURL = "/api/device-mgt/v1.0/users/search/usernames?filter=" + params.term +
+ "&domain=" + encodeURIComponent(domain);
postData.requestPayload = null;
return JSON.stringify(postData);
},
@@ -170,7 +173,8 @@ $(document).ready(function () {
if (!roleName) {
$(errorMsg).text("Role name is a required field. It cannot be empty.");
$(errorMsgWrapper).removeClass("hidden");
- } else if (!inputIsValid(roleNameInput.data("regex"), roleName)) {
+ } else if (!inputIsValid(roleNameInput.data("regex"), roleName) || roleName.indexOf("@") >= 0 ||
+ roleName.indexOf("/") >= 0) {
$(errorMsg).text(roleNameInput.data("error-msg"));
$(errorMsgWrapper).removeClass("hidden");
} else if (!domain) {
@@ -201,7 +205,8 @@ $(document).ready(function () {
$("input#roleName").val("");
$("#domain").val("PRIMARY");
$("#users").val("");
- window.location.href = appContext + "/role/edit-permission/" + roleName;
+ window.location.href = appContext + "/role/edit-permission/?rolename=" +
+ encodeURIComponent(addRoleFormData.roleName);
}
},
function (jqXHR) {
@@ -222,4 +227,12 @@ $(document).ready(function () {
$(roleNameInputElement).blur(function() {
validateInline["role-name"]();
});
+
+ /* When the user store domain value is changed, the users who are assigned to that role should be removed, as
+ user and role can be mapped only if both are in same user store
+ */
+ $("#domain").change(function () {
+ $("#users").select2("val", "");
+ domain = $("#domain").val();
+ });
});
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.edit.permission/permission.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.edit.permission/permission.json
index a6e56c02a5..952c4abe20 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.edit.permission/permission.json
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.edit.permission/permission.json
@@ -1,5 +1,5 @@
{
"version": "1.0.0",
- "uri": "/role/edit-permission/{+any}",
+ "uri": "/role/edit-permission/",
"layout": "cdmf.layout.default"
}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.edit/edit.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.edit/edit.json
index 3efeeeb8e2..6959b98af0 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.edit/edit.json
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.edit/edit.json
@@ -1,5 +1,5 @@
{
"version": "1.0.0",
- "uri": "/role/edit/{+any}",
+ "uri": "/role/edit/",
"layout": "cdmf.layout.default"
}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js
index 19056e28f6..4a6b44fbb8 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js
@@ -17,7 +17,7 @@
*/
var loadRoleBasedActionURL = function (action, rolename) {
- var href = $("#ast-container").data("app-context") + "role/" + action + "/" + rolename;
+ href = $("#ast-container").data("app-context") + "role/" + action + "/?rolename=" + encodeURIComponent(rolename);
$(location).attr('href', href);
};
@@ -188,7 +188,7 @@ function loadRoles() {
"sorting": false
};
- $('#role-grid').datatables_extended_serverside_paging(settings, '/api/device-mgt/v1.0/roles', dataFilter, columns, fnCreatedRow, null, options);
+ $('#role-grid').datatables_extended_serverside_paging(settings, '/api/device-mgt/v1.0/roles?user-store=all', dataFilter, columns, fnCreatedRow, null, options);
loadingContent.hide();
}
@@ -201,8 +201,15 @@ function loadRoles() {
*/
$("#role-grid").on("click", ".remove-role-link", function () {
var role = $(this).data("role");
- var removeRoleAPI = apiBasePath + "/roles/" + role;
-
+ var userStore;
+ if (role.indexOf('/') > 0) {
+ userStore = role.substr(0, role.indexOf('/'));
+ role = role.substr(role.indexOf('/') + 1);
+ }
+ var removeRoleAPI = apiBasePath + "/roles/" + encodeURIComponent(role);
+ if (userStore) {
+ removeRoleAPI += "?user-store=" + encodeURIComponent(userStore);
+ }
$(modalPopupContent).html($('#remove-role-modal-content').html());
showPopup();
@@ -210,7 +217,10 @@ $("#role-grid").on("click", ".remove-role-link", function () {
invokerUtil.delete(
removeRoleAPI,
function () {
- $("#role-" + role).remove();
+ if (userStore) {
+ role = userStore + '/' + role;
+ }
+ $('[id="role-' + role + '"]').remove();
$(modalPopupContent).html($('#remove-role-success-content').html());
$("a#remove-role-success-link").click(function () {
hidePopup();
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/public/js/bottomJs.js
index 2071baf9f9..317cf435e4 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/public/js/bottomJs.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/public/js/bottomJs.js
@@ -180,8 +180,7 @@ $("#userStore").change(
str += $(this).text() + "";
});
if ($("#roles").length > 0) {
- var getRolesAPI = deviceMgtAPIsBasePath + "/roles?user-store=" + str + "&limit=100";
-
+ var getRolesAPI = deviceMgtAPIsBasePath + "/roles?user-store=" + encodeURIComponent(str) + "&limit=100";
invokerUtil.get(
getRolesAPI,
function (data) {
@@ -189,10 +188,10 @@ $("#userStore").change(
if (data.errorMessage) {
$(errorMsg).text("Selected user store prompted an error : " + data.errorMessage);
$(errorMsgWrapper).removeClass("hidden");
- } else if (data["statusCode"] == 200) {
+ } else {
$("#roles").empty();
- for (var i = 0; i < data.responseContent.length; i++) {
- var newOption = $('');
+ for (var i = 0; i < data.roles.length; i++) {
+ var newOption = $('');
$('#roles').append(newOption);
}
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.edit/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.edit/public/js/bottomJs.js
index 00357909e6..2ecada94ad 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.edit/public/js/bottomJs.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.edit/public/js/bottomJs.js
@@ -236,7 +236,8 @@ $(document).ready(function () {
}
addUserFormData.roles = roles;
username = username.substr(username.indexOf('/') + 1);
- var addUserAPI = deviceMgtBasePath + "/users/" + username + "?domain=" + domain;
+ var addUserAPI = deviceMgtBasePath + "/users/" + encodeURIComponent(username) + "?domain=" +
+ encodeURIComponent(domain);
invokerUtil.put(
addUserAPI,
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js
index d8dc9d4860..50f11a3df3 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js
@@ -158,7 +158,7 @@ function resetPassword(username) {
}
var resetPasswordServiceURL = apiBasePath + "/admin/users/" + username + "/credentials";
if (domain) {
- resetPasswordServiceURL += '?domain=' + domain;
+ resetPasswordServiceURL += '?domain=' + encodeURIComponent(domain);
}
invokerUtil.post(
resetPasswordServiceURL,
@@ -198,11 +198,10 @@ function removeUser(username) {
domain = username.substr(0, username.indexOf('/'));
username = username.substr(username.indexOf('/') + 1);
}
- var removeUserAPI = apiBasePath + "/users/" + username;
+ var removeUserAPI = apiBasePath + "/users/" + encodeURIComponent(username);
if (domain) {
- removeUserAPI += '?domain=' + domain;
+ removeUserAPI += '?domain=' + encodeURIComponent(domain);
}
-
modalDialog.header("Remove User");
modalDialog.content("Do you really want to remove this user ?");
modalDialog.footer('