Introduce distinguished name interface.
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 27 Oct 2019 09:15:32 +0000 (10:15 +0100)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 27 Oct 2019 09:15:32 +0000 (10:15 +0100)
org.argeo.enterprise/src/org/argeo/naming/Distinguished.java [new file with mode: 0644]

diff --git a/org.argeo.enterprise/src/org/argeo/naming/Distinguished.java b/org.argeo.enterprise/src/org/argeo/naming/Distinguished.java
new file mode 100644 (file)
index 0000000..ba0db49
--- /dev/null
@@ -0,0 +1,23 @@
+package org.argeo.naming;
+
+import javax.naming.InvalidNameException;
+import javax.naming.ldap.LdapName;
+
+/**
+ * An object that can be identified with an X.500 distinguished name.
+ * 
+ * @see https://tools.ietf.org/html/rfc1779
+ */
+public interface Distinguished {
+       /** The related distinguished name. */
+       String dn();
+
+       /** The related distinguished name as an {@link LdapName}. */
+       default LdapName distinguishedName() {
+               try {
+                       return new LdapName(dn());
+               } catch (InvalidNameException e) {
+                       throw new IllegalArgumentException("Distinguished name " + dn() + " is not properly formatted.", e);
+               }
+       }
+}