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
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],
];
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
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).
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);
}
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()]);
}
}
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
}
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
Missing DirectoryBundle Dependency
ServiceNotFoundException for ccetc_directory.manager.CCETCDirectoryBundle is installed and configured before DirectoryUserBundle.User Entity Mismatch
Class "App\Entity\User" does not implement "CCETC\DirectoryUserBundle\Model\DirectoryUserInterface".DirectoryUserInterface in your custom user class.LDAP Attribute Mapping
ccetc_directory_user:
attribute_mappings:
username: sAMAccountName # Example: Use AD-specific field
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
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']
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()]);
}
Attribute Validation Add constraints to directory attributes (e.g., email format):
use Symfony\Component\Validator\Constraints as Assert;
class User {
/**
* @Assert\Email
*/
private $email;
}
How can I help you explore Laravel packages today?