73 assert(
'is_array($info)');
74 assert(
'is_array($config)');
77 parent::__construct($info, $config);
79 if(!isset($config[0]) || $config[0] !==
'saml:SP') {
80 trigger_error(
'The selected authentication source is not SAML Service Provider');
84 if(!isset($config[
'entityID'])) {
85 trigger_error(
'entityID is not found in the selected authentication source');
90 $config[
'entityid'] = $config[
'entityID'];
92 $this->metadata = SimpleSAML_Configuration::loadFromArray($config,
'authsources[' . var_export($this->authId, TRUE) .
']');
93 $this->entityId = $this->metadata->getString(
'entityID');
94 $this->idp = $this->metadata->getString(
'idp', NULL);
95 $this->discoURL = $this->metadata->getString(
'discoURL', NULL);
97 if (empty($this->discoURL) && SimpleSAML_Module::isModuleEnabled(
'discojuice')) {
98 $this->discoURL = SimpleSAML_Module::getModuleURL(
'discojuice/central.php');
111 assert(
'is_string($idp)');
113 $idpMetadata = $this->getIdPMetadata($idp);
115 $type = $idpMetadata->getString(
'metadata-set');
117 case 'saml20-idp-remote':
135 public function startSSO2(SimpleSAML_Configuration $idpMetadata, array $state) {
136 if (isset($state[
'saml:ProxyCount']) && $state[
'saml:ProxyCount'] < 0) {
137 SimpleSAML_Auth_State::throwException($state,
new SimpleSAML_Error_ProxyCountExceeded(
"ProxyCountExceeded"));
140 $ar = sspmod_saml_Message::buildAuthnRequest($this->metadata, $idpMetadata);
143 $ar->setAssertionConsumerServiceURL($state[
'acs_url']);
145 if (isset($state[
'SimpleSAML_Auth_Default.ReturnURL'])) {
146 $ar->setRelayState($state[
'SimpleSAML_Auth_Default.ReturnURL']);
149 if (isset($state[
'saml:AuthnContextClassRef'])) {
150 $accr = SimpleSAML_Utilities::arrayize($state[
'saml:AuthnContextClassRef']);
151 $ar->setRequestedAuthnContext(array(
'AuthnContextClassRef' => $accr));
154 if (isset($state[
'ForceAuthn'])) {
155 $ar->setForceAuthn((
bool)$state[
'ForceAuthn']);
158 if (isset($state[
'isPassive'])) {
159 $ar->setIsPassive((
bool)$state[
'isPassive']);
162 if (isset($state[
'ProtocolBinding'])) {
163 $ar->setProtocolBinding($state[
'ProtocolBinding']);
166 if (isset($state[
'saml:NameIDPolicy'])) {
167 if (is_string($state[
'saml:NameIDPolicy'])) {
169 'Format' => (
string)$state[
'saml:NameIDPolicy'],
170 'AllowCreate' => TRUE,
172 } elseif (is_array($state[
'saml:NameIDPolicy'])) {
173 $policy = $state[
'saml:NameIDPolicy'];
175 throw new SimpleSAML_Error_Exception(
'Invalid value of $state[\'saml:NameIDPolicy\'].');
177 $ar->setNameIdPolicy($policy);
180 if (isset($state[
'saml:IDPList'])) {
181 $IDPList = $state[
'saml:IDPList'];
186 $ar->setIDPList(array_unique(array_merge($this->metadata->getArray(
'IDPList', array()),
187 $idpMetadata->getArray(
'IDPList', array()),
190 if (isset($state[
'saml:ProxyCount']) && $state[
'saml:ProxyCount'] !== null) {
191 $ar->setProxyCount($state[
'saml:ProxyCount']);
192 } elseif ($idpMetadata->getInteger(
'ProxyCount', null) !== null) {
193 $ar->setProxyCount($idpMetadata->getInteger(
'ProxyCount', null));
194 } elseif ($this->metadata->getInteger(
'ProxyCount', null) !== null) {
195 $ar->setProxyCount($this->metadata->getInteger(
'ProxyCount', null));
198 $requesterID = array();
199 if (isset($state[
'saml:RequesterID'])) {
200 $requesterID = $state[
'saml:RequesterID'];
203 if (isset($state[
'core:SP'])) {
204 $requesterID[] = $state[
'core:SP'];
207 $ar->setRequesterID($requesterID);
209 if (isset($state[
'saml:Extensions'])) {
210 $ar->setExtensions($state[
'saml:Extensions']);
213 $id = SimpleSAML_Auth_State::saveState($state,
'saml:sp:sso', TRUE);
216 SimpleSAML_Logger::debug(
'Sending SAML 2 AuthnRequest to ' . var_export($idpMetadata->getString(
'entityid'), TRUE));
217 if ($this->metadata->getValue(
'ProtocolBinding') ===
'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST') {
218 $b =
new SAML2_HTTPPost();
220 $b =
new SAML2_HTTPRedirect();
235 assert(
'is_array($state)');
236 assert(
'array_key_exists("saml:logout:IdP", $state)');
237 assert(
'array_key_exists("saml:logout:NameID", $state)');
238 assert(
'array_key_exists("saml:logout:SessionIndex", $state)');
240 $id = SimpleSAML_Auth_State::saveState($state,
'saml:slosent');
242 $idp = $state[
'saml:logout:IdP'];
243 $nameId = $state[
'saml:logout:NameID'];
244 $sessionIndex = $state[
'saml:logout:SessionIndex'];
246 $idpMetadata = $this->getIdPMetadata($idp);
248 $endpoint = $idpMetadata->getDefaultEndpoint(
'SingleLogoutService', array(SAML2_Const::BINDING_HTTP_REDIRECT), FALSE);
249 if ($endpoint === FALSE) {
250 SimpleSAML_Logger::info(
'No logout endpoint for IdP ' . var_export($idp, TRUE) .
'.');
254 $lr = sspmod_saml_Message::buildLogoutRequest($this->metadata, $idpMetadata);
255 $lr->setNameId($nameId);
256 $lr->setSessionIndex($sessionIndex);
257 $lr->setRelayState($id);
260 $encryptNameId = $idpMetadata->getBoolean(
'nameid.encryption', NULL);
261 if ($encryptNameId === NULL) {
262 $encryptNameId = $this->metadata->getBoolean(
'nameid.encryption', FALSE);
264 if ($encryptNameId) {
265 $lr->encryptNameId(sspmod_saml_Message::getEncryptionKey($idpMetadata));
268 if ($this->metadata->getValue(
'ProtocolBinding') ===
'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST') {
269 $b =
new SAML2_HTTPPost();
271 $b =
new SAML2_HTTPRedirect();