|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
對於我的 SaaS 應用程序,我想由客戶配置 SAML 配置。我希望能夠更改我的 Symfony One Login Bundle 的配置,以適應客戶的需求配置。

This guide will help you configure SAML SSO for your Symfony application on a per-customer basis. You'll need to adjust the configuration of the Symfony One Login Bundle to match the specific requirements of each customer.
本指南將協助您根據每位客戶為 Symfony 應用程式設定 SAML SSO。您需要調整 Symfony One Login Bundle 的配置以滿足每位客戶的特定要求。
First, determine the appropriate bundle based on your Symfony version:
首先,根據您的 Symfony 版本確定合適的套件:
* For Symfony 6, install the nbgrp/onelogin-saml-bundle from GitHub.
* 對於 Symfony 6,從 GitHub 安裝 nbgrp/onelogin-saml-bundle。
* For earlier Symfony versions, start with the hslaovich/OneloginSamlBundle from GitHub.
* 對於早期的 Symfony 版本,請從 GitHub 上的 hslaovich/OneloginSamlBundle 開始。
Next, add the default configuration. If this step is skipped, the application will fail to function properly. Edit the config/packages/nbgrp_onelogin_saml.yaml file as follows:
接下來,新增預設配置。如果跳過此步驟,應用程式將無法正常運作。編輯 config/packages/nbgrp_onelogin_saml.yaml 文件,如下所示:
```yaml
````yaml
nbgrp_onelogin_saml:
nbgrp_onelogin_saml:
idp:
國內流離失所者:
default:
預設:
settings:
設定:
assertionConsumerService:
斷言消費者服務:
url: '%env(SAML_ASSERTION_CONSUMER_SERVICE)%'
url: '%env(SAML_ASSERTION_CONSUMER_SERVICE)%'
issuer: '%env(SAML_ISSUER)%'
頒發者:“%env(SAML_ISSUER)%”
spEntityId: '%env(SAML_SP_ENTITY_ID)%'
spEntityId: '%env(SAML_SP_ENTITY_ID)%'
x509cert: '%env(SAML_X509_CERT)%'
x509cert: '%env(SAML_X509_CERT)%'
```
````
Update the config/packages/security.yaml file as well:
同時更新 config/packages/security.yaml 檔案:
```yaml
````yaml
security:
安全:
encoders:
編碼器:
Symfony\Component\Security\Core\User\User: plaintext
Symfony\Component\Security\Core\User\User:明文
providers:
提供者:
saml:
薩姆爾:
nbgrp_onelogin_saml
nbgrp_onelogin_saml
firewalls:
防火牆:
main:
主要的:
saml:
薩姆爾:
path: ^/saml
路徑:^/saml
provider: saml
提供者:saml
entry_point: nbgrp_onelogin_saml_entry_point
入口點:nbgrp_onelogin_saml_entry_point
logout_entry_point: nbgrp_onelogin_saml_logout_entry_point
註銷入口點:nbgrp_onelogin_saml_logout_entry_point
logout_success_handler: nbgrp_onelogin_saml_logout_success_handler
logout_success_handler:nbgrp_onelogin_saml_logout_success_handler
logout:
登出:
path: ^/logout$
路徑:^/註銷$
```
````
The nbgrp/onelogin-saml-bundle utilizes compilerpass to inject configuration into a registry in an array indexed by idp, which is then used throughout the application. We'll override this functionality and load the configuration dynamically from the database based on the hostname.
nbgrp/onelogin-saml-bundle 利用compilerpass 將配置注入到由 idp 索引的陣列中的註冊表中,然後在整個應用程式中使用該註冊表。我們將覆蓋此功能並根據主機名稱從資料庫動態載入配置。
Create a new service in the api/config/services.yaml file:
在 api/config/services.yaml 檔案中建立一個新服務:
```yaml
````yaml
services:
服務:
app.saml_configuration_loader:
app.saml_configuration_loader:
class: App\Security\SamlConfigurationLoader
類別:App\Security\SamlConfigurationLoader
arguments:
論點:
- '@doctrine.orm.default_entity_manager'
- '@doctrine.orm.default_entity_manager'
```
````
Override relevant portions of the bundle:
覆蓋捆綁包的相關部分:
Those files will be overridden to enable dynamic configuration of the login controller, metadata, and authenticator.
這些檔案將會被覆寫,以啟用登入控制器、元資料和身份驗證器的動態配置。
Login Controller
登入控制器
Override the api/vendor/nbgrp/onelogin-saml-bundle/src/Controller/Login.php file to utilize our configuration.
覆寫 api/vendor/nbgrp/onelogin-saml-bundle/src/Controller/Login.php 檔案以利用我們的配置。
In the __construct method, we autowire and add our service.
在 __construct 方法中,我們會自動組裝並新增我們的服務。
```php
````php
use App\Security\SamlConfigurationLoader;
使用App\Security\SamlConfigurationLoader;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
使用 Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ContainerInterface;
使用 Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
使用 Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
使用 Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
使用 Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
使用 Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class LoginController extends AbstractController
LoginController 類別擴充 AbstractController
{
{
private $samlConfigurationLoader;
私人$samlConfigurationLoader;
public function __construct(ContainerInterface $container, SamlConfigurationLoader $samlConfigurationLoader)
公用函式 __construct(ContainerInterface $container, SamlConfigurationLoader $samlConfigurationLoader)
{
{
parent::__construct($container);
父級::__construct($container);
$this->samlConfigurationLoader = $samlConfigurationLoader;
$this->samlConfigurationLoader = $samlConfigurationLoader;
}
}
*/
public function login(AuthenticationUtils $authenticationUtils, Request $request): Response
公用函數登入(AuthenticationUtils $authenticationUtils,請求$request):回應
{
{
$host = $request->server->get('HTTP_HOST');
$host = $request->server->get('HTTP_HOST');
$samlSettings = $this->samlConfigurationLoader->getSettingsFromHost($host);
$samlSettings = $this->samlConfigurationLoader->getSettingsFromHost($host);
// ...
// ...
}
}
}
}
```
````
Metadata
元數據
Line 19: Add our service.
第 19 行:新增我們的服務。
```php
````php
use App\Security\SamlConfigurationLoader;
使用App\Security\SamlConfigurationLoader;
use Symfony\Component\DependencyInjection\ContainerInterface;
使用 Symfony\Component\DependencyInjection\ContainerInterface;
class MetadataController extends Controller
類別 MetadataController 擴展了 Controller
{
{
public static function create(ContainerInterface $container): MetadataController
公共靜態函數創建(ContainerInterface $container):MetadataController
{
{
$samlConfigurationLoader = $container->get(SamlConfigurationLoader::class);
$samlConfigurationLoader = $container->get(SamlConfigurationLoader::class);
return new self($samlConfigurationLoader);
返回新的 self($samlConfigurationLoader);
}
}
public function __invoke(Request $request): Response
公共函數 __invoke(Request $request): 回應
{
{
$host = $request->server->get('HTTP_HOST');
$host = $request->server->get('HTTP_HOST');
$samlSettings = $this->samlConfigurationLoader->getSettingsFromHost($host);
$samlSettings = $this->samlConfigurationLoader->getSettingsFromHost($host);
// ...
// ...
}
}
}
}
```
````
免責聲明:info@kdj.com
所提供的資訊並非交易建議。 kDJ.com對任何基於本文提供的資訊進行的投資不承擔任何責任。加密貨幣波動性較大,建議您充分研究後謹慎投資!
如果您認為本網站使用的內容侵犯了您的版權,請立即聯絡我們(info@kdj.com),我們將及時刪除。
-
- 比特幣、eCash 分叉和空投動態:深入探討加密貨幣的最新爭議
- 2026-05-03 00:52:02
- 探索最近的 eCash 分叉、其作為高風險空投的分類,以及對比特幣和加密生態系統的更廣泛影響。
-
-
- 聯準會維持利率穩定,地緣政治緊張局勢引發比特幣價格下跌
- 2026-05-01 04:04:38
- 聯準會維持利率的決定,加上中東衝突,影響了比特幣的價格。分析近期趨勢和市場反應。
-
-
-
-
-
-

































