use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException in project oxTrust by GluuFederation.
the class UserWebService method deleteUser.
@Path("{id}")
@DELETE
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response deleteUser(@HeaderParam("Authorization") String authorization, @PathParam("id") String id) throws Exception {
Response authorizationResponse = processAuthorization(authorization);
if (authorizationResponse != null) {
return authorizationResponse;
}
try {
GluuCustomPerson gluuPerson = personService.getPersonByInum(id);
if (gluuPerson == null) {
return getErrorResponse("Resource " + id + " not found", Response.Status.NOT_FOUND.getStatusCode());
} else {
// For custom script: delete user
if (externalScimService.isEnabled()) {
externalScimService.executeScimDeleteUserMethods(gluuPerson);
}
log.info("person.getMemberOf().size() : " + gluuPerson.getMemberOf().size());
if (gluuPerson.getMemberOf() != null) {
if (gluuPerson.getMemberOf().size() > 0) {
String dn = personService.getDnForPerson(id);
log.info("DN : " + dn);
serviceUtil.deleteUserFromGroup(gluuPerson, dn);
}
}
memberService.removePerson(gluuPerson);
}
return Response.ok().build();
} catch (EntryPersistenceException ex) {
ex.printStackTrace();
return getErrorResponse("Resource " + id + " not found", Response.Status.NOT_FOUND.getStatusCode());
} catch (Exception ex) {
ex.printStackTrace();
return getErrorResponse(INTERNAL_SERVER_ERROR_MESSAGE, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
}
use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException in project oxTrust by GluuFederation.
the class BulkWebService method processGroupOperation.
private BulkOperation processGroupOperation(BulkOperation operation, Map<String, String> processedBulkIds) throws Exception {
log.info(" Operation is for Group ");
// Intercept bulkId
Group group = null;
if (operation.getData() != null) {
// Required in a request when
// "method" is "POST", "PUT", or
// "PATCH".
String serializedData = serialize(operation.getData());
for (Map.Entry<String, String> entry : processedBulkIds.entrySet()) {
String key = "bulkId:" + entry.getKey();
serializedData = serializedData.replaceAll(key, entry.getValue());
}
group = deserializeToGroup(serializedData);
}
String groupRootEndpoint = appConfiguration.getBaseEndpoint() + "/scim/v2/Groups/";
if (operation.getMethod().equalsIgnoreCase(HttpMethod.POST)) {
log.info(" Method is POST ");
try {
group = scim2GroupService.createGroup(group);
GluuGroup gluuGroup = groupService.getGroupByDisplayName(group.getDisplayName());
String id = gluuGroup.getInum();
// String location = (new
// StringBuilder()).append(domain).append("/Groups/").append(id).toString();
String location = groupRootEndpoint + id;
operation.setLocation(location);
operation.setStatus(String.valueOf(Response.Status.CREATED.getStatusCode()));
operation.setResponse(group);
// Set aside successfully-processed bulkId
// bulkId is only required in POST
processedBulkIds.put(operation.getBulkId(), group.getId());
} catch (DuplicateEntryException ex) {
log.error("DuplicateEntryException", ex);
ex.printStackTrace();
operation.setStatus(String.valueOf(Response.Status.CONFLICT.getStatusCode()));
operation.setResponse(createErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, ex.getMessage()));
} catch (Exception ex) {
log.error("Failed to create group", ex);
ex.printStackTrace();
operation.setStatus(String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
operation.setResponse(createErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, null, INTERNAL_SERVER_ERROR_MESSAGE));
}
} else if (operation.getMethod().equalsIgnoreCase(HttpMethod.PUT)) {
log.info(" Method is PUT ");
String path = operation.getPath();
String id = getId(path);
for (Map.Entry<String, String> entry : processedBulkIds.entrySet()) {
String key = "bulkId:" + entry.getKey();
if (id.equalsIgnoreCase(key)) {
id = id.replaceAll(key, entry.getValue());
break;
}
}
try {
group = scim2GroupService.updateGroup(id, group);
// String location = (new
// StringBuilder()).append(domain).append("/Groups/").append(groupiD).toString();
String location = groupRootEndpoint + id;
operation.setLocation(location);
operation.setStatus(String.valueOf(Response.Status.OK.getStatusCode()));
operation.setResponse(group);
// bulkId is only required in POST
if (operation.getBulkId() != null) {
processedBulkIds.put(operation.getBulkId(), group.getId());
}
} catch (EntryPersistenceException ex) {
log.error("Failed to update group", ex);
ex.printStackTrace();
operation.setStatus(String.valueOf(Response.Status.NOT_FOUND.getStatusCode()));
operation.setResponse(createErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found"));
} catch (DuplicateEntryException ex) {
log.error("DuplicateEntryException", ex);
ex.printStackTrace();
operation.setStatus(String.valueOf(Response.Status.CONFLICT.getStatusCode()));
operation.setResponse(createErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, ex.getMessage()));
} catch (Exception ex) {
log.error("Failed to update group", ex);
ex.printStackTrace();
operation.setStatus(String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
operation.setResponse(createErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, null, INTERNAL_SERVER_ERROR_MESSAGE));
}
} else if (operation.getMethod().equalsIgnoreCase(HttpMethod.DELETE)) {
log.info(" Method is DELETE ");
String path = operation.getPath();
String id = getId(path);
for (Map.Entry<String, String> entry : processedBulkIds.entrySet()) {
String key = "bulkId:" + entry.getKey();
if (id.equalsIgnoreCase(key)) {
id = id.replaceAll(key, entry.getValue());
break;
}
}
try {
scim2GroupService.deleteGroup(id);
// Location may be omitted on DELETE
operation.setStatus(String.valueOf(Response.Status.OK.getStatusCode()));
operation.setResponse("Group " + id + " deleted");
// bulkId is only required in POST
if (operation.getBulkId() != null) {
processedBulkIds.put(operation.getBulkId(), id);
}
} catch (EntryPersistenceException ex) {
log.error("Failed to delete group", ex);
ex.printStackTrace();
operation.setStatus(String.valueOf(Response.Status.NOT_FOUND.getStatusCode()));
operation.setResponse(createErrorResponse(Response.Status.NOT_FOUND, null, "Resource " + id + " not found"));
} catch (Exception ex) {
log.error("Failed to delete group", ex);
ex.printStackTrace();
operation.setStatus(String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
operation.setResponse(createErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, null, INTERNAL_SERVER_ERROR_MESSAGE));
}
}
return operation;
}
use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException in project oxTrust by GluuFederation.
the class ClientAssociationWebService method getAssociatedPersons.
@Path("/Client/{cid}")
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getAssociatedPersons(@HeaderParam("Authorization") String authorization, @PathParam("cid") String cid) throws Exception {
Response authorizationResponse = processAuthorization(authorization);
if (authorizationResponse != null) {
return authorizationResponse;
}
try {
log.info("getting the client");
OxAuthClient client = clientService.getClientByInum(cid);
if (client == null) {
// sets HTTP status code 404 Not Found
return getErrorResponse("Resource " + cid + " not found", Response.Status.NOT_FOUND.getStatusCode());
}
log.info("mapping client attributes");
ClientAssociation clientAssociation = MapperUtil.map(client, null);
log.info("getting URL");
URI location = new URI("/ClientAssociation/Client/" + cid);
log.info("returning response");
return Response.ok(clientAssociation).location(location).build();
} catch (EntryPersistenceException ex) {
log.error("Exception: ", ex);
return getErrorResponse("Resource " + cid + " not found", Response.Status.NOT_FOUND.getStatusCode());
} catch (Exception ex) {
log.error("Exception: ", ex);
return getErrorResponse(INTERNAL_SERVER_ERROR_MESSAGE, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
}
use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException in project oxTrust by GluuFederation.
the class GroupWebService method updateGroup.
@Path("{id}")
@PUT
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response updateGroup(@HeaderParam("Authorization") String authorization, @PathParam("id") String id, ScimGroup group) throws Exception {
Response authorizationResponse = processAuthorization(authorization);
if (authorizationResponse != null) {
return authorizationResponse;
}
try {
GluuGroup gluuGroup = groupService.getGroupByInum(id);
if (gluuGroup == null) {
return getErrorResponse("Resource " + id + " not found", Response.Status.NOT_FOUND.getStatusCode());
} else {
// Validate if attempting to update displayName of a different id
if (gluuGroup.getDisplayName() != null) {
GluuGroup groupToFind = new GluuGroup();
groupToFind.setDisplayName(group.getDisplayName());
List<GluuGroup> foundGroups = groupService.findGroups(groupToFind, 2);
if (foundGroups != null && foundGroups.size() > 0) {
for (GluuGroup foundGroup : foundGroups) {
if (foundGroup != null && !foundGroup.getInum().equalsIgnoreCase(gluuGroup.getInum())) {
throw new DuplicateEntryException("Cannot update displayName of a different id: " + group.getDisplayName());
}
}
}
}
}
GluuGroup newGluuGroup = copyUtils.copy(group, gluuGroup, true);
if (group.getMembers().size() > 0) {
serviceUtil.personMembersAdder(newGluuGroup, groupService.getDnForGroup(id));
}
// For custom script: update group
if (externalScimService.isEnabled()) {
externalScimService.executeScimUpdateGroupMethods(newGluuGroup);
}
groupService.updateGroup(newGluuGroup);
log.debug(" group updated ");
ScimGroup newGroup = copyUtils.copy(newGluuGroup, null);
URI location = new URI("/Groups/" + id);
return Response.ok(newGroup).location(location).build();
} catch (EntryPersistenceException ex) {
ex.printStackTrace();
return getErrorResponse("Resource " + id + " not found", Response.Status.NOT_FOUND.getStatusCode());
} catch (DuplicateEntryException ex) {
log.error("Failed to update group", ex);
ex.printStackTrace();
return getErrorResponse(ex.getMessage(), Response.Status.BAD_REQUEST.getStatusCode());
} catch (Exception ex) {
log.error("Failed to update group", ex);
ex.printStackTrace();
return getErrorResponse(INTERNAL_SERVER_ERROR_MESSAGE, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
}
use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException in project oxTrust by GluuFederation.
the class GroupWebService method deleteGroup.
@Path("{id}")
@DELETE
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response deleteGroup(@HeaderParam("Authorization") String authorization, @PathParam("id") String id) throws Exception {
Response authorizationResponse = processAuthorization(authorization);
if (authorizationResponse != null) {
return authorizationResponse;
}
try {
log.info(" Checking if the group exists ");
log.info(" id : " + id);
GluuGroup gluuGroup = groupService.getGroupByInum(id);
if (gluuGroup == null) {
log.info(" the group is null ");
return getErrorResponse("Resource " + id + " not found", Response.Status.NOT_FOUND.getStatusCode());
} else {
// For custom script: delete group
if (externalScimService.isEnabled()) {
externalScimService.executeScimDeleteGroupMethods(gluuGroup);
}
log.info(" getting started to delete members from groups ");
if (gluuGroup.getMembers() != null) {
if (gluuGroup.getMembers().size() > 0) {
log.info(" getting dn for group ");
String dn = groupService.getDnForGroup(id);
log.info(" DN : " + dn);
serviceUtil.deleteGroupFromPerson(gluuGroup, dn);
}
}
log.info(" removing the group ");
groupService.removeGroup(gluuGroup);
}
return Response.ok().build();
} catch (EntryPersistenceException ex) {
ex.printStackTrace();
return getErrorResponse("Resource " + id + " not found", Response.Status.NOT_FOUND.getStatusCode());
} catch (Exception ex) {
ex.printStackTrace();
return getErrorResponse(INTERNAL_SERVER_ERROR_MESSAGE, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
}
Aggregations