Practical Spring LDAP: Using Enterprise Java-Based LDAP in Spring Data and Spring Framework 6 2nd Edition Varanasi Balaji - Download the ebook now to never miss important content
Practical Spring LDAP: Using Enterprise Java-Based LDAP in Spring Data and Spring Framework 6 2nd Edition Varanasi Balaji - Download the ebook now to never miss important content
https://ebookmass.com/product/pro-spring-security-securing-spring-
framework-6-and-boot-3-based-java-applications-third-edition-massimo-
nardone/
https://ebookmass.com/product/beginning-spring-data-data-access-and-
persistence-for-spring-framework-6-and-boot-3-andres-sacco/
https://ebookmass.com/product/pro-spring-6-with-kotlin-an-in-depth-
guide-to-using-kotlin-apis-in-spring-framework-6-1st-edition-peter-
spath/
Spring 6 Recipes: A Problem-Solution Approach to Spring
Framework Marten Deinum
https://ebookmass.com/product/spring-6-recipes-a-problem-solution-
approach-to-spring-framework-marten-deinum/
https://ebookmass.com/product/pro-spring-6-an-in-depth-guide-to-the-
spring-framework-6th-edition-iuliana-cosmina/
https://ebookmass.com/product/beginning-spring-6-joseph-b-ottinger/
https://ebookmass.com/product/hacking-with-spring-boot-2-3-reactive-
edition/
Balaji Varanasi
Andres Sacco
Practical Spring LDAP: Using Enterprise Java-Based LDAP in Spring Data and
Spring Framework 6, Second Edition
Balaji Varanasi Andres Sacco
Salt Lake City, UT, USA Buenos Aires, Buenos Aires, Argentina
Acknowledgments���������������������������������������������������������������������������������������������������xv
Introduction�����������������������������������������������������������������������������������������������������������xvii
Updating an Entry����������������������������������������������������������������������������������������������������������������������� 28
Removing an Entry���������������������������������������������������������������������������������������������������������������������� 30
Searching Entries������������������������������������������������������������������������������������������������������������������������ 31
Check How the Operations Work������������������������������������������������������������������������������������������������� 33
JNDI Drawbacks�������������������������������������������������������������������������������������������������������������������������� 38
Summary������������������������������������������������������������������������������������������������������������������������������������ 38
vi
Table of Contents
vii
Table of Contents
OrFilter��������������������������������������������������������������������������������������������������������������������������������� 145
HardcodedFilter������������������������������������������������������������������������������������������������������������������� 146
WhitespaceWildcardsFilter�������������������������������������������������������������������������������������������������� 147
Handling Special Characters����������������������������������������������������������������������������������������������� 148
LDAP Query Builder Parameters����������������������������������������������������������������������������������������������� 148
Summary���������������������������������������������������������������������������������������������������������������������������������� 152
viii
Table of Contents
Index��������������������������������������������������������������������������������������������������������������������� 313
ix
About the Authors
Balaji Varanasi is a software development manager and technology entrepreneur. He
has over 13 years of experience architecting and developing Java/.NET applications and,
more recently, iPhone apps. During this period, he has worked in the areas of security,
web accessibility, search, and enterprise portals. He has a master’s degree in computer
science and serves as adjunct faculty, teaching programming and information system
courses. When not programming, he enjoys spending time with his lovely wife in Salt
Lake City, Utah.
xi
Visit https://ebookmass.com today to explore
a vast collection of ebooks across various
genres, available in popular formats like
PDF, EPUB, and MOBI, fully compatible with
all devices. Enjoy a seamless reading
experience and effortlessly download high-
quality materials in just a few simple steps.
Plus, don’t miss out on exciting offers that
let you access a wealth of knowledge at the
best prices!
About the Technical Reviewer
Manuel Jordan is an autodidactic developer and researcher who enjoys learning new
technologies for his own experiments about creating new integrations among them.
Manuel won the 2010 Springy Award – Community Champion and Spring Champion
2013. In his little free time, he reads the Bible and composes music on his bass
and guitar.
You can reach him through his Twitter account, @dr_pompeii.
xiii
Acknowledgments
I would like to thank my family members and friends for their encouragement and
support during the writing of this book:
• My wife, Gisela, who was always patient when I spent long hours at
my computer desk working on this book
xv
Introduction
Practical Spring LDAP provides complete coverage of Spring LDAP, a framework
designed to take the pain out of LDAP programming. This book starts by explaining the
fundamental concepts of LDAP and showing the reader how to set up the development
environment. It then dives into Spring LDAP, analyzing the problems it is designed to
solve. After that, the book focuses on the practical aspects of unit testing and integration
testing with LDAP. An in-depth treatment of LDAP controls and Spring LDAP features,
such as Object-Directory Mapping and LDIF (LDAP Data Interchange Format) parsing,
follows this. Finally, it concludes with discussions on LDAP authentication and
connection pooling.
xvii
Introduction
Chapter 5 introduces the basics of JNDI object factories and uses these factories
for creating objects that are more meaningful to the application. You then examine
a complete Data Access Object (DAO) layer implementation using Spring LDAP and
object factories.
Chapter 6 covers LDAP search. This chapter begins with the underlying ideas of
LDAP search. I then introduce various Spring LDAP filters that make LDAP searching
easier. Finally, you look at creating a custom search filter to address situations where the
current set is insufficient.
Chapter 7 provides an in-depth overview of LDAP controls that can be used for
extending LDAP server functionality. Then it moves on to sorting and paging LDAP
results using sort and page controls.
Chapter 8 deals with Object-Directory Mapping (ODM), a feature in Spring LDAP. In
this chapter, you look at bridging the gap between the domain model and the directory
server. You then re-implement the DAO using ODM concepts.
Chapter 9 introduces the important ideas of transactions and transactional integrity
before analyzing the transaction abstractions provided by Spring Framework. Finally, it
takes a look at Spring LDAP’s compensating transaction support.
Chapter 10 starts with implementing authentication, the most common operation
against LDAP. It then deals with parsing LDIF files using another feature introduced
in Spring. I end the chapter by looking at the connection pooling support provided by
Spring LDAP.
Target Audience
Practical Spring LDAP is intended for developers interested in building Java/JEE
applications using LDAP. It also teaches techniques for creating unit/integration tests for
LDAP applications. The book assumes basic familiarity with Spring Framework; prior
exposure to LDAP is helpful but optional. Developers already familiar with Spring LDAP
will find best practices and examples to help them get the most out of the framework.
xviii
Introduction
P
rerequisites
You should install Java JDK1 21 or higher on your machine, Maven2 3.8.0 or higher, and
some IDE. Some options for the IDE could be Eclipse,3 IntelliJ IDEA,4 Visual Studio
Code,5 and others, but you can choose which is the best for you.
To reduce the complexity of installing all LDAP vendors on your machine, I
recommend you install Docker6 and use it to run each LDAP. The use and installation of
Docker are outside the scope of this book, but there are some tutorials7 or cheatsheet8
with the most common commands.
Note If you don’t have it installed on your machine, you can check Appendixes A,
B, and C, which have information about installing the different tools and loading the
information on LDAP.
After installing all the tools, you must check if they are correctly installed before
reading the different chapters.
In the case of Java, you need to run the following command:
% java -version
openjdk 21 2023-09-19
OpenJDK Runtime Environment (build 21+35-2513)
OpenJDK 64-Bit Server VM (build 21+35-2513, mixed mode, sharing)
After that, you need to check if the version of Maven is correct using this command:
% mvn --version
Apache Maven 3.9.1
Maven home: /usr/share/maven
1
https://jdk.java.net/
2
https://maven.apache.org/
3
https://www.eclipse.org/downloads
4
https://www.jetbrains.com/es-es/idea/
5
https://code.visualstudio.com/
6
https://www.docker.com/
7
https://docker-curriculum.com/
8
https://michaelhaar.dev/my-docker-compose-cheatsheet
xix
Introduction
Last, if you want to check whether Docker runs correctly on your machine, you can
do that using the following command:
% docker --version
Docker version 24.0.2, build cb74dfc
Remember that I mentioned that Docker is optional. It’s only recommended for
reducing the complexity of installing LDAP vendors on your machine.
Questions?
If you have any questions or suggestions, contact the author at [email protected].
xx
CHAPTER 1
Introduction to LDAP
We all deal with directories daily. We use a telephone directory to look up phone
numbers. When visiting a library, we use the library catalog to look up the books we
want to read. We use the file system directory with computers to store our files and
documents. Simply put, a directory is a repository of information. The information is
usually organized so that it can be retrieved easily.
Directories on a network are typically accessed using the client/server
communication model. Applications wanting to read or write data to a directory
communicate with specialized servers. The directory server performs a read or write
operation on the actual directory. Figure 1-1 shows this client/server interaction.
The communication between the directory server and client applications is usually
accomplished using standardized protocols. The Lightweight Directory Access Protocol
(LDAP) provides a standard protocol for communicating with a directory. The directory
servers that implement the LDAP protocol are usually called LDAP servers. The LDAP
1
© Balaji Varanasi and Andres Sacco 2023
B. Varanasi and A. Sacco, Practical Spring LDAP, https://doi.org/10.1007/979-8-8688-0002-3_1
Chapter 1 Introduction to LDAP
LDAP Overview
LDAP defines a message protocol used by directory clients and directory servers. LDAP
can be better understood by considering the following four models it is based on:
1
https://docs.oracle.com/javase/jndi/tutorial/ldap/models/x500.html
2
https://en.wikipedia.org/wiki/Write_Once_Read_Many
3
https://www.techtarget.com/searchstorage/definition/WORM-write-once-read-many
2
Chapter 1 Introduction to LDAP
Information Model
The basic unit of information stored in LDAP is an entry. Entries hold information about
real-world objects such as employees, servers, printers, and organizations. Each entry in
an LDAP directory comprises zero or more attributes. Attributes are key-value pairs that
hold information about the object the entry represents. The key portion of an attribute
is also called the attribute type and describes the information that can be stored in the
attribute. The value portion of the attribute contains the actual information. Table 1-1
shows a portion of an entry representing an employee. The left column in the entry
contains the attribute types, and the right column holds the attribute values.
4
https://www.oracle.com/in/database/what-is-a-relational-database/
5
https://www.ibm.com/products/db2
6
https://www.mysql.com/
7
https://www.postgresql.org/
8
https://cassandra.apache.org/_/index.html
9
https://www.mongodb.com/
3
Chapter 1 Introduction to LDAP
objectClass inetOrgPerson
givenName John
surname Smith
mail [email protected]
[email protected]
mobile +1 801 100 1000
You will notice that the mail attribute has two values. Attributes that are allowed to
hold multiple values are called multivalued attributes. Single-valued attributes, on the
other hand, can only hold a single value. The LDAP specification does not guarantee the
order of the values in a multivalued attribute.
Each attribute type is associated with a syntax that dictates the format of the
data stored as an attribute value. For example, the mobile attribute type has a
telephoneNumber syntax. This forces the attribute to hold a string value with a length
between 1 and 32.
Additionally, the syntax also defines the attribute value behavior during search
operations. For example, the givenName attribute has the syntax DirectoryString. This
syntax enforces that only alphanumeric characters are allowed as values. Table 1-2 lists
some common attributes and their associated syntax description.
4
Visit https://ebookmass.com today to explore
a vast collection of ebooks across various
genres, available in popular formats like
PDF, EPUB, and MOBI, fully compatible with
all devices. Enjoy a seamless reading
experience and effortlessly download high-
quality materials in just a few simple steps.
Plus, don’t miss out on exciting offers that
let you access a wealth of knowledge at the
best prices!
Other documents randomly have
different content
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookmass.com