|
28 | 28 | Control |
29 | 29 | StartTLSPostConnectProcessor |
30 | 30 | CompareRequest |
31 | | - CompareResult]) |
| 31 | + CompareResult BindResult]) |
32 | 32 | (:import [com.unboundid.ldap.sdk.extensions |
33 | 33 | PasswordModifyExtendedRequest |
34 | 34 | PasswordModifyExtendedResult |
|
93 | 93 | adding the DN. We pass along the byte-valued collection to properly |
94 | 94 | return binary data." |
95 | 95 | ([byte-valued] |
96 | | - (entry-as-map byte-valued true)) |
| 96 | + (entry-as-map byte-valued true)) |
97 | 97 | ([byte-valued dn?] |
98 | 98 | (fn [entry] |
99 | 99 | (let [attrs (seq (.getAttributes entry))] |
|
109 | 109 | (condp instance? control |
110 | 110 | PreReadResponseControl |
111 | 111 | (update-in m [:pre-read] merge ((entry-as-map [] false) |
112 | | - (.getEntry control))) |
| 112 | + (.getEntry control))) |
113 | 113 | PostReadResponseControl |
114 | 114 | (update-in m [:post-read] merge ((entry-as-map [] false) |
115 | | - (.getEntry control))) |
| 115 | + (.getEntry control))) |
116 | 116 | m)) |
117 | 117 |
|
118 | 118 | (defn- add-response-controls |
|
192 | 192 | conn) |
193 | 193 | :else (LDAPConnection. opt host ldap-port)))) |
194 | 194 |
|
| 195 | +(defn- bind-based-on-connection |
| 196 | + "Common bind approach for the api: |
| 197 | + connection represents pool then authenticate and revert bind association on pool connection, or |
| 198 | + connection is plain then authenticate and remain bound. |
| 199 | + Note: There is a retainIdentity control (1.3.6.1.4.1.30221.2.5.3) which might also be useful option in the plain |
| 200 | + connection context but since we make this the default behavior of pool binds it is likely unnecessary." |
| 201 | + [connection bind-dn password] |
| 202 | + (if (instance? LDAPConnectionPool connection) |
| 203 | + (.bindAndRevertAuthentication connection bind-dn password nil) |
| 204 | + (.bind connection bind-dn password))) |
| 205 | + |
195 | 206 | (defn- bind-request |
196 | 207 | "Returns a BindRequest object" |
197 | 208 | [{:keys [bind-dn password]}] |
|
462 | 473 | [(createServerSideSort server-sort)] |
463 | 474 | []) |
464 | 475 | proxied-auth-control (if (not-nil? proxied-auth) |
465 | | - [(ProxiedAuthorizationV2RequestControl. proxied-auth)] |
466 | | - [])] |
| 476 | + [(ProxiedAuthorizationV2RequestControl. proxied-auth)] |
| 477 | + [])] |
467 | 478 | (merge original {:base base |
468 | 479 | :scope (get-scope scope) |
469 | 480 | :filter filter |
|
524 | 535 | [pool connection] |
525 | 536 | (.releaseAndReAuthenticateConnection pool connection)) |
526 | 537 |
|
| 538 | +(defn bind |
| 539 | + "Performs a bind operation using the provided connection or pool, bindDN and |
| 540 | + password. If the bind is unsuccessful LDAPException is thrown. Otherwise, a |
| 541 | + map is returned with :code, :name, and optional :diagnostic-message keys. |
| 542 | + The :diagnostic-message might contain password expiration warnings, for instance. |
| 543 | +
|
| 544 | + When an LDAP connection object is used as the connection argument the |
| 545 | + bind function will attempt to change the identity of that connection |
| 546 | + to that of the provided DN. Subsequent operations on that connection |
| 547 | + will be done using the bound identity. |
| 548 | +
|
| 549 | + If an LDAP connection pool object is passed as the connection argument |
| 550 | + the bind attempt will have no side-effects, leaving the state of the |
| 551 | + underlying connections unchanged." |
| 552 | + [connection bind-dn password] |
| 553 | + (let [^BindResult r (bind-based-on-connection connection bind-dn password)] |
| 554 | + (merge (ldap-result r) |
| 555 | + (when-let [diagnostic-message (.getDiagnosticMessage r)] |
| 556 | + {:diagnostic-message diagnostic-message})))) |
| 557 | + |
527 | 558 | (defn bind? |
528 | 559 | "Performs a bind operation using the provided connection, bindDN and |
529 | | -password. Returns true if successful. |
| 560 | + password. Returns true if successful and false otherwise. |
530 | 561 |
|
531 | | -When an LDAP connection object is used as the connection argument the |
532 | | -bind? function will attempt to change the identity of that connection |
533 | | -to that of the provided DN. Subsequent operations on that connection |
534 | | -will be done using the bound identity. |
| 562 | + When an LDAP connection object is used as the connection argument the |
| 563 | + bind? function will attempt to change the identity of that connection |
| 564 | + to that of the provided DN. Subsequent operations on that connection |
| 565 | + will be done using the bound identity. |
535 | 566 |
|
536 | | -If an LDAP connection pool object is passed as the connection argument |
537 | | -the bind attempt will have no side-effects, leaving the state of the |
538 | | -underlying connections unchanged." |
| 567 | + If an LDAP connection pool object is passed as the connection argument |
| 568 | + the bind attempt will have no side-effects, leaving the state of the |
| 569 | + underlying connections unchanged." |
539 | 570 | [connection bind-dn password] |
540 | 571 | (try |
541 | | - (let [r (if (instance? LDAPConnectionPool connection) |
542 | | - (.bindAndRevertAuthentication connection bind-dn password nil) |
543 | | - (.bind connection bind-dn password))] |
| 572 | + (let [r (bind-based-on-connection connection bind-dn password)] |
544 | 573 | (= ResultCode/SUCCESS (.getResultCode r))) |
545 | 574 | (catch Exception _ false))) |
546 | 575 |
|
@@ -583,7 +612,7 @@ underlying connections unchanged." |
583 | 612 | "Adds an entry to the connected ldap server. The entry is assumed to be |
584 | 613 | a map. The options map supports control :proxied-auth." |
585 | 614 | ([connection dn entry] |
586 | | - (add connection dn entry nil)) |
| 615 | + (add connection dn entry nil)) |
587 | 616 | ([connection dn entry options] |
588 | 617 | (let [entry-obj (Entry. dn)] |
589 | 618 | (set-entry-map! entry-obj entry) |
@@ -629,7 +658,7 @@ Where :add adds an attribute value, :delete deletes an attribute value and |
629 | 658 | The entries :pre-read and :post-read specify attributes that have be read and |
630 | 659 | returned either before or after the modifications have taken place." |
631 | 660 | ([connection dn modifications] |
632 | | - (modify connection dn modifications nil)) |
| 661 | + (modify connection dn modifications nil)) |
633 | 662 | ([connection dn modifications options] |
634 | 663 | (let [modify-obj (get-modify-request dn modifications)] |
635 | 664 | (when options |
@@ -662,7 +691,7 @@ returned either before or after the modifications have taken place." |
662 | 691 | RDN value from the target entry. The options map supports pre/post-read |
663 | 692 | and proxied-auth controls." |
664 | 693 | ([connection dn new-rdn delete-old-rdn] |
665 | | - (modify-rdn connection dn new-rdn delete-old-rdn nil)) |
| 694 | + (modify-rdn connection dn new-rdn delete-old-rdn nil)) |
666 | 695 | ([connection dn new-rdn delete-old-rdn options] |
667 | 696 | (let [request (ModifyDNRequest. dn new-rdn delete-old-rdn)] |
668 | 697 | (when options |
|
0 commit comments