throws Exception {
try {
String[] parts = request.getRequestURI().toString().split("/");
String member = Val.chkStr(request.getParameter("member"));
String attempt = Val.chkStr(request.getParameter("attempt"));
IdentityAdapter idAdapter = context.newIdentityAdapter();
User user = new User();
user.setDistinguishedName(member);
idAdapter.readUserProfile(user);
if(parts.length > 0) {
String groupIdentifier = URLDecoder.decode(parts[5].trim(),"UTF-8");
if(!groupIdentifier.endsWith(groupDIT)){
IdentityConfiguration idConfig = context.getIdentityConfiguration();
Roles configuredRoles = idConfig.getConfiguredRoles();
Role roleRegistered = configuredRoles.get(groupIdentifier);
groupIdentifier = roleRegistered.getDistinguishedName();
}
boolean isSelf = checkSelf(context,member);
if((isSelf && attempt.equals("2")) || !isSelf){
boolean checkGroupConfigured = true;
if(checkIfAllowConfigured(context)){
checkGroupConfigured = checkIfConfigured(context,groupIdentifier);
}
boolean isAllowedToManage = true;
isAllowedToManage = checkIfAllowedToManage(context, groupIdentifier);
if(checkGroupConfigured){
if(isAllowedToManage){
idAdapter.removeUserFromGroup(user, groupIdentifier);
response.getWriter().write(msgBroker.retrieveMessage("catalog.identity.removeRole.success"));
}else{
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "{ \"error\":\""+ groupIdentifier +" is not allowed to be managed in geoportal. \"}");
return;
}