use of org.gluu.persist.model.AttributeData in project oxCore by GluuFederation.
the class LdapEntryManager method persist.
@Override
protected void persist(String dn, List<AttributeData> attributes) {
List<Attribute> ldapAttributes = new ArrayList<Attribute>(attributes.size());
for (AttributeData attribute : attributes) {
String attributeName = attribute.getName();
String[] attributeValues = attribute.getValues();
if (ArrayHelper.isNotEmpty(attributeValues) && StringHelper.isNotEmpty(attributeValues[0])) {
if (ldapOperationService.isCertificateAttribute(attributeName)) {
byte[][] binaryValues = toBinaryValues(attributeValues);
ldapAttributes.add(new Attribute(attributeName + ";binary", binaryValues));
} else {
ldapAttributes.add(new Attribute(attributeName, attributeValues));
}
}
}
// Persist entry
try {
boolean result = this.ldapOperationService.addEntry(dn, ldapAttributes);
if (!result) {
throw new EntryPersistenceException(String.format("Failed to persist entry: %s", dn));
}
} catch (ConnectionException ex) {
throw new EntryPersistenceException(String.format("Failed to persist entry: %s", dn), ex.getCause());
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to persist entry: %s", dn), ex);
}
}
use of org.gluu.persist.model.AttributeData in project oxCore by GluuFederation.
the class LdapEntryManager method createEntities.
protected <T> List<T> createEntities(Class<T> entryClass, List<PropertyAnnotation> propertiesAnnotations, SearchResultEntry... searchResultEntries) {
List<T> result = new ArrayList<T>(searchResultEntries.length);
Map<String, List<AttributeData>> entriesAttributes = new HashMap<String, List<AttributeData>>(100);
int count = 0;
for (int i = 0; i < searchResultEntries.length; i++) {
count++;
SearchResultEntry entry = searchResultEntries[i];
entriesAttributes.put(entry.getDN(), getAttributeDataList(entry));
// Remove reference to allow java clean up object
searchResultEntries[i] = null;
// Allow java to clean up temporary objects
if (count >= 100) {
List<T> currentResult = createEntities(entryClass, propertiesAnnotations, entriesAttributes);
result.addAll(currentResult);
entriesAttributes = new HashMap<String, List<AttributeData>>(100);
count = 0;
}
}
List<T> currentResult = createEntities(entryClass, propertiesAnnotations, entriesAttributes);
result.addAll(currentResult);
return result;
}
use of org.gluu.persist.model.AttributeData in project oxCore by GluuFederation.
the class LdapEntryManager method find.
@Override
protected List<AttributeData> find(String dn, String... ldapReturnAttributes) {
try {
SearchResultEntry entry = this.ldapOperationService.lookup(dn, ldapReturnAttributes);
List<AttributeData> result = getAttributeDataList(entry);
if (result != null) {
return result;
}
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entry: %s", dn), ex);
}
throw new EntryPersistenceException(String.format("Failed to find entry: %s", dn));
}
use of org.gluu.persist.model.AttributeData in project oxCore by GluuFederation.
the class LdapEntryManager method getAttributeDataList.
private List<AttributeData> getAttributeDataList(SearchResultEntry entry) {
if (entry == null) {
return null;
}
List<AttributeData> result = new ArrayList<AttributeData>();
for (Attribute attribute : entry.getAttributes()) {
String[] attributeValueStrings = NO_STRINGS;
String attributeName = attribute.getName();
if (LOG.isTraceEnabled()) {
if (attribute.needsBase64Encoding()) {
LOG.trace("Found binary attribute: " + attributeName + ". Is defined in LDAP config: " + ldapOperationService.isBinaryAttribute(attributeName));
}
}
attributeValueStrings = attribute.getValues();
if (attribute.needsBase64Encoding()) {
boolean binaryAttribute = ldapOperationService.isBinaryAttribute(attributeName);
boolean certificateAttribute = ldapOperationService.isCertificateAttribute(attributeName);
if (binaryAttribute || certificateAttribute) {
byte[][] attributeValues = attribute.getValueByteArrays();
if (attributeValues != null) {
attributeValueStrings = new String[attributeValues.length];
for (int i = 0; i < attributeValues.length; i++) {
attributeValueStrings[i] = Base64.encodeBase64String(attributeValues[i]);
LOG.trace("Binary attribute: " + attribute.getName() + " value (hex): " + org.apache.commons.codec.binary.Hex.encodeHexString(attributeValues[i]) + " value (base64): " + attributeValueStrings[i]);
}
}
}
if (certificateAttribute) {
attributeName = ldapOperationService.getCertificateAttributeName(attributeName);
}
}
AttributeData tmpAttribute = new AttributeData(attributeName, attributeValueStrings);
result.add(tmpAttribute);
}
return result;
}
use of org.gluu.persist.model.AttributeData in project oxCore by GluuFederation.
the class LdapEntryManager method createEntitiesVirtualListView.
@Deprecated
private <T> List<T> createEntitiesVirtualListView(Class<T> entryClass, List<PropertyAnnotation> propertiesAnnotations, SearchResultEntry... searchResultEntries) {
List<T> result = new LinkedList<T>();
Map<String, List<AttributeData>> entriesAttributes = new LinkedHashMap<String, List<AttributeData>>(100);
int count = 0;
for (int i = 0; i < searchResultEntries.length; i++) {
count++;
SearchResultEntry entry = searchResultEntries[i];
LinkedList<AttributeData> attributeDataLinkedList = new LinkedList<AttributeData>();
attributeDataLinkedList.addAll(getAttributeDataList(entry));
entriesAttributes.put(entry.getDN(), attributeDataLinkedList);
// Remove reference to allow java clean up object
searchResultEntries[i] = null;
// Allow java to clean up temporary objects
if (count >= 100) {
List<T> currentResult = new LinkedList<T>();
currentResult.addAll(createEntities(entryClass, propertiesAnnotations, entriesAttributes, false));
result.addAll(currentResult);
entriesAttributes = new LinkedHashMap<String, List<AttributeData>>(100);
count = 0;
}
}
List<T> currentResult = createEntities(entryClass, propertiesAnnotations, entriesAttributes, false);
result.addAll(currentResult);
return result;
}
Aggregations