Fixing the problems that happend when we have special chracters in roles

merge-requests/7/head
Megala 8 years ago
parent 4ec6883ec8
commit 1ff86289fd

@ -39,8 +39,10 @@ import org.wso2.carbon.user.mgt.common.UserAdminException;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.io.UnsupportedEncodingException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -231,9 +233,9 @@ public class RoleManagementServiceImpl implements RoleManagementService {
userStoreManager.addRole(roleInfo.getRoleName(), roleInfo.getUsers(), permissions); userStoreManager.addRole(roleInfo.getRoleName(), roleInfo.getUsers(), permissions);
//TODO fix what's returned in the entity //TODO fix what's returned in the entity
return Response.created(new URI(API_BASE_PATH + "/" + roleInfo.getRoleName())).entity( return Response.created(new URI(API_BASE_PATH + "/" + URLEncoder.encode(roleInfo.getRoleName(), "UTF-8"))).
"Role '" + roleInfo.getRoleName() + "' has " + entity("Role '" + roleInfo.getRoleName() + "' has " + "successfully been"
"successfully been added").build(); + " added").build();
} catch (UserStoreException e) { } catch (UserStoreException e) {
String msg = "Error occurred while adding role '" + roleInfo.getRoleName() + "'"; String msg = "Error occurred while adding role '" + roleInfo.getRoleName() + "'";
log.error(msg, e); log.error(msg, e);
@ -245,6 +247,11 @@ public class RoleManagementServiceImpl implements RoleManagementService {
log.error(msg, e); log.error(msg, e);
return Response.serverError().entity( return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
} catch (UnsupportedEncodingException e) {
String msg = "Error occurred while encoding role name";
log.error(msg, e);
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
} }
} }

@ -83,8 +83,8 @@ clearInline["role-name"] = function () {
*/ */
validateInline["role-name"] = function () { validateInline["role-name"] = function () {
var roleNameInput = $("input#roleName"); var roleNameInput = $("input#roleName");
if (inputIsValid( roleNameInput.data("regex"), roleNameInput.val()) && roleNameInput.indexOf("@") < 0 && var roleName = roleNameInput.val();
roleNameInput.indexOf("/") < 0) { if (inputIsValid( roleNameInput.data("regex"), roleName) && roleName.indexOf("@") < 0 && roleName.indexOf("/") < 0) {
disableInlineError("roleNameField", "roleNameEmpty", "roleNameError"); disableInlineError("roleNameField", "roleNameEmpty", "roleNameError");
} else { } else {
enableInlineError("roleNameField", "roleNameEmpty", "roleNameError"); enableInlineError("roleNameField", "roleNameEmpty", "roleNameError");
@ -173,7 +173,8 @@ $(document).ready(function () {
if (!roleName) { if (!roleName) {
$(errorMsg).text("Role name is a required field. It cannot be empty."); $(errorMsg).text("Role name is a required field. It cannot be empty.");
$(errorMsgWrapper).removeClass("hidden"); $(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")); $(errorMsg).text(roleNameInput.data("error-msg"));
$(errorMsgWrapper).removeClass("hidden"); $(errorMsgWrapper).removeClass("hidden");
} else if (!domain) { } else if (!domain) {

@ -220,7 +220,7 @@ $("#role-grid").on("click", ".remove-role-link", function () {
if (userStore) { if (userStore) {
role = userStore + '/' + role; role = userStore + '/' + role;
} }
$('[id=role-' + role + ']').remove(); $('[id="role-' + role + '"]').remove();
$(modalPopupContent).html($('#remove-role-success-content').html()); $(modalPopupContent).html($('#remove-role-success-content').html());
$("a#remove-role-success-link").click(function () { $("a#remove-role-success-link").click(function () {
hidePopup(); hidePopup();

@ -220,7 +220,7 @@ function removeUser(username) {
if (domain) { if (domain) {
username = domain + '/' + username; username = domain + '/' + username;
} }
$('[id=user-' + username + ']').remove(); $('[id="user-' + username + '"]').remove();
// update modal-content with success message // update modal-content with success message
modalDialog.header("User Removed."); modalDialog.header("User Removed.");
modalDialog.content("Done. User was successfully removed."); modalDialog.content("Done. User was successfully removed.");

Loading…
Cancel
Save