Search in sources :

Example 1 with ResultCode

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

the class LdifDataUtility method deleteEntryWithAllSubs.

/**
	 * Remove base entry with all sub entries
	 * 
	 * @param connection
	 *            Connection to LDAP server
	 * @param baseDN
	 *            Base DN entry
	 * @return The result code for the processing that was performed.
	 */
public ResultCode deleteEntryWithAllSubs(LDAPConnection connection, String baseDN) {
    ResultCode resultCode = ResultCode.SUCCESS;
    SearchResult searchResult = null;
    try {
        searchResult = connection.search(baseDN, SearchScope.SUB, "objectClass=*");
        if ((searchResult == null) || (searchResult.getEntryCount() == 0)) {
            return ResultCode.LOCAL_ERROR;
        }
    } catch (LDAPSearchException le) {
        log.error("Failed to search subordinate entries", le);
        return ResultCode.LOCAL_ERROR;
    }
    LinkedList<String> dns = new LinkedList<String>();
    for (SearchResultEntry entry : searchResult.getSearchEntries()) {
        dns.add(entry.getDN());
    }
    ListIterator<String> listIterator = dns.listIterator(dns.size());
    while (listIterator.hasPrevious()) {
        try {
            connection.delete(listIterator.previous());
        } catch (LDAPException le) {
            log.error("Failed to delete entry", le);
            resultCode = ResultCode.LOCAL_ERROR;
            break;
        }
    }
    return resultCode;
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) LDAPSearchException(com.unboundid.ldap.sdk.LDAPSearchException) SearchResult(com.unboundid.ldap.sdk.SearchResult) ResultCode(com.unboundid.ldap.sdk.ResultCode) LinkedList(java.util.LinkedList) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

Example 2 with ResultCode

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

the class AttributeImportAction method importAttributes.

public String importAttributes() throws Exception {
    if (!fileDataToImport.isReady()) {
        return OxTrustConstants.RESULT_FAILURE;
    }
    InputStream is = new ByteArrayInputStream(fileDataToImport.getData());
    ResultCode result = null;
    try {
        result = ldifService.importLdifFileInLdap(is);
    } catch (LDAPException ex) {
        facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to import LDIF file");
    } finally {
        IOUtils.closeQuietly(is);
    }
    removeFileToImport();
    if ((result != null) && result.equals(ResultCode.SUCCESS)) {
        facesMessages.add(FacesMessage.SEVERITY_INFO, "Attributes added successfully");
        return OxTrustConstants.RESULT_SUCCESS;
    } else {
        facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to import LDIF file");
        return OxTrustConstants.RESULT_FAILURE;
    }
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ResultCode(com.unboundid.ldap.sdk.ResultCode)

Example 3 with ResultCode

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

the class AttributeImportAction method validateFileToImport.

public void validateFileToImport() {
    removeFileDataToImport();
    String dn = attributeService.getDnForAttribute(null);
    if (uploadedFile == null) {
        return;
    }
    InputStream is = new ByteArrayInputStream(this.fileData);
    ResultCode result = null;
    try {
        result = ldifService.validateLdifFile(is, dn);
    } catch (LDAPException ex) {
        facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to parse LDIF file");
    } finally {
        IOUtils.closeQuietly(is);
    }
    if ((result != null) && result.equals(ResultCode.SUCCESS)) {
        this.fileDataToImport.setReady(true);
        this.fileDataToImport.setData(this.fileData);
    } else {
        removeFileDataToImport();
        this.fileDataToImport.setReady(false);
        facesMessages.add(FacesMessage.SEVERITY_ERROR, "Invalid LDIF File. Validation failed");
    }
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ResultCode(com.unboundid.ldap.sdk.ResultCode)

Example 4 with ResultCode

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

the class LdifService method importLdifFileInLdap.

public ResultCode importLdifFileInLdap(InputStream is) throws LDAPException {
    ResultCode result = ResultCode.UNAVAILABLE;
    LDAPConnection connection = ldapEntryManager.getLdapOperationService().getConnection();
    try {
        LdifDataUtility ldifDataUtility = LdifDataUtility.instance();
        LDIFReader importLdifReader = new LDIFReader(is);
        result = ldifDataUtility.importLdifFile(connection, importLdifReader);
        importLdifReader.close();
    } catch (Exception ex) {
        log.error("Failed to import ldif file: ", ex);
    } finally {
        ldapEntryManager.getLdapOperationService().releaseConnection(connection);
    }
    return result;
}
Also used : LDIFReader(com.unboundid.ldif.LDIFReader) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) LdifDataUtility(org.gluu.site.ldap.persistence.LdifDataUtility) ResultCode(com.unboundid.ldap.sdk.ResultCode) IOException(java.io.IOException) LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException) LDAPException(com.unboundid.ldap.sdk.LDAPException)

Example 5 with ResultCode

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

the class LdifService method validateLdifFile.

public ResultCode validateLdifFile(InputStream is, String dn) throws LDAPException {
    ResultCode result = ResultCode.UNAVAILABLE;
    try {
        LdifDataUtility ldifDataUtility = LdifDataUtility.instance();
        LDIFReader validateLdifReader = new LDIFReader(is);
        result = ldifDataUtility.validateLDIF(validateLdifReader, dn);
        validateLdifReader.close();
    } catch (Exception ex) {
        log.error("Failed to validate ldif file: ", ex);
    }
    return result;
}
Also used : LDIFReader(com.unboundid.ldif.LDIFReader) LdifDataUtility(org.gluu.site.ldap.persistence.LdifDataUtility) ResultCode(com.unboundid.ldap.sdk.ResultCode) IOException(java.io.IOException) LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException) LDAPException(com.unboundid.ldap.sdk.LDAPException)

Aggregations

ResultCode (com.unboundid.ldap.sdk.ResultCode)7 LDAPException (com.unboundid.ldap.sdk.LDAPException)5 IOException (java.io.IOException)4 LDIFReader (com.unboundid.ldif.LDIFReader)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 LdifDataUtility (org.gluu.site.ldap.persistence.LdifDataUtility)2 LdapMappingException (org.gluu.site.ldap.persistence.exception.LdapMappingException)2 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)1 LDAPSearchException (com.unboundid.ldap.sdk.LDAPSearchException)1 SearchResult (com.unboundid.ldap.sdk.SearchResult)1 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)1 LDIFChangeRecord (com.unboundid.ldif.LDIFChangeRecord)1 LDIFException (com.unboundid.ldif.LDIFException)1 LdapException (com.zimbra.cs.ldap.LdapException)1 LinkedList (java.util.LinkedList)1