100% found this document useful (1 vote)
17 views

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

The document promotes the book 'Practical Spring LDAP: Using Enterprise Java-Based LDAP in Spring Data and Spring Framework 6, 2nd Edition' by Balaji Varanasi and Andres Sacco, providing a link for download. It also lists several other recommended books related to Spring and Java development, each with their respective download links. The document includes copyright information and details about the authors and publisher.

Uploaded by

paidjonva
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
17 views

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

The document promotes the book 'Practical Spring LDAP: Using Enterprise Java-Based LDAP in Spring Data and Spring Framework 6, 2nd Edition' by Balaji Varanasi and Andres Sacco, providing a link for download. It also lists several other recommended books related to Spring and Java development, each with their respective download links. The document includes copyright information and details about the authors and publisher.

Uploaded by

paidjonva
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Visit ebookmass.

com to download the full version and


explore more ebook or textbook

Practical Spring LDAP: Using Enterprise Java-Based


LDAP in Spring Data and Spring Framework 6 2nd
Edition Varanasi Balaji

_____ Click the link below to download _____


https://ebookmass.com/product/practical-spring-ldap-using-
enterprise-java-based-ldap-in-spring-data-and-spring-
framework-6-2nd-edition-varanasi-balaji/

Explore and download more ebook or textbook at ebookmass.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Practical Spring LDAP: Using Enterprise Java-Based LDAP in


Spring Data and Spring Framework 6 2nd Edition Varanasi
Balaji
https://ebookmass.com/product/practical-spring-ldap-using-enterprise-
java-based-ldap-in-spring-data-and-spring-framework-6-2nd-edition-
varanasi-balaji/

Pro Spring Security: Securing Spring Framework 6 and Boot


3–based Java Applications, Third Edition Massimo Nardone

https://ebookmass.com/product/pro-spring-security-securing-spring-
framework-6-and-boot-3-based-java-applications-third-edition-massimo-
nardone/

Beginning Spring Data: Data Access and Persistence for


Spring Framework 6 and Boot 3 Andres Sacco

https://ebookmass.com/product/beginning-spring-data-data-access-and-
persistence-for-spring-framework-6-and-boot-3-andres-sacco/

Pro Spring 6 with Kotlin: An In-depth Guide to Using


Kotlin APIs in Spring Framework 6 1st Edition Peter Späth

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/

Pro Spring 6: An In-Depth Guide to the Spring Framework,


6th Edition Iuliana Cosmina

https://ebookmass.com/product/pro-spring-6-an-in-depth-guide-to-the-
spring-framework-6th-edition-iuliana-cosmina/

Beginning Spring 6 Joseph B. Ottinger

https://ebookmass.com/product/beginning-spring-6-joseph-b-ottinger/

Hacking with Spring Boot 2.3: Reactive Edition

https://ebookmass.com/product/hacking-with-spring-boot-2-3-reactive-
edition/

Building Modern Business Applications: Reactive Cloud


Architecture for Java, Spring, and PostgreSQL 1st Edition
Peter Royal
https://ebookmass.com/product/building-modern-business-applications-
reactive-cloud-architecture-for-java-spring-and-postgresql-1st-
edition-peter-royal-2/
Practical Spring
LDAP
Using Enterprise Java-Based LDAP in
Spring Data and Spring Framework 6

Second 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
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

ISBN-13 (pbk): 979-8-8688-0001-6 ISBN-13 (electronic): 979-8-8688-0002-3


https://doi.org/10.1007/979-8-8688-0002-3

Copyright © 2023 by Balaji Varanasi and Andres Sacco


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Melissa Duffy
Development Editor: James Markham
Coordinating Editor: Gryffin Winkler
Cover designed by eStudioCalamar
Cover image by iulia_cristiana on unsplash (www.unsplash.com/)
Distributed to the book trade worldwide by Apress Media, LLC, 1 New York Plaza, New York, NY 10004,
U.S.A. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit
www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer
Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail [email protected]; for reprint,
paperback, or audio rights, please e-mail [email protected].
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub (https://github.com/Apress). For more detailed information, please visit https://www.
apress.com/gp/services/source-code.
Paper in this product is recyclable
To my grandparents who taught me the importance of
learning new things all the time.
To my wife and children for supporting me while
writing this book.
Table of Contents
About the Authors���������������������������������������������������������������������������������������������������� xi

About the Technical Reviewer������������������������������������������������������������������������������� xiii

Acknowledgments���������������������������������������������������������������������������������������������������xv
Introduction�����������������������������������������������������������������������������������������������������������xvii

Chapter 1: Introduction to LDAP������������������������������������������������������������������������������� 1


LDAP Overview������������������������������������������������������������������������������������������������������������������������������ 2
Directory vs. Database������������������������������������������������������������������������������������������������������������ 2
Information Model������������������������������������������������������������������������������������������������������������������������� 3
Object Classes������������������������������������������������������������������������������������������������������������������������������ 6
Directory Schema������������������������������������������������������������������������������������������������������������������������� 8
Naming Model������������������������������������������������������������������������������������������������������������������������������� 9
Functional Model������������������������������������������������������������������������������������������������������������������������ 11
Security Model���������������������������������������������������������������������������������������������������������������������������� 12
LDIF Format�������������������������������������������������������������������������������������������������������������������������������� 13
LDAP History������������������������������������������������������������������������������������������������������������������������������� 14
LDAP Vendors������������������������������������������������������������������������������������������������������������������������������ 15
Sample Application��������������������������������������������������������������������������������������������������������������������� 17
Summary������������������������������������������������������������������������������������������������������������������������������������ 18

Chapter 2: Java Support for LDAP�������������������������������������������������������������������������� 19


LDAP Using JNDI������������������������������������������������������������������������������������������������������������������������� 21
Connect to LDAP������������������������������������������������������������������������������������������������������������������������� 21
LDAP Operations������������������������������������������������������������������������������������������������������������������������� 25
Closing Resources���������������������������������������������������������������������������������������������������������������������� 25
Creating a New Entry������������������������������������������������������������������������������������������������������������������ 25
v
Table of Contents

Updating an Entry����������������������������������������������������������������������������������������������������������������������� 28
Removing an Entry���������������������������������������������������������������������������������������������������������������������� 30
Searching Entries������������������������������������������������������������������������������������������������������������������������ 31
Check How the Operations Work������������������������������������������������������������������������������������������������� 33
JNDI Drawbacks�������������������������������������������������������������������������������������������������������������������������� 38
Summary������������������������������������������������������������������������������������������������������������������������������������ 38

Chapter 3: Introducing Spring LDAP����������������������������������������������������������������������� 39


Motivation����������������������������������������������������������������������������������������������������������������������������������� 40
Documentation and Source Code Spring LDAP��������������������������������������������������������������������������� 40
Spring LDAP Packaging�������������������������������������������������������������������������������������������������������������� 41
Installing Spring LDAP Using Maven������������������������������������������������������������������������������������������� 42
Spring LDAP Archetypes������������������������������������������������������������������������������������������������������������� 43
Creating Projects Using IntelliJ��������������������������������������������������������������������������������������������������� 58
Spring LDAP Hello World������������������������������������������������������������������������������������������������������������� 61
Spring ApplicationContext����������������������������������������������������������������������������������������������������������� 65
Spring-Powered Search Client���������������������������������������������������������������������������������������������������� 65
Spring LdapTemplate Operations������������������������������������������������������������������������������������������������ 70
Add Operation����������������������������������������������������������������������������������������������������������������������������� 70
Modify Operation������������������������������������������������������������������������������������������������������������������������� 71
Deleting Operation���������������������������������������������������������������������������������������������������������������������� 72
Summary������������������������������������������������������������������������������������������������������������������������������������ 75

Chapter 4: Testing LDAP Code��������������������������������������������������������������������������������� 77


Concepts About Testing��������������������������������������������������������������������������������������������������������������� 77
Unit Testing���������������������������������������������������������������������������������������������������������������������������� 78
Mock Testing������������������������������������������������������������������������������������������������������������������������� 80
Integration Testing����������������������������������������������������������������������������������������������������������������� 81
Libraries to Do Tests�������������������������������������������������������������������������������������������������������������������� 82
JUnit�������������������������������������������������������������������������������������������������������������������������������������� 82
Mockito���������������������������������������������������������������������������������������������������������������������������������� 88
Testcontainers����������������������������������������������������������������������������������������������������������������������� 91

vi
Table of Contents

Creating the Tests����������������������������������������������������������������������������������������������������������������������� 94


Mocking the Templates��������������������������������������������������������������������������������������������������������� 97
Testing Using Embedded Server�������������������������������������������������������������������������������������������� 99
Moving to Tests with Testcontainers������������������������������������������������������������������������������������ 103
Summary���������������������������������������������������������������������������������������������������������������������������������� 105

Chapter 5: Advanced Spring LDAP������������������������������������������������������������������������ 107


JNDI Object Factories��������������������������������������������������������������������������������������������������������������� 107
Spring and Object Factories������������������������������������������������������������������������������������������������������ 111
DAO Implementation Using Object Factory������������������������������������������������������������������������������� 112
Implementing Finder Methods�������������������������������������������������������������������������������������������������� 115
Create Method�������������������������������������������������������������������������������������������������������������������������� 120
Update Method�������������������������������������������������������������������������������������������������������������������������� 122
Delete Method��������������������������������������������������������������������������������������������������������������������������� 124
Summary���������������������������������������������������������������������������������������������������������������������������������� 125

Chapter 6: Searching LDAP����������������������������������������������������������������������������������� 127


LDAP Search Criteria����������������������������������������������������������������������������������������������������������������� 127
Base Parameter������������������������������������������������������������������������������������������������������������������� 127
Scope Parameter����������������������������������������������������������������������������������������������������������������� 128
Filter Parameter������������������������������������������������������������������������������������������������������������������� 129
Optional Parameters������������������������������������������������������������������������������������������������������������ 130
LDAP Injection��������������������������������������������������������������������������������������������������������������������� 131
Spring LDAP Filters������������������������������������������������������������������������������������������������������������������� 132
EqualsFilter�������������������������������������������������������������������������������������������������������������������������� 136
LikeFilter������������������������������������������������������������������������������������������������������������������������������ 137
PresentFilter������������������������������������������������������������������������������������������������������������������������ 139
NotPresentFilter������������������������������������������������������������������������������������������������������������������� 140
Not Filter������������������������������������������������������������������������������������������������������������������������������ 141
GreaterThanOrEqualsFilter�������������������������������������������������������������������������������������������������� 142
LessThanOrEqualsFilter������������������������������������������������������������������������������������������������������� 143
AndFilter������������������������������������������������������������������������������������������������������������������������������ 144

vii
Table of Contents

OrFilter��������������������������������������������������������������������������������������������������������������������������������� 145
HardcodedFilter������������������������������������������������������������������������������������������������������������������� 146
WhitespaceWildcardsFilter�������������������������������������������������������������������������������������������������� 147
Handling Special Characters����������������������������������������������������������������������������������������������� 148
LDAP Query Builder Parameters����������������������������������������������������������������������������������������������� 148
Summary���������������������������������������������������������������������������������������������������������������������������������� 152

Chapter 7: Sorting and Paging Results����������������������������������������������������������������� 153


LDAP Controls��������������������������������������������������������������������������������������������������������������������������� 153
Identifying Supported Controls������������������������������������������������������������������������������������������������� 156
JNDI and Controls��������������������������������������������������������������������������������������������������������������������� 160
Spring LDAP and Controls��������������������������������������������������������������������������������������������������������� 162
Sort Control������������������������������������������������������������������������������������������������������������������������������� 163
Implementing Custom DirContextProcessor����������������������������������������������������������������������������� 171
Paged Search Controls�������������������������������������������������������������������������������������������������������������� 177
Summary���������������������������������������������������������������������������������������������������������������������������������� 186

Chapter 8: Object-Directory Mapping������������������������������������������������������������������� 187


Spring ODM Basics������������������������������������������������������������������������������������������������������������������� 188
ODM Metadata�������������������������������������������������������������������������������������������������������������������������� 191
ODM Service Class�������������������������������������������������������������������������������������������������������������������� 195
Creating Custom Converter������������������������������������������������������������������������������������������������������� 201
Summary���������������������������������������������������������������������������������������������������������������������������������� 211

Chapter 9: LDAP Transactions������������������������������������������������������������������������������ 213


Transaction Basics�������������������������������������������������������������������������������������������������������������������� 213
Local vs. Global Transactions���������������������������������������������������������������������������������������������������� 215
Programmatic vs. Declarative Transactions������������������������������������������������������������������������������ 217
Programmatically���������������������������������������������������������������������������������������������������������������������� 217
Declaratively����������������������������������������������������������������������������������������������������������������������������� 218
Spring Transaction Abstraction������������������������������������������������������������������������������������������������� 218
Declarative Transactions Using Spring�������������������������������������������������������������������������������������� 220

viii
Table of Contents

LDAP Transaction Support��������������������������������������������������������������������������������������������������������� 224


Spring LDAP Transaction Support��������������������������������������������������������������������������������������������� 225
Compensating Transactions������������������������������������������������������������������������������������������������������ 226
Summary���������������������������������������������������������������������������������������������������������������������������������� 243

Chapter 10: Odds and Ends���������������������������������������������������������������������������������� 245


Authentication Using Spring LDAP�������������������������������������������������������������������������������������������� 245
Handling Authentication Exceptions����������������������������������������������������������������������������������������� 252
Parsing LDIF Data���������������������������������������������������������������������������������������������������������������������� 255
LDAP Connection Pooling���������������������������������������������������������������������������������������������������������� 261
Built-In Connection Pooling������������������������������������������������������������������������������������������������������� 261
Spring LDAP Connection Pooling���������������������������������������������������������������������������������������������� 262
Pool Validation��������������������������������������������������������������������������������������������������������������������������� 267
Summary���������������������������������������������������������������������������������������������������������������������������������� 269

Appendix A: Setting Up Environment Tools����������������������������������������������������������� 271

Appendix B: Recommended and Alternative Tools����������������������������������������������� 281

Appendix C: Set Up LDAP Server��������������������������������������������������������������������������� 287

Appendix D: Opening a Project����������������������������������������������������������������������������� 307

Appendix E: Further Reading�������������������������������������������������������������������������������� 311

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.

Andres Sacco has been working as a developer since


2007 in different languages, including Java, PHP, Node.js,
Scala, and Kotlin. His background is mostly in Java and the
libraries or frameworks associated with this language. At
most of the companies he worked for, he researched new
technologies to improve the performance, stability, and
quality of the applications of each company. In 2017, he
started to find new ways to optimize the transference of data
between applications to reduce the cost of infrastructure. He
suggested some actions, some applicable in all of the manual microservices and others
in just a few. All of this work includes creating a series of theoretic-practical projects
(available on Manning.com). Recently, he coauthored an Apress book titled Beginning
Scala 3. He also published a set of theoretic-practical projects about uncommon ways of
testing, such as architecture tests and chaos engineering.

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

• My little daughter, Francesca, who helped me relax while writing


each chapter

• My baby, Allegra, who is the new family member and my inspiration


to write this book

• My friends, German Canale and Julian Delley, who always trusted me


to write a book and supported me during tough times

Specially mentioning Manuel Jordan for guiding me in improving the quality of


the book.
My sincere thanks to the beautiful team at Apress for their support during the
publication of this book. Thanks to Shonmirin P.A. for providing excellent support.
Finally, thanks to Mark Powers and Melissa Duffy for suggesting and allowing me to
write a book. Also, I want to mention the great job that Balaji Varanasi did with the first
edition of this book which gave the base to write the second edition.

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.

What the Book Covers


Chapter 1 starts with an overview of directory servers. It then discusses the basics of
LDAP and introduces the four LDAP information models. It finishes with an introduction
to the LDIF format used for representing LDAP data.
Chapter 2 focuses on the Java Naming and Directory Interface (JNDI). In this chapter,
you look at creating applications that interact with LDAP using plain JNDI.
Chapter 3 explains Spring LDAP and why it is an important option in an enterprise
developer’s repertoire. In this chapter, you set up the development environment to
create Spring LDAP applications and other important tools, such as Maven and a test
LDAP server. Finally, you implement a basic but complete Spring LDAP application
using annotations.
Chapter 4 covers the fundamentals of unit and integration testing. You then
look at setting up an embedded LDAP server for unit testing your application code;
alternatively, you will see how to use Testcontainers to run LDAP using a docker image.
You also review available tools for generating test data. Finally, you use the Mockito
library to mock test LDAP code.

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.

Downloading Source Code


The source code for the examples in this book can be downloaded from www.apress.com.
For detailed information about locating this book’s source code, visit www.apress.com/gp/
services/source-code. The code is organized by chapter and can be built using Maven.

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.

Figure 1-1. Directory server and client 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

protocol is based on an earlier X.5001 standard but is significantly simpler (lightweight)


and easily extensible. Over the years, the LDAP protocol went through iterations and is
currently at version 3.0.

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:

• The Information model determines the structure of information


stored in the directory.

• The Naming model defines how information is organized and


identified in the directory.

• The Functional model defines the operations performed on the


directory.

• The Security model defines how to protect information from


unauthorized access.

We will look at each of these models in the following sections.

Directory vs. Database


Beginners often need clarification and picture an LDAP directory as a relational
database. Like a database, an LDAP directory stores information. However, several key
characteristics set a directory apart from relational databases.
LDAP directories typically store data that is relatively static. For example, employee
information stored in LDAP, such as their phone number or name, does not change
daily. However, users and applications look up this information very frequently. Since
the data in a directory is accessed more often than updated, LDAP directories follow the
WORM principle2, 3 and are heavily optimized for read performance. Placing data that
change quite often in LDAP does not make sense.

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

Relational databases employ referential integrity and locking techniques to ensure


data consistency. The type of data stored in LDAP usually does not warrant such strict
consistency requirements. Hence, most of these features need to be present on LDAP
servers. Also, transactional semantics to roll back transactions are not defined under
LDAP specification.
Relational databases follow normalization principles to avoid data duplication
and redundancy. On the other hand, LDAP directories are organized in a hierarchical,
object-oriented way. This organization violates some of the normalization principles.
Also, there needs to be a concept of table joins in LDAP.
Even though directories lack several of the RDBMS4 features mentioned earlier, many
modern LDAP directories are built on top of relational databases such as DB2,5 MySQL,6
and PostgreSQL.7
At some point, LDAP has similar characteristics to nonrelational databases like
Cassandra,8 MongoDB,9 and many others where the performance of the write/read, high
availability, and scalability are more relevant than the consistency.

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

Table 1-1. Employee LDAP Entry


Employee Entry

objectClass inetOrgPerson
givenName John
surname Smith
mail [email protected]
[email protected]
mobile +1 801 100 1000

Note Attribute names, by default, are case-insensitive. However, it is


recommended to use camel case format in LDAP operations.

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.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of damages.
If any disclaimer or limitation set forth in this agreement violates the
law of the state applicable to this agreement, the agreement shall be
interpreted to make the maximum disclaimer or limitation permitted
by the applicable state law. The invalidity or unenforceability of any
provision of this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the Foundation,


the trademark owner, any agent or employee of the Foundation,
anyone providing copies of Project Gutenberg™ electronic works in
accordance with this agreement, and any volunteers associated with
the production, promotion and distribution of Project Gutenberg™
electronic works, harmless from all liability, costs and expenses,
including legal fees, that arise directly or indirectly from any of the
following which you do or cause to occur: (a) distribution of this or
any Project Gutenberg™ work, (b) alteration, modification, or
additions or deletions to any Project Gutenberg™ work, and (c) any
Defect you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new computers.
It exists because of the efforts of hundreds of volunteers and
donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project Gutenberg™’s
goals and ensuring that the Project Gutenberg™ collection will
remain freely available for generations to come. In 2001, the Project
Gutenberg Literary Archive Foundation was created to provide a
secure and permanent future for Project Gutenberg™ and future
generations. To learn more about the Project Gutenberg Literary
Archive Foundation and how your efforts and donations can help,
see Sections 3 and 4 and the Foundation information page at
www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-profit
501(c)(3) educational corporation organized under the laws of the
state of Mississippi and granted tax exempt status by the Internal
Revenue Service. The Foundation’s EIN or federal tax identification
number is 64-6221541. Contributions to the Project Gutenberg
Literary Archive Foundation are tax deductible to the full extent
permitted by U.S. federal laws and your state’s laws.

The Foundation’s business office is located at 809 North 1500 West,


Salt Lake City, UT 84116, (801) 596-1887. Email contact links and up
to date contact information can be found at the Foundation’s website
and official page at www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission of
increasing the number of public domain and licensed works that can
be freely distributed in machine-readable form accessible by the
widest array of equipment including outdated equipment. Many
small donations ($1 to $5,000) are particularly important to
maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws regulating


charities and charitable donations in all 50 states of the United
States. Compliance requirements are not uniform and it takes a
considerable effort, much paperwork and many fees to meet and
keep up with these requirements. We do not solicit donations in
locations where we have not received written confirmation of
compliance. To SEND DONATIONS or determine the status of
compliance for any particular state visit www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states where


we have not met the solicitation requirements, we know of no
prohibition against accepting unsolicited donations from donors in
such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot make


any statements concerning tax treatment of donations received from
outside the United States. U.S. laws alone swamp our small staff.

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.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could be
freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose network of
volunteer support.
Project Gutenberg™ eBooks are often created from several printed
editions, all of which are confirmed as not protected by copyright in
the U.S. unless a copyright notice is included. Thus, we do not
necessarily keep eBooks in compliance with any particular paper
edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg Literary
Archive Foundation, how to help produce our new eBooks, and how
to subscribe to our email newsletter to hear about new eBooks.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

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.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookmass.com

You might also like