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

revert-70aa11f8
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.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -231,9 +233,9 @@ public class RoleManagementServiceImpl implements RoleManagementService {
userStoreManager.addRole(roleInfo.getRoleName(), roleInfo.getUsers(), permissions);
//TODO fix what's returned in the entity
return Response.created(new URI(API_BASE_PATH + "/" + roleInfo.getRoleName())).entity(
"Role '" + roleInfo.getRoleName() + "' has " +
"successfully been added").build();
return Response.created(new URI(API_BASE_PATH + "/" + URLEncoder.encode(roleInfo.getRoleName(), "UTF-8"))).
entity("Role '" + roleInfo.getRoleName() + "' has " + "successfully been"
+ " added").build();
} catch (UserStoreException e) {
String msg = "Error occurred while adding role '" + roleInfo.getRoleName() + "'";
log.error(msg, e);
@ -245,6 +247,11 @@ public class RoleManagementServiceImpl implements RoleManagementService {
log.error(msg, e);
return Response.serverError().entity(
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 () {
var roleNameInput = $("input#roleName");
if (inputIsValid( roleNameInput.data("regex"), roleNameInput.val()) && roleNameInput.indexOf("@") < 0 &&
roleNameInput.indexOf("/") < 0) {
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");
@ -173,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) {

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

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

Loading…
Cancel
Save