Address JavaFormat Violations in Ldif

Issue gh-743
This commit is contained in:
Josh Cummings
2023-05-09 16:28:01 -06:00
parent 97cc49ca47
commit fa0fc45365
3 changed files with 39 additions and 36 deletions

View File

@@ -221,8 +221,9 @@ public class LdifParser implements Parser, InitializingBean {
}
public void close() throws IOException {
if (this.resource.isOpen())
if (this.resource.isOpen()) {
this.reader.close();
}
}
public void reset() throws IOException {
@@ -319,8 +320,8 @@ public class LdifParser implements Parser, InitializingBean {
"Record [dn: " + record.getDN() + "] does not conform to specification.");
}
}
catch (NamingException e) {
LOG.error("Error adding attribute to record", e);
catch (NamingException ex) {
LOG.error("Error adding attribute to record", ex);
return null;
}
}
@@ -372,11 +373,11 @@ public class LdifParser implements Parser, InitializingBean {
}
}
}
catch (NamingException e) {
LOG.error("Error adding attribute to record", e);
catch (NamingException ex) {
LOG.error("Error adding attribute to record", ex);
}
catch (NoSuchElementException e) {
LOG.error("Error adding attribute to record", e);
catch (NoSuchElementException ex) {
LOG.error("Error adding attribute to record", ex);
}
}

View File

@@ -393,8 +393,8 @@ public class DefaultAttributeValidationPolicy implements AttributeValidationPoli
return new LdapAttribute(id, LdapEncoder.parseBase64Binary(value), options, this.ordered);
}
}
catch (IllegalArgumentException e) {
throw new InvalidAttributeFormatException(e);
catch (IllegalArgumentException ex) {
throw new InvalidAttributeFormatException(ex);
}
}
@@ -412,8 +412,8 @@ public class DefaultAttributeValidationPolicy implements AttributeValidationPoli
return new LdapAttribute(id, new URI(value), options, this.ordered);
}
}
catch (URISyntaxException e) {
throw new InvalidAttributeFormatException(e);
catch (URISyntaxException ex) {
throw new InvalidAttributeFormatException(ex);
}
}

View File

@@ -44,35 +44,37 @@ public class BasicSchemaSpecification implements Specification<LdapAttributes> {
* @throws NamingException
*/
public boolean isSatisfiedBy(LdapAttributes record) throws NamingException {
if (record != null) {
if (record == null) {
return false;
}
// DN is required.
LdapName dn = record.getName();
if (dn != null) {
// DN is required.
LdapName dn = record.getName();
if (dn == null) {
return false;
}
// objectClass definition is required.
if (record.get("objectClass") != null) {
// objectClass definition is required.
if (record.get("objectClass") == null) {
return false;
}
// Naming attribute is required.
Rdn rdn = dn.getRdn(dn.size() - 1);
if (record.get(rdn.getType()) != null) {
Object object = record.get(rdn.getType()).get();
// Naming attribute is required.
Rdn rdn = dn.getRdn(dn.size() - 1);
if (record.get(rdn.getType()) == null) {
return false;
}
if (object instanceof String) {
String value = (String) object;
if (((String) rdn.getValue()).equalsIgnoreCase(value)) {
return true;
}
}
else if (object instanceof byte[]) {
String rdnValue = LdapEncoder.printBase64Binary(((String) rdn.getValue()).getBytes());
String attributeValue = LdapEncoder.printBase64Binary((byte[]) object);
if (rdnValue.equals(attributeValue))
return true;
}
}
}
}
Object object = record.get(rdn.getType()).get();
if (object instanceof String) {
String value = (String) object;
return ((String) rdn.getValue()).equalsIgnoreCase(value);
}
else if (object instanceof byte[]) {
String rdnValue = LdapEncoder.printBase64Binary(((String) rdn.getValue()).getBytes());
String attributeValue = LdapEncoder.printBase64Binary((byte[]) object);
return rdnValue.equals(attributeValue);
}
return false;