如何在yii框架中使用SimpleSAMLphp?
我在yii框架中有两个项目,我想使用SimpleSAMLphp和SSO来使用这两个项目。我需要的条件是,如果我从第一个项目登录,我希望访问第二个项目。如何在yii框架中使用SimpleSAMLphp?,yii,yii-components,simplesamlphp,Yii,Yii Components,Simplesamlphp,我在yii框架中有两个项目,我想使用SimpleSAMLphp和SSO来使用这两个项目。我需要的条件是,如果我从第一个项目登录,我希望访问第二个项目。 提前谢谢。只需使用“供应商”目录即可 从下载PHP库 将其作为供应商库在Yii框架中实现。() 祝您好运:)首先,通过临时禁用Yii自动加载程序加载SAML库。这只是为了让您使用SAML类和方法: <?php class YiiSAML extends CComponent { private $_yiiSAML = null;
提前谢谢。只需使用“供应商”目录即可
祝您好运:)首先,通过临时禁用Yii自动加载程序加载SAML库。这只是为了让您使用SAML类和方法:
<?php
class YiiSAML extends CComponent {
private $_yiiSAML = null;
static private function pre() {
require_once (Yii::app()->params['simpleSAML'] . '/lib/_autoload.php');
// temporary disable Yii autoloader
spl_autoload_unregister(array(
'YiiBase',
'autoload'
));
}
static private function post() {
// enable Yii autoloader
spl_autoload_register(array(
'YiiBase',
'autoload'
));
}
public function __construct() {
self::pre();
//We select our authentication source:
$this->_yiiSAML = new SimpleSAML_Auth_Simple(Yii::app()->params['authSource']);
self::post();
}
static public function loggedOut($param, $stage) {
self::pre();
$state = SimpleSAML_Auth_State::loadState($param, $stage);
self::post();
if (isset($state['saml:sp:LogoutStatus'])) {
$ls = $state['saml:sp:LogoutStatus']; /* Only for SAML SP */
} else return true;
return $ls['Code'] === 'urn:oasis:names:tc:SAML:2.0:status:Success' && !isset($ls['SubCode']);
}
public function __call($method, $args) {
$params = (is_array($args) and !empty($args)) ? $args[0] : $args;
if (method_exists($this->_yiiSAML, $method)) return $this->_yiiSAML->$method($params);
else throw new YiiSAMLException(Yii::t('app', 'The method {method} does not exist in the SAML class', array(
'{method}' => $method
)));
}
}
class YiiSAMLException extends CException {
}
最后,在您感兴趣的控制器中,您可以覆盖filters()
方法:
public function filters() {
return array(
array(
'lib.SAMLControl'
) , // perform access control for CRUD operations
...
);
}
希望有帮助。我在github中发现了SimpleSAMLphp的Yii扩展 您可以将simplesamlphp作为供应商库加载,然后在扩展名中指定自动加载文件
除了扩展之外,您还可以将所有必要的配置和元数据复制到应用程序中,并配置SimpleSAML配置以从目录加载配置,这样您就可以保持供应商软件包不受影响,以备将来更新。如果您放置一些代码并澄清问题的确切原因,那就太好了。请看这个,你在@Rohan Ale签出,谢谢你的建议,但是你能告诉我在yii框架中实现它的方法吗?很好,但问题是5年前提出的:)这意味着Yi1包我仍然在寻找Yi1包
public function filters() {
return array(
array(
'lib.SAMLControl'
) , // perform access control for CRUD operations
...
);
}