0N/A * The contents of this file are subject to the terms of the 0N/A * Common Development and Distribution License, Version 1.0 only 0N/A * (the "License"). You may not use this file except in compliance 0N/A * You can obtain a copy of the license at 0N/A * See the License for the specific language governing permissions 0N/A * and limitations under the License. 0N/A * When distributing Covered Code, include this CDDL HEADER in each 0N/A * file and include the License file at 0N/A * add the following below this CDDL HEADER, with the fields enclosed 873N/A * by brackets "[]" replaced with your own identifying information: 0N/A * Portions Copyright [yyyy] [name of copyright owner] 5137N/A * Copyright 2006-2010 Sun Microsystems, Inc. 6318N/A * Portions Copyright 2012-2013 ForgeRock AS 0N/A * This class provides the ability to read information from an LDIF file. It 0N/A * provides support for both standard entries and change entries (as would be 0N/A * used with a tool like ldapmodify). 1400N/A * The tracer object for the debug logger. 0N/A // The reader that will be used to read the data. 0N/A // The buffer to use to read data from a URL. 0N/A // The import configuration that specifies what should be imported. 0N/A // The lines that comprise the body of the last entry read. 0N/A // The lines that comprise the header (DN and any comments) for the last entry 0N/A // The number of entries that have been ignored by this LDIF reader because 0N/A // they didn't match the criteria. 0N/A // The number of entries that have been read by this LDIF reader, including 0N/A // those that were ignored because they didn't match the criteria, and 0N/A // including those that were rejected because they were invalid in some way. 0N/A // The number of entries that have been rejected by this LDIF reader. 0N/A // The line number on which the last entry started. 0N/A // The line number of the last line read from the LDIF file, starting with 1. 0N/A // The plugin config manager that will be used if we are to invoke plugins 0N/A // on the entries as they are read. 0N/A * Creates a new LDIF reader that will read information from the specified 402N/A * @param importConfig The import configuration for this LDIF reader. It 402N/A * must not be <CODE>null</CODE>. 0N/A * @throws IOException If a problem occurs while opening the LDIF file for 4748N/A // If we should invoke import plugins, then do so. 4748N/A // Inform LDIF import plugins that an import session is ending 4591N/A * Creates a new LDIF reader that will read information from the 4591N/A * The import configuration for this LDIF reader. It must not 4591N/A * @param rootContainer The root container needed to get the next entry ID. 4591N/A * @param size The size of the buffer to read the LDIF bytes into. 4591N/A * If a problem occurs while opening the LDIF file for 4748N/A // If we should invoke import plugins, then do so. 4748N/A // Inform LDIF import plugins that an import session is ending 0N/A * Reads the next entry from the LDIF source. 0N/A * @return The next entry read from the LDIF source, or <CODE>null</CODE> if 0N/A * the end of the LDIF data is reached. 0N/A * @throws IOException If an I/O problem occurs while reading from the file. 0N/A * @throws LDIFException If the information read cannot be parsed as an LDIF 4643N/A * Reads the next entry from the LDIF source. 4591N/A * @return The next entry read from the LDIF source, or <CODE>null</CODE> if 4591N/A * the end of the LDIF data is reached. 4643N/A * @param map A map of suffixes instances. 4643N/A * @param entryInfo A object to hold information about the entry ID and what 4591N/A * @throws IOException If an I/O problem occurs while reading from the file. 4591N/A * @throws LDIFException If the information read cannot be parsed as an LDIF 4591N/A // Read the set of lines that make up the next entry. 4591N/A // Read the DN of the entry and see if it is one that should be included 4591N/A // This should only happen if the LDIF starts with the "version:" line 4591N/A // and has a blank line immediately after that. In that case, simply 4591N/A // read and return the next entry. 4591N/A "one that should be included based on the include and " +
4707N/A "one that should be included based on a suffix match" +
4591N/A // Read the set of attributes from the entry. 4591N/A // Create the entry and see if it is one that should be included in the 5849N/A // Create the entry and see if it is one that should be included in the 4591N/A "that should be included based on the include and exclude " +
4591N/A // If we should invoke import plugins, then do so. 4591N/A // Make sure that the entry is valid as per the server schema if it is 5169N/A //Add any superior objectclass(s) missing in the objectclass map. 4591N/A // The entry should be included in the import, so return it. 0N/A * Reads the next entry from the LDIF source. 0N/A * @param checkSchema Indicates whether this reader should perform schema 0N/A * checking on the entry before returning it to the 0N/A * caller. Note that some basic schema checking (like 0N/A * refusing multiple values for a single-valued 0N/A * attribute) may always be performed. 0N/A * @return The next entry read from the LDIF source, or <CODE>null</CODE> if 0N/A * the end of the LDIF data is reached. 0N/A * @throws IOException If an I/O problem occurs while reading from the file. 0N/A * @throws LDIFException If the information read cannot be parsed as an LDIF 0N/A // Read the set of lines that make up the next entry. 0N/A // Read the DN of the entry and see if it is one that should be included 0N/A // This should only happen if the LDIF starts with the "version:" line 0N/A // and has a blank line immediately after that. In that case, simply 0N/A // read and return the next entry. 1400N/A "should be included based on the include and exclude branches.",
0N/A // Read the set of attributes from the entry. 0N/A // Create the entry and see if it is one that should be included in the 1400N/A "that should be included based on the include and exclude " +
0N/A // If we should invoke import plugins, then do so. 0N/A // Make sure that the entry is valid as per the server schema if it is 0N/A // appropriate to do so. 4388N/A //Add any superior objectclass(s) missing in an entries 0N/A // The entry should be included in the import, so return it. 0N/A * Reads the next change record from the LDIF source. 0N/A * @param defaultAdd Indicates whether the change type should default to 0N/A * "add" if none is explicitly provided. 0N/A * @return The next change record from the LDIF source, or <CODE>null</CODE> 0N/A * if the end of the LDIF data is reached. 0N/A * @throws IOException If an I/O problem occurs while reading from the file. 0N/A * @throws LDIFException If the information read cannot be parsed as an LDIF 0N/A // Read the set of lines that make up the next entry. 0N/A // Read the DN of the entry and see if it is one that should be included 0N/A // This should only happen if the LDIF starts with the "version:" line 0N/A // and has a blank line immediately after that. In that case, simply 0N/A // read and return the next entry. 0N/A // default to "add"? 0N/A * Reads a set of lines from the next entry in the LDIF source. 0N/A * @return A set of lines from the next entry in the LDIF source. 0N/A * @throws IOException If a problem occurs while reading from the LDIF 0N/A * @throws LDIFException If the information read is not valid LDIF. 0N/A // Read the entry lines into a buffer. 0N/A // This must mean that we have reached the end of the LDIF source. 0N/A // If the set of lines read so far is empty, then move onto the next 0N/A // file or return null. Otherwise, break out of this loop. 0N/A // This is a blank line. If the set of lines read so far is empty, 0N/A // then just skip over it. Otherwise, break out of this loop. 0N/A // This is a comment. Ignore it. 0N/A // This is a continuation of the previous line. If there is no 465N/A // previous line, then that's a problem. Note that while RFC 2849 465N/A // technically only allows a space in this position, both OpenLDAP and 465N/A // the Sun Java System Directory Server allow a tab as well, so we will 465N/A // too for compatibility reasons. See issue #852 for details. 0N/A // This is a new line. 5137N/A // This is a UTF-8 BOM that Java doesn't skip. We will skip it here. 0N/A * Reads the DN of the entry from the provided list of lines. The DN must be 0N/A * the first line in the list, unless the first line starts with "version", 0N/A * in which case the DN should be the second line. 0N/A * @param lines The set of lines from which the DN should be read. 0N/A * @return The decoded entry DN. 0N/A * @throws LDIFException If DN is not the first element in the list (or the 0N/A * second after the LDIF version), or if a problem 0N/A * occurs while trying to parse it. 0N/A // This is possible if the contents of the first "entry" were just 0N/A // the version identifier. If that is the case, then return null and 0N/A // use that as a signal to the caller to go ahead and read the next entry. 0N/A // This is the version line, and we can skip it. 0N/A // Look at the character immediately after the colon. If there is none, 0N/A // then assume the null DN. If it is another colon, then the DN must be 0N/A // base64-encoded. Otherwise, it may be one or more spaces. 0N/A // The DN is base64-encoded. Find the first non-blank character and 0N/A // take the rest of the line, base64-decode it, and parse it as a DN. 0N/A // The value did not have a valid base64-encoding. 0N/A // The rest of the value should be the DN. Skip over any spaces and 0N/A // attempt to decode the rest of the line as the DN. 0N/A * Reads the changetype of the entry from the provided list of lines. If 0N/A * there is no changetype attribute then an add is assumed. 0N/A * @param lines The set of lines from which the DN should be read. 0N/A * @return The decoded entry DN. 0N/A * @throws LDIFException If DN is not the first element in the list (or the 0N/A * second after the LDIF version), or if a problem 0N/A * occurs while trying to parse it. 0N/A // Error. There must be other entries. 0N/A // No changetype attribute - return null 0N/A // Look at the character immediately after the colon. If there is none, 0N/A // then no value was specified. Throw an exception 0N/A // The change type is base64-encoded. Find the first non-blank 0N/A // take the rest of the line, and base64-decode it. 0N/A // The value did not have a valid base64-encoding. 0N/A // The rest of the value should be the changetype. 0N/A // Skip over any spaces and 0N/A // attempt to decode the rest of the line as the changetype string. 0N/A * Decodes the provided line as an LDIF attribute and adds it to the 0N/A * @param lines The full set of lines that comprise the 0N/A * entry (used for writing reject information). 0N/A * @param line The line to decode. 0N/A * @param entryDN The DN of the entry being decoded. 0N/A * @param objectClasses The set of objectclasses decoded so far for 0N/A * the current entry. 4591N/A * @param userAttrBuilders The map of user attribute builders decoded 4591N/A * so far for the current entry. 4591N/A * @param operationalAttrBuilders The map of operational attribute builders 4591N/A * decoded so far for the current entry. 1101N/A * @param checkSchema Indicates whether to perform schema 1101N/A * validation for the attribute. 0N/A * @throws LDIFException If a problem occurs while trying to decode the 0N/A * attribute contained in the provided entry. 165N/A // Parse the attribute type description. 165N/A // Now parse the attribute value. 0N/A // See if this is an objectclass or an attribute. Then get the 0N/A // corresponding definition and add the value to the appropriate hash. 3853N/A //The attribute is not being ignored so check for binary option. 0N/A // Check to see if any of the attributes in the list have the same set of 0N/A // options. If so, then try to add a value to that attribute. 3853N/A // No set of matching options was found, so create a new one and 0N/A * Decodes the provided line as an LDIF attribute and returns the 0N/A * Attribute (name and values) for the specified attribute name. 0N/A * @param lines The full set of lines that comprise the 0N/A * entry (used for writing reject information). 0N/A * @param line The line to decode. 0N/A * @param entryDN The DN of the entry being decoded. 770N/A * @param attributeName The name and options of the attribute to 770N/A * return the values for. 0N/A * @return The attribute in octet string form. 0N/A * @throws LDIFException If a problem occurs while trying to decode 0N/A * the attribute contained in the provided 0N/A * entry or if the parsed attribute name does 0N/A * not match the specified attribute name. 165N/A // Parse the attribute type description. 165N/A // Now parse the attribute value. 0N/A * Retrieves the starting line number for the last entry read from the LDIF 0N/A * @return The starting line number for the last entry read from the LDIF 0N/A * Rejects the last entry read from the LDIF. This method is intended for use 0N/A * by components that perform their own validation of entries (e.g., backends 0N/A * during import processing) in which the entry appeared valid to the LDIF 0N/A * reader but some other problem was encountered. 0N/A * @param message A human-readable message providing the reason that the 0N/A * last entry read was not acceptable. 4328N/A * Log the specified entry and messages in the reject writer. The method is 4328N/A * intended to be used in a threaded environment, where individual import 4328N/A * threads need to log an entry and message to the reject file. 4328N/A * @param e The entry to log. 4328N/A * @param message The message to log. 0N/A * Closes this LDIF reader and the underlying file or input stream. 4748N/A // If we should invoke import plugins, then do so. 4748N/A // Inform LDIF import plugins that an import session is ending 3853N/A * Parse an AttributeDescription (an attribute type name and its 3853N/A * The attribute description to be parsed. 3853N/A * @return A new attribute with no values, representing the 3853N/A * attribute type and its options. 3853N/A //resetting doesn't hurt and returns false. 0N/A * Retrieves the total number of entries read so far by this LDIF reader, 0N/A * including those that have been ignored or rejected. 0N/A * @return The total number of entries read so far by this LDIF reader. 0N/A * Retrieves the total number of entries that have been ignored so far by this 0N/A * LDIF reader because they did not match the import criteria. 0N/A * @return The total number of entries ignored so far by this LDIF reader. 0N/A * Retrieves the total number of entries rejected so far by this LDIF reader. 0N/A * This includes both entries that were rejected because of internal 0N/A * validation failure (e.g., they didn't conform to the defined server 0N/A * schema) or an external validation failure (e.g., the component using this 0N/A * LDIF reader didn't accept the entry because it didn't have a parent). 0N/A * @return The total number of entries rejected so far by this LDIF reader. 165N/A * Parse a modifyDN change record entry from LDIF. 165N/A * The name of the entry being modified. 165N/A * @return Returns the parsed modifyDN change record entry. 165N/A * @throws LDIFException 165N/A * If there was an error when parsing the change record. 165N/A * Return the string value for the specified attribute name which only 165N/A * The set of lines for this change record entry. 165N/A * The line currently being examined. 165N/A * The name of the entry being modified. 165N/A * @return the string value for the attribute name. 165N/A * @throws LDIFException 165N/A * If a problem occurs while attempting to determine the 165N/A * Parse a modify change record entry from LDIF. 165N/A * The name of the entry being modified. 165N/A * @return Returns the parsed modify change record entry. 165N/A * @throws LDIFException 165N/A * If there was an error when parsing the change record. 165N/A // Get the attribute description 165N/A // Invalid attribute name. 3853N/A "add, delete, replace, increment");
165N/A // Now go through the rest of the attributes till the "-" line is 165N/A * Parse a delete change record entry from LDIF. 165N/A * The name of the entry being deleted. 165N/A * @return Returns the parsed delete change record entry. 165N/A * @throws LDIFException 165N/A * If there was an error when parsing the change record. 165N/A * Parse an add change record entry from LDIF. 165N/A * The name of the entry being added. 165N/A * @return Returns the parsed add change record entry. 165N/A * @throws LDIFException 165N/A * If there was an error when parsing the change record. 165N/A // Reconstruct the object class attribute. 165N/A * Parse colon position in an attribute description. 165N/A * The current set of lines. 165N/A * @return The colon position. 165N/A * @throws LDIFException 165N/A * If the colon was badly placed or not found. 165N/A * Parse a single attribute value from a line of LDIF. 165N/A * The current set of lines. 165N/A * The DN of the entry being parsed. 165N/A * The position of the separator colon in the line. 165N/A * The name of the attribute being parsed. 165N/A * @return The parsed attribute value. 165N/A * @throws LDIFException 165N/A * If an error occurred when parsing the attribute value. 165N/A // Look at the character immediately after the colon. If there is 165N/A // none, then assume an attribute with an empty value. If it is another 165N/A // colon, then the value must be base64-encoded. If it is a less-than 165N/A // sign, then assume that it is a URL. Otherwise, it is a regular value. 165N/A // The value is base64-encoded. Find the first non-blank 165N/A // character, take the rest of the line, and base64-decode it. 165N/A // The value did not have a valid base64-encoding. 165N/A // Find the first non-blank character, decode the rest of the 165N/A // line as a URL, and read its contents. 165N/A // The URL was malformed or had an invalid protocol. 165N/A // We were unable to read the contents of that URL for some 165N/A // The rest of the line should be the value. Skip over any 165N/A // spaces and take the rest of the line as the value. 165N/A * Log a message to the reject writer if one is configured. 165N/A * The set of rejected lines. 165N/A * The associated error message. 1773N/A * Log a message to the reject writer if one is configured. 1773N/A * The set of rejected lines. 1773N/A * The associated error message. 1773N/A * Log a message to the given writer. 2086N/A * The set of rejected lines. 1773N/A * The associated error message. 5169N/A * Adds any missing RDN attributes to the entry that is being imported.