use of org.gluu.oxtrust.model.GluuCustomPerson in project oxTrust by GluuFederation.
the class CopyUtils2 method copy.
/**
* Copy data from ScimPerson object to GluuCustomPerson object "Reda"
*
* @param source
* @param destination
* @return
* @throws Exception
*/
public GluuCustomPerson copy(User source, GluuCustomPerson destination, boolean isUpdate) throws Exception {
if (source == null || !isValidData(source, isUpdate)) {
return null;
}
if (destination == null) {
log.trace(" creating a new GluuCustomPerson instant ");
destination = new GluuCustomPerson();
}
log.trace(" setting schemas ");
destination.setSchemas(source.getSchemas());
if (isUpdate) {
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 && source.getName().getGivenName().length() > 0) {
destination.setGivenName(source.getName().getGivenName());
}
log.trace(" setting famillyname ");
if (source.getName().getFamilyName() != null && source.getName().getFamilyName().length() > 0) {
destination.setSurname(source.getName().getFamilyName());
}
log.trace(" setting middlename ");
if (source.getName().getMiddleName() != null && source.getName().getMiddleName().length() > 0) {
// destination.setAttribute("oxTrustMiddleName", source.getName().getMiddleName());
destination.setAttribute("middleName", source.getName().getMiddleName());
}
log.trace(" setting honor");
if (source.getName().getHonorificPrefix() != null && source.getName().getHonorificPrefix().length() > 0) {
destination.setAttribute("oxTrusthonorificPrefix", source.getName().getHonorificPrefix());
}
if (source.getName().getHonorificSuffix() != null && source.getName().getHonorificSuffix().length() > 0) {
destination.setAttribute("oxTrusthonorificSuffix", source.getName().getHonorificSuffix());
}
}
log.trace(" setting displayname ");
if (source.getDisplayName() != null && source.getDisplayName().length() > 0) {
destination.setDisplayName(source.getDisplayName());
}
log.trace(" setting externalID ");
if (source.getExternalId() != null && source.getExternalId().length() > 0) {
destination.setAttribute("oxTrustExternalId", source.getExternalId());
}
log.trace(" setting nickname ");
if (source.getNickName() != null && source.getNickName().length() > 0) {
// destination.setAttribute("oxTrustNickName", source.getNickName());
destination.setAttribute("nickname", source.getNickName());
}
log.trace(" setting profileURL ");
if (source.getProfileUrl() != null && source.getProfileUrl().length() > 0) {
destination.setAttribute("oxTrustProfileURL", source.getProfileUrl());
}
// getting emails
log.trace(" setting emails ");
if (source.getEmails() != null && source.getEmails().size() > 0) {
/*
List<Email> emails = source.getEmails();
// StringWriter listOfEmails = new StringWriter();
// mapper.writeValue(listOfEmails, emails);
List<String> emailList = new ArrayList<String>();
for (Email email : emails) {
emailList.add(mapper.writeValueAsString(email));
}
// destination.setAttribute("oxTrustEmail", listOfEmails.toString());
destination.setAttribute("oxTrustEmail", emailList.toArray(new String[]{}));
*/
setAttributeListValue(destination, source.getEmails(), "oxTrustEmail");
}
// getting addresses
log.trace(" setting addresses ");
if (source.getAddresses() != null && source.getAddresses().size() > 0) {
setAttributeListValue(destination, source.getAddresses(), "oxTrustAddresses");
}
// getting phone numbers;
log.trace(" setting phoneNumbers ");
if (source.getPhoneNumbers() != null && source.getPhoneNumbers().size() > 0) {
setAttributeListValue(destination, source.getPhoneNumbers(), "oxTrustPhoneValue");
}
// getting ims
log.trace(" setting ims ");
if (source.getIms() != null && source.getIms().size() > 0) {
setAttributeListValue(destination, source.getIms(), "oxTrustImsValue");
}
// getting Photos
log.trace(" setting photos ");
if (source.getPhotos() != null && source.getPhotos().size() > 0) {
setAttributeListValue(destination, source.getPhotos(), "oxTrustPhotos");
}
if (source.getUserType() != null && source.getUserType().length() > 0) {
destination.setAttribute("oxTrustUserType", source.getUserType());
}
if (source.getTitle() != null && source.getTitle().length() > 0) {
destination.setAttribute("oxTrustTitle", source.getTitle());
}
if (source.getPreferredLanguage() != null && source.getPreferredLanguage().length() > 0) {
destination.setPreferredLanguage(source.getPreferredLanguage());
}
if (source.getLocale() != null && source.getLocale().length() > 0) {
// destination.setAttribute("oxTrustLocale", source.getLocale());
destination.setAttribute("locale", source.getLocale());
}
if (source.getTimezone() != null && source.getTimezone().length() > 0) {
destination.setTimezone(source.getTimezone());
}
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<GroupRef> listGroups = source.getGroups();
List<String> members = new ArrayList<String>();
for (GroupRef group : listGroups) {
members.add(groupService.getDnForGroup(group.getValue()));
}
destination.setMemberOf(members);
}
// getting roles
log.trace(" setting roles ");
if (source.getRoles() != null && source.getRoles().size() > 0) {
setAttributeListValue(destination, source.getRoles(), "oxTrustRole");
}
// getting entitlements
log.trace(" setting entitlements ");
if (source.getEntitlements() != null && source.getEntitlements().size() > 0) {
setAttributeListValue(destination, source.getEntitlements(), "oxTrustEntitlements");
}
// getting x509Certificates
log.trace(" setting certs ");
if (source.getX509Certificates() != null && source.getX509Certificates().size() > 0) {
setAttributeListValue(destination, source.getX509Certificates(), "oxTrustx509Certificate");
}
log.trace(" setting extensions ");
if (source.getExtensions() != null && (source.getExtensions().size() > 0)) {
destination.setExtensions(source.getExtensions());
}
/*
// getting customAttributes
log.trace("getting custom attributes");
if (source.getCustomAttributes() != null) {
log.trace("source.getCustomAttributes() != null");
log.trace("getting a list of ScimCustomAttributes");
List<CustomAttributes> customAttr = source.getCustomAttributes();
log.trace("checling every attribute in the request");
for (CustomAttributes oneAttr : customAttr) {
if (oneAttr == null) {
continue;
}
int countValues = oneAttr.getValues().size();
if (countValues == 0) {
log.trace("setting a empty attribute");
destination.setAttribute(oneAttr.getName().replaceAll(" ", ""), oneAttr.getValues().toArray(new String[0]));
} else if (countValues == 1) {
log.trace("setting a single attribute");
destination.setAttribute(oneAttr.getName().replaceAll(" ", ""), oneAttr.getValues().get(0));
} else if (countValues > 1) {
log.trace("setting a multivalued attribute");
List<String> listOfAttr = oneAttr.getValues();
String[] AttrArray = new String[listOfAttr.size()];
int i = 0;
for (String oneValue : listOfAttr) {
if (oneValue != null && oneValue.length() > 0) {
log.trace("setting a value");
AttrArray[i] = oneValue;
i++;
}
}
log.trace("setting the list of multivalued attributes");
destination.setAttribute(oneAttr.getName().replaceAll(" ", ""), AttrArray);
}
}
}
*/
// log.trace("getting meta attributes");
/*
if (source.getMeta()!=null && source.getMeta().getAttributes() != null) {
log.trace("source.getCustomAttributes() != null");
log.trace("getting a list of ScimCustomAttributes");
Set<String> customAttr = source.getMeta().getAttributes();
log.trace("checling every attribute in the request");
for (String oneAttr : customAttr) {
if (oneAttr == null) {
continue;
}
destination.setAttribute(oneAttr.replaceAll(" ", ""), "");
*/
/* NOTE : WRITE CODE FOR THIS
int countValues = oneAttr.getValues().size();
if (countValues == 0) {
log.trace("setting a empty attribute");
destination.setAttribute(oneAttr.getName().replaceAll(" ", ""), oneAttr.getValues().toArray(new String[0]));
} else if (countValues == 1) {
log.trace("setting a single attribute");
destination.setAttribute(oneAttr.getName().replaceAll(" ", ""), oneAttr.getValues().get(0));
} else if (countValues > 1) {
log.trace("setting a multivalued attribute");
List<String> listOfAttr = oneAttr.getValues();
String[] AttrArray = new String[listOfAttr.size()];
int i = 0;
for (String oneValue : listOfAttr) {
if (oneValue != null && oneValue.length() > 0) {
log.trace("setting a value");
AttrArray[i] = oneValue;
i++;
}
}
log.trace("setting the list of multivalued attributes");
destination.setAttribute(oneAttr.getName().replaceAll(" ", ""), AttrArray);
}
*/
/*
}
}
*/
} else {
try {
if (personService.getPersonByUid(source.getUserName()) != null) {
throw new DuplicateEntryException("Duplicate UID value: " + source.getUserName());
}
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 && source.getName().getGivenName().length() > 0) {
destination.setGivenName(source.getName().getGivenName());
}
log.trace(" setting famillyname ");
if (source.getName().getFamilyName() != null && source.getName().getFamilyName().length() > 0) {
destination.setSurname(source.getName().getFamilyName());
}
log.trace(" setting middlename ");
if (source.getName().getMiddleName() != null && source.getName().getMiddleName().length() > 0) {
destination.setAttribute("middleName", source.getName().getMiddleName());
}
log.trace(" setting honor");
if (source.getName().getHonorificPrefix() != null && source.getName().getHonorificPrefix().length() > 0) {
destination.setAttribute("oxTrusthonorificPrefix", source.getName().getHonorificPrefix());
}
if (source.getName().getHonorificSuffix() != null && source.getName().getHonorificSuffix().length() > 0) {
destination.setAttribute("oxTrusthonorificSuffix", source.getName().getHonorificSuffix());
}
}
log.trace(" setting displayname ");
if (source.getDisplayName() != null && source.getDisplayName().length() > 0) {
destination.setDisplayName(source.getDisplayName());
}
log.trace(" setting externalID ");
if (source.getExternalId() != null && source.getExternalId().length() > 0) {
destination.setAttribute("oxTrustExternalId", source.getExternalId());
}
log.trace(" setting nickname ");
if (source.getNickName() != null && source.getNickName().length() > 0) {
destination.setAttribute("nickname", source.getNickName());
}
log.trace(" setting profileURL ");
if (source.getProfileUrl() != null && source.getProfileUrl().length() > 0) {
destination.setAttribute("oxTrustProfileURL", source.getProfileUrl());
}
// getting emails
log.trace(" setting emails ");
if (source.getEmails() != null && source.getEmails().size() > 0) {
/*
List<Email> emails = source.getEmails();
// StringWriter listOfEmails = new StringWriter();
// mapper.writeValue(listOfEmails, emails);
List<String> emailList = new ArrayList<String>();
for (Email email : emails) {
emailList.add(mapper.writeValueAsString(email));
}
// destination.setAttribute("oxTrustEmail", listOfEmails.toString());
destination.setAttribute("oxTrustEmail", emailList.toArray(new String[]{}));
*/
setAttributeListValue(destination, source.getEmails(), "oxTrustEmail");
}
// getting addresses
log.trace(" setting addresses ");
if (source.getAddresses() != null && source.getAddresses().size() > 0) {
setAttributeListValue(destination, source.getAddresses(), "oxTrustAddresses");
}
// getting phone numbers;
log.trace(" setting phoneNumbers ");
if (source.getPhoneNumbers() != null && source.getPhoneNumbers().size() > 0) {
setAttributeListValue(destination, source.getPhoneNumbers(), "oxTrustPhoneValue");
}
// getting ims
log.trace(" setting ims ");
if (source.getIms() != null && source.getIms().size() > 0) {
setAttributeListValue(destination, source.getIms(), "oxTrustImsValue");
}
// getting Photos
log.trace(" setting photos ");
if (source.getPhotos() != null && source.getPhotos().size() > 0) {
setAttributeListValue(destination, source.getPhotos(), "oxTrustPhotos");
}
if (source.getUserType() != null && source.getUserType().length() > 0) {
destination.setAttribute("oxTrustUserType", source.getUserType());
}
if (source.getTitle() != null && source.getTitle().length() > 0) {
destination.setAttribute("oxTrustTitle", source.getTitle());
}
if (source.getPreferredLanguage() != null && source.getPreferredLanguage().length() > 0) {
destination.setPreferredLanguage(source.getPreferredLanguage());
}
if (source.getLocale() != null && source.getLocale().length() > 0) {
// destination.setAttribute("oxTrustLocale", source.getLocale());
destination.setAttribute("locale", source.getLocale());
}
if (source.getTimezone() != null && source.getTimezone().length() > 0) {
destination.setTimezone(source.getTimezone());
}
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<GroupRef> listGroups = source.getGroups();
List<String> members = new ArrayList<String>();
for (GroupRef group : listGroups) {
members.add(groupService.getDnForGroup(group.getValue()));
}
destination.setMemberOf(members);
}
// getting roles
log.trace(" setting roles ");
if (source.getRoles() != null && source.getRoles().size() > 0) {
setAttributeListValue(destination, source.getRoles(), "oxTrustRole");
}
// getting entitlements
log.trace(" setting entitlements ");
if (source.getEntitlements() != null && source.getEntitlements().size() > 0) {
setAttributeListValue(destination, source.getEntitlements(), "oxTrustEntitlements");
}
// getting x509Certificates
log.trace(" setting certs ");
if (source.getX509Certificates() != null && source.getX509Certificates().size() > 0) {
setAttributeListValue(destination, source.getX509Certificates(), "oxTrustx509Certificate");
}
log.trace(" setting extensions ");
if (source.getExtensions() != null && (source.getExtensions().size() > 0)) {
destination.setExtensions(source.getExtensions());
}
/*
// getting customAttributes
log.trace("getting custom attributes");
if (source.getCustomAttributes() != null && source.getCustomAttributes().size() > 0) {
log.trace("source.getCustomAttributes() != null");
log.trace("getting a list of CustomAttributes");
List<CustomAttributes> customAttr = source.getCustomAttributes();
log.trace("checling every attribute in the request");
for (CustomAttributes oneAttr : customAttr) {
if (oneAttr != null && oneAttr.getValues().size() == 1) {
log.trace("setting a single attribute");
destination.setAttribute(oneAttr.getName().replaceAll(" ", ""), oneAttr.getValues().get(0));
} else if (oneAttr != null && oneAttr.getValues().size() > 1) {
log.trace("setting a multivalued attribute");
List<String> listOfAttr = oneAttr.getValues();
String[] AttrArray = new String[listOfAttr.size()];
int i = 0;
for (String oneValue : listOfAttr) {
if (oneValue != null && oneValue.length() > 0) {
log.trace("setting a value");
AttrArray[i] = oneValue;
i++;
}
}
log.trace("setting the list of multivalued attributes");
destination.setAttribute(oneAttr.getName().replaceAll(" ", ""), AttrArray);
}
}
}
*/
} catch (DuplicateEntryException e) {
throw e;
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
setGluuStatus(source, destination);
return destination;
}
use of org.gluu.oxtrust.model.GluuCustomPerson in project oxTrust by GluuFederation.
the class CopyUtils2 method copy.
public GluuGroup copy(ScimGroup source, GluuGroup destination, List<GluuGroup> attributes) throws Exception {
if (source == null) {
return null;
}
if (destination == null) {
destination = new GluuGroup();
}
destination.setInum(source.getId());
destination.setDisplayName(source.getDisplayName());
List<ScimGroupMembers> mapMembers = source.getMembers();
List<String> listMembers = new ArrayList<String>();
for (String dn : listMembers) {
GluuCustomPerson gluuPerson = personService.getPersonByDn(dn);
ScimGroupMembers member = new ScimGroupMembers();
member.setDisplay(gluuPerson.getDisplayName());
member.setValue(gluuPerson.getInum());
mapMembers.add(member);
}
destination.setMembers(listMembers);
return destination;
}
use of org.gluu.oxtrust.model.GluuCustomPerson in project oxTrust by GluuFederation.
the class CopyUtils2 method copy.
/**
* Copy data from GluuCustomPerson object to Person object
*
* @param source
* @param destination
* @return
* @throws Exception
*/
public Person copy(GluuCustomPerson source, Person destination, List<GluuAttribute> attributes) {
if (source == null) {
return null;
}
if (destination == null) {
destination = new Person();
}
destination.setInum(source.getInum());
destination.setIname(source.getIname());
destination.setUserId(source.getUid());
destination.setFirstName(source.getGivenName());
destination.setDisplayName(source.getDisplayName());
destination.setLastName(source.getSurname());
destination.setEmail(source.getMail());
destination.setPassword(source.getUserPassword());
destination.setCommonName(source.getGivenName() + " " + source.getDisplayName());
List<PersonAttribute> personAttrList = new ArrayList<PersonAttribute>();
for (GluuAttribute attribute : attributes) {
PersonAttribute personAttr = new PersonAttribute(attribute.getName(), source.getAttribute(attribute.getName()), attribute.getDisplayName());
personAttrList.add(personAttr);
}
destination.setPersonAttrList(personAttrList);
return destination;
}
use of org.gluu.oxtrust.model.GluuCustomPerson in project oxTrust by GluuFederation.
the class BulkWebService method createUser.
private boolean createUser(ScimPerson person) throws Exception {
GluuCustomPerson gluuPerson = copyUtils.copy(person, null, false);
if (gluuPerson == null) {
return false;
}
try {
// inumService.generateInums(Configuration.INUM_TYPE_PEOPLE_SLUG);
String inum = personService.generateInumForNewPerson();
// //personService.generateInumForNewPerson();
String dn = personService.getDnForPerson(inum);
String iname = personService.generateInameForNewPerson(person.getUserName());
gluuPerson.setDn(dn);
gluuPerson.setInum(inum);
gluuPerson.setIname(iname);
gluuPerson.setCommonName(gluuPerson.getGivenName() + " " + gluuPerson.getSurname());
if (person.getGroups().size() > 0) {
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);
}
personService.addPerson(gluuPerson);
return true;
} 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 updateUser.
private boolean updateUser(String uid, ScimPerson person_update) throws Exception {
try {
GluuCustomPerson gluuPerson = personService.getPersonByInum(uid);
if (gluuPerson == null) {
return false;
}
gluuPerson = copyUtils.copy(person_update, gluuPerson, true);
if (person_update.getGroups().size() > 0) {
serviceUtil.groupMembersAdder(gluuPerson, personService.getDnForPerson(uid));
}
// Sync email, forward ("oxTrustEmail" -> "mail")
gluuPerson = ServiceUtil.syncEmailForward(gluuPerson, false);
// For custom script: update user
if (externalScimService.isEnabled()) {
externalScimService.executeScimUpdateUserMethods(gluuPerson);
}
personService.updatePerson(gluuPerson);
return true;
} catch (EntryPersistenceException ex) {
log.error("Exception: ", ex);
return false;
} catch (Exception ex) {
log.error("Exception: ", ex);
ex.printStackTrace();
return false;
}
}
Aggregations