-
Notifications
You must be signed in to change notification settings - Fork 22
/
Services.php
96 lines (84 loc) · 3.7 KB
/
Services.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
class EngineBlock_Corto_Module_Services_Exception extends EngineBlock_Corto_ProxyServer_Exception
{
public function __construct($message, $severity = self::CODE_NOTICE, Exception $previous = null)
{
parent::__construct($message, $severity, $previous);
}
}
class EngineBlock_Corto_Module_Services_SessionLostException extends EngineBlock_Corto_Module_Services_Exception
{
}
class EngineBlock_Corto_Module_Services extends EngineBlock_Corto_Module_Abstract
{
protected $_aliases = array(
'spCertificateService' => 'Certificate',
'idpCertificateService' => 'Certificate',
'spMetadataService' => 'Metadata',
'idpMetadataService' => 'Metadata',
'unsolicitedSingleSignOnService'=> 'singleSignOn',
'debugSingleSignOnService' => 'singleSignOn',
);
const BINDING_TYPE_HTTP_REDIRECT = 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect';
const BINDING_TYPE_HTTP_POST = 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST';
const DEFAULT_REQUEST_BINDING = self::BINDING_TYPE_HTTP_REDIRECT;
const DEFAULT_RESPONSE_BINDING = self::BINDING_TYPE_HTTP_POST;
const RESPONSE_CACHE_TYPE_IN = 'in';
const RESPONSE_CACHE_TYPE_OUT = 'out';
const INTRODUCTION_EMAIL = 'introduction_email';
/**
* @param string $serviceName
* @throws EngineBlock_Corto_Module_Services_Exception
*/
public function serve($serviceName)
{
// If we have an alias, use the alias
$resolvedServiceName = $serviceName;
if (isset($this->_aliases[$serviceName])) {
$resolvedServiceName = $this->_aliases[$serviceName];
}
$className = 'EngineBlock_Corto_Module_Service_' . ucfirst($resolvedServiceName);
if (strtolower(substr($className, -1 * strlen('service'))) === "service") {
$className = substr($className, 0, -1 * strlen('service'));
}
if (class_exists($className, true)) {
/** @var $serviceName EngineBlock_Corto_Module_Service_Abstract */
$service = $this->factoryService($className, $this->_server);
$service->serve($serviceName);
return;
}
throw new EngineBlock_Corto_Module_Services_Exception(
"Unable to load service '$serviceName' (resolved to '$resolvedServiceName') tried className '$className'!"
);
}
/**
* Creates services objects with their own specific needs
*
* @param string $className
* @param EngineBlock_Corto_ProxyServer $server
* @return EngineBlock_Corto_Module_Service_Abstract
*/
private function factoryService($className, EngineBlock_Corto_ProxyServer $server)
{
$diContainer = EngineBlock_ApplicationSingleton::getInstance()->getDiContainer();
switch($className) {
case 'EngineBlock_Corto_Module_Service_ProvideConsent' :
return new EngineBlock_Corto_Module_Service_ProvideConsent(
$server,
$diContainer->getXmlConverter(),
$diContainer->getConsentFactory()
);
case 'EngineBlock_Corto_Module_Service_ProcessConsent' :
$preferredNameAttributeFilter = new EngineBlock_User_PreferredNameAttributeFilter();
return new EngineBlock_Corto_Module_Service_ProcessConsent(
$server,
$diContainer->getXmlConverter(),
$diContainer->getConsentFactory(),
$diContainer->getMailer(),
$preferredNameAttributeFilter
);
default :
return new $className($server, $diContainer->getXmlConverter());
}
}
}