LDAP-336 - Remove usage of internal class sun.misc.BASE64Encoder.

Replaced usage of sun.misc.BASE64Encoder/Decoder with a wrapping
implementation backed by JAXB's DatatypeConverter which is
available since Java 6. Introduced parseBase64Binary and printBase64Binary
to LdapEncoder as wrappers around DatatypeConverter which does additional line
wrapping as required by the RFC2849 for LDAP attributes.
This commit is contained in:
Thomas Darimont
2015-08-04 01:35:13 +02:00
parent 963232f9a9
commit 4eae1aa150
5 changed files with 76 additions and 14 deletions

View File

@@ -17,8 +17,8 @@ package org.springframework.ldap.core;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ldap.support.LdapEncoder;
import org.springframework.ldap.support.LdapUtils;
import sun.misc.BASE64Encoder;
import javax.naming.Name;
import javax.naming.NamingEnumeration;
@@ -122,7 +122,7 @@ public class LdapAttributes extends BasicAttributes {
LdapName dn = getName();
if (!dn.toString().matches(SAFE_INIT_CHAR + SAFE_CHAR + "*")) {
sb.append("dn:: " + new BASE64Encoder().encode(dn.toString().getBytes()) + "\n");
sb.append("dn:: " + LdapEncoder.printBase64Binary(dn.toString().getBytes()) + "\n");
} else {
sb.append("dn: " + getDN() + "\n");
}
@@ -140,8 +140,8 @@ public class LdapAttributes extends BasicAttributes {
sb.append(attribute.getID() + ": " + (String) value + "\n");
} else if (value instanceof byte[]) {
sb.append(attribute.getID() + ":: " + new BASE64Encoder().encode((byte[]) value) + "\n");
sb.append(attribute.getID() + ":: " + LdapEncoder.printBase64Binary((byte[]) value) + "\n");
} else if (value instanceof URI) {
sb.append(attribute.getID() + ":< " + (URI) value + "\n");

View File

@@ -19,10 +19,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ldap.core.LdapAttribute;
import org.springframework.ldap.ldif.InvalidAttributeFormatException;
import org.springframework.ldap.support.LdapEncoder;
import org.springframework.util.StringUtils;
import sun.misc.BASE64Decoder;
import javax.naming.directory.Attribute;
import javax.xml.bind.DatatypeConverter;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
@@ -337,11 +338,11 @@ public class DefaultAttributeValidationPolicy implements AttributeValidationPoli
List<String> options = Arrays.asList((StringUtils.isEmpty(matcher.group(2)) ? new String[] {} : matcher.group(2).replaceFirst(";","").split(OPTION_SEPARATOR)));
if (options.isEmpty()) {
return new LdapAttribute(id, new BASE64Decoder().decodeBuffer(value), ordered);
return new LdapAttribute(id, LdapEncoder.parseBase64Binary(value), ordered);
} else {
return new LdapAttribute(id, new BASE64Decoder().decodeBuffer(value), options, ordered);
return new LdapAttribute(id, LdapEncoder.parseBase64Binary(value), options, ordered);
}
} catch (IOException e) {
} catch (IllegalArgumentException e) {
throw new InvalidAttributeFormatException(e);
}
}

View File

@@ -1,7 +1,7 @@
package org.springframework.ldap.schema;
import org.springframework.ldap.core.LdapAttributes;
import sun.misc.BASE64Encoder;
import org.springframework.ldap.support.LdapEncoder;
import javax.naming.NamingException;
import javax.naming.ldap.LdapName;
@@ -49,9 +49,8 @@ public class BasicSchemaSpecification implements Specification<LdapAttributes> {
return true;
}
} else if(object instanceof byte[]) {
BASE64Encoder encoder = new BASE64Encoder();
String rdnValue = encoder.encode(((String)rdn.getValue()).getBytes());
String attributeValue = encoder.encode((byte[]) object);
String rdnValue = LdapEncoder.printBase64Binary(((String)rdn.getValue()).getBytes());
String attributeValue = LdapEncoder.printBase64Binary((byte[]) object);
if (rdnValue.equals(attributeValue)) return true;
}
}