use of org.gluu.oxtrust.model.scim.ScimPerson in project oxTrust by GluuFederation.
the class UserWebService method updateUser.
@Path("{id}")
@PUT
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response updateUser(@HeaderParam("Authorization") String authorization, @PathParam("id") String id, ScimPerson person) 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 {
// Validate if attempting to update userName of a different id
if (person.getUserName() != null) {
GluuCustomPerson personToFind = new GluuCustomPerson();
personToFind.setUid(person.getUserName());
List<GluuCustomPerson> foundPersons = personService.findPersons(personToFind, 2);
if (foundPersons != null && foundPersons.size() > 0) {
for (GluuCustomPerson foundPerson : foundPersons) {
if (foundPerson != null && !foundPerson.getInum().equalsIgnoreCase(gluuPerson.getInum())) {
throw new DuplicateEntryException("Cannot update userName of a different id: " + person.getUserName());
}
}
}
}
}
GluuCustomPerson newGluuPerson = copyUtils.copy(person, gluuPerson, true);
if (person.getGroups().size() > 0) {
serviceUtil.groupMembersAdder(newGluuPerson, personService.getDnForPerson(id));
}
// Sync email, forward ("oxTrustEmail" -> "mail")
newGluuPerson = ServiceUtil.syncEmailForward(newGluuPerson, false);
// For custom script: update user
if (externalScimService.isEnabled()) {
externalScimService.executeScimUpdateUserMethods(newGluuPerson);
}
personService.updatePerson(newGluuPerson);
log.debug(" person updated ");
ScimPerson newPerson = copyUtils.copy(newGluuPerson, null);
// person_update = copyUtils.copy(gluuPerson, null, attributes);
URI location = new URI("/Users/" + id);
return Response.ok(newPerson).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 user", ex);
ex.printStackTrace();
return getErrorResponse(ex.getMessage(), Response.Status.BAD_REQUEST.getStatusCode());
} catch (Exception ex) {
log.error("Failed to update user", ex);
ex.printStackTrace();
return getErrorResponse(INTERNAL_SERVER_ERROR_MESSAGE, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
}
use of org.gluu.oxtrust.model.scim.ScimPerson in project oxTrust by GluuFederation.
the class UserWebService method getUserByUid.
@Path("{uid}")
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getUserByUid(@HeaderParam("Authorization") String authorization, @PathParam("uid") String uid) throws Exception {
Response authorizationResponse = processAuthorization(authorization);
if (authorizationResponse != null) {
return authorizationResponse;
}
try {
GluuCustomPerson gluuPerson = personService.getPersonByInum(uid);
if (gluuPerson == null) {
// sets HTTP status code 404 Not Found
return getErrorResponse("Resource " + uid + " not found", Response.Status.NOT_FOUND.getStatusCode());
}
ScimPerson person = copyUtils.copy(gluuPerson, null);
URI location = new URI("/Users/" + uid);
return Response.ok(person).location(location).build();
} catch (EntryPersistenceException ex) {
ex.printStackTrace();
return getErrorResponse("Resource " + uid + " 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.oxtrust.model.scim.ScimPerson in project oxTrust by GluuFederation.
the class UserWebService method createUser.
@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createUser(@HeaderParam("Authorization") String authorization, ScimPerson person) throws Exception {
Response authorizationResponse = processAuthorization(authorization);
if (authorizationResponse != null) {
return authorizationResponse;
}
try {
log.debug(" copying gluuperson ");
GluuCustomPerson gluuPerson = copyUtils.copy(person, null, false);
if (gluuPerson == null) {
return getErrorResponse("Failed to create user", Response.Status.BAD_REQUEST.getStatusCode());
}
log.debug(" generating inum ");
// inumService.generateInums(Configuration.INUM_TYPE_PEOPLE_SLUG);
String inum = personService.generateInumForNewPerson();
// //personService.generateInumForNewPerson();
log.debug(" getting DN ");
String dn = personService.getDnForPerson(inum);
log.debug(" getting iname ");
String iname = personService.generateInameForNewPerson(person.getUserName());
log.debug(" setting dn ");
gluuPerson.setDn(dn);
log.debug(" setting inum ");
gluuPerson.setInum(inum);
log.debug(" setting iname ");
gluuPerson.setIname(iname);
log.debug(" setting commonName ");
gluuPerson.setCommonName(gluuPerson.getGivenName() + " " + gluuPerson.getSurname());
log.info("gluuPerson.getMemberOf().size() : " + gluuPerson.getMemberOf().size());
if (person.getGroups().size() > 0) {
log.info(" jumping to groupMembersAdder ");
log.info("gluuPerson.getDn() : " + gluuPerson.getDn());
serviceUtil.groupMembersAdder(gluuPerson, gluuPerson.getDn());
}
// Sync email, forward ("oxTrustEmail" -> "mail")
gluuPerson = ServiceUtil.syncEmailForward(gluuPerson, false);
// For custom script: create user
if (externalScimService.isEnabled()) {
externalScimService.executeScimCreateUserMethods(gluuPerson);
}
log.debug("adding new GluuPerson");
personService.addPerson(gluuPerson);
ScimPerson newPerson = copyUtils.copy(gluuPerson, null);
String uri = "/Users/" + newPerson.getId();
return Response.created(URI.create(uri)).entity(newPerson).build();
} catch (DuplicateEntryException ex) {
log.error("Failed to create user", ex);
ex.printStackTrace();
return getErrorResponse(ex.getMessage(), Response.Status.BAD_REQUEST.getStatusCode());
} catch (PersonRequiredFieldsException ex) {
log.error("PersonRequiredFieldsException: ", ex);
return getErrorResponse(ex.getMessage(), Response.Status.BAD_REQUEST.getStatusCode());
} catch (Exception ex) {
log.error("Failed to create user", ex);
ex.printStackTrace();
return getErrorResponse(ex.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
}
use of org.gluu.oxtrust.model.scim.ScimPerson in project oxTrust by GluuFederation.
the class UserWebService method searchPersons.
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@HeaderParam("Accept")
@DefaultValue(MediaType.APPLICATION_JSON)
public Response searchPersons(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_FILTER) final String filterString, @QueryParam(OxTrustConstants.QUERY_PARAMETER_START_INDEX) final int startIndex, @QueryParam(OxTrustConstants.QUERY_PARAMETER_COUNT) final int count, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_BY) final String sortBy, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_ORDER) final String sortOrder, @QueryParam(OxTrustConstants.QUERY_PARAMETER_ATTRIBUTES) final String attributesArray) throws Exception {
Response authorizationResponse = processAuthorization(authorization);
if (authorizationResponse != null) {
return authorizationResponse;
}
try {
if (count > getMaxCount()) {
String detail = "Too many results (=" + count + ") would be returned; max is " + getMaxCount() + " only.";
return getErrorResponse(detail, Response.Status.BAD_REQUEST.getStatusCode());
} else {
log.info(" Searching persons from LDAP ");
VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
List<GluuCustomPerson> gluuCustomPersons = search(personService.getDnForPerson(null), GluuCustomPerson.class, filterString, startIndex, count, sortBy, sortOrder, vlvResponse, attributesArray);
// List<GluuCustomPerson> personList = personService.findAllPersons(null);
GluuCustomPersonList personsList = new GluuCustomPersonList();
List<String> schema = new ArrayList<String>();
schema.add(Constants.SCIM1_CORE_SCHEMA_ID);
log.info(" setting schema");
personsList.setSchemas(schema);
// Set total
personsList.setTotalResults(vlvResponse.getTotalResults());
if (count > 0 && gluuCustomPersons != null && !gluuCustomPersons.isEmpty()) {
for (GluuCustomPerson gluuPerson : gluuCustomPersons) {
ScimPerson person = copyUtils.copy(gluuPerson, null);
log.info(" person to be added id : " + person.getUserName());
personsList.getResources().add(person);
log.info(" person added? : " + personsList.getResources().contains(person));
}
// Set the rest of results info
personsList.setItemsPerPage(vlvResponse.getItemsPerPage());
personsList.setStartIndex(vlvResponse.getStartIndex());
}
URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v1/Users");
// Serialize to JSON
ObjectMapper mapper = new ObjectMapper();
mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
SimpleModule customScimFilterModule = new SimpleModule("CustomScim1PersonFilterModule", new Version(1, 0, 0, ""));
GluuCustomPersonListSerializer serializer = new GluuCustomPersonListSerializer();
serializer.setAttributesArray(attributesArray);
customScimFilterModule.addSerializer(ScimPerson.class, serializer);
mapper.registerModule(customScimFilterModule);
String json = mapper.writeValueAsString(personsList);
return Response.ok(json).location(location).build();
}
} catch (Exception ex) {
log.error("Error in searchPersons", ex);
ex.printStackTrace();
return getErrorResponse(INTERNAL_SERVER_ERROR_MESSAGE, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
}
use of org.gluu.oxtrust.model.scim.ScimPerson in project oxTrust by GluuFederation.
the class CopyUtilsTestCreate method testCopyScim1MixedCreate.
@Test
public void testCopyScim1MixedCreate() throws Exception {
GluuCustomPerson destination = new GluuCustomPerson();
ScimPerson source = new ScimPerson();
source.setActive("false");
ScimPersonAddresses address = new ScimPersonAddresses();
address.setCountry("country");
address.setFormatted("");
address.setPostalCode("postalCode");
address.setPrimary("address_primary");
address.setRegion("region");
address.setLocality(null);
address.setStreetAddress("streetAddress");
address.setType("address_type");
List<ScimPersonAddresses> addresses = new ArrayList<ScimPersonAddresses>();
addresses.add(address);
source.setAddresses(addresses);
List<ScimCustomAttributes> customAttributes = new ArrayList<ScimCustomAttributes>();
source.setCustomAttributes(customAttributes);
source.setDisplayName("displayName");
ScimPersonEmails email = new ScimPersonEmails();
email.setPrimary("email_primary");
email.setType("email_type");
email.setValue("email_value");
List<ScimPersonEmails> emails = new ArrayList<ScimPersonEmails>();
emails.add(email);
source.setEmails(emails);
ScimEntitlements entitlement = new ScimEntitlements();
entitlement.setValue("entitlement_value");
List<ScimEntitlements> entitlements = new ArrayList<ScimEntitlements>();
entitlements.add(entitlement);
source.setEntitlements(entitlements);
source.setExternalId("externalId");
List<ScimPersonGroups> groups = new ArrayList<ScimPersonGroups>();
source.setGroups(groups);
source.setId("id");
ScimPersonIms personims = new ScimPersonIms();
personims.setType("ims_type");
personims.setValue("ims_value");
List<ScimPersonIms> ims = new ArrayList<ScimPersonIms>();
ims.add(personims);
source.setIms(ims);
source.setLocale("locale");
PersonMeta meta = new PersonMeta();
meta.setCreated("");
meta.setLastModified("");
meta.setLocation("");
meta.setVersion("");
source.setMeta(meta);
ScimName name = new ScimName();
name.setFamilyName("familyName");
name.setGivenName("givenName");
name.setHonorificPrefix("honorificPrefix");
name.setHonorificSuffix("honorificSuffix");
name.setMiddleName("middleName");
source.setName(name);
source.setNickName("nickName");
source.setPassword("password");
ScimPersonPhones phonenumber = new ScimPersonPhones();
phonenumber.setType("phone_type");
phonenumber.setValue("phone_value");
List<ScimPersonPhones> phoneNumbers = new ArrayList<ScimPersonPhones>();
phoneNumbers.add(phonenumber);
source.setPhoneNumbers(phoneNumbers);
ScimPersonPhotos photo = new ScimPersonPhotos();
photo.setType("photo_type");
photo.setValue("photo_value");
List<ScimPersonPhotos> photos = new ArrayList<ScimPersonPhotos>();
photos.add(photo);
source.setPhotos(photos);
source.setPreferredLanguage("");
source.setProfileUrl("profileUrl");
ScimRoles role = new ScimRoles();
role.setValue("role_value");
List<ScimRoles> roles = new ArrayList<ScimRoles>();
roles.add(role);
source.setRoles(roles);
List<String> schemas = new ArrayList<String>();
schemas.add("shema");
source.setSchemas(schemas);
source.setTimezone("");
source.setTitle("title");
source.setUserName("userName");
source.setUserType("userType");
source.setX509Certificates(null);
GluuCustomPerson copy = copyUtils.copy(source, destination, false);
assertNotNull(copy);
assertEquals(copy.getUid(), "userName");
assertEquals(copy.getGivenName(), "givenName");
assertEquals(copy.getSurname(), "familyName");
assertEquals(copy.getDisplayName(), "displayName");
assertNull(copy.getPreferredLanguage());
assertNull(copy.getTimezone());
assertEquals(copy.getUserPassword(), "password");
assertNotNull(copy.getMemberOf());
assertEquals(copy.getMemberOf().size(), 0);
assertEquals(copy.getAttribute(GLUU_STATUS), "false");
assertNull(copy.getAttribute(OX_TRUST_PHOTOS_TYPE));
assertNull(copy.getAttribute(OX_TRUST_PHONE_TYPE));
assertNull(copy.getAttribute(OX_TRUST_ADDRESS_PRIMARY));
assertNull(copy.getAttribute(OX_TRUST_ADDRESS_TYPE));
assertNull(copy.getAttribute(OX_TRUST_COUNTRY));
assertNull(copy.getAttribute(OX_TRUST_POSTAL_CODE));
assertNull(copy.getAttribute(OX_TRUST_REGION));
assertNull(copy.getAttribute(OX_TRUST_LOCALITY));
assertNull(copy.getAttribute(OX_TRUST_ADDRESS_FORMATTED));
assertNull(copy.getAttribute(OX_TRUST_STREET));
assertNull(copy.getAttribute(OX_TRUST_EMAIL_PRIMARY));
assertNull(copy.getAttribute(OX_TRUST_EMAIL_TYPE));
assertNull(copy.getAttribute(OX_TRUST_META_LOCATION));
assertNull(copy.getAttribute(OX_TRUST_META_VERSION));
assertNull(copy.getAttribute(OX_TRUST_META_LAST_MODIFIED));
assertNull(copy.getAttribute(OX_TRUST_META_CREATED));
assertNull(copy.getAttribute(OX_TRUSTX509_CERTIFICATE));
assertEquals(copy.getAttribute(OX_TRUST_ENTITLEMENTS), "[{\"value\":\"entitlement_value\"}]");
assertEquals(copy.getAttribute(OX_TRUST_ROLE), "[{\"value\":\"role_value\"}]");
assertEquals(copy.getAttribute(OX_TRUST_ACTIVE), "false");
assertEquals(copy.getAttribute(OX_TRUST_LOCALE), "locale");
assertEquals(copy.getAttribute(OX_TRUST_TITLE), "title");
assertEquals(copy.getAttribute(OX_TRUST_USER_TYPE), "userType");
assertEquals(copy.getAttribute(OX_TRUST_PHOTOS), "[{\"value\":\"photo_value\",\"type\":\"photo_type\"}]");
assertEquals(copy.getAttribute(OX_TRUST_IMS_VALUE), "[{\"value\":\"ims_value\",\"type\":\"ims_type\"}]");
assertEquals(copy.getAttribute(OX_TRUST_PHONE_VALUE), "[{\"value\":\"phone_value\",\"type\":\"phone_type\"}]");
assertEquals(copy.getAttribute(OX_TRUST_ADDRESSES), "[{\"type\":\"address_type\",\"streetAddress\":\"streetAddress\",\"locality\":null,\"region\":\"region\",\"postalCode\":\"postalCode\",\"country\":\"country\",\"formatted\":\"\",\"primary\":\"address_primary\"}]");
assertEquals(copy.getAttribute(OX_TRUST_EMAIL), "[{\"value\":\"email_value\",\"type\":\"email_type\",\"primary\":\"email_primary\"}]");
assertEquals(copy.getAttribute(OX_TRUST_PROFILE_URL), "profileUrl");
assertEquals(copy.getAttribute(OX_TRUST_NICK_NAME), "nickName");
assertEquals(copy.getAttribute(OX_TRUST_EXTERNAL_ID), "externalId");
assertEquals(copy.getAttribute(OX_TRUSTHONORIFIC_SUFFIX), "honorificSuffix");
assertEquals(copy.getAttribute(OX_TRUSTHONORIFIC_PREFIX), "honorificPrefix");
assertEquals(copy.getAttribute(OX_TRUST_MIDDLE_NAME), "middleName");
}
Aggregations