SimpleSAMLphp Service Provider QuickStart

本文指导您如何配置简单SAML php为服务提供者(SP),包括配置SP、启用证书、添加身份提供商、设置默认身份提供商、与身份提供商交换元数据、集成身份验证到自定义应用以及支持。

This guide will describe how to configure simpleSAMLphp as a service provider (SP).

1 Configuring the SP

The SP is configured by an entry in config/authsources.php.

This is a minimal authsources.php for a SP:

<?php
$config = array(

    /* This is the name of this authentication source, and will be used to access it later. */
    'default-sp' => array(
        'saml:SP',
    ),
);

For more information about additional options available for the SP, see the saml:SP reference.

If you want mulitple Service Providers in the same site and installation, you can add more entries in the authsources.php configuration. If so remember to set the EntityID explicitly. Here is an example:

'sp1' => array(
    'saml:SP',
    'entityID' => 'https://sp1.example.org/',
),
'sp2' => array(
    'saml:SP',
    'entityID' => 'https://sp2.example.org/',
),

1.1 Enabling a certificate for your Service Provider

Some Identity Providers / Federations may require that your Service Providers holds a certificate. If you enable a certificate for your Service Provider, it may be able to sign requests and response sent to the Identity Provider, as well as receiving encrypted responses.

Create a self-signed certificate in the cert/ directory.

cd cert
openssl req -newkey rsa:2048 -new -x509 -days 3652 -nodes -out saml.crt -keyout saml.pem

Then edit your authsources.php entry, and add references to your certificate:

'default-sp' => array(
    'saml:SP',
    'privatekey' => 'saml.pem',
    'certificate' => 'saml.crt',
),

2 Adding IdPs to the SP

The service provider you are configuring needs to know about the identity providers you are going to connect to it. This is configured by metadata stored in metadata/saml20-idp-remote.php and metadata/shib13-idp-remote.php.This is a minimal example of a metadata/saml20-idp-remote.php metadata file:

<?php
$metadata['https://openidp.feide.no'] = array(
    'SingleSignOnService'  => 'https://openidp.feide.no/simplesaml/saml2/idp/SSOService.php',
    'SingleLogoutService'  => 'https://openidp.feide.no/simplesaml/saml2/idp/SingleLogoutService.php',
    'certFingerprint'      => 'c9ed4dfb07caf13fc21e0fec1572047eb8a7a4cb',
);

For more information about available options in the idp-remote metadata files, see the IdP remote reference.

If you have the metadata of the remote IdP as an XML file, you can use the built-in XML to simpleSAMLphp metadata converter, which by default is available as /admin/metadata-converter.php in your simpleSAMLphp installation.

Note that the idp-remote file lists all IdPs you trust. You should remove all IdPs that you don't use.

3 Setting the default IdP

An option in the authentication source allows you to configure which IdP should be used.This is the idp option.

<?php
$config = array(

    'default-sp' => array(
        'saml:SP',

        /*
         * The entity ID of the IdP this should SP should contact.
         * Can be NULL/unset, in which case the user will be shown a list of available IdPs.
         */
        'idp' => 'https://openidp.feide.no',
    ),
);

4 Exchange metadata with the IdP

If you do not have an IdP yourself, you could use the Feide OpenIdP to test your Service Provider.The metadata for Feide OpenIdP is already included in the metadata distributed with simpleSAMLphp.

In order to complete the connection between your SP and Feide OpenIdP, you must add the metadata for your SP to the IdP.The metadata for your SP can be found on the Federation-tab.Copy the SAML 2.0 XML Metadata document automatically generated by simpleSAMLphp, and go to the OpenIdP Metadata Self-Service Registry:

You need to login with an OpenIdP account to authenticate (you can create a new account if you do not have one already).Next, click the link 'Add from SAML 2.0 XML metadata', and paste in your SAML 2.0 XML Metadata.After clicking the 'Import metadata' button, you will be presented with a form where you can edit your metadata.You can check that your metadata was parsed correctly by looking at the 'SAML 2.0' tab.The textfields for AssertionConsumerService and SingleLogoutService should contain two URLs:

