【发布时间】:2016-09-22 06:46:17
【问题描述】:
我有 integrated SimpleSAMLphp with my application,但它仅适用于生产环境,因为与其他地方的 IdP 服务器没有连接。我如何才能继续在需要身份验证的事物上开发环境?
我编写了一个包装类,它将必要的方法公开给SimpleSAML_Auth_Simple 类。相关代码如下:
需要认证的页面
<?php
// (assume autoloading)
$saml = new SAMLWrapper('name-of-sp');
$saml->requireAuthentication('https://[::1]/app/saml-controller.php?callback=1');
$userAttributes = $saml->getAttributes();
// rest of application code below...
包装类
class SAMLWrapper extends IAuthentication
{
private $as;
public function __construct($sp) {
require_once('/var/simplesamlphp/lib/_autoload.php');
// THIS PATH DOES NOT EXIST ON DEV
$this->as = new \SimpleSAML_Auth_Simple($sp);
}
public function requireAuthentication($callback) {
$this->as->requireAuth(array('ReturnTo' => $callback));
}
public function getAttributes() {
return $this->as->getAttributes();
}
}
虚拟包装类
我考虑过像这样编写一个虚拟包装器:
class DummySAML extends IAuthentication
{
private $attrs;
public function __construct(array $attrs) {
$this->attrs = $attrs;
}
public function requireAuthentication() {
return;
}
public function getAttributes() {
return $this->attrs;
}
}
但这意味着我必须在所有需要身份验证的页面上在 SAMLWrapper 和 DummySAML 类之间切换:
if (getenv('SLIM_MODE') === 'DEV') {
// instantiate DummySAML with test attributes
} else {
// instantiate SAMLWrapper with service provider name
}
有没有更简单更好的方法?
【问题讨论】:
标签: php environment simplesamlphp dev-to-production