use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException in project oxTrust by GluuFederation.
the class BulkWebService method deleteUser.
private boolean deleteUser(String uid) throws Exception {
try {
GluuCustomPerson gluuPerson = personService.getPersonByInum(uid);
if (gluuPerson == null) {
return false;
} else {
// For custom script: delete user
if (externalScimService.isEnabled()) {
externalScimService.executeScimDeleteUserMethods(gluuPerson);
}
if (gluuPerson.getMemberOf() != null) {
if (gluuPerson.getMemberOf().size() > 0) {
String dn = personService.getDnForPerson(uid);
serviceUtil.deleteUserFromGroup(gluuPerson, dn);
}
}
memberService.removePerson(gluuPerson);
}
return true;
} catch (EntryPersistenceException ex) {
log.error("Exception: ", ex);
return false;
} catch (Exception ex) {
log.error("Exception: ", ex);
return false;
}
}
use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException in project oxTrust by GluuFederation.
the class BulkWebService method deleteGroup.
private boolean deleteGroup(String id) throws Exception {
try {
GluuGroup gluuGroup = groupService.getGroupByInum(id);
if (gluuGroup == null) {
return false;
} else {
// For custom script: delete group
if (externalScimService.isEnabled()) {
externalScimService.executeScimDeleteGroupMethods(gluuGroup);
}
if (gluuGroup.getMembers() != null) {
if (gluuGroup.getMembers().size() > 0) {
String dn = groupService.getDnForGroup(id);
serviceUtil.deleteGroupFromPerson(gluuGroup, dn);
}
}
groupService.removeGroup(gluuGroup);
}
return true;
} catch (EntryPersistenceException ex) {
log.error("Exception: ", ex);
return false;
} catch (Exception ex) {
log.error("Exception: ", ex);
return false;
}
}
use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException in project oxTrust by GluuFederation.
the class BulkWebService method processUserOperation.
private BulkOperation processUserOperation(BulkOperation operation, Map<String, String> processedBulkIds) throws Exception {
log.info(" Operation is for User ");
// Intercept bulkId
User user = 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());
}
user = deserializeToUser(serializedData);
}
String userRootEndpoint = appConfiguration.getBaseEndpoint() + "/scim/v2/Users/";
if (operation.getMethod().equalsIgnoreCase(HttpMethod.POST)) {
log.info(" Method is POST ");
try {
user = scim2UserService.createUser(user);
GluuCustomPerson gluuPerson = personService.getPersonByUid(user.getUserName());
String inum = gluuPerson.getInum();
// String location = (new
// StringBuilder()).append(domain).append("/Users/").append(inum).toString();
String location = userRootEndpoint + inum;
operation.setLocation(location);
operation.setStatus(String.valueOf(Response.Status.CREATED.getStatusCode()));
operation.setResponse(user);
// Set aside successfully-processed bulkId
// bulkId is only required in POST
processedBulkIds.put(operation.getBulkId(), user.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 (PersonRequiredFieldsException ex) {
log.error("PersonRequiredFieldsException: ", ex);
operation.setStatus(String.valueOf(Response.Status.BAD_REQUEST.getStatusCode()));
operation.setResponse(createErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_VALUE, ex.getMessage()));
} catch (Exception ex) {
log.error("Failed to create user", 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 {
user = scim2UserService.updateUser(id, user);
// String location = (new
// StringBuilder()).append(domain).append("/Users/").append(personiD).toString();
String location = userRootEndpoint + id;
operation.setLocation(location);
operation.setStatus(String.valueOf(Response.Status.OK.getStatusCode()));
operation.setResponse(user);
// bulkId is only required in POST
if (operation.getBulkId() != null) {
processedBulkIds.put(operation.getBulkId(), user.getId());
}
} catch (EntryPersistenceException ex) {
log.error("Failed to update user", 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 user", 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 {
scim2UserService.deleteUser(id);
// Location may be omitted on DELETE
operation.setStatus(String.valueOf(Response.Status.OK.getStatusCode()));
operation.setResponse("User " + 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 user", 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 user", 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 GroupWebService method searchGroupsPost.
@Path("/.search")
@POST
@Produces({ Constants.MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
@ApiOperation(value = "Search group POST /.search", notes = "Returns a list of groups (https://tools.ietf.org/html/rfc7644#section-3.4.3)", response = ListResponse.class)
public Response searchGroupsPost(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @ApiParam(value = "SearchRequest", required = true) SearchRequest searchRequest) throws Exception {
try {
log.info("IN GroupWebService.searchGroupsPost()...");
// Authorization check is done in searchGroups()
Response response = searchGroups(authorization, token, searchRequest.getFilter(), searchRequest.getStartIndex(), searchRequest.getCount(), searchRequest.getSortBy(), searchRequest.getSortOrder(), searchRequest.getAttributesArray());
URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/Groups/.search");
log.info("LEAVING GroupWebService.searchGroupsPost()...");
return Response.fromResponse(response).location(location).build();
} catch (EntryPersistenceException ex) {
log.error("Error in searchGroupsPost", ex);
ex.printStackTrace();
return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource not found");
} catch (Exception ex) {
log.error("Error in searchGroupsPost", ex);
ex.printStackTrace();
return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_FILTER, INTERNAL_SERVER_ERROR_MESSAGE);
}
}
use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException in project oxTrust by GluuFederation.
the class OxChooserWebService method editUser.
@Path("/EditUser/{email}")
@GET
@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response editUser(@HeaderParam("Authorization") String authorization, @PathParam("email") String email, ScimPerson person_update) throws Exception {
Response authorizationResponse = processAuthorization(authorization);
if (authorizationResponse != null) {
return authorizationResponse;
}
try {
GluuCustomPerson gluuPerson = personService.getPersonByEmail(email);
if (gluuPerson == null) {
return getErrorResponse("Resource " + email + " not found", Response.Status.NOT_FOUND.getStatusCode());
}
GluuCustomPerson newGluuPesron = copyUtils.copy(person_update, gluuPerson, true);
if (person_update.getGroups().size() > 0) {
serviceUtil.groupMembersAdder(newGluuPesron, personService.getDnForPerson(gluuPerson.getUid()));
}
personService.updatePerson(newGluuPesron);
log.debug(" person updated ");
ScimPerson newPerson = copyUtils.copy(newGluuPesron, null);
URI location = new URI("/oxChooser/AddUser/" + gluuPerson.getUid());
return Response.ok(newPerson).location(location).build();
} catch (EntryPersistenceException ex) {
return getErrorResponse("Resource " + email + " not found", Response.Status.NOT_FOUND.getStatusCode());
} catch (Exception ex) {
log.error("Exception: ", ex);
ex.printStackTrace();
return getErrorResponse(INTERNAL_SERVER_ERROR_MESSAGE, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
}
Aggregations