AssertionConsumerService
https://sp.example.org/simplesaml/module.php/saml/sp/saml2-acs.php/default-sp
SingleLogoutService
https://sp.example.org/simplesaml/module.php/saml/sp/saml2-logout.php/default-sp

After checking your metadata, give your SP a proper name and description and click 'save'.

The procedure for managing trust in federations differ, but the common part is that you would need to provide the SAML 2.0 metadataof your SP, and register that with the federation administration.

5 Test the SP

After the metadata is configured on the IdP, you should be able to test the configuration.The installation page of simpleSAMLphp has a link to test authentication sources.When you click the link, you should receive a list of authentication sources, including the one you have created for the SP.

After you click the link for that authentication source, you will be redirected to the IdP.After entering your credentials, you should be redirected back to the test page.The test page should contain a list of your attributes:

Screenshot of the status page after an user have succesfully authenticated

For a better looking, more advanced Discovery Service with tabs and live search, you may want to use the discopower modulein simpleSAMLphp. Take a look at the following blog entry for more information:

6 Integrating authentication with your own application

The API is documented in the SP API reference.

For those web resources you want to protect, you must add a fewlines of PHP code:

  • Register the simpleSAMLphp classes with the PHP autoloader.

  • Require authentication of the user for those places it is required.

  • Access the users attributes.

Example code:

We start off with loading a file which registers the simpleSAMLphp classes with the autoloader.

require_once('../../lib/_autoload.php');

We select our authentication source:

$as = new SimpleSAML_Auth_Simple('default-sp');

We then require authentication:

$as->requireAuth();

And print the attributes:

$attributes = $as->getAttributes();
print_r($attributes);

Each attribute name can be used as an index into $attributes to obtain the value. Every attribute value is an array - a single-valued attribute is an array of a single element.

We can also request authentication with a specific IdP:

$as->login(array(
    'saml:idp' => 'https://idp.example.org/',
));

Other options are also available.Take a look in the documentation for the SP module for a list of all parameters.

7 Support

If you need help to make this work, or want to discuss simpleSAMLphp with other users of the software, you are fortunate: Around simpleSAMLphp there is a great Open source community, and you are welcome to join! The forums are open for you to ask questions, contribute answers other further questions, request improvements or contribute with code or plugins of your own.

https://simplesamlphp.org/docs/stable/simplesamlphp-sp

基于遗传算法的微电网调度(风、光、蓄电池、微型燃气轮机)(Matlab代码实现)内容概要:本文档介绍了基于遗传算法的微电网调度模型,涵盖风能、太阳能、蓄电池和微型燃气轮机等多种能源形式,并通过Matlab代码实现系统优化调度。该模型旨在解决微电网中多能源协调运行的问题,优化能源分配,降低运行成本,提高可再生能源利用率,同时考虑系统稳定性与经济性。文中详细阐述了遗传算法在求解微电网多目标优化问题中的应用,包括编码方式、适应度函数设计、约束处理及算法流程,并提供了完整的仿真代码供复现与学习。此外,文档还列举了大量相关电力系统优化案例,如负荷预测、储能配置、潮流计算等,展示了广泛的应用背景和技术支撑。; 适合人群:具备一定电力系统基础知识和Matlab编程能力的研究生、科研人员及从事微电网、智能电网优化研究的工程技术人员。; 使用场景及目标:①学习遗传算法在微电网调度中的具体实现方法;②掌握多能源系统建模与优化调度的技术路线;③为科研项目、毕业设计或实际工程提供可复用的代码框架与算法参考; 阅读建议:建议结合Matlab代码逐段理解算法实现细节,重点关注目标函数构建与约束条件处理,同时可参考文档中提供的其他优化案例进行拓展学习,以提升综合应用能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值