Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Relay Core Connector Ldap Bundle Laravel Package

dbp/relay-core-connector-ldap-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install the Bundle

    composer require dbp/relay-core-connector-ldap-bundle
    

    Ensure digital-blueprint/relay-core is also installed (dependency).

  2. Enable the Bundle Add to config/bundles.php:

    return [
        // ...
        DigitalBlueprint\RelayCoreConnectorLdapBundle\DbpRelayCoreConnectorLdapBundle::class => ['all' => true],
    ];
    
  3. Configure LDAP Connection Publish the default config:

    php bin/console dbp:ldap:install
    

    Edit config/packages/dbp_relay_core_connector_ldap.yaml:

    dbp_relay_core_connector_ldap:
        host: 'ldap.example.com'
        port: 389
        base_dn: 'dc=example,dc=com'
        username: 'cn=admin,dc=example,dc=com'
        password: 'admin_password'
        search_attribute: 'uid'
    
  4. First Use Case: LDAP User Lookup Inject the AuthorizationDataProviderInterface into a service:

    use DigitalBlueprint\RelayCore\Authorization\AuthorizationDataProviderInterface;
    
    class MyService {
        public function __construct(
            private AuthorizationDataProviderInterface $ldapProvider
        ) {}
    
        public function fetchUserRoles(string $username): array {
            $userData = $this->ldapProvider->getUserData($username);
            return $userData['roles'] ?? [];
        }
    }
    

Implementation Patterns

Core Workflows

  1. User Authentication Integration Use the bundle with Symfony’s security component:

    # config/packages/security.yaml
    security:
        providers:
            ldap_provider:
                id: dbp_relay_core_connector_ldap.ldap_user_provider
    
  2. Role-Based Access Control (RBAC) Map LDAP groups to Symfony roles in config/packages/security.yaml:

    access_control:
        - { path: ^/admin, roles: ROLE_ADMIN }
    

    Ensure LDAP groups are synced to Symfony roles via the provider’s loadUserByUsername().

  3. Custom Attribute Mapping Override the default attribute mapping in a custom service:

    // src/Service/CustomLdapMapper.php
    use DigitalBlueprint\RelayCoreConnectorLdapBundle\Mapper\LdapAttributeMapperInterface;
    
    class CustomLdapMapper implements LdapAttributeMapperInterface {
        public function mapAttributes(array $ldapEntry): array {
            return [
                'username' => $ldapEntry['uid'][0] ?? null,
                'email' => $ldapEntry['mail'][0] ?? null,
                'roles' => ['ROLE_CUSTOM_' . strtoupper($ldapEntry['department'][0])],
            ];
        }
    }
    

    Register the mapper in services.yaml:

    services:
        DigitalBlueprint\RelayCoreConnectorLdapBundle\Mapper\LdapAttributeMapperInterface: '@App\Service\CustomLdapMapper'
    
  4. Caching LDAP Responses Cache user data to reduce LDAP queries:

    # config/packages/framework.yaml
    framework:
        cache:
            app: cache.adapter.redis
    

    Configure the provider to use cache:

    dbp_relay_core_connector_ldap:
        cache_enabled: true
        cache_ttl: 3600
    

Integration Tips

  • Symfony Flex Recipes: Use php bin/console make:ldap-provider (if a recipe exists; check the docs).
  • Environment-Specific Config: Use %env() for sensitive data:
    password: '%env(LDAP_ADMIN_PASSWORD)%'
    
  • Testing: Mock the AuthorizationDataProviderInterface in PHPUnit:
    $this->createMock(AuthorizationDataProviderInterface::class)
         ->method('getUserData')
         ->willReturn(['roles' => ['ROLE_TEST']]);
    

Gotchas and Tips

Pitfalls

  1. Connection Timeouts

    • LDAP timeouts may cause silent failures. Log errors explicitly:
      try {
          $this->ldapProvider->getUserData($username);
      } catch (\Exception $e) {
          // Log with stack trace
          throw new \RuntimeException('LDAP lookup failed', 0, $e);
      }
      
    • Configure timeout in dbp_relay_core_connector_ldap.yaml:
      timeout: 5.0  # seconds
      
  2. Case Sensitivity in Usernames

    • LDAP searches are case-insensitive by default, but some providers (e.g., Active Directory) may vary. Normalize usernames:
      $username = strtolower($username);
      
  3. Group Membership Caching

    • Group membership queries can be expensive. Cache results aggressively:
      dbp_relay_core_connector_ldap:
          cache_groups: true
      
  4. Schema Differences

    • Not all LDAP servers use uid for usernames. Adjust search_attribute:
      search_attribute: 'sAMAccountName'  # For Active Directory
      

Debugging

  • Enable LDAP Debugging Add to config/packages/monolog.yaml:

    handlers:
        ldap:
            type: stream
            path: "%kernel.logs_dir%/ldap.log"
            level: debug
            channels: ["ldap"]
    

    Enable debug mode in the bundle config:

    dbp_relay_core_connector_ldap:
        debug: true
    
  • Validate LDAP Connection Use the dbp:ldap:test-connection command:

    php bin/console dbp:ldap:test-connection
    

Extension Points

  1. Custom User Provider Extend the default provider to add logic:

    class CustomLdapUserProvider extends \DigitalBlueprint\RelayCoreConnectorLdapBundle\Security\LdapUserProvider {
        public function refreshUser(UserInterface $user) {
            // Custom refresh logic
            return parent::refreshUser($user);
        }
    }
    

    Override in services.yaml:

    services:
        DigitalBlueprint\RelayCoreConnectorLdapBundle\Security\LdapUserProvider: '@App\Security\CustomLdapUserProvider'
    
  2. Event Listeners Listen for LDAP events (e.g., ldap.user.loaded):

    use Symfony\Component\EventDispatcher\GenericEvent;
    
    class LdapUserListener {
        public function onUserLoaded(GenericEvent $event) {
            $userData = $event->getSubject();
            // Modify user data before Symfony processes it
        }
    }
    

    Register in services.yaml:

    services:
        App\EventListener\LdapUserListener:
            tags:
                - { name: kernel.event_listener, event: ldap.user.loaded, method: onUserLoaded }
    
  3. Dynamic Configuration Load LDAP config from a database or API:

    // src/DependencyInjection/Compiler/LdapConfigPass.php
    use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
    use Symfony\Component\DependencyInjection\ContainerBuilder;
    
    class LdapConfigPass implements CompilerPassInterface {
        public function process(ContainerBuilder $container) {
            $ldapConfig = $this->fetchConfigFromDatabase();
            $container->setParameter('dbp_relay_core_connector_ldap.config', $ldapConfig);
        }
    }
    

    Register the pass in services.yaml:

    services:
        App\DependencyInjection\Compiler\LdapConfigPass:
            tags: [{ name: compiler.pass }]
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware