Skip to content
Permalink
Browse files
Fixed a LDIF parsing error. Get rid of Base64, replaced it with the j…
…ava.util class
  • Loading branch information
elecharny committed Jan 6, 2022
1 parent 91d0f13 commit 037eca5e990855a836439ecf63204d72efc02664
Showing 12 changed files with 68 additions and 52 deletions.
@@ -20,7 +20,9 @@
package org.apache.directory.api.dsmlv2;


import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collection;

import javax.xml.transform.Transformer;
@@ -39,7 +41,6 @@
import org.apache.directory.api.ldap.model.entry.Value;
import org.apache.directory.api.ldap.model.ldif.LdifUtils;
import org.apache.directory.api.ldap.model.message.Control;
import org.apache.directory.api.util.Base64;
import org.apache.directory.api.util.Strings;
import org.dom4j.Document;
import org.dom4j.Element;
@@ -181,11 +182,11 @@ public static String base64Encode( Object value )
{
if ( value instanceof byte[] )
{
return new String( Base64.encode( ( byte[] ) value ) );
return new String( Base64.getEncoder().encode( ( byte[] ) value ), StandardCharsets.UTF_8 );
}
else if ( value instanceof String )
{
return new String( Base64.encode( Strings.getBytesUtf8( ( String ) value ) ) );
return new String( Base64.getEncoder().encode( Strings.getBytesUtf8( ( String ) value ) ), StandardCharsets.UTF_8 );
}

return "";
@@ -23,6 +23,7 @@

import java.io.IOException;
import java.lang.reflect.Array;
import java.util.Base64;
import java.util.HashMap;

import org.apache.directory.api.asn1.DecoderException;
@@ -67,7 +68,6 @@
import org.apache.directory.api.ldap.model.message.controls.OpaqueControl;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.api.ldap.model.name.Rdn;
import org.apache.directory.api.util.Base64;
import org.apache.directory.api.util.Strings;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -380,7 +380,7 @@ public void action( Dsmlv2Container container ) throws XmlPullParserException
{
if ( ParserUtils.isBase64BinaryValue( xpp, typeValue ) )
{
addRequest.addAttributeValue( Base64.decode( nextText.trim().toCharArray() ) );
addRequest.addAttributeValue( Base64.getDecoder().decode( nextText.trim() ) );
}
else
{
@@ -562,7 +562,7 @@ public void action( Dsmlv2Container container ) throws XmlPullParserException
{
if ( ParserUtils.isBase64BinaryValue( xpp, typeValue ) )
{
compareRequest.setAssertionValue( Base64.decode( nextText.trim().toCharArray() ) );
compareRequest.setAssertionValue( Base64.getDecoder().decode( nextText.trim() ) );
}
else
{
@@ -741,7 +741,7 @@ public void action( Dsmlv2Container container ) throws XmlPullParserException
{
if ( ParserUtils.isBase64BinaryValue( xpp, typeValue ) )
{
extendedRequest.setRequestValue( Base64.decode( nextText.trim().toCharArray() ) );
extendedRequest.setRequestValue( Base64.getDecoder().decode( nextText.trim() ) );
}
else
{
@@ -1014,7 +1014,7 @@ public void action( Dsmlv2Container container ) throws XmlPullParserException
{
if ( ParserUtils.isBase64BinaryValue( xpp, typeValue ) )
{
modifyRequest.addAttributeValue( Base64.decode( nextText.trim().toCharArray() ) );
modifyRequest.addAttributeValue( Base64.getDecoder().decode( nextText.trim() ) );
}
else
{
@@ -1314,7 +1314,7 @@ public void action( Dsmlv2Container container ) throws XmlPullParserException
if ( ParserUtils.isBase64BinaryValue( xpp, typeValue ) )
{
substringFilter
.setInitialSubstrings( Strings.utf8ToString( Base64.decode( nextText.trim().toCharArray() ) ) );
.setInitialSubstrings( Strings.utf8ToString( Base64.getDecoder().decode( nextText.trim() ) ) );
}
else
{
@@ -1359,7 +1359,8 @@ public void action( Dsmlv2Container container ) throws XmlPullParserException
{
if ( ParserUtils.isBase64BinaryValue( xpp, typeValue ) )
{
substringFilter.addAnySubstrings( Strings.utf8ToString( Base64.decode( nextText.trim().toCharArray() ) ) );
substringFilter.addAnySubstrings( Strings.utf8ToString(
Base64.getDecoder().decode( nextText.trim() ) ) );
}
else
{
@@ -1405,7 +1406,8 @@ public void action( Dsmlv2Container container ) throws XmlPullParserException
if ( ParserUtils.isBase64BinaryValue( xpp, typeValue ) )
{
substringFilter
.setFinalSubstrings( Strings.utf8ToString( Base64.decode( nextText.trim().toCharArray() ) ) );
.setFinalSubstrings( Strings.utf8ToString(
Base64.getDecoder().decode( nextText.trim() ) ) );
}
else
{
@@ -1775,7 +1777,7 @@ public void action( Dsmlv2Container container ) throws XmlPullParserException
{
if ( ParserUtils.isBase64BinaryValue( xpp, typeValue ) )
{
Value value = new Value( Base64.decode( nextText.trim().toCharArray() ) );
Value value = new Value( Base64.getDecoder().decode( nextText.trim() ) );
assertion.setAssertionValue( value );
}
else
@@ -1972,7 +1974,7 @@ public void action( Dsmlv2Container container ) throws XmlPullParserException
{
if ( ParserUtils.isBase64BinaryValue( xpp, typeValue ) )
{
filter.setMatchValue( new Value( Base64.decode( nextText.trim().toCharArray() ) ) );
filter.setMatchValue( new Value( Base64.getDecoder().decode( nextText.trim() ) ) );
}
else
{
@@ -2082,7 +2084,7 @@ public void action( Dsmlv2Container container ) throws XmlPullParserException
{
if ( ParserUtils.isBase64BinaryValue( xpp, typeValue ) )
{
control.setValue( Base64.decode( nextText.trim().toCharArray() ) );
control.setValue( Base64.getDecoder().decode( nextText.trim() ) );
}
else
{
@@ -22,6 +22,7 @@

import java.io.IOException;
import java.lang.reflect.Array;
import java.util.Base64;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
@@ -67,7 +68,6 @@
import org.apache.directory.api.ldap.model.message.controls.OpaqueControl;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.api.ldap.model.url.LdapUrl;
import org.apache.directory.api.util.Base64;
import org.apache.directory.api.util.Strings;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -1145,7 +1145,7 @@ public void action( Dsmlv2Container container ) throws XmlPullParserException
{
if ( ParserUtils.isBase64BinaryValue( xpp, typeValue ) )
{
searchResultEntry.addAttributeValue( Base64.decode( nextText.toCharArray() ) );
searchResultEntry.addAttributeValue( Base64.getDecoder().decode( nextText ) );
}
else
{
@@ -1282,7 +1282,7 @@ public void action( Dsmlv2Container container ) throws XmlPullParserException

if ( ParserUtils.isBase64BinaryValue( xpp, typeValue ) )
{
extendedResponse.setResponseValue( Base64.decode( nextText.trim().toCharArray() ) );
extendedResponse.setResponseValue( Base64.getDecoder().decode( nextText.trim() ) );
}
else
{
@@ -2074,7 +2074,7 @@ private void createAndAddControlValue( Dsmlv2Container container,
{
if ( ParserUtils.isBase64BinaryValue( xpp, typeValue ) )
{
control.setValue( Base64.decode( nextText.trim().toCharArray() ) );
control.setValue( Base64.getDecoder().decode( nextText.trim() ) );
}
else
{
@@ -24,6 +24,7 @@
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Set;

@@ -65,7 +66,6 @@
import org.apache.directory.api.ldap.model.schema.registries.AbstractSchemaLoader;
import org.apache.directory.api.ldap.model.schema.registries.DefaultSchema;
import org.apache.directory.api.ldap.model.schema.registries.Schema;
import org.apache.directory.api.util.Base64;
import org.apache.directory.api.util.Strings;
import org.apache.directory.ldap.client.api.exception.InvalidConnectionException;
import org.slf4j.Logger;
@@ -1068,7 +1068,7 @@ private Entry getEntry( LdapComparatorDescription comparatorDescription )
if ( comparatorDescription.getBytecode() != null )
{
entry.put( MetaSchemaConstants.M_BYTECODE_AT,
Base64.decode( comparatorDescription.getBytecode().toCharArray() ) );
Base64.getDecoder().decode( comparatorDescription.getBytecode() ) );
}

if ( comparatorDescription.getDescription() != null )
@@ -1095,7 +1095,7 @@ private Entry getEntry( SyntaxCheckerDescription syntaxCheckerDescription )
if ( syntaxCheckerDescription.getBytecode() != null )
{
entry.put( MetaSchemaConstants.M_BYTECODE_AT,
Base64.decode( syntaxCheckerDescription.getBytecode().toCharArray() ) );
Base64.getDecoder().decode( syntaxCheckerDescription.getBytecode() ) );
}

if ( syntaxCheckerDescription.getDescription() != null )
@@ -1122,7 +1122,7 @@ private Entry getEntry( NormalizerDescription normalizerDescription )
if ( normalizerDescription.getBytecode() != null )
{
entry.put( MetaSchemaConstants.M_BYTECODE_AT,
Base64.decode( normalizerDescription.getBytecode().toCharArray() ) );
Base64.getDecoder().decode( normalizerDescription.getBytecode() ) );
}

if ( normalizerDescription.getDescription() != null )
@@ -22,7 +22,9 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -41,7 +43,6 @@
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.api.ldap.model.schema.AttributeType;
import org.apache.directory.api.ldap.model.schema.SchemaManager;
import org.apache.directory.api.util.Base64;
import org.apache.directory.api.util.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -381,7 +382,7 @@ private Entry createEntry( SchemaManager schemaManager, Object... elements )
else if ( element instanceof byte[] )
{
sb.append( ":: " );
sb.append( new String( Base64.encode( ( byte[] ) element ) ) );
sb.append( new String( Base64.getEncoder().encode( ( byte[] ) element ), StandardCharsets.UTF_8 ) );
sb.append( '\n' );
}
else
@@ -24,6 +24,8 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
@@ -48,7 +50,6 @@
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.api.ldap.model.name.Rdn;
import org.apache.directory.api.ldap.model.schema.SchemaManager;
import org.apache.directory.api.util.Base64;
import org.apache.directory.api.util.Strings;


@@ -190,7 +191,7 @@ public LdifEntry( Dn dn, Object... avas ) throws LdapInvalidAttributeValueExcept
}
else
{
sb.append( "dn:: " ).append( Base64.encode( Strings.getBytesUtf8( dnStr ) ) ).append( '\n' );
sb.append( "dn:: " ).append( Base64.getEncoder().encode( Strings.getBytesUtf8( dnStr ) ) ).append( '\n' );
}

for ( Object ava : avas )
@@ -224,7 +225,7 @@ public LdifEntry( Dn dn, Object... avas ) throws LdapInvalidAttributeValueExcept
else if ( ava instanceof byte[] )
{
sb.append( ":: " );
sb.append( new String( Base64.encode( ( byte[] ) ava ) ) );
sb.append( new String( Base64.getEncoder().encode( ( byte[] ) ava ), StandardCharsets.UTF_8 ) );
sb.append( '\n' );
}
else
@@ -36,6 +36,7 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
@@ -55,7 +56,6 @@
import org.apache.directory.api.ldap.model.name.Rdn;
import org.apache.directory.api.ldap.model.schema.AttributeType;
import org.apache.directory.api.ldap.model.schema.SchemaManager;
import org.apache.directory.api.util.Base64;
import org.apache.directory.api.util.Chars;
import org.apache.directory.api.util.Strings;
import org.apache.directory.api.util.exception.NotImplementedException;
@@ -555,7 +555,7 @@ else if ( line.charAt( 3 ) == ':' )
// This is a base 64 encoded Dn.
String trimmedLine = line.substring( 4 ).trim();

dn = Strings.utf8ToString( Base64.decode( trimmedLine.toCharArray() ) );
dn = Strings.utf8ToString( Base64.getDecoder().decode( trimmedLine ) );
}
else
{
@@ -604,7 +604,7 @@ protected static Object parseSimpleValue( String line, int pos )
{
String value = Strings.trim( line.substring( pos + 2 ) );

return Base64.decode( value.toCharArray() );
return Base64.getDecoder().decode( value );
}
else
{
@@ -666,7 +666,7 @@ protected Object parseValue( String attributeName, String line, int pos ) throws
{
String value = Strings.trim( line.substring( pos + 2 ) );

byte[] decoded = Base64.decode( value.toCharArray() );
byte[] decoded = Base64.getDecoder().decode( value );

return getValue( attributeName, decoded );
}
@@ -896,14 +896,14 @@ else if ( criticalLength != 0 )
// Base 64 encoded value

// Skip the <fill>
pos = criticalPos + 2;
pos = criticalPos + 3;

while ( Chars.isCharASCII( controlValue, pos, ' ' ) )
{
pos++;
}

byte[] value = Base64.decode( line.substring( pos ).toCharArray() );
byte[] value = Base64.getDecoder().decode( line.substring( pos ) );
control.setValue( value );
}
else if ( Chars.isCharASCII( controlValue, criticalPos + 1, '<' ) )

0 comments on commit 037eca5

Please sign in to comment.