- // TODO check consistency of DN with attributes
- writer.append("dn:").append(name.toString()).append('\n');
+ // check consistency
+ Rdn nameRdn = name.getRdn(name.size() - 1);
+ Attribute nameAttr = attributes.get(nameRdn.getType());
+ if (!nameAttr.get().equals(nameRdn.getValue()))
+ throw new UserDirectoryException("Attribute "
+ + nameAttr.getID() + "=" + nameAttr.get()
+ + " not consistent with DN " + name);
+
+ writer.append(dn.name() + ":").append(name.toString()).append('\n');