| | |
| | | |
| | | import static org.opends.messages.UtilityMessages.*; |
| | | import static org.opends.server.loggers.ErrorLogger.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | import static org.forgerock.util.Reject.*; |
| | | |
| | |
| | | import org.opends.server.backends.jeb.importLDIF.Suffix; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.PluginConfigManager; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.opends.server.protocols.ldap.LDAPAttribute; |
| | | import org.opends.server.protocols.ldap.LDAPModification; |
| | | import org.opends.server.types.*; |
| | |
| | | mayInvoke=true) |
| | | public final class LDIFReader implements Closeable |
| | | { |
| | | /** |
| | | * The tracer object for the debug logger. |
| | | */ |
| | | private static final DebugTracer TRACER = getTracer(); |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | /** The reader that will be used to read the data. */ |
| | | private BufferedReader reader; |
| | |
| | | } |
| | | else if (!importConfig.includeEntry(entryDN)) |
| | | { |
| | | if (debugEnabled()) |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugInfo("Skipping entry %s because the DN isn't" + |
| | | logger.trace("Skipping entry %s because the DN isn't" + |
| | | "one that should be included based on the include and " + |
| | | "exclude branches.", entryDN); |
| | | } |
| | |
| | | suffix = Importer.getMatchSuffix(entryDN, map); |
| | | if(suffix == null) |
| | | { |
| | | if (debugEnabled()) |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugInfo("Skipping entry %s because the DN isn't" + |
| | | logger.trace("Skipping entry %s because the DN isn't" + |
| | | "one that should be included based on a suffix match" + |
| | | "check." ,entryDN); |
| | | } |
| | |
| | | } |
| | | catch (LDIFException e) |
| | | { |
| | | if (debugEnabled()) |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugInfo("Skipping entry %s because reading" + |
| | | logger.trace("Skipping entry %s because reading" + |
| | | "its attributes failed.", entryDN); |
| | | } |
| | | LocalizableMessage message = ERR_LDIF_READ_ATTR_SKIP.get(String.valueOf(entryDN), |
| | |
| | | toAttributesMap(operationalAttrBuilders); |
| | | Entry entry = new Entry(entryDN, objectClasses, userAttributes, |
| | | operationalAttributes); |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, entry.toString()); |
| | | logger.trace(entry.toString()); |
| | | |
| | | try |
| | | { |
| | | if (! importConfig.includeEntry(entry)) |
| | | { |
| | | if (debugEnabled()) |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugInfo("Skipping entry %s because the DN is not one " + |
| | | logger.trace("Skipping entry %s because the DN is not one " + |
| | | "that should be included based on the include and exclude " + |
| | | "filters.", entryDN); |
| | | } |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | suffix.removePending(entryDN); |
| | | LocalizableMessage message = ERR_LDIF_COULD_NOT_EVALUATE_FILTERS_FOR_IMPORT. |
| | | get(String.valueOf(entry.getName()), lastEntryLineNumber, |
| | |
| | | } |
| | | else if (!importConfig.includeEntry(entryDN)) |
| | | { |
| | | if (debugEnabled()) |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugInfo("Skipping entry %s because the DN is not one that " + |
| | | logger.trace("Skipping entry %s because the DN is not one that " + |
| | | "should be included based on the include and exclude branches.", |
| | | entryDN); |
| | | } |
| | |
| | | toAttributesMap(operationalAttrBuilders); |
| | | Entry entry = new Entry(entryDN, objectClasses, userAttributes, |
| | | operationalAttributes); |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, entry.toString()); |
| | | logger.trace(entry.toString()); |
| | | |
| | | try |
| | | { |
| | | if (! importConfig.includeEntry(entry)) |
| | | { |
| | | if (debugEnabled()) |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugInfo("Skipping entry %s because the DN is not one " + |
| | | logger.trace("Skipping entry %s because the DN is not one " + |
| | | "that should be included based on the include and exclude " + |
| | | "filters.", entryDN); |
| | | } |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | |
| | | LocalizableMessage message = ERR_LDIF_COULD_NOT_EVALUATE_FILTERS_FOR_IMPORT. |
| | | get(String.valueOf(entry.getName()), lastEntryLineNumber, |
| | |
| | | { |
| | | // The value did not have a valid base64-encoding. |
| | | final String stackTrace = StaticUtils.stackTraceToSingleLineString(e); |
| | | if (debugEnabled()) |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugInfo( |
| | | logger.trace( |
| | | "Base64 decode failed for dn '%s', exception stacktrace: %s", |
| | | encodedStr, stackTrace); |
| | | } |
| | |
| | | } |
| | | catch (DirectoryException de) |
| | | { |
| | | if (debugEnabled()) |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugInfo("DN decode failed for: ", dnString); |
| | | logger.trace("DN decode failed for: ", dnString); |
| | | } |
| | | |
| | | LocalizableMessage message = ERR_LDIF_INVALID_DN.get( |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugInfo("DN decode failed for: ", dnString); |
| | | logger.trace("DN decode failed for: ", dnString); |
| | | } |
| | | LocalizableMessage message = ERR_LDIF_INVALID_DN.get( |
| | | lastEntryLineNumber, line.toString(), |
| | |
| | | { |
| | | if (! importConfig.includeObjectClasses()) |
| | | { |
| | | if (debugEnabled()) |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugVerbose("Skipping objectclass %s for entry %s due to " + |
| | | logger.trace("Skipping objectclass %s for entry %s due to " + |
| | | "the import configuration.", value, entryDN); |
| | | } |
| | | return; |
| | |
| | | |
| | | if (! importConfig.includeAttribute(attrType)) |
| | | { |
| | | if (debugEnabled()) |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugVerbose("Skipping attribute %s for entry %s due to the " + |
| | | logger.trace("Skipping attribute %s for entry %s due to the " + |
| | | "import configuration.", attrName, entryDN); |
| | | } |
| | | return; |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | rejectWriter.newLine(); |
| | | } catch (IOException ex) { |
| | | if (debugEnabled()) |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, ex); |
| | | if (logger.isTraceEnabled()) |
| | | logger.traceException(ex); |
| | | } |
| | | } |
| | | } |
| | |
| | | newRDN = RDN.decode(rdnStr); |
| | | } catch (DirectoryException de) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, de); |
| | | } |
| | | logger.traceException(de); |
| | | LocalizableMessage message = ERR_LDIF_INVALID_DN.get( |
| | | lineNumber, line.toString(), de.getMessageObject()); |
| | | throw new LDIFException(message, lineNumber, true); |
| | | } catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | LocalizableMessage message = |
| | | ERR_LDIF_INVALID_DN.get(lineNumber, line.toString(), e.getMessage()); |
| | | throw new LDIFException(message, lineNumber, true); |
| | |
| | | newSuperiorDN = DN.valueOf(dnStr); |
| | | } catch (DirectoryException de) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, de); |
| | | } |
| | | logger.traceException(de); |
| | | LocalizableMessage message = ERR_LDIF_INVALID_DN.get( |
| | | lineNumber, line.toString(), de.getMessageObject()); |
| | | throw new LDIFException(message, lineNumber, true); |
| | | } catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | LocalizableMessage message = ERR_LDIF_INVALID_DN.get( |
| | | lineNumber, line.toString(), e.getMessage()); |
| | | throw new LDIFException(message, lineNumber, true); |
| | |
| | | catch (Exception e) |
| | | { |
| | | // The value did not have a valid base64-encoding. |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | |
| | | LocalizableMessage message = ERR_LDIF_COULD_NOT_BASE64_DECODE_ATTR.get( |
| | | String.valueOf(entryDN), |
| | |
| | | catch (Exception e) |
| | | { |
| | | // The URL was malformed or had an invalid protocol. |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | |
| | | LocalizableMessage message = ERR_LDIF_INVALID_URL.get(String.valueOf(entryDN), |
| | | lastEntryLineNumber, |
| | |
| | | catch (Exception e) |
| | | { |
| | | // We were unable to read the contents of that URL for some reason. |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | |
| | | LocalizableMessage message = ERR_LDIF_URL_IO_ERROR.get(String.valueOf(entryDN), |
| | | lastEntryLineNumber, |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | } |
| | | } |
| | | } |