adactive-sas/saml2-bridge-bundle
Symfony bundle adding basic SAML2 IdP capabilities via simplesamlphp/saml2: metadata, SSO and SLO with HTTP-POST/Redirect bindings, signed requests/responses, and IdP/SP-initiated logout. Configure routes, keys, and repositories via YAML.
Installation
Run composer require adactive-sas/saml2-bridge-bundle and enable the bundle in config/bundles.php:
return [
// ...
AdactiveSas\Saml2BridgeBundle\AdactiveSasSaml2BridgeBundle::class => ['all' => true],
];
Configuration Publish the default config:
php bin/console config:dump-reference AdactiveSasSaml2BridgeBundle
Then configure config/packages/adactive_sas_saml2_bridge.yaml with your SAML IdP settings (e.g., entity_id, certificate, private_key).
First Use Case: Basic SSO Redirect users to the SAML IdP login endpoint:
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
$url = $this->generateUrl('saml2_bridge_idp_initiate', [
'sp_entity_id' => 'https://example.com/sp-metadata.xml',
]);
return $this->redirect($url);
Metadata Management
$metadata = $this->get('adactive_sas_saml2_bridge.metadata');
$xml = $metadata->generateMetadata();
$validator = $this->get('adactive_sas_saml2_bridge.metadata_validator');
$validator->validate($spMetadataXml);
Authentication Flow
saml2_bridge_idp_initiate route with sp_entity_id.saml2_bridge_idp_sso route with target_entity_id (SP).saml2_bridge_idp_logout (supports both IdP/SP-initiated).User Mapping
config/packages/adactive_sas_saml2_bridge.yaml:
user_provider:
class: App\Security\SamlUserProvider
method: loadUserBySAMLAttributes
loadUserBySAMLAttributes to map SAML attributes (e.g., email, uid) to your user model.Event Listeners Leverage Symfony events for custom logic:
// src/EventListener/SamlAuthListener.php
class SamlAuthListener implements EventSubscriberInterface {
public static function getSubscribedEvents() {
return [
'saml2_bridge.idp.authenticate' => 'onAuthenticate',
];
}
public function onAuthenticate(AuthenticateEvent $event) {
$attributes = $event->getAttributes();
// Custom logic (e.g., role assignment)
}
}
CSRF Protection Enable CSRF protection in config:
security:
csrf_protection: true
Metadata Validation
AdactiveSas\Saml2BridgeBundle\Validator\MetadataValidator for strict checks.Certificate Management
private_key and certificate in config are PEM-encoded and properly formatted.openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes).Time Synchronization
Debugging
debug: true
var/log/saml2_bridge.log:
logging: true
Deprecated Features
onelogin/php-saml).Dynamic SP Configuration Store SP metadata in a database and fetch dynamically:
$spMetadata = $this->getSpMetadataFromDb($spEntityId);
$validator->validate($spMetadata);
Attribute Mapping Use a YAML-based mapping for flexibility:
attribute_mapping:
email: 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress'
groups: 'http://schemas.xmlsoap.org/claims/Group'
Testing
FROM simplesamlphp/simplesamlphp:1.18
$this->get('adactive_sas_saml2_bridge.test.saml_response')->setMockResponse($xml);
Performance
$cache = $this->get('cache.app');
$metadata = $cache->get('saml_metadata', function() use ($metadataService) {
return $metadataService->generateMetadata();
});
Security Hardening
firewall:
saml:
pattern: ^/saml
ip: 192.168.1.0/24
Http-Artifact) in config.Upgrade Path
OpenConext/Stepup-saml-bundle, note breaking changes in:
saml2_bridge_idp_initiate vs. stepup_saml_initiate).saml2_bridge.* vs. stepup_saml.*).
How can I help you explore Laravel packages today?