use of org.xdi.model.GluuAttribute in project oxTrust by GluuFederation.
the class UserSerializer method serializeUserExtension.
protected void serializeUserExtension(Map.Entry<String, JsonNode> rootNodeEntry, ObjectMapper mapper, User user, JsonGenerator jsonGenerator) throws Exception {
Extension extension = user.getExtension(rootNodeEntry.getKey());
Map<String, Object> list = new HashMap<String, Object>();
boolean enclosingWritten = false;
for (Map.Entry<String, Extension.Field> extEntry : extension.getFields().entrySet()) {
if (attributes != null && attributes.size() > 0) {
for (String attribute : attributes) {
attribute = FilterUtil.stripScim2Schema(attribute);
if (extEntry.getKey().equalsIgnoreCase(attribute)) {
if (!enclosingWritten) {
jsonGenerator.writeFieldName(rootNodeEntry.getKey());
enclosingWritten = true;
}
break;
}
}
} else {
if (!enclosingWritten) {
jsonGenerator.writeFieldName(rootNodeEntry.getKey());
enclosingWritten = true;
}
}
if (enclosingWritten) {
GluuAttribute gluuAttribute = attributeService.getAttributeByName(extEntry.getKey());
GluuAttributeDataType attributeDataType = gluuAttribute.getDataType();
if ((gluuAttribute.getOxMultivaluedAttribute() != null) && gluuAttribute.getOxMultivaluedAttribute().equals(OxMultivalued.TRUE)) {
if (attributeDataType.equals(GluuAttributeDataType.STRING) || attributeDataType.equals(GluuAttributeDataType.PHOTO)) {
List<String> stringList = Arrays.asList(mapper.readValue(extEntry.getValue().getValue(), String[].class));
list.put(extEntry.getKey(), stringList);
} else if (attributeDataType.equals(GluuAttributeDataType.DATE)) {
List<Date> dateList = Arrays.asList(mapper.readValue(extEntry.getValue().getValue(), Date[].class));
List<String> stringList = new ArrayList<String>();
DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime().withZoneUTC();
for (Date date : dateList) {
String dateString = dateTimeFormatter.print(date.getTime());
stringList.add(dateString);
}
list.put(extEntry.getKey(), stringList);
} else if (attributeDataType.equals(GluuAttributeDataType.NUMERIC)) {
List<BigDecimal> numberList = Arrays.asList(mapper.readValue(extEntry.getValue().getValue(), BigDecimal[].class));
list.put(extEntry.getKey(), numberList);
}
} else {
list.put(extEntry.getKey(), extEntry.getValue().getValue());
}
}
}
if (enclosingWritten) {
jsonGenerator.writeObject(list);
}
}
use of org.xdi.model.GluuAttribute in project oxTrust by GluuFederation.
the class AttributeService method generateInumForNewAttribute.
/**
* Generate new inum for attribute
*
* @return New inum for attribute
*/
public String generateInumForNewAttribute() {
GluuAttribute attribute = null;
String newInum = null;
do {
newInum = generateInumForNewAttributeImpl();
String newDn = getDnForAttribute(newInum);
attribute = new GluuAttribute();
attribute.setDn(newDn);
} while (containsAttribute(attribute));
return newInum;
}
use of org.xdi.model.GluuAttribute in project oxTrust by GluuFederation.
the class AttributeService method removeAttribute.
/**
* Remove attribute with specified Inum
*
* @param inum
* Inum
*/
public void removeAttribute(String inum) {
GluuAttribute attribute = new GluuAttribute();
attribute.setDn(getDnForAttribute(inum));
removeAttribute(attribute);
}
use of org.xdi.model.GluuAttribute in project oxTrust by GluuFederation.
the class AttributeService method searchPersonAttributes.
public List<GluuAttribute> searchPersonAttributes(String pattern, int sizeLimit) throws Exception {
String[] objectClassTypes = appConfiguration.getPersonObjectClassTypes();
String[] targetArray = new String[] { pattern };
List<Filter> originFilters = new ArrayList<Filter>();
Filter displayNameFilter = Filter.createSubstringFilter(OxTrustConstants.displayName, null, targetArray, null);
Filter descriptionFilter = Filter.createSubstringFilter(OxTrustConstants.description, null, targetArray, null);
Filter inameFilter = Filter.createSubstringFilter(OxTrustConstants.iname, null, targetArray, null);
for (String objectClassType : objectClassTypes) {
Filter originFilter = Filter.createEqualityFilter(OxTrustConstants.origin, objectClassType);
originFilters.add(originFilter);
}
Filter searchFilter = Filter.createORFilter(displayNameFilter, descriptionFilter, inameFilter);
Filter originFilter = Filter.createORFilter(originFilters.toArray(new Filter[0]));
Filter filter = Filter.createANDFilter(searchFilter, originFilter);
List<GluuAttribute> result = ldapEntryManager.findEntries(getDnForAttribute(null), GluuAttribute.class, filter, 0, sizeLimit);
return result;
}
use of org.xdi.model.GluuAttribute in project oxTrust by GluuFederation.
the class AttributeService method getCustomAttributesByAttributeDNs.
/**
* Get custom attributes by attribute DNs
*
* @param customAttributes
* List of attribute DNs
* @param attributes
* List of custom attributes
*/
public List<GluuCustomAttribute> getCustomAttributesByAttributeDNs(List<String> attributeDNs, HashMap<String, GluuAttribute> attributesByDNs) {
List<GluuCustomAttribute> customAttributes = new ArrayList<GluuCustomAttribute>();
if (attributeDNs == null) {
return customAttributes;
}
for (String releasedAttributeDn : attributeDNs) {
GluuAttribute attribute = attributesByDNs.get(releasedAttributeDn);
if (attribute != null) {
GluuCustomAttribute customAttribute = new GluuCustomAttribute(attribute.getName(), releasedAttributeDn);
customAttribute.setMetadata(attribute);
customAttributes.add(customAttribute);
}
}
return customAttributes;
}
Aggregations