- Spring Security(Third Edition)
- Mick Knutson Robert Winch Peter Mularien
- 290字
- 2025-04-04 17:54:29
Updating our dependencies
We have already included all of the dependencies you need for this chapter, so you will not need to make any updates to your build.gradle file. However, if you were just adding LDAP support to your own application, you would need to add spring-security-ldap as a dependency in build.gradle, as follows:
//build.gradle
dependencies {
// LDAP:
compile('org.springframework.boot:spring-boot-starter-data-ldap')
compile("org.springframework.ldap:spring-ldap-core")
compile("org.springframework.security:spring-security-ldap")
compile("org.springframework:spring-tx")
compile("com.unboundid:unboundid-ldapsdk")
...
}
Due to an artifact resolution issue with Gradle, spring-tx must be pulled in or Gradle will fetch an older one that doesn’t work.
As mentioned previously, Spring Security's LDAP support is built on top of Spring LDAP. Gradle will automatically bring this dependency in as a transitive dependency, so there is no need to explicitly list it.
If you were using ApacheDS to run an LDAP server within your web application, as we are doing in our calendar application, you would need to add dependencies on the relevant ApacheDS JARs. There is no need to make these updates to our sample application, since we have already included them. Note that these dependencies are not necessary if you are connecting to an external LDAP server:
//build.gradle
compile 'org.apache.directory.server:apacheds-core:2.0.0-M23'
compile 'org.apache.directory.server:apacheds-protocol-ldap:2.0.0-M23'
compile 'org.apache.directory.server:apacheds-protocol-shared:2.0.0
-M23'
Configuring embedded LDAP integration
Let's now enable the JBCP calendar application to support LDAP-based authentication. Fortunately, this is a relatively simple exercise, using the embedded LDAP server and a sample LDIF file. For this exercise, we will be using an LDIF file created for this book, intended to capture many of the common configuration scenarios with LDAP and Spring Security. We have included several more sample LDIF files, some from Apache DS 2.0.0-M23 and one from the Spring Security unit tests, which you may choose to experiment with as well.