Installation
Add the bundle to composer.json:
composer require dbellettini/shibboleth-bundle
Enable it in config/bundles.php:
return [
// ...
Dbellettini\UniversiboShibbolethBundle\UniversiboShibbolethBundle::class => ['all' => true],
];
Configuration Publish the default config:
php bin/console universibo:shibboleth:install
Edit config/packages/universibo_shibboleth.yaml to match your Shibboleth SP (Service Provider) settings (e.g., entity_id, private_key, certificate).
First Use Case Trigger a test login via Shibboleth:
php bin/console universibo:shibboleth:test-login
Verify the REMOTE_USER header is populated in your environment (e.g., via php -r 'var_dump(getallheaders());').
EventSubscriber/ShibbolethAuthenticationSubscriber.php for authentication logic.{{ shibboleth_attributes }} in templates to debug attributes (e.g., mail, eduPersonPrincipalName).Authentication Flow
REMOTE_USER and Shibboleth attributes (e.g., HTTP_SHIBBOLETH_* headers).ShibbolethAuthenticationListener to map attributes to FOSUserBundle users:
# config/packages/universibo_shibboleth.yaml
universibo_shibboleth:
user_provider:
attribute_to_username: 'mail' # Maps 'mail' attribute to username
attribute_to_firstname: 'givenName'
attribute_to_lastname: 'sn'
User Creation/Update
FOSUserBundle's UserManager).ShibbolethUserProvider (extend Dbellettini\UniversiboShibbolethBundle\Security\User\ShibbolethUserProvider).Attribute Handling
$attributes = $this->get('universibo_shibboleth.attribute_reader')->getAttributes();
// In your User entity
public function setShibbolethAttributes(array $attributes) {
$this->setExtraData($attributes); // Assuming FOSUserBundle's extra fields
}
config/packages/security.yaml:
firewalls:
main:
shibboleth: ~ # Uses the bundle's auth provider
use Dbellettini\UniversiboShibbolethBundle\Security\AttributeReader;
$reader = $this->get(AttributeReader::class);
dump($reader->getAttributes());
universibo_shibboleth:
user_provider: App\Security\CustomShibbolethUserProvider
Header Mismatches
HTTP_SHIBBOLETH_* headers match your IdP configuration.bin/console debug:config universibo_shibboleth to validate settings.FOSUserBundle Conflicts
UserManager is compatible.ShibbolethUserProvider and inject your UserManager:
public function __construct(UserManagerInterface $userManager) {
$this->userManager = $userManager;
}
HTTPS Requirements
ngrok or configure your dev server for HTTPS.universibo_shibboleth.secure_only: false in config for testing (not production).Attribute Mapping
mail) will break user creation.ShibbolethUserProvider:
public function loadUserByUsername($username) {
$user = $this->userManager->findUserBy(['username' => $username]);
if (!$user) {
$user = $this->userManager->createUser([
'username' => $username ?? 'shib_' . uniqid(),
'enabled' => true,
]);
}
return $user;
}
Enable Verbose Logging
Add to config/packages/monolog.yaml:
handlers:
shibboleth:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.shibboleth.log"
level: debug
Then log attributes:
$this->get('logger')->debug('Shibboleth Attributes', $attributes);
Test Locally
Use the test-login command with a mock IdP (e.g., SimpleSAMLphp):
php bin/console universibo:shibboleth:test-login --env=test
Custom Attribute Handlers
Extend AttributeReader to transform attributes:
class CustomAttributeReader extends AttributeReader {
public function getFormattedName() {
$givenName = $this->getAttribute('givenName');
$surName = $this->getAttribute('sn');
return "$givenName $surName";
}
}
Register as a service:
services:
universibo_shibboleth.attribute_reader:
class: App\Security\CustomAttributeReader
Post-Authentication Logic
Subscribe to shibboleth.post_authenticate:
use Dbellettini\UniversiboShibbolethBundle\Event\PostAuthenticateEvent;
class MySubscriber implements EventSubscriberInterface {
public static function getSubscribedEvents() {
return [
PostAuthenticateEvent::NAME => 'onPostAuthenticate',
];
}
public function onPostAuthenticate(PostAuthenticateEvent $event) {
$user = $event->getUser();
// Custom logic (e.g., logins, role assignment)
}
}
IdP-Specific Quirks
Override ShibbolethAuthenticator for non-standard IdP responses:
class CustomAuthenticator extends ShibbolethAuthenticator {
protected function getOptions() {
return array_merge(parent::getOptions(), [
'custom_attribute' => 'http://idp.example/attribute',
]);
}
}
How can I help you explore Laravel packages today?