This repository has been archived by the owner on May 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
dn.html
179 lines (170 loc) · 7.54 KB
/
dn.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<!DOCTYPE html>
<html lang="en">
<head>
<title>DN API | ldapjs</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="media/css/style.css">
<link rel="stylesheet" type="text/css" href="media/css/highlight.css">
</head>
<body>
<div id="header">
<h1>DN API | ldapjs Documentation</h1>
</div>
<div id="sidebar">
<div>Sections</div>
<span>
<ul>
<li><div><a href="index.html">Home</a></div></li>
<li><div><a href="guide.html">Guide</a></div></li>
<li><div><a href="examples.html">Examples</a></div></li>
<li><div><a href="client.html">Client API</a></div></li>
<li><div><a href="server.html">Server API</a></div></li>
<li><div><a href="dn.html">DN API</a></div></li>
<li><div><a href="filters.html">Filters API</a></div></li>
<li><div><a href="errors.html">Error API</a></div></li>
</ul>
</span>
<div>Contents</div>
</span>
<ul>
<li>
<div>
<a href="#parsedndnstring">parseDN(dnString)</a>
</div>
</li>
<li>
<div>
<a href="#dn">DN</a>
</div>
<ul>
<li>
<div>
<a href="#childofdn">childOf(dn)</a>
</div>
</li>
<li>
<div>
<a href="#parentofdn">parentOf(dn)</a>
</div>
</li>
<li>
<div>
<a href="#equalsdn">equals(dn)</a>
</div>
</li>
<li>
<div>
<a href="#parent">parent()</a>
</div>
</li>
<li>
<div>
<a href="#formatoptions">format(options)</a>
</div>
</li>
<li>
<div>
<a href="#setformatoptions">setFormat(options)</a>
</div>
</li>
<li>
<div>
<a href="#tostring">toString()</a>
</div>
</li>
</ul>
</li>
</ul>
</div>
<div id="content">
<h1 id="ldapjs-dn-api">ldapjs DN API</h1>
<div class="intro">
<p>This document covers the ldapjs DN API and assumes that you are familiar
with LDAP. If you're not, read the <a href="guide.html">guide</a> first.</p>
</div>
<p>DNs are LDAP distinguished names, and are composed of a set of RDNs (relative
distinguished names). <a href="http://www.ietf.org/rfc/rfc2253.txt">RFC2253</a> has the
complete specification, but basically an RDN is an attribute value assertion
with <code>=</code> as the seperator, like: <code>cn=foo</code> where 'cn' is 'commonName' and 'foo'
is the value. You can have compound RDNs by using the <code>+</code> character:
<code>cn=foo+sn=bar</code>. As stated above, DNs are a set of RDNs, typically separated
with the <code>,</code> character, like: <code>cn=foo, ou=people, o=example</code>. This uniquely
identifies an entry in the tree, and is read "bottom up".</p>
<h1 id="parsedndnstring">parseDN(dnString)</h1>
<p>The <code>parseDN</code> API converts a string representation of a DN into an ldapjs DN
object; in most cases this will be handled for you under the covers of the
ldapjs framework, but if you need it, it's there.</p>
<pre><code class="language-js"><span class="hljs-keyword">const</span> parseDN = <span class="hljs-built_in">require</span>(<span class="hljs-string">'ldapjs'</span>).<span class="hljs-property">parseDN</span>;
<span class="hljs-keyword">const</span> dn = <span class="hljs-title function_">parseDN</span>(<span class="hljs-string">'cn=foo+sn=bar, ou=people, o=example'</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(dn.<span class="hljs-title function_">toString</span>());
</code></pre>
<h1 id="dn">DN</h1>
<p>The DN object is largely what you'll be interacting with, since all the server
APIs are setup to give you a DN object.</p>
<h2 id="childofdn">childOf(dn)</h2>
<p>Returns a boolean indicating whether 'this' is a child of the passed in dn. The
<code>dn</code> argument can be either a string or a DN.</p>
<pre><code class="language-js">server.<span class="hljs-title function_">add</span>(<span class="hljs-string">'o=example'</span>, <span class="hljs-function">(<span class="hljs-params">req, res, next</span>) =></span> {
<span class="hljs-keyword">if</span> (req.<span class="hljs-property">dn</span>.<span class="hljs-title function_">childOf</span>(<span class="hljs-string">'ou=people, o=example'</span>)) {
...
} <span class="hljs-keyword">else</span> {
...
}
});
</code></pre>
<h2 id="parentofdn">parentOf(dn)</h2>
<p>The inverse of <code>childOf</code>; returns a boolean on whether or not <code>this</code> is a parent
of the passed in dn. Like <code>childOf</code>, can take either a string or a DN.</p>
<pre><code class="language-js">server.<span class="hljs-title function_">add</span>(<span class="hljs-string">'o=example'</span>, <span class="hljs-function">(<span class="hljs-params">req, res, next</span>) =></span> {
<span class="hljs-keyword">const</span> dn = <span class="hljs-title function_">parseDN</span>(<span class="hljs-string">'ou=people, o=example'</span>);
<span class="hljs-keyword">if</span> (dn.<span class="hljs-title function_">parentOf</span>(req.<span class="hljs-property">dn</span>)) {
...
} <span class="hljs-keyword">else</span> {
...
}
});
</code></pre>
<h2 id="equalsdn">equals(dn)</h2>
<p>Returns a boolean indicating whether <code>this</code> is equivalent to the passed in <code>dn</code>
argument. <code>dn</code> can be a string or a DN.</p>
<pre><code class="language-js">server.<span class="hljs-title function_">add</span>(<span class="hljs-string">'o=example'</span>, <span class="hljs-function">(<span class="hljs-params">req, res, next</span>) =></span> {
<span class="hljs-keyword">if</span> (req.<span class="hljs-property">dn</span>.<span class="hljs-title function_">equals</span>(<span class="hljs-string">'cn=foo, ou=people, o=example'</span>)) {
...
} <span class="hljs-keyword">else</span> {
...
}
});
</code></pre>
<h2 id="parent">parent()</h2>
<p>Returns a DN object that is the direct parent of <code>this</code>. If there is no parent
this can return <code>null</code> (e.g. <code>parseDN('o=example').parent()</code> will return null).</p>
<h2 id="formatoptions">format(options)</h2>
<p>Convert a DN object to string according to specified formatting options. These
options are divided into two types. Preservation Options use data recorded
during parsing to preserve details of the original DN. Modification options
alter string formatting defaults. Preservation options <em>always</em> take
precedence over Modification Options.</p>
<p>Preservation Options:</p>
<ul>
<li><code>keepOrder</code>: Order of multi-value RDNs.</li>
<li><code>keepQuote</code>: RDN values which were quoted will remain so.</li>
<li><code>keepSpace</code>: Leading/trailing spaces will be output.</li>
<li><code>keepCase</code>: Parsed attribute name will be output instead of lowercased version.</li>
</ul>
<p>Modification Options:</p>
<ul>
<li><code>upperName</code>: RDN names will be uppercased instead of lowercased.</li>
<li><code>skipSpace</code>: Disable trailing space after RDN separators</li>
</ul>
<h2 id="setformatoptions">setFormat(options)</h2>
<p>Sets the default <code>options</code> for string formatting when <code>toString</code> is called.
It accepts the same parameters as <code>format</code>.</p>
<h2 id="tostring">toString()</h2>
<p>Returns the string representation of <code>this</code>.</p>
<pre><code class="language-js">server.<span class="hljs-title function_">add</span>(<span class="hljs-string">'o=example'</span>, <span class="hljs-function">(<span class="hljs-params">req, res, next</span>) =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(req.<span class="hljs-property">dn</span>.<span class="hljs-title function_">toString</span>());
});
</code></pre>
</div><!-- end #content -->
</body>
</html>