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;
}
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;
}
}
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");
}
}
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;
}
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;
}
Aggregations