Search in sources :

Example 11 with SearchResultEntry

use of com.unboundid.ldap.sdk.SearchResultEntry 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;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) AttributeData(org.gluu.persist.model.AttributeData) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

Example 12 with SearchResultEntry

use of com.unboundid.ldap.sdk.SearchResultEntry 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));
}
Also used : EntryPersistenceException(org.gluu.persist.exception.mapping.EntryPersistenceException) AttributeData(org.gluu.persist.model.AttributeData) SearchException(org.gluu.persist.exception.operation.SearchException) AuthenticationException(org.gluu.persist.exception.operation.AuthenticationException) MappingException(org.gluu.persist.exception.mapping.MappingException) SearchScopeException(org.gluu.persist.exception.operation.SearchScopeException) ParseException(java.text.ParseException) EntryPersistenceException(org.gluu.persist.exception.mapping.EntryPersistenceException) ConnectionException(org.gluu.persist.exception.operation.ConnectionException) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

Example 13 with SearchResultEntry

use of com.unboundid.ldap.sdk.SearchResultEntry 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;
}
Also used : ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) LinkedList(java.util.LinkedList) AttributeData(org.gluu.persist.model.AttributeData) LinkedHashMap(java.util.LinkedHashMap) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

Example 14 with SearchResultEntry

use of com.unboundid.ldap.sdk.SearchResultEntry in project oxCore by GluuFederation.

the class LdapEntryManager method getLDIF.

@Override
public List<String[]> getLDIF(String dn, String[] attributes) {
    SearchResult searchResult;
    try {
        searchResult = this.ldapOperationService.search(dn, toLdapFilter(Filter.create("objectclass=*")), toLdapSearchScope(SearchScope.BASE), -1, 0, null, attributes);
        if (!ResultCode.SUCCESS.equals(searchResult.getResultCode())) {
            throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s", dn));
        }
    } catch (Exception ex) {
        throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s, filter: %s", dn, null), ex);
    }
    List<String[]> result = new ArrayList<String[]>();
    if (searchResult.getEntryCount() == 0) {
        return result;
    }
    for (SearchResultEntry searchResultEntry : searchResult.getSearchEntries()) {
        result.add(searchResultEntry.toLDIF());
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) EntryPersistenceException(org.gluu.persist.exception.mapping.EntryPersistenceException) SearchResult(com.unboundid.ldap.sdk.SearchResult) SearchException(org.gluu.persist.exception.operation.SearchException) AuthenticationException(org.gluu.persist.exception.operation.AuthenticationException) MappingException(org.gluu.persist.exception.mapping.MappingException) SearchScopeException(org.gluu.persist.exception.operation.SearchScopeException) ParseException(java.text.ParseException) EntryPersistenceException(org.gluu.persist.exception.mapping.EntryPersistenceException) ConnectionException(org.gluu.persist.exception.operation.ConnectionException) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

Example 15 with SearchResultEntry

use of com.unboundid.ldap.sdk.SearchResultEntry in project oxTrust by GluuFederation.

the class LdifService method exportLDIFFile.

public void exportLDIFFile(List<String> checkedItems, OutputStream output) throws LDAPException {
    List<SearchResultEntry> result = null;
    LDAPConnection connection = ldapEntryManager.getOperationService().getConnection();
    try {
        LdifDataUtility ldifDataUtility = LdifDataUtility.instance();
        result = ldifDataUtility.getAttributeResultEntryLDIF(connection, checkedItems, attributeService.getDnForAttribute(null));
    } catch (Exception ex) {
        log.error("Failed to export ldif file: ", ex);
    } finally {
        ldapEntryManager.getOperationService().releaseConnection(connection);
    }
    if (result != null && result.size() > 0) {
        // Write all of the matching entries to LDIF.
        LDIFWriter ldifWriter;
        try {
            ldifWriter = new LDIFWriter(output);
            for (SearchResultEntry entry : result) {
                ldifWriter.writeEntry(entry);
            }
            ldifWriter.close();
        } catch (IOException e) {
            throw new BaseMappingException("Error writing to file, try again", e);
        }
    }
}
Also used : BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) LDIFWriter(com.unboundid.ldif.LDIFWriter) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) IOException(java.io.IOException) LdifDataUtility(org.gluu.persist.ldap.impl.LdifDataUtility) IOException(java.io.IOException) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) LDAPException(com.unboundid.ldap.sdk.LDAPException) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

Aggregations

SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)31 SearchResult (com.unboundid.ldap.sdk.SearchResult)22 ArrayList (java.util.ArrayList)13 LDAPException (com.unboundid.ldap.sdk.LDAPException)11 SearchException (org.gluu.persist.exception.operation.SearchException)10 MappingException (org.gluu.persist.exception.mapping.MappingException)9 ConnectionException (org.gluu.persist.exception.operation.ConnectionException)9 SearchRequest (com.unboundid.ldap.sdk.SearchRequest)7 EntryPersistenceException (org.gluu.persist.exception.mapping.EntryPersistenceException)7 LdapConnection (com.gitblit.ldap.LdapConnection)6 ParseException (java.text.ParseException)6 AuthenticationException (org.gluu.persist.exception.operation.AuthenticationException)6 SearchScopeException (org.gluu.persist.exception.operation.SearchScopeException)6 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)5 BindResult (com.unboundid.ldap.sdk.BindResult)5 LDAPSearchException (com.unboundid.ldap.sdk.LDAPSearchException)5 TeamModel (com.gitblit.models.TeamModel)4 Attribute (com.unboundid.ldap.sdk.Attribute)4 LinkedList (java.util.LinkedList)4 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)3