use of org.gluu.oxtrust.model.GluuCustomPerson in project oxTrust by GluuFederation.
the class PatchUtil method addPatch.
public GluuCustomPerson addPatch(User source, GluuCustomPerson destination) throws Exception {
if (source == null) {
return null;
}
if (destination == null) {
log.trace(" creating a new GluuCustomPerson instant ");
destination = new GluuCustomPerson();
}
log.trace(" setting schemas ");
destination.setSchemas(source.getSchemas());
personService.addCustomObjectClass(destination);
// getting emails
log.trace(" setting emails ");
if (source.getEmails() != null && source.getEmails().size() > 0) {
List<Email> emails = copyUtils2.getAttributeListValue(destination, Email.class, "oxTrustEmail");
if (emails == null) {
emails = new ArrayList<Email>();
}
emails.addAll(source.getEmails());
copyUtils2.setAttributeListValue(destination, emails, "oxTrustEmail");
}
// getting addresses
log.trace(" setting addresses ");
if (source.getAddresses() != null && source.getAddresses().size() > 0) {
List<Address> addresses = copyUtils2.getAttributeListValue(destination, Address.class, "oxTrustAddresses");
if (addresses == null) {
addresses = new ArrayList<Address>();
}
addresses.addAll(source.getAddresses());
copyUtils2.setAttributeListValue(destination, addresses, "oxTrustAddresses");
}
// getting phone numbers;
log.trace(" setting phoneNumbers ");
if (source.getPhoneNumbers() != null && source.getPhoneNumbers().size() > 0) {
List<PhoneNumber> phoneNumbers = copyUtils2.getAttributeListValue(destination, PhoneNumber.class, "oxTrustPhoneValue");
if (phoneNumbers == null) {
phoneNumbers = new ArrayList<PhoneNumber>();
}
phoneNumbers.addAll(source.getPhoneNumbers());
copyUtils2.setAttributeListValue(destination, phoneNumbers, "oxTrustPhoneValue");
}
// getting ims
log.trace(" setting ims ");
if (source.getIms() != null && source.getIms().size() > 0) {
List<Im> ims = copyUtils2.getAttributeListValue(destination, Im.class, "oxTrustImsValue");
if (ims == null) {
ims = new ArrayList<Im>();
}
ims.addAll(source.getIms());
copyUtils2.setAttributeListValue(destination, ims, "oxTrustImsValue");
}
// getting Photos
log.trace(" setting photos ");
if (source.getPhotos() != null && source.getPhotos().size() > 0) {
List<Photo> photos = copyUtils2.getAttributeListValue(destination, Photo.class, "oxTrustPhotos");
if (photos == null) {
photos = new ArrayList<Photo>();
}
photos.addAll(source.getPhotos());
copyUtils2.setAttributeListValue(destination, photos, "oxTrustPhotos");
}
// getting user groups
log.trace(" setting groups ");
if (source.getGroups() != null && source.getGroups().size() > 0) {
List<String> groupsList = destination.getMemberOf();
List<GroupRef> listGroups = source.getGroups();
for (GroupRef group : listGroups) {
String groupToAdd = groupService.getDnForGroup(group.getValue());
if (groupToAdd != null || !groupToAdd.trim().equalsIgnoreCase("")) {
groupsList.add(groupToAdd);
}
}
destination.setMemberOf(groupsList);
}
// getting roles
log.trace(" setting roles ");
if (source.getRoles() != null && source.getRoles().size() > 0) {
List<Role> roles = copyUtils2.getAttributeListValue(destination, Role.class, "oxTrustRole");
if (roles == null) {
roles = new ArrayList<Role>();
}
roles.addAll(source.getRoles());
copyUtils2.setAttributeListValue(destination, roles, "oxTrustRole");
}
// getting entitlements
log.trace(" setting entitlements ");
if (source.getEntitlements() != null && source.getEntitlements().size() > 0) {
List<Entitlement> entitlements = copyUtils2.getAttributeListValue(destination, Entitlement.class, "oxTrustEntitlements");
if (entitlements == null) {
entitlements = new ArrayList<Entitlement>();
}
entitlements.addAll(source.getEntitlements());
copyUtils2.setAttributeListValue(destination, entitlements, "oxTrustEntitlements");
}
// getting x509Certificates
log.trace(" setting certs ");
if (source.getX509Certificates() != null && source.getX509Certificates().size() > 0) {
List<X509Certificate> X509Certificates = copyUtils2.getAttributeListValue(destination, X509Certificate.class, "oxTrustx509Certificate");
if (X509Certificates == null) {
X509Certificates = new ArrayList<X509Certificate>();
}
X509Certificates.addAll(source.getX509Certificates());
copyUtils2.setAttributeListValue(destination, X509Certificates, "oxTrustx509Certificate");
}
log.trace(" setting extensions ");
if (source.getExtensions() != null && (source.getExtensions().size() > 0)) {
Map<String, Extension> destMap = destination.fetchExtensions();
if (destMap == null) {
destMap = new HashMap<String, Extension>();
}
destMap.putAll(source.getExtensions());
destination.setExtensions(destMap);
}
if (source.isActive() != null) {
copyUtils2.setGluuStatus(source, destination);
}
return destination;
}
use of org.gluu.oxtrust.model.GluuCustomPerson in project oxTrust by GluuFederation.
the class PatchUtil method removePatch.
public GluuCustomPerson removePatch(User source, GluuCustomPerson destination) throws Exception {
if (source == null) {
return null;
}
if (destination == null) {
log.trace(" creating a new GluuCustomPerson instant ");
destination = new GluuCustomPerson();
}
log.trace(" setting schemas ");
destination.setSchemas(source.getSchemas());
personService.addCustomObjectClass(destination);
log.trace(" setting userName ");
if (source.getUserName() != null && source.getUserName().length() > 0) {
destination.setUid(source.getUserName());
}
if (source.getName() != null) {
log.trace(" setting givenname ");
if (source.getName().getGivenName() != null) {
destination.setGivenName("");
}
log.trace(" setting famillyname ");
if (source.getName().getFamilyName() != null) {
destination.setSurname("");
}
log.trace(" setting middlename ");
if (source.getName().getMiddleName() != null) {
// destination.setAttribute("oxTrustMiddleName",
// source.getName().getMiddleName());
destination.setAttribute("middleName", "");
}
log.trace(" setting honor");
if (source.getName().getHonorificPrefix() != null) {
destination.setAttribute("oxTrusthonorificPrefix", "");
}
if (source.getName().getHonorificSuffix() != null) {
destination.setAttribute("oxTrusthonorificSuffix", "");
}
}
log.trace(" setting displayname ");
if (source.getDisplayName() != null) {
destination.setDisplayName(source.getDisplayName());
}
log.trace(" setting externalID ");
if (source.getExternalId() != null) {
destination.setAttribute("oxTrustExternalId", source.getExternalId());
}
log.trace(" setting nickname ");
if (source.getNickName() != null) {
// destination.setAttribute("oxTrustNickName",
// source.getNickName());
destination.setAttribute("nickname", "");
}
log.trace(" setting profileURL ");
if (source.getProfileUrl() != null) {
destination.setAttribute("oxTrustProfileURL", "");
}
// getting emails
log.trace(" setting emails ");
if (source.getEmails() != null && source.getEmails().size() > 0) {
List<Email> emails = copyUtils2.getAttributeListValue(destination, Email.class, "oxTrustEmail");
if (emails != null && emails.size() > 0) {
List<Email> newemails = source.getEmails();
Iterator<Email> emailsIt = emails.iterator();
Iterator<Email> newemailsIt = newemails.iterator();
while (emailsIt.hasNext()) {
Email email = emailsIt.next();
if (email != null && email.getType() != null) {
while (newemailsIt.hasNext()) {
Email newEmail = newemailsIt.next();
if (newEmail.getType() != null && newEmail.getType().getValue().equals(email.getType().getValue())) {
emailsIt.remove();
}
}
}
}
copyUtils2.setAttributeListValue(destination, emails, "oxTrustEmail");
}
}
// getting addresses
log.trace(" setting addresses ");
if (source.getAddresses() != null && source.getAddresses().size() > 0) {
List<Address> addresses = copyUtils2.getAttributeListValue(destination, Address.class, "oxTrustAddresses");
if (addresses != null && addresses.size() > 0) {
List<Address> newaddresses = source.getAddresses();
Iterator<Address> addressesIt = addresses.iterator();
Iterator<Address> newaddressesIt = newaddresses.iterator();
while (addressesIt.hasNext()) {
Address address = addressesIt.next();
if (address != null && address.getType() != null) {
while (newaddressesIt.hasNext()) {
Address newaddress = newaddressesIt.next();
if (newaddress.getType().getValue() != null && newaddress.getType().getValue().equals(address.getType().getValue())) {
addressesIt.remove();
}
}
}
}
copyUtils2.setAttributeListValue(destination, addresses, "oxTrustAddresses");
}
}
// getting phone numbers;
log.trace(" setting phoneNumbers ");
if (source.getPhoneNumbers() != null && source.getPhoneNumbers().size() > 0) {
List<PhoneNumber> phoneNumbers = copyUtils2.getAttributeListValue(destination, PhoneNumber.class, "oxTrustPhoneValue");
if (phoneNumbers != null && phoneNumbers.size() > 0) {
List<PhoneNumber> newPhoneNumbers = source.getPhoneNumbers();
Iterator<PhoneNumber> phoneNumbersIt = phoneNumbers.iterator();
Iterator<PhoneNumber> newPhoneNumbersIt = newPhoneNumbers.iterator();
while (phoneNumbersIt.hasNext()) {
PhoneNumber phoneNumber = phoneNumbersIt.next();
while (newPhoneNumbersIt.hasNext()) {
PhoneNumber newPhoneNumber = newPhoneNumbersIt.next();
if (newPhoneNumber.getType() != null && newPhoneNumber.getType().getValue().equals(phoneNumber.getType().getValue())) {
phoneNumbersIt.remove();
}
}
}
copyUtils2.setAttributeListValue(destination, phoneNumbers, "oxTrustPhoneValue");
}
}
// getting ims
log.trace(" setting ims ");
if (source.getIms() != null && source.getIms().size() > 0) {
List<Im> ims = copyUtils2.getAttributeListValue(destination, Im.class, "oxTrustImsValue");
if (ims != null && ims.size() > 0) {
List<Im> newims = source.getIms();
Iterator<Im> imsIt = ims.iterator();
Iterator<Im> newimssIt = newims.iterator();
while (imsIt.hasNext()) {
Im im = imsIt.next();
if (im != null && im.getType() != null) {
while (newimssIt.hasNext()) {
Im newIm = newimssIt.next();
if (newIm.getType() != null && newIm.getType().getValue().equals(im.getType().getValue())) {
imsIt.remove();
}
}
}
}
copyUtils2.setAttributeListValue(destination, ims, "oxTrustImsValue");
}
}
// getting Photos
log.trace(" setting photos ");
if (source.getPhotos() != null && source.getPhotos().size() > 0) {
List<Photo> photos = copyUtils2.getAttributeListValue(destination, Photo.class, "oxTrustPhotos");
if (photos != null && photos.size() > 0) {
List<Photo> newPhotos = source.getPhotos();
Iterator<Photo> photosIt = photos.iterator();
Iterator<Photo> newphotosIt = newPhotos.iterator();
while (photosIt.hasNext()) {
Photo old = photosIt.next();
if (old != null && old.getType() != null) {
while (newphotosIt.hasNext()) {
Photo newelement = newphotosIt.next();
if (newelement.getType() != null && newelement.getType().getValue().equals(old.getType().getValue())) {
photosIt.remove();
}
}
}
}
copyUtils2.setAttributeListValue(destination, photos, "oxTrustPhotos");
}
}
if (source.getUserType() != null) {
destination.setAttribute("oxTrustUserType", "");
}
if (source.getTitle() != null) {
destination.setAttribute("oxTrustTitle", "");
}
if (source.getPreferredLanguage() != null) {
destination.setPreferredLanguage("");
}
if (source.getLocale() != null) {
// destination.setAttribute("oxTrustLocale", source.getLocale());
destination.setAttribute("locale", "");
}
if (source.getTimezone() != null) {
destination.setTimezone("");
}
if (source.isActive() != null) {
destination.setAttribute("oxTrustActive", source.isActive().toString());
}
if (source.getPassword() != null && source.getPassword().length() > 0) {
destination.setUserPassword(source.getPassword());
}
// getting user groups
log.trace(" setting groups ");
if (source.getGroups() != null && source.getGroups().size() > 0) {
List<String> members = destination.getMemberOf();
if (members != null || members.size() > 0) {
members.removeAll(source.getGroups());
}
destination.setMemberOf(members);
}
// getting roles
log.trace(" setting roles ");
if (source.getRoles() != null && source.getRoles().size() > 0) {
List<Role> roles = copyUtils2.getAttributeListValue(destination, Role.class, "oxTrustRole");
if (roles != null && roles.size() > 0) {
List<Role> newRoles = source.getRoles();
Iterator<Role> oldsIt = roles.iterator();
Iterator<Role> newsIt = newRoles.iterator();
while (oldsIt.hasNext()) {
Role old = oldsIt.next();
if (old != null && old.getType() != null) {
while (newsIt.hasNext()) {
Role newelement = newsIt.next();
if (newelement.getType() != null && newelement.getType().getValue().equals(old.getType().getValue())) {
oldsIt.remove();
}
}
}
}
copyUtils2.setAttributeListValue(destination, roles, "oxTrustRole");
}
}
// getting entitlements
log.trace(" setting entitlements ");
if (source.getEntitlements() != null && source.getEntitlements().size() > 0) {
List<Entitlement> entitlements = copyUtils2.getAttributeListValue(destination, Entitlement.class, "oxTrustEntitlements");
if (entitlements != null && entitlements.size() > 0) {
List<Entitlement> newEentitlements = source.getEntitlements();
Iterator<Entitlement> oldsIt = entitlements.iterator();
Iterator<Entitlement> newsIt = newEentitlements.iterator();
while (oldsIt.hasNext()) {
Entitlement old = oldsIt.next();
if (old != null && old.getType() != null) {
while (newsIt.hasNext()) {
Entitlement newelement = newsIt.next();
if (newelement.getType() != null && newelement.getType().getValue().equals(old.getType().getValue())) {
oldsIt.remove();
}
}
}
}
copyUtils2.setAttributeListValue(destination, entitlements, "oxTrustEntitlements");
}
}
// getting x509Certificates
log.trace(" setting certs ");
if (source.getX509Certificates() != null && source.getX509Certificates().size() > 0) {
List<X509Certificate> X509Certificates = copyUtils2.getAttributeListValue(destination, X509Certificate.class, "oxTrustx509Certificate");
if (X509Certificates != null && X509Certificates.size() > 0) {
List<X509Certificate> newX509Certificates = source.getX509Certificates();
Iterator<X509Certificate> oldsIt = X509Certificates.iterator();
Iterator<X509Certificate> newsIt = newX509Certificates.iterator();
while (oldsIt.hasNext()) {
X509Certificate old = oldsIt.next();
if (old != null && old.getType() != null) {
while (newsIt.hasNext()) {
X509Certificate newelement = newsIt.next();
if (newelement.getType() != null && newelement.getType().getValue().equals(old.getType().getValue())) {
oldsIt.remove();
}
}
}
}
copyUtils2.setAttributeListValue(destination, X509Certificates, "oxTrustx509Certificate");
}
}
log.trace(" setting extensions ");
if (source.getExtensions() != null && (source.getExtensions().size() > 0)) {
destination.setExtensions(source.getExtensions());
}
if (source.isActive() != null) {
copyUtils2.setGluuStatus(source, destination);
}
return destination;
}
use of org.gluu.oxtrust.model.GluuCustomPerson 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.oxtrust.model.GluuCustomPerson in project oxTrust by GluuFederation.
the class BulkWebService method bulkOperation.
@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response bulkOperation(@Context HttpServletRequest request, @HeaderParam("Authorization") String authorization, ScimBulkOperation operation) throws Exception {
Response authorizationResponse = processAuthorization(authorization);
if (authorizationResponse != null) {
return authorizationResponse;
}
String domain;
URL reconstructedURL;
reconstructedURL = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), "");
domain = reconstructedURL.toString();
log.info(" getting list of BulkRequest ");
List<BulkRequests> bulkRequests = operation.getOperations();
ScimBulkResponse scimBulkResponse = new ScimBulkResponse();
List<BulkResponses> listResponses = new ArrayList<BulkResponses>();
for (BulkRequests oneRequest : bulkRequests) {
log.info(" checking operations ");
if (oneRequest.getPath().contains("Users")) {
log.info(" operations is for Users ");
log.info(" method : " + oneRequest.getMethod());
if (oneRequest.getMethod().equalsIgnoreCase("POST")) {
log.info(" method is post ");
String bulkId = oneRequest.getBulkId();
String method = oneRequest.getMethod();
ScimPerson person = oneRequest.getData();
boolean status = createUser(person);
if (status) {
log.info(" POST status is true ");
BulkResponses bulkResponses = new BulkResponses();
bulkResponses.setBulkId(bulkId);
bulkResponses.setMethod(method);
GluuCustomPerson gluuPerson = personService.getPersonByUid(person.getUserName());
String iD = gluuPerson.getInum();
String location = (new StringBuilder()).append(domain).append("/oxTrust/seam/resource/restv1/Users/").append(iD).toString();
bulkResponses.setLocation(location);
BulkResponseStatus result = new BulkResponseStatus();
result.setCode("201");
bulkResponses.setStatus(result);
listResponses.add(bulkResponses);
} else if (!status) {
log.info(" POST status is false ");
BulkResponses bulkResponses = new BulkResponses();
bulkResponses.setBulkId(bulkId);
bulkResponses.setMethod(method);
BulkResponseStatus result = new BulkResponseStatus();
result.setCode("400");
result.setDescription("Request is unparseable, syntactically incorrect, or violates schema.");
bulkResponses.setStatus(result);
listResponses.add(bulkResponses);
}
} else if (oneRequest.getMethod().equalsIgnoreCase("PUT")) {
log.info(" Status is PUT ");
String method = oneRequest.getMethod();
String version = oneRequest.getVersion();
String path = oneRequest.getPath();
ScimPerson person = oneRequest.getData();
String personiD = getId(path);
log.info(" Inum : " + getId(path));
boolean status = updateUser(personiD, person);
if (status) {
log.info(" PUT status is true ");
BulkResponses bulkResponses = new BulkResponses();
bulkResponses.setMethod(method);
String iD = personiD;
String location = (new StringBuilder()).append(domain).append("/oxTrust/seam/resource/restv1/Users/").append(iD).toString();
bulkResponses.setLocation(location);
EntityTag eTag = new EntityTag(version, true);
String newVersion = eTag.getValue();
bulkResponses.setVersion(newVersion);
BulkResponseStatus result = new BulkResponseStatus();
result.setCode("200");
bulkResponses.setStatus(result);
listResponses.add(bulkResponses);
} else if (!status) {
log.info(" PUT status is false ");
BulkResponses bulkResponses = new BulkResponses();
bulkResponses.setMethod(method);
bulkResponses.setVersion(version);
BulkResponseStatus result = new BulkResponseStatus();
result.setCode("400");
result.setDescription("Request is unparseable, syntactically incorrect, or violates schema.");
bulkResponses.setStatus(result);
listResponses.add(bulkResponses);
}
} else if (oneRequest.getMethod().equalsIgnoreCase("DELETE")) {
log.info(" Operation is DELETE ");
String method = oneRequest.getMethod();
String path = oneRequest.getPath();
String personiD = getId(path);
boolean status = deleteUser(personiD);
if (status) {
log.info(" DELETE operation is true ");
BulkResponses bulkResponses = new BulkResponses();
bulkResponses.setMethod(method);
String location = (new StringBuilder()).append(domain).append("/oxTrust/seam/resource/restv1/Users/").append(personiD).toString();
bulkResponses.setLocation(location);
BulkResponseStatus result = new BulkResponseStatus();
result.setCode("200");
bulkResponses.setStatus(result);
listResponses.add(bulkResponses);
} else if (!status) {
log.info(" DELETE operation is False ");
BulkResponses bulkResponses = new BulkResponses();
bulkResponses.setMethod(method);
BulkResponseStatus result = new BulkResponseStatus();
result.setCode("400");
result.setDescription("Request is unparseable, syntactically incorrect, or violates schema.");
bulkResponses.setStatus(result);
listResponses.add(bulkResponses);
}
}
//
} else if (oneRequest.getPath().contains("Groups")) {
if (oneRequest.getMethod().equalsIgnoreCase("POST")) {
log.info(" method is post ");
String bulkId = oneRequest.getBulkId();
String method = oneRequest.getMethod();
ScimGroup group = copyUtils.copy(oneRequest.getData(), null);
boolean status = createGroup(group);
if (status) {
log.info(" POST status is true ");
BulkResponses bulkResponses = new BulkResponses();
bulkResponses.setBulkId(bulkId);
bulkResponses.setMethod(method);
GluuGroup gluuGroup = groupService.getGroupByDisplayName(group.getDisplayName());
String iD = gluuGroup.getInum();
String location = (new StringBuilder()).append(domain).append("/oxTrust/seam/resource/restv1/Groups/").append(iD).toString();
bulkResponses.setLocation(location);
BulkResponseStatus result = new BulkResponseStatus();
result.setCode("201");
bulkResponses.setStatus(result);
listResponses.add(bulkResponses);
} else if (!status) {
log.info(" POST status is false ");
BulkResponses bulkResponses = new BulkResponses();
bulkResponses.setBulkId(bulkId);
bulkResponses.setMethod(method);
BulkResponseStatus result = new BulkResponseStatus();
result.setCode("400");
result.setDescription("Request is unparseable, syntactically incorrect, or violates schema.");
bulkResponses.setStatus(result);
listResponses.add(bulkResponses);
}
} else if (oneRequest.getMethod().equalsIgnoreCase("PUT")) {
log.info(" Status is PUT ");
String method = oneRequest.getMethod();
String version = oneRequest.getVersion();
String path = oneRequest.getPath();
ScimGroup group = copyUtils.copy(oneRequest.getData(), null);
String groupiD = getId(path);
boolean status = updateGroup(groupiD, group);
if (status) {
log.info(" PUT status is true ");
BulkResponses bulkResponses = new BulkResponses();
bulkResponses.setMethod(method);
String iD = groupiD;
String location = (new StringBuilder()).append(domain).append("/oxTrust/seam/resource/restv1/Groups/").append(iD).toString();
bulkResponses.setLocation(location);
EntityTag eTag = new EntityTag(version, true);
String newVersion = eTag.getValue();
bulkResponses.setVersion(newVersion);
BulkResponseStatus result = new BulkResponseStatus();
result.setCode("200");
bulkResponses.setStatus(result);
listResponses.add(bulkResponses);
} else if (!status) {
log.info(" PUT status is false ");
BulkResponses bulkResponses = new BulkResponses();
bulkResponses.setMethod(method);
bulkResponses.setVersion(version);
BulkResponseStatus result = new BulkResponseStatus();
result.setCode("400");
result.setDescription("Request is unparseable, syntactically incorrect, or violates schema.");
bulkResponses.setStatus(result);
listResponses.add(bulkResponses);
}
} else if (oneRequest.getMethod().equalsIgnoreCase("DELETE")) {
log.info(" Operation is DELETE ");
String method = oneRequest.getMethod();
String path = oneRequest.getPath();
String groupiD = getId(path);
boolean status = deleteGroup(groupiD);
if (status) {
log.info(" DELETE operation is true ");
BulkResponses bulkResponses = new BulkResponses();
bulkResponses.setMethod(method);
String location = (new StringBuilder()).append(domain).append("/oxTrust/seam/resource/restv1/Groups/").append(groupiD).toString();
bulkResponses.setLocation(location);
BulkResponseStatus result = new BulkResponseStatus();
result.setCode("200");
bulkResponses.setStatus(result);
listResponses.add(bulkResponses);
} else if (!status) {
log.info(" DELETE operation is False ");
BulkResponses bulkResponses = new BulkResponses();
bulkResponses.setMethod(method);
BulkResponseStatus result = new BulkResponseStatus();
result.setCode("400");
result.setDescription("Request is unparseable, syntactically incorrect, or violates schema.");
bulkResponses.setStatus(result);
listResponses.add(bulkResponses);
}
}
}
}
List<String> schemas = new ArrayList<String>();
schemas.add(Constants.SCIM1_CORE_SCHEMA_ID);
scimBulkResponse.setSchemas(schemas);
scimBulkResponse.setOperations(listResponses);
URI location = new URI("/Bulk/");
return Response.ok(scimBulkResponse).location(location).build();
}
use of org.gluu.oxtrust.model.GluuCustomPerson 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;
}
Aggregations