SlideShare uma empresa Scribd logo
1 de 24
LDAP
LDAP
Lightweight Directory Access Protocol
No crap, just what you need to know about it.
1. De nities
2. Gebruik in php
3. Opbouw lterstring
4. Nog iets?
Directory
•   Soort database met gegevens in een boomstructuur
•   Vergelijkbaar met folderstructuur op een opslagmedium
•   Geen vaste structuurregels
•   Voorafgaande kennis van de serveropbouw noodzakelijk
Bekend(st)e voorbeelden:
‣   Microsoft Active Directory
‣   Apache Directory Server
‣   OpenLDAP
‣   Red Hat Directory Server
‣   IBM Tivoli Directory Server
dn
•   = distinguishedName
•   Identi ceert een object
•   voorbeelden:
     •   cn=John Smith,ou=Accounts,o=Netlash-bSeen,c=BE
     •   cn=John Smith,ou=Users,dc=ncube,dc=be
dn     •   cn=John Smith,ou=Accounts,o=Netlash-bSeen,c=BE
       •   cn=John Smith,ou=Users,dc=ncube,dc=be
•   c = country
•   o = organization
•   dc = domainComponent
•   ou = organizationUnit
•   cn = commonName
1. De nities
2. Gebruik in php
3. Opbouw lterstring
4. Nog iets?
// maak connectie met de server
$connection = ldap_connect($hostname, $port = 389); //636 voor SSL

// de nieer de protocol versie
ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3);

// login (anoniem) meestal enkel read only access
ldap_bind($connection);

// login (met authenticatie)
$userDn = "cn=apache Mod_ldap Search,ou=Service Accounts,ou=COMMON,dc=ncube,dc=be";
ldap_bind($connection, $userDn, $password);

/* acties */

// uitloggen
ldap_close($connection);
/**
 * acties
 **/
// niveau waarop gestart wordt met zoeken
$baseDn = "ou=Users,dc=ncube,dc=be";
// attribuutnamen waarop kan worden gezocht (goede ltering op minder velden = betere performantie)
$attributeArray = array(‘samaccountname’, ‘givenname’, ‘telephonenumber’, ‘mobile’, ‘mail’, ‘info’);
//limit, aantal resultaten die moet worden opgehaald
$limit = 0; // 0 haalt alles op
// attribuut waarop de resultaten worden gesorteerd
$sortAttribute = ‘samaccountname’;

// lees de data in
$readData = ldap_search($connection, $baseDn, $ lter, $attributeArray, 0, $limit);

// aantal resultaten
$numResults = ldap_count_entries($connection, $readData);

// sorteer de ingelezen resultaten
ldap_sort($connection, $readData, $sortAttribute);

// haal de data op
$info = ldap_get_entries($connection, $readData);
1. De nities
2. Gebruik in php
3. Opbouw lterstring
4. Nog iets?
Opbouw lterstring
•   wildcard: *
•   1 attribuut: “(<attribuutnaam>=<waarde>)”
•   AND: “(&(<a1>=<w1>)(<a2>=<w2>))”
•   OR: “(|(<a1>=<w1>)(<a2>=<w2>))”
•   NOT: “(!(<attribuutnaam>=<waarde>))”
1. De nities
2. Gebruik in php
3. Opbouw lterstring
4. Nog iets?
De wildcard kan, afhankelijk van de
server, niet gebruikt worden op het begin
van een zoekterm (rara welke)
Met de juiste dn bereik je alles
Attributen ALTIJD als lowercase opgeven!
Attributen zijn vast gede nieerd maar kunnen een
andere bestemming krijgen.
vb:
- “physicalDeliveryOf ceName” als subdepartement
binnen een bedrijf
- “postOf ceBox” als departementscode
- “info” als multi-value veld (bij voorkeur 1 value/lijn)
Wachtwoorden van de users binnen de Active
Directory zijn niet (zo maar) te achterhalen.
Hoe checken via LDAP of een user toegang heeft?
$connection = ldap_connect($hostname, $port = 389);

ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3);

if( ldap_bind($connection, 'cn=' . $_SERVER['PHP_AUTH_USER'] . ',' . $baseDn, $_SERVER['PHP_AUTH_PW']))
{
       echo 'The user is valid';
}
else
{
       echo 'Invalid user';
}
http://docs.php.net/manual/en/book.ldap.php
QUESTIONS?
twitter.com/dofken
davyvanvooren@netlash.com
www.netlash.com

