ldap.adoc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. [[servlet-authentication-ldap]]
  2. = LDAP Authentication
  3. LDAP (Lightweight Directory Access Protocol) is often used by organizations as a central repository for user information and as an authentication service.
  4. It can also be used to store the role information for application users.
  5. Spring Security's LDAP-based authentication is used by Spring Security when it is configured to xref:servlet/authentication/passwords/index.adoc#servlet-authentication-unpwd-input[accept a username/password] for authentication.
  6. However, despite using a username and password for authentication, it does not use `UserDetailsService`, because, in <<servlet-authentication-ldap-bind,bind authentication>>, the LDAP server does not return the password, so the application cannot perform validation of the password.
  7. There are many different scenarios for how an LDAP server can be configured, so Spring Security's LDAP provider is fully configurable.
  8. It uses separate strategy interfaces for authentication and role retrieval and provides default implementations, which can be configured to handle a wide range of situations.
  9. [[servlet-authentication-ldap-prerequisites]]
  10. == Prerequisites
  11. You should be familiar with LDAP before trying to use it with Spring Security.
  12. The following link provides a good introduction to the concepts involved and a guide to setting up a directory using the free LDAP server, OpenLDAP: https://www.zytrax.com/books/ldap/.
  13. Some familiarity with the JNDI APIs used to access LDAP from Java can also be useful.
  14. We do not use any third-party LDAP libraries (Mozilla, JLDAP, or others) in the LDAP provider, but extensive use is made of Spring LDAP, so some familiarity with that project may be useful if you plan on adding your own customizations.
  15. When using LDAP authentication, you should ensure that you properly configure LDAP connection pooling.
  16. If you are unfamiliar with how to do so, see the https://docs.oracle.com/javase/jndi/tutorial/ldap/connect/config.html[Java LDAP documentation].
  17. // FIXME:
  18. // ldap server
  19. // embedded (both java and xml)
  20. // external
  21. // authentication
  22. // bind
  23. // password
  24. // roles
  25. // search, etc (other APIs)
  26. [[servlet-authentication-ldap-embedded]]
  27. == Setting up an Embedded LDAP Server
  28. The first thing you need to do is to ensure that you have an LDAP Server to which to point your configuration.
  29. For simplicity, it is often best to start with an embedded LDAP Server.
  30. Spring Security supports using either:
  31. * <<servlet-authentication-ldap-unboundid>>
  32. * <<servlet-authentication-ldap-apacheds>>
  33. In the following samples, we expose `users.ldif` as a classpath resource to initialize the embedded LDAP server with two users, `user` and `admin`, both of which have a password of `password`:
  34. .users.ldif
  35. ====
  36. [source,ldif]
  37. ----
  38. dn: ou=groups,dc=springframework,dc=org
  39. objectclass: top
  40. objectclass: organizationalUnit
  41. ou: groups
  42. dn: ou=people,dc=springframework,dc=org
  43. objectclass: top
  44. objectclass: organizationalUnit
  45. ou: people
  46. dn: uid=admin,ou=people,dc=springframework,dc=org
  47. objectclass: top
  48. objectclass: person
  49. objectclass: organizationalPerson
  50. objectclass: inetOrgPerson
  51. cn: Rod Johnson
  52. sn: Johnson
  53. uid: admin
  54. userPassword: password
  55. dn: uid=user,ou=people,dc=springframework,dc=org
  56. objectclass: top
  57. objectclass: person
  58. objectclass: organizationalPerson
  59. objectclass: inetOrgPerson
  60. cn: Dianne Emu
  61. sn: Emu
  62. uid: user
  63. userPassword: password
  64. dn: cn=user,ou=groups,dc=springframework,dc=org
  65. objectclass: top
  66. objectclass: groupOfNames
  67. cn: user
  68. uniqueMember: uid=admin,ou=people,dc=springframework,dc=org
  69. uniqueMember: uid=user,ou=people,dc=springframework,dc=org
  70. dn: cn=admin,ou=groups,dc=springframework,dc=org
  71. objectclass: top
  72. objectclass: groupOfNames
  73. cn: admin
  74. uniqueMember: uid=admin,ou=people,dc=springframework,dc=org
  75. ----
  76. ====
  77. [[servlet-authentication-ldap-unboundid]]
  78. === Embedded UnboundID Server
  79. If you wish to use https://ldap.com/unboundid-ldap-sdk-for-java/[UnboundID], specify the following dependencies:
  80. .UnboundID Dependencies
  81. ====
  82. .Maven
  83. [source,xml,role="primary",subs="verbatim,attributes"]
  84. ----
  85. <dependency>
  86. <groupId>com.unboundid</groupId>
  87. <artifactId>unboundid-ldapsdk</artifactId>
  88. <version>{unboundid-ldapsdk-version}</version>
  89. <scope>runtime</scope>
  90. </dependency>
  91. ----
  92. .Gradle
  93. [source,groovy,role="secondary",subs="verbatim,attributes"]
  94. ----
  95. depenendencies {
  96. runtimeOnly "com.unboundid:unboundid-ldapsdk:{unboundid-ldapsdk-version}"
  97. }
  98. ----
  99. ====
  100. You can then configure the Embedded LDAP Server using an `EmbeddedLdapServerContextSourceFactoryBean`.
  101. This will instruct Spring Security to start an in-memory LDAP server:
  102. .Embedded LDAP Server Configuration
  103. ====
  104. .Java
  105. [source,java,role="primary"]
  106. ----
  107. @Bean
  108. public EmbeddedLdapServerContextSourceFactoryBean contextSourceFactoryBean() {
  109. return EmbeddedLdapServerContextSourceFactoryBean.fromEmbeddedLdapServer();
  110. }
  111. ----
  112. .Kotlin
  113. [source,kotlin,role="secondary"]
  114. ----
  115. @Bean
  116. fun contextSourceFactoryBean(): EmbeddedLdapServerContextSourceFactoryBean {
  117. return EmbeddedLdapServerContextSourceFactoryBean.fromEmbeddedLdapServer()
  118. }
  119. ----
  120. ====
  121. Alternatively, you can manually configure the Embedded LDAP Server.
  122. If you choose this approach, you will be responsible for managing the lifecycle of the Embedded LDAP Server.
  123. .Explicit Embedded LDAP Server Configuration
  124. ====
  125. .Java
  126. [source,java,role="primary"]
  127. ----
  128. @Bean
  129. UnboundIdContainer ldapContainer() {
  130. return new UnboundIdContainer("dc=springframework,dc=org",
  131. "classpath:users.ldif");
  132. }
  133. ----
  134. .XML
  135. [source,xml,role="secondary"]
  136. ----
  137. <b:bean class="org.springframework.security.ldap.server.UnboundIdContainer"
  138. c:defaultPartitionSuffix="dc=springframework,dc=org"
  139. c:ldif="classpath:users.ldif"/>
  140. ----
  141. .Kotlin
  142. [source,kotlin,role="secondary"]
  143. ----
  144. @Bean
  145. fun ldapContainer(): UnboundIdContainer {
  146. return UnboundIdContainer("dc=springframework,dc=org","classpath:users.ldif")
  147. }
  148. ----
  149. ====
  150. [[servlet-authentication-ldap-apacheds]]
  151. === Embedded ApacheDS Server
  152. [NOTE]
  153. ====
  154. Spring Security uses ApacheDS 1.x, which is no longer maintained.
  155. Unfortunately, ApacheDS 2.x has only released milestone versions with no stable release.
  156. Once a stable release of ApacheDS 2.x is available, we will consider updating.
  157. ====
  158. If you wish to use https://directory.apache.org/apacheds/[Apache DS], specify the following dependencies:
  159. .ApacheDS Dependencies
  160. ====
  161. .Maven
  162. [source,xml,role="primary",subs="+attributes"]
  163. ----
  164. <dependency>
  165. <groupId>org.apache.directory.server</groupId>
  166. <artifactId>apacheds-core</artifactId>
  167. <version>{apacheds-core-version}</version>
  168. <scope>runtime</scope>
  169. </dependency>
  170. <dependency>
  171. <groupId>org.apache.directory.server</groupId>
  172. <artifactId>apacheds-server-jndi</artifactId>
  173. <version>{apacheds-core-version}</version>
  174. <scope>runtime</scope>
  175. </dependency>
  176. ----
  177. .Gradle
  178. [source,groovy,role="secondary",subs="+attributes"]
  179. ----
  180. depenendencies {
  181. runtimeOnly "org.apache.directory.server:apacheds-core:{apacheds-core-version}"
  182. runtimeOnly "org.apache.directory.server:apacheds-server-jndi:{apacheds-core-version}"
  183. }
  184. ----
  185. ====
  186. You can then configure the Embedded LDAP Server:
  187. .Embedded LDAP Server Configuration
  188. ====
  189. .Java
  190. [source,java,role="primary"]
  191. ----
  192. @Bean
  193. ApacheDSContainer ldapContainer() {
  194. return new ApacheDSContainer("dc=springframework,dc=org",
  195. "classpath:users.ldif");
  196. }
  197. ----
  198. .XML
  199. [source,xml,role="secondary"]
  200. ----
  201. <b:bean class="org.springframework.security.ldap.server.ApacheDSContainer"
  202. c:defaultPartitionSuffix="dc=springframework,dc=org"
  203. c:ldif="classpath:users.ldif"/>
  204. ----
  205. .Kotlin
  206. [source,kotlin,role="secondary"]
  207. ----
  208. @Bean
  209. fun ldapContainer(): ApacheDSContainer {
  210. return ApacheDSContainer("dc=springframework,dc=org", "classpath:users.ldif")
  211. }
  212. ----
  213. ====
  214. [[servlet-authentication-ldap-contextsource]]
  215. == LDAP ContextSource
  216. Once you have an LDAP Server to which to point your configuration, you need to configure Spring Security to point to an LDAP server that should be used to authenticate users.
  217. To do so, create an LDAP `ContextSource` (which is the equivalent of a JDBC `DataSource`).
  218. If you have already configured an `EmbeddedLdapServerContextSourceFactoryBean`, Spring Security will create an LDAP `ContextSource` that points to the embedded LDAP server.
  219. .LDAP Context Source with Embedded LDAP Server
  220. ====
  221. .Java
  222. [source,java,role="primary"]
  223. ----
  224. @Bean
  225. public EmbeddedLdapServerContextSourceFactoryBean contextSourceFactoryBean() {
  226. EmbeddedLdapServerContextSourceFactoryBean contextSourceFactoryBean =
  227. EmbeddedLdapServerContextSourceFactoryBean.fromEmbeddedLdapServer();
  228. contextSourceFactoryBean.setPort(0);
  229. return contextSourceFactoryBean;
  230. }
  231. ----
  232. .Kotlin
  233. [source,kotlin,role="secondary"]
  234. ----
  235. @Bean
  236. fun contextSourceFactoryBean(): EmbeddedLdapServerContextSourceFactoryBean {
  237. val contextSourceFactoryBean = EmbeddedLdapServerContextSourceFactoryBean.fromEmbeddedLdapServer()
  238. contextSourceFactoryBean.setPort(0)
  239. return contextSourceFactoryBean
  240. }
  241. ----
  242. ====
  243. Alternatively, you can explicitly configure the LDAP `ContextSource` to connect to the supplied LDAP server:
  244. .LDAP Context Source
  245. ====
  246. .Java
  247. [source,java,role="primary"]
  248. ----
  249. ContextSource contextSource(UnboundIdContainer container) {
  250. return new DefaultSpringSecurityContextSource("ldap://localhost:53389/dc=springframework,dc=org");
  251. }
  252. ----
  253. .XML
  254. [source,xml,role="secondary"]
  255. ----
  256. <ldap-server
  257. url="ldap://localhost:53389/dc=springframework,dc=org" />
  258. ----
  259. .Kotlin
  260. [source,kotlin,role="secondary"]
  261. ----
  262. fun contextSource(container: UnboundIdContainer): ContextSource {
  263. return DefaultSpringSecurityContextSource("ldap://localhost:53389/dc=springframework,dc=org")
  264. }
  265. ----
  266. ====
  267. [[servlet-authentication-ldap-authentication]]
  268. == Authentication
  269. Spring Security's LDAP support does not use the xref:servlet/authentication/passwords/user-details-service.adoc#servlet-authentication-userdetailsservice[UserDetailsService] because LDAP bind authentication does not let clients read the password or even a hashed version of the password.
  270. This means there is no way for a password to be read and then authenticated by Spring Security.
  271. For this reason, LDAP support is implemented through the `LdapAuthenticator` interface.
  272. The `LdapAuthenticator` interface is also responsible for retrieving any required user attributes.
  273. This is because the permissions on the attributes may depend on the type of authentication being used.
  274. For example, if binding as the user, it may be necessary to read the attributes with the user's own permissions.
  275. Spring Security supplies two `LdapAuthenticator` implementations:
  276. * <<servlet-authentication-ldap-bind>>
  277. * <<servlet-authentication-ldap-pwd>>
  278. [[servlet-authentication-ldap-bind]]
  279. == Using Bind Authentication
  280. https://ldap.com/the-ldap-bind-operation/[Bind Authentication] is the most common mechanism for authenticating users with LDAP.
  281. In bind authentication, the user's credentials (username and password) are submitted to the LDAP server, which authenticates them.
  282. The advantage to using bind authentication is that the user's secrets (the password) do not need to be exposed to clients, which helps to protect them from leaking.
  283. The following example shows bind authentication configuration:
  284. .Bind Authentication
  285. ====
  286. .Java
  287. [source,java,role="primary",attrs="-attributes"]
  288. ----
  289. @Bean
  290. AuthenticationManager authenticationManager(BaseLdapPathContextSource contextSource) {
  291. LdapBindAuthenticationManagerFactory factory = new LdapBindAuthenticationManagerFactory(contextSource);
  292. factory.setUserDnPatterns("uid={0},ou=people");
  293. return factory.createAuthenticationManager();
  294. }
  295. ----
  296. .XML
  297. [source,xml,role="secondary",attrs="-attributes"]
  298. ----
  299. <ldap-authentication-provider
  300. user-dn-pattern="uid={0},ou=people"/>
  301. ----
  302. .Kotlin
  303. [source,kotlin,role="secondary",attrs="-attributes"]
  304. ----
  305. @Bean
  306. fun authenticationManager(contextSource: BaseLdapPathContextSource): AuthenticationManager {
  307. val factory = LdapBindAuthenticationManagerFactory(contextSource)
  308. factory.setUserDnPatterns("uid={0},ou=people")
  309. return factory.createAuthenticationManager()
  310. }
  311. ----
  312. ====
  313. The preceding simple example would obtain the DN for the user by substituting the user login name in the supplied pattern and attempting to bind as that user with the login password.
  314. This is OK if all your users are stored under a single node in the directory.
  315. If, instead, you wish to configure an LDAP search filter to locate the user, you could use the following:
  316. .Bind Authentication with Search Filter
  317. ====
  318. .Java
  319. [source,java,role="primary",attrs="-attributes"]
  320. ----
  321. @Bean
  322. AuthenticationManager authenticationManager(BaseLdapPathContextSource contextSource) {
  323. LdapBindAuthenticationManagerFactory factory = new LdapBindAuthenticationManagerFactory(contextSource);
  324. factory.setUserSearchFilter("(uid={0})");
  325. factory.setUserSearchBase("ou=people");
  326. return factory.createAuthenticationManager();
  327. }
  328. ----
  329. .XML
  330. [source,xml,role="secondary",attrs="-attributes"]
  331. ----
  332. <ldap-authentication-provider
  333. user-search-filter="(uid={0})"
  334. user-search-base="ou=people"/>
  335. ----
  336. .Kotlin
  337. [source,kotlin,role="secondary",attrs="-attributes"]
  338. ----
  339. @Bean
  340. fun authenticationManager(contextSource: BaseLdapPathContextSource): AuthenticationManager {
  341. val factory = LdapBindAuthenticationManagerFactory(contextSource)
  342. factory.setUserSearchFilter("(uid={0})")
  343. factory.setUserSearchBase("ou=people")
  344. return factory.createAuthenticationManager()
  345. }
  346. ----
  347. ====
  348. If used with the `ContextSource` <<servlet-authentication-ldap-contextsource,definition shown earlier>>, this would perform a search under the DN `ou=people,dc=springframework,dc=org` by using `+(uid={0})+` as a filter.
  349. Again, the user login name is substituted for the parameter in the filter name, so it searches for an entry with the `uid` attribute equal to the user name.
  350. If a user search base is not supplied, the search is performed from the root.
  351. [[servlet-authentication-ldap-pwd]]
  352. == Using Password Authentication
  353. Password comparison is when the password supplied by the user is compared with the one stored in the repository.
  354. This can either be done by retrieving the value of the password attribute and checking it locally or by performing an LDAP "`compare`" operation, where the supplied password is passed to the server for comparison and the real password value is never retrieved.
  355. An LDAP compare cannot be done when the password is properly hashed with a random salt.
  356. .Minimal Password Compare Configuration
  357. ====
  358. .Java
  359. [source,java,role="primary"]
  360. ----
  361. @Bean
  362. AuthenticationManager authenticationManager(BaseLdapPathContextSource contextSource) {
  363. LdapPasswordComparisonAuthenticationManagerFactory factory = new LdapPasswordComparisonAuthenticationManagerFactory(
  364. contextSource, NoOpPasswordEncoder.getInstance());
  365. factory.setUserDnPatterns("uid={0},ou=people");
  366. return factory.createAuthenticationManager();
  367. }
  368. ----
  369. .XML
  370. [source,xml,role="secondary",attrs="-attributes"]
  371. ----
  372. <ldap-authentication-provider
  373. user-dn-pattern="uid={0},ou=people">
  374. <password-compare />
  375. </ldap-authentication-provider>
  376. ----
  377. .Kotlin
  378. [source,kotlin,role="secondary"]
  379. ----
  380. @Bean
  381. fun authenticationManager(contextSource: BaseLdapPathContextSource?): AuthenticationManager? {
  382. val factory = LdapPasswordComparisonAuthenticationManagerFactory(
  383. contextSource, NoOpPasswordEncoder.getInstance()
  384. )
  385. factory.setUserDnPatterns("uid={0},ou=people")
  386. return factory.createAuthenticationManager()
  387. }
  388. ----
  389. ====
  390. The following example shows a more advanced configuration with some customizations:
  391. .Password Compare Configuration
  392. ====
  393. .Java
  394. [source,java,role="primary"]
  395. ----
  396. @Bean
  397. AuthenticationManager authenticationManager(BaseLdapPathContextSource contextSource) {
  398. LdapPasswordComparisonAuthenticationManagerFactory factory = new LdapPasswordComparisonAuthenticationManagerFactory(
  399. contextSource, new BCryptPasswordEncoder());
  400. factory.setUserDnPatterns("uid={0},ou=people");
  401. factory.setPasswordAttribute("pwd"); // <1>
  402. return factory.createAuthenticationManager();
  403. }
  404. ----
  405. .XML
  406. [source,xml,role="secondary",attrs="-attributes"]
  407. ----
  408. <ldap-authentication-provider
  409. user-dn-pattern="uid={0},ou=people">
  410. <password-compare password-attribute="pwd"> <!--1-->
  411. <password-encoder ref="passwordEncoder" /> <!--2-->
  412. </password-compare>
  413. </ldap-authentication-provider>
  414. <b:bean id="passwordEncoder"
  415. class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder" />
  416. ----
  417. .Kotlin
  418. [source,kotlin,role="secondary"]
  419. ----
  420. @Bean
  421. fun authenticationManager(contextSource: BaseLdapPathContextSource): AuthenticationManager {
  422. val factory = LdapPasswordComparisonAuthenticationManagerFactory(
  423. contextSource, BCryptPasswordEncoder()
  424. )
  425. factory.setUserDnPatterns("uid={0},ou=people")
  426. factory.setPasswordAttribute("pwd") // <1>
  427. return factory.createAuthenticationManager()
  428. }
  429. ----
  430. ====
  431. <1> Specify the password attribute as `pwd`.
  432. == LdapAuthoritiesPopulator
  433. Spring Security's `LdapAuthoritiesPopulator` is used to determine what authorities are returned for the user.
  434. The following example shows how configure `LdapAuthoritiesPopulator`:
  435. .LdapAuthoritiesPopulator Configuration
  436. ====
  437. .Java
  438. [source,java,role="primary",attrs="-attributes"]
  439. ----
  440. @Bean
  441. LdapAuthoritiesPopulator authorities(BaseLdapPathContextSource contextSource) {
  442. String groupSearchBase = "";
  443. DefaultLdapAuthoritiesPopulator authorities =
  444. new DefaultLdapAuthoritiesPopulator(contextSource, groupSearchBase);
  445. authorities.setGroupSearchFilter("member={0}");
  446. return authorities;
  447. }
  448. @Bean
  449. AuthenticationManager authenticationManager(BaseLdapPathContextSource contextSource, LdapAuthoritiesPopulator authorities) {
  450. LdapBindAuthenticationManagerFactory factory = new LdapBindAuthenticationManagerFactory(contextSource);
  451. factory.setUserDnPatterns("uid={0},ou=people");
  452. factory.setLdapAuthoritiesPopulator(authorities);
  453. return factory.createAuthenticationManager();
  454. }
  455. ----
  456. .XML
  457. [source,xml,role="secondary",attrs="-attributes"]
  458. ----
  459. <ldap-authentication-provider
  460. user-dn-pattern="uid={0},ou=people"
  461. group-search-filter="member={0}"/>
  462. ----
  463. .Kotlin
  464. [source,kotlin,role="secondary",attrs="-attributes"]
  465. ----
  466. @Bean
  467. fun authorities(contextSource: BaseLdapPathContextSource): LdapAuthoritiesPopulator {
  468. val groupSearchBase = ""
  469. val authorities = DefaultLdapAuthoritiesPopulator(contextSource, groupSearchBase)
  470. authorities.setGroupSearchFilter("member={0}")
  471. return authorities
  472. }
  473. @Bean
  474. fun authenticationManager(
  475. contextSource: BaseLdapPathContextSource,
  476. authorities: LdapAuthoritiesPopulator): AuthenticationManager {
  477. val factory = LdapBindAuthenticationManagerFactory(contextSource)
  478. factory.setUserDnPatterns("uid={0},ou=people")
  479. factory.setLdapAuthoritiesPopulator(authorities)
  480. return factory.createAuthenticationManager()
  481. }
  482. ----
  483. ====
  484. == Active Directory
  485. Active Directory supports its own non-standard authentication options, and the normal usage pattern does not fit too cleanly with the standard `LdapAuthenticationProvider`.
  486. Typically, authentication is performed by using the domain username (in the form of `user@domain`), rather than using an LDAP distinguished name.
  487. To make this easier, Spring Security has an authentication provider, which is customized for a typical Active Directory setup.
  488. Configuring `ActiveDirectoryLdapAuthenticationProvider` is quite straightforward.
  489. You need only supply the domain name and an LDAP URL that supplies the address of the server.
  490. [NOTE]
  491. ====
  492. It is also possible to obtain the server's IP address byusing a DNS lookup.
  493. This is not currently supported, but hopefully will be in a future version.
  494. ====
  495. The following example configures Active Directory:
  496. .Example Active Directory Configuration
  497. ====
  498. .Java
  499. [source,java,role="primary"]
  500. ----
  501. @Bean
  502. ActiveDirectoryLdapAuthenticationProvider authenticationProvider() {
  503. return new ActiveDirectoryLdapAuthenticationProvider("example.com", "ldap://company.example.com/");
  504. }
  505. ----
  506. .XML
  507. [source,xml,role="secondary"]
  508. ----
  509. <bean id="authenticationProvider"
  510. class="org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider">
  511. <constructor-arg value="example.com" />
  512. <constructor-arg value="ldap://company.example.com/" />
  513. </bean>
  514. ----
  515. .Kotlin
  516. [source,kotlin,role="secondary"]
  517. ----
  518. @Bean
  519. fun authenticationProvider(): ActiveDirectoryLdapAuthenticationProvider {
  520. return ActiveDirectoryLdapAuthenticationProvider("example.com", "ldap://company.example.com/")
  521. }
  522. ----
  523. ====