Installation:
composer require amorebietakoudala/user-bundle
Publish the bundle’s assets and configuration:
php bin/console amoreu:user:install
Configuration:
Update config/packages/amoreu_user.yaml (auto-generated after installation). Key settings include:
amoreu_user:
ldap:
host: 'your-ldap-server'
base_dn: 'dc=example,dc=com'
username_attribute: 'sAMAccountName'
email_domain: 'example.com' # For email-based auth
passport:
enabled: true # Required for Symfony 6.3+
First Use Case:
/login (uses LoginFormPassportAuthenticator)./admin/users (Twig-based UI). Enable pagination with query string params (e.g., ?page=2).Authentication:
LoginFormPassportAuthenticator for custom logic. Override createToken() to inject LDAP-specific claims:
use AMREU\UserBundle\Security\Passport\LoginFormPassportAuthenticator;
class CustomAuthenticator extends LoginFormPassportAuthenticator {
protected function createToken(Credentials $credentials, UserProviderInterface $userProvider, string $firewallName): Passport {
return new Passport(
new UserCredentials($credentials->getUsername(), $credentials->getPassword()),
new RememberMeToken(), // Optional
[
new LdapUserAttribute('idNumber', $this->fetchLdapAttribute($credentials->getUsername()))
]
);
}
}
internet_domain in YAML to allow user@example.com logins.User Management:
AMREU\UserBundle\Controller\UserController). Extend with custom fields:
// config/packages/doctrine.yaml
orm:
mappings:
AMREUUserBundle: ~
App\Entity: # Add your custom user entity
type: attribute
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
templates/user/index.html.twig) to customize:
{{ paginate(users, 'app_user_index') }} {# Uses query string params #}
Integration with Laravel:
config/services.yaml:
services:
AMREU\UserBundle\:
resource: '../vendor/amorebietakoudala/user-bundle/src/'
exclude: '../vendor/amorebietakoudala/user-bundle/src/{Entity,DependencyInjection,Tests}'
AMREU\UserBundle\Event\UserEvents (e.g., USER_POST_CREATE) for post-save actions:
use AMREU\UserBundle\Event\UserEvent;
public function onUserCreated(UserEvent $event) {
$user = $event->getUser();
// Sync with Laravel models or external APIs
}
LDAP Connection Errors:
500 on /login. Check var/log/dev.log for:
[LDAP] Could not connect to server: ...
host, base_dn, and firewall rules. Use php bin/console debug:config amoreu_user to validate config.Passport Authenticator:
passport.enabled: true. Older versions may fail silently.php bin/console cache:clear
Email Authentication:
internet_domain must match LDAP’s mail attribute exactly (e.g., example.com vs example.com.).ldap_filter in config to customize:
ldap:
filter: '(|(mail=%s)(sAMAccountName=%s))'
CSRF Token:
/admin/users) validate CSRF by default. Disable in config/packages/security.yaml if needed:
firewall:
main:
csrf_token_generator: security.csrf.token_manager
LDAP Queries: Enable debug mode in amoreu_user.yaml:
ldap:
debug: true
Logs queries to var/log/dev.log.
Route Attributes: Since v2.1.0, routes use attributes (e.g., [Route('/users', name: 'app_user_index')]). Update custom routes accordingly.
YAML Config: Always validate schema after changes:
php bin/console debug:config amoreu_user
Custom User Fields:
User entity (e.g., App\Entity\User) and map to LDAP:
#[ORM\Attribute]
class User extends AMREU\UserBundle\Entity\User {
#[ORM\Column]
private string $customField;
public function getCustomField(): string {
return $this->customField;
}
}
UserProvider:
use AMREU\UserBundle\Security\User\LdapUserProvider;
class CustomLdapUserProvider extends LdapUserProvider {
public function loadUserByIdentifier(string $identifier): UserInterface {
$user = parent::loadUserByIdentifier($identifier);
$user->setCustomField($this->fetchCustomAttribute($identifier));
return $user;
}
}
Translation Overrides:
translations/messages.en.yaml:
'AMREU\UserBundle::user.invalid_credentials': 'Custom error message'
Badge Customization:
UserBadge class to add columns:
use AMREU\UserBundle\Badge\UserBadge;
class CustomUserBadge extends UserBadge {
public function configureColumns(BadgeInterface $badge): void {
parent::configureColumns($badge);
$badge->addColumn('customField', 'Custom Field', 'text');
}
}
config/packages/amoreu_user.yaml:
badge:
class: App\Badge\CustomUserBadge
How can I help you explore Laravel packages today?