Weave 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

Directory User Bundle Laravel Package

ccetc/directory-user-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install Dependencies Ensure ccetc/directory-user-bundle and its parent bundles (FOSUserBundle, CCETCDirectoryBundle) are installed via Composer:

    composer require ccetc/directory-user-bundle ccetc/directory-bundle friendsofsymfony/user-bundle
    
  2. Bundle Registration Add the bundle to config/bundles.php:

    return [
        // ...
        CCETC\DirectoryBundle\CCETCDirectoryBundle::class => ['all' => true],
        CCETC\DirectoryUserBundle\CCETCDirectoryUserBundle::class => ['all' => true],
        Symfony\Bundle\FOSUserBundle\FOSUserBundle::class => ['all' => true],
    ];
    
  3. Configuration Override FOSUserBundle defaults in config/packages/ccetc_directory_user.yaml:

    fos_user:
        db_driver: orm
        firewall_name: main
        user_class: CCETC\DirectoryUserBundle\Entity\User  # Custom user entity
    
  4. First Use Case Sync users from the directory (e.g., LDAP) to your database:

    php bin/console ccetc:directory:user:sync
    

    Verify users in the user table with directory attributes (e.g., directory_id).


Implementation Patterns

Workflow: Directory-Authenticated User Management

  1. User Provisioning Use the DirectoryUserManager service to create/update users from the directory:

    $manager = $container->get('ccetc_directory_user.manager');
    $user = $manager->findUserByDirectoryId($directoryId);
    if (!$user) {
        $user = $manager->createUserFromDirectory($directoryEntry);
    }
    
  2. Event Listeners Extend FOSUserBundle events (e.g., UserEvent::REGISTERED) to log directory syncs:

    // src/EventListener/DirectoryUserListener.php
    public function onUserRegistered(UserEvent $event) {
        $user = $event->getUser();
        if ($user instanceof DirectoryUserInterface) {
            $this->logger->info('Synced user', ['directory_id' => $user->getDirectoryId()]);
        }
    }
    
  3. Custom User Entity Extend FOSUserBundle\Model\User to include directory-specific fields:

    // src/Entity/User.php
    use CCETC\DirectoryUserBundle\Model\DirectoryUserInterface;
    
    class User extends BaseUser implements DirectoryUserInterface {
        private $directoryId;
        private $directoryAttributes;
    
        // Getters/setters for directory fields
    }
    
  4. Command Automation Schedule periodic syncs via cron:

    # Sync daily at 2 AM
    0 2 * * * php /path/to/bin/console ccetc:directory:user:sync --env=prod
    

Gotchas and Tips

Pitfalls

  1. Missing DirectoryBundle Dependency

    • Error: ServiceNotFoundException for ccetc_directory.manager.
    • Fix: Ensure CCETCDirectoryBundle is installed and configured before DirectoryUserBundle.
  2. User Entity Mismatch

    • Error: Class "App\Entity\User" does not implement "CCETC\DirectoryUserBundle\Model\DirectoryUserInterface".
    • Fix: Extend DirectoryUserInterface in your custom user class.
  3. LDAP Attribute Mapping

    • Gotcha: Default attribute mappings may not align with your directory schema.
    • Solution: Override mappings in config:
      ccetc_directory_user:
          attribute_mappings:
              username: sAMAccountName  # Example: Use AD-specific field
      

Debugging Tips

  • Log Directory Entries: Enable debug mode and inspect the DirectoryEntry object passed to createUserFromDirectory():

    $this->logger->debug('Directory entry', ['data' => $directoryEntry->toArray()]);
    
  • Sync Dry Run: Test syncs without DB writes:

    php bin/console ccetc:directory:user:sync --dry-run
    

Extension Points

  1. Custom Directory Sync Logic Override the DirectoryUserManager service to add pre/post-sync logic:

    # config/services.yaml
    services:
        App\Service\CustomDirectoryUserManager:
            decorates: 'ccetc_directory_user.manager'
            arguments: ['@.inner']
    
  2. Webhook Triggers Dispatch events after syncs (e.g., Slack notifications):

    // src/EventListener/DirectorySyncListener.php
    public function onDirectorySync(DirectorySyncEvent $event) {
        $this->slack->send('Directory sync completed', ['users' => $event->getUsers()]);
    }
    
  3. Attribute Validation Add constraints to directory attributes (e.g., email format):

    use Symfony\Component\Validator\Constraints as Assert;
    
    class User {
        /**
         * @Assert\Email
         */
        private $email;
    }
    
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.
andydefer/laravel-notification
adachsoft/cli-process-tester
jhaskell13/laraflow
sebastienheyd/boilerplate-media-manager
ccast/tagixo-primix
pretendtrue/laravel-builder
sawmainek/laravel-scout-tntsearch-driver
tomshaw/laravel-calendar-table
dibakar/laravel-ownership
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo
stevenay/myanfont
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc