PDF Practical Spring LDAP: Using Enterprise Java-Based LDAP in Spring Data and Spring Framework 6 2nd Edition Balaji Varanasi download
PDF Practical Spring LDAP: Using Enterprise Java-Based LDAP in Spring Data and Spring Framework 6 2nd Edition Balaji Varanasi download
com
https://ebookmeta.com/product/practical-spring-ldap-using-
enterprise-java-based-ldap-in-spring-data-and-spring-
framework-6-2nd-edition-balaji-varanasi/
OR CLICK HERE
DOWLOAD NOW
https://ebookmeta.com/product/spring-rest-building-java-microservices-
and-cloud-applications-balaji-varanasi/
ebookmeta.com
https://ebookmeta.com/product/pro-spring-security-securing-spring-
framework-6-and-boot-3-based-java-applications-third-edition-massimo-
nardone/
ebookmeta.com
https://ebookmeta.com/product/beginning-spring-data-data-access-and-
persistence-for-spring-framework-6-and-boot-3-1st-edition-andres-
sacco/
ebookmeta.com
https://ebookmeta.com/product/beauty-in-chaos-1st-edition-nacole-
stayton/
ebookmeta.com
The Aliens Are Coming 1st Edition Ben Miller
https://ebookmeta.com/product/the-aliens-are-coming-1st-edition-ben-
miller-2/
ebookmeta.com
Vegan Junk Food 200 Vegan Recipes for the Foods You Crave
Minus the Ingredients You Don t Lane Gold
https://ebookmeta.com/product/vegan-junk-food-200-vegan-recipes-for-
the-foods-you-crave-minus-the-ingredients-you-don-t-lane-gold/
ebookmeta.com
https://ebookmeta.com/product/worlds-worst-conspiracies-the-truth-is-
they-dont-want-you-to-know-1st-edition-mike-rothschild/
ebookmeta.com
https://ebookmeta.com/product/america-unbound-encyclopedic-literature-
and-hemispheric-studies-1st-edition-antonio-barrenechea/
ebookmeta.com
Let s Taco Bout Love Man of the Month May a fake
relationship curvy girl romance 1st Edition Kat Baxter
https://ebookmeta.com/product/let-s-taco-bout-love-man-of-the-month-
may-a-fake-relationship-curvy-girl-romance-1st-edition-kat-baxter/
ebookmeta.com
Balaji Varanasi and Andres Sacco
Andres Sacco
Buenos Aires, Buenos Aires, Argentina
This work is subject to copyright. All rights are solely and exclusively
licensed 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.
The publisher, the authors, and the editors are safe to assume that the
advice and information in this book are believed to be true and accurate
at the date of publication. Neither the publisher nor the authors or the
editors give a warranty, expressed or implied, with respect to the
material contained herein or for any errors or omissions that may have
been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.
This Apress imprint is published by the registered company APress
Media, LLC, part of Springer Nature.
The registered company address is: 1 New York Plaza, New York, NY
10004, U.S.A.
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.
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.
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.
Prerequisites
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
% docker --version
Docker version 24.0.2, build cb74dfc
Questions?
If you have any questions or suggestions, contact the author at
sacco.andres@gmail.com.
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.
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.
Table of Contents
Chapter 1:Introduction to LDAP
LDAP Overview
Directory vs.Database
Information Model
Object Classes
Directory Schema
Naming Model
Functional Model
Security Model
LDIF Format
LDAP History
LDAP Vendors
Sample Application
Summary
Chapter 2:Java Support for LDAP
LDAP Using JNDI
Connect to LDAP
LDAP Operations
Closing Resources
Creating a New Entry
Updating an Entry
Removing an Entry
Searching Entries
Check How the Operations Work
JNDI Drawbacks
Summary
Chapter 3:Introducing Spring LDAP
Motivation
Documentation and Source Code Spring LDAP
Spring LDAP Packaging
Installing Spring LDAP Using Maven
Spring LDAP Archetypes
Creating Projects Using IntelliJ
Spring LDAP Hello World
Spring ApplicationContext
Spring-Powered Search Client
Spring LdapTemplate Operations
Add Operation
Modify Operation
Deleting Operation
Summary
Chapter 4:Testing LDAP Code
Concepts About Testing
Unit Testing
Mock Testing
Integration Testing
Libraries to Do Tests
JUnit
Mockito
Testcontainers
Creating the Tests
Mocking the Templates
Testing Using Embedded Server
Moving to Tests with Testcontainers
Summary
Chapter 5:Advanced Spring LDAP
JNDI Object Factories
Spring and Object Factories
DAO Implementation Using Object Factory
Implementing Finder Methods
Create Method
Update Method
Delete Method
Summary
Chapter 6:Searching LDAP
LDAP Search Criteria
Base Parameter
Scope Parameter
Filter Parameter
Optional Parameters
LDAP Injection
Spring LDAP Filters
EqualsFilter
LikeFilter
PresentFilter
NotPresentFilter
Not Filter
Other documents randomly have
different content
She stopped, wishing her last words unsaid; but he took her remark to be
general and nodded, and leaned forward to look at Peter, lying wan and
sleepy in her lap. He was very tired; but not fretful: only silent and languid.
Julian touched his cheek.
‘And is Peter part of the dream too?’ he asked softly.
‘Yes. Isn’t he?’
He was the passive, waiting core of the ominousness, the unexpected
thing you shrank from yet knew you had to come back to find. In the dream,
it was quite natural to sit there with Julian, holding Charlie’s child.
‘Isn’t it strange,’ he said musingly, ‘that this is the only proof—the only
proof that Charlie ever lived? A child! Not another whisper from him.... I
haven’t even a letter. I suppose she has.’ An utter misery showed for a
moment in his face, and he paused before adding: ‘And no portrait. Do you
remember him?’
‘Of course.’ Her throat ached with tears. ‘He was the most beautiful
person——’
‘Yes he was. A spring of beauty. He didn’t care about that, you know, in
spite of what people said. His physical brilliance somehow obscured his
character, I think, made it difficult to judge. But he had a very simple heart.’
Was it true? Who had ever known Charlie’s heart? Was not Julian
speaking as it were in epitaphs, as if his brother had become unreal to him,
—a symbol for grief,—the individual ghost forgotten? Perhaps Mariella
alone of all people had known his heart—strange thought!—and still had
him quick within her; but she would never tell.
‘It’s not often I speak of him to anyone,’ said Julian; and his usually
narrow swift-glancing eyes suddenly opened wide and held hers as if he had
some unendurable thought. They were pits of misery. What was he
remembering?
After a long silence he took the boy on his lap again and said softly:
‘Peter shall play.’
Peter put out both his hands, and carefully, delicately dropped them on
the keys, listening and smiling.
‘Is he musical?’
Julian nodded.
‘Oh yes. He’s that—more or less. I seem to detect all the symptoms.’
He looked down at the leaning head on his shoulder with a sort of harsh
tenderness; and after a while he spoke again as if out of a deep musing.
‘What, one asks oneself, is she going to do about him?’
‘Mariella?’
‘Yes.’
‘Well—it’s more or less mechanical, with a boy, isn’t it? School and
university,—and in his case, musical instruments?’
‘How wretched he’s going to be,’ he said fiercely, ‘Can’t you see?’
‘She wouldn’t let him be wretched,’ she said, startled.
‘She?—she won’t know it! And if she did, she’d be helpless.’
‘Well, he’s got you.’
‘Me!’ He gave his bark of laughter.
‘I mean—you like him,’ she ventured timidly.
‘I can’t stand brats. And they can’t stand me.’
‘I’m not talking about brats. I’m talking about Peter. I thought you liked
him.’
He laughed.
‘You look so shocked. Do you like brats then?’
‘Yes.’
‘Hmm—Well, I dare say Mariella says the same. In fact, I’ve heard her.
She’s very correct, poor darling, in all her little contributions.’ He looked at
the clock. ‘It’s time I took him up. Wait for me.’
When he came back he laughed again.
‘You still look shocked. I’m not a nice man, am I?’
‘I’m not thinking about you.’
After a pause he said:
‘It’s all right, Judy. You’re right. I do like him. But because I’m bound to
feel, must I refuse to think?’
‘Think what?’
‘That he ought never to have been born.’
‘Oh!’ she blushed, horrified.
He flung at her:
‘What do you wish for the people you love? Life?’
‘Of course. Don’t you?’ She was confused, out of her depth.
‘No—God, no!’
‘Then what?’
‘Unconsciousness. Heavenly, heavenly annihilation.’
‘Then why don’t you kill him?’ She was shocked at the sound of her
own words.
‘Because I don’t love him enough.’ He laughed. ‘Luckily I don’t love
anyone enough—never shall. Not even myself.’ He turned to the window
and said, speaking low, with strained composure: ‘Sometimes—in moments
of clear vision—I see it all, the whole futile sickening farce. But it gets
obscured. So my friends are safe. Besides, I’m so damned emotional: if they
implored me to save them I shouldn’t have the heart to argue how much
wiser they’d be to die.’
She wondered with alarm if he were mad and sat silent, waiting in vain
for an intelligent counter-argument to present itself. Finally she stammered:
‘But it’s not a futile sickening farce to normal people.’
‘Oh, normal people! they’re the whole trouble. They don’t think. They
don’t see that you can’t miss anything of which you’ve never been
conscious. All the things for which they value life—their food, their loves
and lusts and little schemes and athletic exercises, all the little excitements
—what are they but a desperate questioning: ‘What shall I do to be happy,
to fill up the emptiness, leaven the dreariness? How can I best cheat myself
and God?’ And, strange to say, they don’t think what a lot of trouble would
have been saved if they’d never been—never had to go hunting for their
pleasures or flying from their pains. A trivial agitation that should never
have begun; and back into nothing again. How silly!... As you may have
guessed, I am not altogether convinced of the One Increasing Purpose. I
have the misfortune to be doubtful of the objective value of life, and
especially of its pains. Neither do my own griefs either interest or purify
me. So you see——’
He turned from the window and smiled at her.
‘Yet even I have my compensations: music, food, beautiful people,
conversation—or should I say monologue?—especially this sort of bogus
philosophy to which you have been so patiently listening. Do you agree
with me, by the way?’
‘No. Do you?’
He laughed and shrugged.
‘Still,’ she added, ‘it’s a point of view. I’ll think about it. I can’t think
quickly. But oh!—--’ She stopped.
‘What?’
‘I’m so thankful I’ve been born.’ She blushed. ‘Even if I knew you were
right I wouldn’t feel it.’
‘Ah, you’ve never bored yourself. Perhaps you never will. I hope and
believe it’s unlikely.’
She looked at him with distress. Poor Julian! He had to be theatrical, but
his unhappiness was sincere enough. His jesting was so humourless, so
affected that it crushed the spirit; and all his talking seemed less a normal
exercise than a forced hysterical activity assumed to ease sharp
wretchedness. It was not fair to judge and dislike him: he was a sick man.
He sat down again at the piano, and she rose on an impulse and went and
stood beside him.
‘Some chaps dance,’ he said. ‘They haven’t stopped dancing since
they’ve been back. I play——’ He plunged into a medley of ragtime—‘and
play—and play—and play. Syncopation—gets you—right on the nerves—
like cocaine—No wonder it’s popular.’
‘Do you like it?’
‘Intellectually,’ he said, ‘I adore it. It’s so clever.’
He played on loudly, rapidly, with pyrotechnical brilliance, then stopped.
‘My passions, however, are too debile to be stirred.’
He flung round on the piano stool and dropped his face into his hands,
rubbing his eyes wearily.
‘Julian—I wish you weren’t—I wish you could——’
He looked up, startled, saw her expression, looked quickly away again
and gave an embarrassed laugh like a boy.
‘It’s all right,’ he said, ‘You needn’t take any notice of me. I’m being a
bore. I’m sorry.’ The last words were faintly husky.
‘Oh, you’re not a bore, you’re not! Only—don’t be so miserable.’
In the awkward silence that followed she said:
‘I must go.’
‘No, you’re not to go,’ he said gently. ‘Stay and talk to me.’ He paused.
‘The trouble is, I can’t sleep, you know, and it makes me a bit jumpy. I
don’t like my thoughts, and they will, they will be thought about. But I shall
get better in time.’
‘Poor Julian!’
He allowed his face to relax, and his manner was suddenly quiet and
simple, almost happy: the unexpected sympathy had made him cheerful.
‘You mustn’t go, Judith, you must stay to supper.’
‘I can’t. What will Mariella say?’
‘Mariella doesn’t say. Whether she thinks is the problem,—or even feels.
Is she a very remarkable person? Or is it simply arrested development?’
‘No. I don’t think so.’
‘Not?’
She smiled to herself, struck with a fancy.
‘Perhaps she’s a fairy, Julian.’
As she said it she grew suddenly thoughtful; for it had flashed upon her
that perhaps that was the explanation of Roddy; perhaps he was a fairy, and
in that case it was no use—he would never....
‘A fairy. I never thought of that.’ He mused, pleased with the idea. ‘You
know it must mean something, that nobody’s ever suggested giving her a
petit nom, or curtailing the mouthful; she’s always been Mariella.’
He began humming a little tune in his contentment. Quickly she said:
‘Just to go back to Peter. You don’t mean it, do you? Why should he be
wretched? Think of the things you can teach him. You know you’ll love
that.’
He looked a trifle dashed; but after a moment his face cleared again, and
his eyes smiled kindly at her.
‘Don’t worry. At all events, I’ll see he’s not ill-treated—except in my
own way. That is, if she’ll let me. She will. She’s very good-tempered, I
must say. She’s never allowed me to quarrel with her. She well might have.’
He looked like brooding again; but seeing her gazing at him anxiously,
added:
‘It’s odd how natural it seems to be talking to you alone like this. You
haven’t changed a bit. I always remember you listening so solemnly and
staring at me. I’m so glad I’ve found you again. I could always talk to you.’
‘At me,’ she corrected.
He made a face at her, but looked cheerful. She had always known how
near the edge to venture without upsetting him. He hummed his little tune
again, then played it on the piano.
‘I think I made that up.... It’s rather a nice little tune. Perhaps I’ll take up
my music seriously again.’
‘Oh, you must, Julian. It is so well worth it: such a special talent.’
He looked at her with sudden attention.
‘How old are you, Judith?’
‘Seventeen. Nearly eighteen.’
He studied her.
‘You must put your hair up.’
‘Must I?’
‘Yes, because then you’ll be beautiful.’
She was still speechless when Mariella, Martin, two Great Danes and the
puppy came in.
4
It was some weeks later. The day had been long and fruitless. She had
idled through the hours, playing the piano, reading ‘Pecheurs d’Islande’
with voluptuous sorrow, doing nothing. A letter from her mother in Paris
had arrived in the afternoon. They were not coming home just yet. Father
had caught another of his colds and seemed so exhausted by it. He was in
bed and she was nursing him, and it had meant cancelling his party, that
party. Why should not Judith come out and join them, now that her
examinations were over? It would amuse her; and Father would be glad to
have her. They would expect her in a few days; she was old enough now to
make the journey by herself.
Her heart was heavy. She could not leave the house, the spring garden,
this delicious solitude, these torturing and exquisite hopes. How could she
drag herself to Paris when she dared not even venture beyond the garden for
fear of missing them if they came for her? If she went now, the great
opportunity would be gone irrevocably; they would slip from her again just
as life was beginning to tremble on the verge of revelation. She must devise
an excuse; but it was difficult. She swallowed a few mouthfuls of supper
and wandered back into the library.
The last of the sun lay in the great room like blond water, lightly
clouded, still, mysterious. The brown and gold and red ranks of the dear
books shone mellow through it, all round the room from the floor three
quarters way to the ceiling; the Persian rugs, the Greek bronzes on the
mantlepiece, the bronze lamps with their red shades, the tapestry curtains,
the heavy oak chairs and tables, all the dim richnesses, were lit and caressed
by it into a single harmony. The portrait of her father as a dark-eyed, dark-
browed young man of romantic beauty was above the level of the sun,
staring sombrely down at his possessions. She could sit in this room,
especially now with hair brushed smooth and coiled low across the nape,
defining the lines of head and neck and the clear curve of the jaw,—she
could sit alone here in her wine-red frock and feel part of the room in
darkness and richness and simplicity of line; decorating it so naturally that,
if he saw, his uncommunicating eyes would surely dwell and approve.
She and the young man of the portrait recognised each other as of the
same blood, springing with kindred thoughts and dreams from a common
root of being, and with the same physical likeness at the source of their
unlikeness which she had noticed in the cousins next-door. She was knit by
a heart-pulling bond to the portrait; through it, she knew she loved the
elderly man whose silent, occasional presence embarrassed her.
There was sadness in everything,—in the room, in the ringing bird-calls
from the garden, in the lit, golden lawn beyond the window, with its single