Mais conteúdo relacionado

Destaque

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destaque (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Ldap

  • 2.
  • 3.
  • 4. LDAP Lightweight Directory Access Protocol No crap, just what you need to know about it.
  • 5. 1. De nities 2. Gebruik in php 3. Opbouw lterstring 4. Nog iets?
  • 6. Directory • Soort database met gegevens in een boomstructuur • Vergelijkbaar met folderstructuur op een opslagmedium • Geen vaste structuurregels • Voorafgaande kennis van de serveropbouw noodzakelijk
  • 7. Bekend(st)e voorbeelden: ‣ Microsoft Active Directory ‣ Apache Directory Server ‣ OpenLDAP ‣ Red Hat Directory Server ‣ IBM Tivoli Directory Server
  • 8. dn • = distinguishedName • Identi ceert een object • voorbeelden: • cn=John Smith,ou=Accounts,o=Netlash-bSeen,c=BE • cn=John Smith,ou=Users,dc=ncube,dc=be
  • 9. dn • cn=John Smith,ou=Accounts,o=Netlash-bSeen,c=BE • cn=John Smith,ou=Users,dc=ncube,dc=be • c = country • o = organization • dc = domainComponent • ou = organizationUnit • cn = commonName
  • 10. 1. De nities 2. Gebruik in php 3. Opbouw lterstring 4. Nog iets?
  • 11. // maak connectie met de server $connection = ldap_connect($hostname, $port = 389); //636 voor SSL // de nieer de protocol versie ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3); // login (anoniem) meestal enkel read only access ldap_bind($connection); // login (met authenticatie) $userDn = "cn=apache Mod_ldap Search,ou=Service Accounts,ou=COMMON,dc=ncube,dc=be"; ldap_bind($connection, $userDn, $password); /* acties */ // uitloggen ldap_close($connection);
  • 12. /** * acties **/ // niveau waarop gestart wordt met zoeken $baseDn = "ou=Users,dc=ncube,dc=be"; // attribuutnamen waarop kan worden gezocht (goede ltering op minder velden = betere performantie) $attributeArray = array(‘samaccountname’, ‘givenname’, ‘telephonenumber’, ‘mobile’, ‘mail’, ‘info’); //limit, aantal resultaten die moet worden opgehaald $limit = 0; // 0 haalt alles op // attribuut waarop de resultaten worden gesorteerd $sortAttribute = ‘samaccountname’; // lees de data in $readData = ldap_search($connection, $baseDn, $ lter, $attributeArray, 0, $limit); // aantal resultaten $numResults = ldap_count_entries($connection, $readData); // sorteer de ingelezen resultaten ldap_sort($connection, $readData, $sortAttribute); // haal de data op $info = ldap_get_entries($connection, $readData);
  • 13. 1. De nities 2. Gebruik in php 3. Opbouw lterstring 4. Nog iets?
  • 14. Opbouw lterstring • wildcard: * • 1 attribuut: “(<attribuutnaam>=<waarde>)” • AND: “(&(<a1>=<w1>)(<a2>=<w2>))” • OR: “(|(<a1>=<w1>)(<a2>=<w2>))” • NOT: “(!(<attribuutnaam>=<waarde>))”
  • 15. 1. De nities 2. Gebruik in php 3. Opbouw lterstring 4. Nog iets?
  • 16. De wildcard kan, afhankelijk van de server, niet gebruikt worden op het begin van een zoekterm (rara welke)
  • 17. Met de juiste dn bereik je alles
  • 18. Attributen ALTIJD als lowercase opgeven!
  • 19. Attributen zijn vast gede nieerd maar kunnen een andere bestemming krijgen. vb: - “physicalDeliveryOf ceName” als subdepartement binnen een bedrijf - “postOf ceBox” als departementscode - “info” als multi-value veld (bij voorkeur 1 value/lijn)
  • 20. Wachtwoorden van de users binnen de Active Directory zijn niet (zo maar) te achterhalen.
  • 21. Hoe checken via LDAP of een user toegang heeft? $connection = ldap_connect($hostname, $port = 389); ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3); if( ldap_bind($connection, 'cn=' . $_SERVER['PHP_AUTH_USER'] . ',' . $baseDn, $_SERVER['PHP_AUTH_PW'])) { echo 'The user is valid'; } else { echo 'Invalid user'; }

Notas do Editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n