use of org.gluu.oxtrust.model.GluuCustomAttribute in project oxTrust by GluuFederation.
the class WhitePagesAction method getPhotoThumbData.
public byte[] getPhotoThumbData(GluuCustomPerson person) {
List<GluuAttribute> attributes = attributeService.getAllPersonAttributes(GluuUserRole.USER);
GluuAttribute photoAttribute = attributeService.getAttributeByName(PHOTO_NAME, attributes);
GluuCustomAttribute customAttribute = new GluuCustomAttribute(PHOTO_NAME, person.getAttribute(PHOTO_NAME));
customAttribute.setMetadata(photoAttribute);
GluuImage image = imageService.getImage(customAttribute);
if (image == null || (person.getGluuOptOuts() != null && person.getGluuOptOuts().contains(PHOTO_NAME))) {
return imageService.getBlankPhotoData();
}
return imageService.getThumImageData(image);
}
use of org.gluu.oxtrust.model.GluuCustomAttribute in project oxTrust by GluuFederation.
the class CacheRefreshTimer method getRemovedPersons.
private List<GluuSimplePerson> getRemovedPersons(HashMap<String, Integer> currInumWithEntryHashCodeMap, Map<String, Integer> prevInumWithEntryHashCodeMap) {
// First time run
if (prevInumWithEntryHashCodeMap == null) {
return new ArrayList<GluuSimplePerson>(0);
}
// Add all inums which not exist in new snapshot
Set<String> deletedInums = new HashSet<String>();
for (String prevInumKey : prevInumWithEntryHashCodeMap.keySet()) {
if (!currInumWithEntryHashCodeMap.containsKey(prevInumKey)) {
deletedInums.add(prevInumKey);
}
}
List<GluuSimplePerson> deletedPersons = new ArrayList<GluuSimplePerson>(deletedInums.size());
for (String deletedInum : deletedInums) {
GluuSimplePerson person = new GluuSimplePerson();
String personDn = personService.getDnForPerson(deletedInum);
person.setDn(personDn);
List<GluuCustomAttribute> customAttributes = new ArrayList<GluuCustomAttribute>();
customAttributes.add(new GluuCustomAttribute(OxTrustConstants.inum, deletedInum));
person.setCustomAttributes(customAttributes);
deletedPersons.add(person);
}
return deletedPersons;
}
use of org.gluu.oxtrust.model.GluuCustomAttribute in project oxTrust by GluuFederation.
the class ServiceUtil method syncEmailForward.
/**
* One-way sync from "oxTrustEmail" to "mail". Ultimately this is persisted so "mail" will be
* updated by values from "oxTrustEmail".
*
* @param gluuCustomPerson
* @return
* @throws Exception
*/
public static GluuCustomPerson syncEmailForward(GluuCustomPerson gluuCustomPerson, boolean isScim2) throws Exception {
logger.info(" IN Utils.syncEmailForward()...");
GluuCustomAttribute oxTrustEmail = gluuCustomPerson.getGluuCustomAttribute("oxTrustEmail");
if (oxTrustEmail != null && oxTrustEmail.getValues().length > 0) {
// JSON array in element 0
String[] oxTrustEmails = oxTrustEmail.getValues();
String[] newMails = new String[oxTrustEmails.length];
ObjectMapper mapper = getObjectMapper();
if (isScim2) {
for (int i = 0; i < oxTrustEmails.length; i++) {
Email email = mapper.readValue(oxTrustEmails[i], Email.class);
newMails[i] = email.getValue();
}
} else {
for (int i = 0; i < oxTrustEmails.length; i++) {
ScimPersonEmails email = mapper.readValue(oxTrustEmails[i], ScimPersonEmails.class);
newMails[i] = email.getValue();
}
}
gluuCustomPerson.setAttribute("mail", newMails);
/* // Just do nothing if null, same as in UserWebService.updateUser()
} else {
gluuCustomPerson.setAttribute("mail", new String[0]);
*/
}
logger.info(" LEAVING Utils.syncEmailForward()...");
return gluuCustomPerson;
}
use of org.gluu.oxtrust.model.GluuCustomAttribute in project oxTrust by GluuFederation.
the class UpdatePersonAction method save.
/**
* Saves person to ldap
*
* @return String describing success of the operation
*/
public String save() throws Exception {
if (!organizationService.isAllowPersonModification()) {
return OxTrustConstants.RESULT_FAILURE;
}
updateCustomObjectClasses();
List<GluuCustomAttribute> removedAttributes = customAttributeAction.detectRemovedAttributes();
customAttributeAction.updateOriginCustomAttributes();
List<GluuCustomAttribute> customAttributes = customAttributeAction.getCustomAttributes();
for (GluuCustomAttribute customAttribute : customAttributes) {
if (customAttribute.getName().equalsIgnoreCase("gluuStatus")) {
customAttribute.setValue(gluuStatus.getValue());
}
}
this.person.setCustomAttributes(customAttributeAction.getCustomAttributes());
this.person.getCustomAttributes().addAll(removedAttributes);
// Sync email, in reverse ("oxTrustEmail" <- "mail")
this.person = ServiceUtil.syncEmailReverse(this.person, true);
if (update) {
try {
if (externalUpdateUserService.isEnabled()) {
externalUpdateUserService.executeExternalUpdateUserMethods(this.person);
}
personService.updatePerson(this.person);
} catch (LdapMappingException ex) {
log.error("Failed to update person {}", ex, inum);
return OxTrustConstants.RESULT_FAILURE;
}
} else {
if (personService.getPersonByUid(this.person.getUid()) != null) {
return OxTrustConstants.RESULT_DUPLICATE;
}
this.inum = personService.generateInumForNewPerson();
String iname = personService.generateInameForNewPerson(this.person.getUid());
String dn = personService.getDnForPerson(this.inum);
// Save person
this.person.setDn(dn);
this.person.setInum(this.inum);
this.person.setIname(iname);
this.person.setUserPassword(this.password);
List<GluuCustomAttribute> personAttributes = this.person.getCustomAttributes();
if (!personAttributes.contains(new GluuCustomAttribute("cn", ""))) {
List<GluuCustomAttribute> changedAttributes = new ArrayList<GluuCustomAttribute>();
changedAttributes.addAll(personAttributes);
changedAttributes.add(new GluuCustomAttribute("cn", this.person.getGivenName() + " " + this.person.getDisplayName()));
this.person.setCustomAttributes(changedAttributes);
} else {
this.person.setCommonName(this.person.getCommonName() + " " + this.person.getGivenName());
}
try {
if (externalUpdateUserService.isEnabled()) {
externalUpdateUserService.executeExternalAddUserMethods(this.person);
}
personService.addPerson(this.person);
} catch (Exception ex) {
log.error("Failed to add new person {}", ex, this.person.getInum());
return OxTrustConstants.RESULT_FAILURE;
}
this.update = true;
}
return OxTrustConstants.RESULT_SUCCESS;
}
use of org.gluu.oxtrust.model.GluuCustomAttribute in project oxTrust by GluuFederation.
the class PersonImportAction method save.
public String save() {
if (!organizationService.isAllowPersonModification()) {
return OxTrustConstants.RESULT_FAILURE;
}
personService.addCustomObjectClass(this.person);
if (personService.getPersonByUid(this.person.getUid()) != null) {
return OxTrustConstants.RESULT_DUPLICATE;
}
this.inum = personService.generateInumForNewPerson();
String iname = personService.generateInameForNewPerson(this.person.getUid());
String dn = personService.getDnForPerson(this.inum);
// Save person
this.person.setDn(dn);
this.person.setInum(this.inum);
this.person.setIname(iname);
List<GluuCustomAttribute> personAttributes = this.person.getCustomAttributes();
if (!personAttributes.contains(new GluuCustomAttribute("cn", ""))) {
List<GluuCustomAttribute> changedAttributes = new ArrayList<GluuCustomAttribute>();
changedAttributes.addAll(personAttributes);
changedAttributes.add(new GluuCustomAttribute("cn", this.person.getGivenName() + " " + this.person.getDisplayName()));
this.person.setCustomAttributes(changedAttributes);
} else {
this.person.setCommonName(this.person.getCommonName() + " " + this.person.getGivenName());
}
try {
if (externalUpdateUserService.isEnabled()) {
externalUpdateUserService.executeExternalAddUserMethods(this.person);
}
personService.addPerson(this.person);
} catch (Exception ex) {
log.error("Failed to add new person {}", ex, this.person.getInum());
return OxTrustConstants.RESULT_FAILURE;
}
return OxTrustConstants.RESULT_SUCCESS;
}
Aggregations