How buffcleb/buffcleb-saml-sp works
1. What this repo is
- This is a WordPress plugin that turns a site into a SAML 2.0 Service Provider (SP).
- It is not a standalone service: it runs inside WordPress, uses WordPress admin/UI hooks, and exposes SAML endpoints through query parameters on the normal site URL.
2. Top-level structure
- buffcleb-saml-sp.php is the plugin bootstrap entrypoint.
- includes/ contains the protocol, security, user, logging, CLI, and lifecycle classes.
- admin/ contains the WordPress admin tabs and list-table UI.
- docs/ is extensive operational and architectural documentation, which closely matches the plugin’s runtime responsibilities.
3. Request-routing and public endpoints
- The plugin exposes five main public endpoints via ?buffcleb_saml_sp=...:
- metadata for SP metadata output
- login to start SP-initiated SSO
- acs for the SAML Assertion Consumer Service callback
- sls for Single Logout
- attributes for per-user attribute display
- These endpoints are the main boundary between the browser/IdP and the plugin’s internal SAML engine.
4. SAML protocol core
- The core protocol implementation is split across classes such as:
- authn-request, response, logout, acs
- metadata, idp-metadata, metadata-refresh
- xml, xml-verifier, schema, crypto, decrypter
- request-store
- Together they handle request construction, XML parsing, signature verification, assertion decryption, replay protection, and logout message handling.
5. Security model is a first-class subsystem
- The plugin deliberately avoids third-party SAML libraries and implements XML signing/verification directly with PHP ext-dom and ext-openssl.
- Security-sensitive code enforces anti-wrapping checks, destination/audience/recipient/timing validation, XXE-safe XML loading, login-CSRF browser binding, and SSRF-safe metadata retrieval.
- The architecture is therefore “WordPress integration + custom SAML engine,” rather than “WordPress wrapper around a SAML SDK.”
6. Identity Provider lifecycle
- Identity Providers are managed as first-class configuration objects through the admin UI and metadata import.
- The plugin supports importing IdP metadata from URL, paste, or file, then refreshing it automatically later.
- It also supports certificate rollover by staging a primary and “next” signing certificate, which matters for zero-downtime IdP key rotation.
7. User resolution, provisioning, and access control
- After a successful SAML response, the plugin maps the assertion to a WordPress user via user, transform, and related access-control logic.
- It supports matching by email or username, optional auto-provisioning, attribute-to-field/meta mapping, role mapping, and per-IdP allow/deny rules.
- Access-denied handling is a distinct flow with customizable denial messages, so authorization is separate from authentication.
8. Login UX and WordPress integration points
- The plugin integrates into wp-login.php with a branded “Sign in with SSO” button and per-IdP buttons/logos.
- Shortcodes expose the same login entry points inside content, which makes the login UI reusable outside the default login screen.
- “Force SSO” changes the normal WordPress authentication boundary by disabling local passwords, with an emergency token as a recovery path.
9. Administration, monitoring, and operational controls
- admin/ contains tabbed screens for SP settings, IdPs, logs, maintenance, and users.
- The plugin extends the Users list with SSO-related columns and a per-user attributes view.
- Logging is a core subsystem: searchable/filterable activity logs, verbose SAML message capture, CSV export, retention controls, failure-spike alerts, and IP anonymization.
10. External integrations and operational outputs
- Beyond WordPress and IdPs, the main external operational sink is optional SIEM forwarding to a file in JSON Lines or CEF format.
- There is also certificate-expiry monitoring and metadata refresh automation, both of which behave like scheduled maintenance jobs inside WordPress.
11. Automation and lifecycle management
- includes/class-buffcleb-saml-sp-cli.php supports WP-CLI operations for maintenance and admin automation.
- uninstall.php indicates a clean teardown path, and the docs mention config export/import for moving settings between environments.
- This means the plugin has a full operational lifecycle: install, configure, observe, rotate keys, migrate config, and uninstall.
12. How the main data flow works
- Admin imports or refreshes IdP metadata → settings/certs are stored → SP publishes metadata to the IdP → user hits login → plugin sends AuthnRequest → IdP POSTs SAMLResponse to ACS → response is verified/decrypted → attributes are mapped → WordPress user is matched/provisioned → session/login state is established → logs/alerts/SIEM are updated.
Main entry points: class-buffcleb-saml-sp-response.php SAML response · class-buffcleb-saml-sp-admin.php Admin hub · class-buffcleb-saml-sp-maintenance.php Maintenance · buffcleb-saml-sp.php Plugin bootstrap
Components 34
Public SAML
Browser and IdP-facing endpoints exposed through WordPress routing.
- Endpoint router · Dispatches ?buffcleb_saml_sp=... requests into the SAML flows.
- SP metadata · Publishes service-provider metadata for IdP configuration.
includes/class-buffcleb-saml-sp-metadata.php - SSO login · Starts SP-initiated login and browser binding flow.
includes/class-buffcleb-saml-sp-authn-request.php - ACS callback · Consumes SAML responses posted back from the IdP.
includes/class-buffcleb-saml-sp-acs.php - SLS endpoint · Handles single logout requests and responses.
includes/class-buffcleb-saml-sp-logout.php - Attributes view · Displays per-user SSO attributes and resolved identity data.
SAML Core
Protocol, XML, cryptography, and request tracking.
- AuthnRequest · Builds outbound authentication requests to the IdP.
includes/class-buffcleb-saml-sp-authn-request.php - SAML response · Parses and validates inbound assertions and response messages.
includes/class-buffcleb-saml-sp-response.php - Request store · Tracks request IDs and state to prevent replay and correlate flows.
includes/class-buffcleb-saml-sp-request-store.php - XML verifier · Verifies signatures and protects against wrapping and malformed XML.
includes/class-buffcleb-saml-sp-xml-verifier.php - XML utils · Safe XML loading, parsing, and serialization helpers.
includes/class-buffcleb-saml-sp-xml.php - Crypto · Signing and cryptographic helpers built on PHP OpenSSL.
includes/class-buffcleb-saml-sp-crypto.php - Decrypter · Decrypts encrypted assertions and related SAML payloads.
includes/class-buffcleb-saml-sp-decrypter.php
Admin UI
WordPress administration screens and user list extensions.
- Admin hub · Coordinates the plugin's WordPress admin screens.
admin/class-buffcleb-saml-sp-admin.php - SP tab · Service-provider settings and operational configuration screen.
admin/class-buffcleb-saml-sp-admin-tab-sp.php - IdP tab · Identity-provider management, metadata import, and cert rollover UI.
admin/class-buffcleb-saml-sp-admin-tab-idps.php - Logs tab · Searchable activity logs and SAML message review screen.
admin/class-buffcleb-saml-sp-admin-tab-logs.php - Maintenance tab · Retention, export, refresh, and operational maintenance controls.
admin/class-buffcleb-saml-sp-admin-tab-maintenance.php - Users list · Extends the WordPress users table with SSO-related columns.
admin/class-buffcleb-saml-sp-users-list.php - Shortcodes · Reusable login-entry shortcodes for content and theme surfaces.
includes/class-buffcleb-saml-sp-shortcodes.php
Identity Flow
User matching, provisioning, role mapping, and access control.
- User resolver · Matches assertions to WordPress users and handles provisioning.
includes/class-buffcleb-saml-sp-user.php - Attribute map · Transforms SAML attributes into user fields, meta, and roles.
includes/class-buffcleb-saml-sp-transform.php - Access control · Applies IdP/user allow-deny rules and denial messaging.
includes/class-buffcleb-saml-sp-access-denied.php - Force SSO · Overrides local password login and provides emergency recovery.
includes/class-buffcleb-saml-sp-force-sso.php
Operations
Logging, alerts, maintenance, CLI, and lifecycle management.
- Settings · Central plugin settings and stored configuration.
includes/class-buffcleb-saml-sp-settings.php - IdP metadata · Imports, stores, and refreshes identity-provider metadata and certs.
includes/class-buffcleb-saml-sp-idp-metadata.php - Metadata refresh · Automatically refreshes remote IdP metadata on a schedule.
includes/class-buffcleb-saml-sp-metadata-refresh.php - Logger · Captures plugin activity, verbose protocol traces, and exports.
includes/class-buffcleb-saml-sp-logger.php - Alerts · Failure-spike and operational alerting for SSO events.
includes/class-buffcleb-saml-sp-alerts.php - SIEM export · Forwards operational events to JSON Lines or CEF sinks.
includes/class-buffcleb-saml-sp-siem.php - Maintenance · Runs cleanup, retention, and admin automation tasks.
includes/class-buffcleb-saml-sp-maintenance.php - WP-CLI · Command-line entrypoint for administrative and maintenance tasks.
includes/class-buffcleb-saml-sp-cli.php - Cert status · Checks signing certificate expiry and rotation state.
includes/class-buffcleb-saml-sp-cert-status.php
Other components
- Plugin bootstrap · Main plugin file that wires WordPress hooks and loads subsystems.
buffcleb-saml-sp.php
Connections 39
- Plugin bootstrap → Settings: loads · Initializes configuration and stored options.
- Plugin bootstrap → Endpoint router: registers · Attaches request handling to WordPress routing.
- Plugin bootstrap → Admin hub: boots · Registers admin screens and WordPress UI hooks.
- Plugin bootstrap → Shortcodes: registers · Adds reusable login UI shortcodes.
- Plugin bootstrap → Logger: wires · Initializes logging and activity capture.
- Endpoint router → SP metadata: dispatches · Serves SP metadata requests.
- Endpoint router → SSO login: dispatches · Starts SSO login requests.
- Endpoint router → ACS callback: dispatches · Handles SAML assertion callbacks.
- Endpoint router → SLS endpoint: dispatches · Handles SLO requests and responses.
- Endpoint router → Attributes view: dispatches · Shows user attribute details.
- SSO login → AuthnRequest: builds · Creates outbound AuthnRequest messages.
- SSO login → Request store: tracks · Stores request state and correlation IDs.
- ACS callback → SAML response: parses · Consumes the inbound SAML response.
- SAML response → XML verifier: verifies · Checks signatures and XML integrity.
- SAML response → XML utils: loads · Safely parses XML documents.
- SAML response → Decrypter: decrypts · Decrypts encrypted assertions.
- SAML response → Crypto: uses · Uses cryptographic primitives for validation and signing.
- SAML response → Request store: checks · Validates response against saved request state.
- SAML response → User resolver: maps to · Resolves the assertion to a WordPress user.
- User resolver → Attribute map: applies · Transforms attributes into fields, meta, and roles.
- User resolver → Access control: guards · Separates authorization failures from authentication.
- User resolver → Force SSO: constrains · Enforces SSO-only login policy when enabled.
- IdP metadata → Metadata refresh: schedules · Refreshes imported metadata automatically.
- IdP metadata → Crypto: stores certs · Manages signing certificate rollover.
- Admin hub → SP tab: shows · Service-provider configuration screen.
- Admin hub → IdP tab: shows · IdP management and metadata import screen.
- Admin hub → Logs tab: shows · Logs and protocol trace screen.
- Admin hub → Maintenance tab: shows · Maintenance and retention controls screen.
- Admin hub → Users list: extends · Adds user columns and SSO details.
- Logs tab → Logger: reads · Displays activity and protocol logs.
- Maintenance tab → Maintenance: runs · Invokes cleanup and operational jobs.
- Maintenance → Cert status: checks · Monitors certificate expiry.
- Maintenance → Metadata refresh: triggers · Runs metadata refresh operations.
- Maintenance → SIEM export: exports · Forwards event data to SIEM output.
- Maintenance → Alerts: evaluates · Detects operational failure spikes.
- WP-CLI → Maintenance: invokes · Exposes maintenance actions through WP-CLI.
- WP-CLI → IdP metadata: manages · Supports automation around IdP configuration.
- Logger → SIEM export: forwards · Sends selected events to external sinks.
- Logger → Alerts: feeds · Supplies data for alert generation.