Apply PHPCS fixes.

This commit is contained in:
very-ape 2021-05-17 10:55:15 -07:00
parent e39e621421
commit 092605c2c2

View file

@ -25,7 +25,9 @@ function saml_module($a)
function saml_init($a) function saml_init($a)
{ {
if ($a->argc < 2) return; if ($a->argc < 2) {
return;
}
switch ($a->argv[1]) { switch ($a->argv[1]) {
case "metadata.xml": case "metadata.xml":
@ -37,10 +39,10 @@ function saml_init($a)
case "slo": case "slo":
saml_slo_reply(); saml_slo_reply();
break; break;
case "moo": case "moo":
echo DI::baseUrl(); echo DI::baseUrl();
echo $_SERVER['REQUEST_URI']; echo $_SERVER['REQUEST_URI'];
break; break;
} }
exit(); exit();
} }
@ -62,7 +64,7 @@ function saml_metadata()
); );
} }
} catch (Exception $e) { } catch (Exception $e) {
Logger::error($e->getMessage()); Logger::error($e->getMessage());
} }
} }
@ -101,12 +103,13 @@ function saml_is_configured()
DI::config()->get('saml', 'sp_key') && DI::config()->get('saml', 'sp_key') &&
DI::config()->get('saml', 'sp_cert') && DI::config()->get('saml', 'sp_cert') &&
DI::config()->get('saml', 'idp_cert'); DI::config()->get('saml', 'idp_cert');
} }
function saml_sso_initiate(&$a, &$b) function saml_sso_initiate(&$a, &$b)
{ {
if (!saml_is_configured()) return; if (!saml_is_configured()) {
return;
}
$auth = new \OneLogin\Saml2\Auth(saml_settings()); $auth = new \OneLogin\Saml2\Auth(saml_settings());
$ssoBuiltUrl = $auth->login(null, array(), false, false, true); $ssoBuiltUrl = $auth->login(null, array(), false, false, true);
@ -132,7 +135,7 @@ function saml_sso_reply($a)
$errors = $auth->getErrors(); $errors = $auth->getErrors();
if (!empty($errors)) { if (!empty($errors)) {
echo "Errors encountered."; echo "Errors encountered.";
Logger::error(implode(', ', $errors)); Logger::error(implode(', ', $errors));
exit(); exit();
} }
@ -162,8 +165,7 @@ function saml_sso_reply($a)
} }
if (isset($_POST['RelayState']) if (isset($_POST['RelayState'])
&& \OneLogin\Saml2\Utils::getSelfURL() != $_POST['RelayState']) && \OneLogin\Saml2\Utils::getSelfURL() != $_POST['RelayState']) {
{
$auth->redirectTo($_POST['RelayState']); $auth->redirectTo($_POST['RelayState']);
} }
} }
@ -214,9 +216,9 @@ function saml_input($key, $label, $description)
]; ];
} }
function saml_addon_admin (&$a, &$o) function saml_addon_admin(&$a, &$o)
{ {
$form = $form =
saml_input( saml_input(
'settings_statement', 'settings_statement',
DI::l10n()->t('Settings statement'), DI::l10n()->t('Settings statement'),
@ -265,14 +267,13 @@ function saml_addon_admin (&$a, &$o)
[ [
'$submit' => DI::l10n()->t('Save Settings'), '$submit' => DI::l10n()->t('Save Settings'),
]; ];
$t = Renderer::getMarkupTemplate( "admin.tpl", "addon/saml/" ); $t = Renderer::getMarkupTemplate("admin.tpl", "addon/saml/");
$o = Renderer::replaceMacros( $t, $form); $o = Renderer::replaceMacros($t, $form);
} }
function saml_addon_admin_post (&$a) function saml_addon_admin_post(&$a)
{ {
$safeset = function ($key) $safeset = function ($key) {
{
$val = (!empty($_POST[$key]) ? Strings::escapeTags(trim($_POST[$key])) : ''); $val = (!empty($_POST[$key]) ? Strings::escapeTags(trim($_POST[$key])) : '');
DI::config()->set('saml', $key, $val); DI::config()->set('saml', $key, $val);
}; };
@ -312,8 +313,7 @@ function saml_create_user($username, $email, $name)
'verified' => true 'verified' => true
]); ]);
return $user; return $user;
} catch (Exception $e) { } catch (Exception $e) {
Logger::error( Logger::error(
'Exception while creating user', 'Exception while creating user',
@ -323,7 +323,8 @@ function saml_create_user($username, $email, $name)
'name' => $name, 'name' => $name,
'exception' => $e->getMessage(), 'exception' => $e->getMessage(),
'trace' => $e->getTraceAsString() 'trace' => $e->getTraceAsString()
]); ]
);
return false; return false;
} }
@ -351,7 +352,7 @@ function saml_settings()
// Service Provider Data that we are deploying. // Service Provider Data that we are deploying.
'sp' => array( 'sp' => array(
// Identifier of the SP entity (must be a URI) // Identifier of the SP entity (must be a URI)
'entityId' => DI::config()->get('saml','client_id'), 'entityId' => DI::config()->get('saml', 'client_id'),
// Specifies info about where and how the <AuthnResponse> message MUST be // Specifies info about where and how the <AuthnResponse> message MUST be
// returned to the requester, in this case our SP. // returned to the requester, in this case our SP.
'assertionConsumerService' => array( 'assertionConsumerService' => array(
@ -391,19 +392,19 @@ function saml_settings()
'NameIDFormat' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified', 'NameIDFormat' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified',
// Usually x509cert and privateKey of the SP are provided by files placed at // Usually x509cert and privateKey of the SP are provided by files placed at
// the certs folder. But we can also provide them with the following parameters // the certs folder. But we can also provide them with the following parameters
'x509cert' => DI::config()->get('saml','sp_cert'), 'x509cert' => DI::config()->get('saml', 'sp_cert'),
'privateKey' => DI::config()->get('saml','sp_key'), 'privateKey' => DI::config()->get('saml', 'sp_key'),
), ),
// Identity Provider Data that we want connected with our SP. // Identity Provider Data that we want connected with our SP.
'idp' => array( 'idp' => array(
// Identifier of the IdP entity (must be a URI) // Identifier of the IdP entity (must be a URI)
'entityId' => DI::config()->get('saml','idp_id'), 'entityId' => DI::config()->get('saml', 'idp_id'),
// SSO endpoint info of the IdP. (Authentication Request protocol) // SSO endpoint info of the IdP. (Authentication Request protocol)
'singleSignOnService' => array( 'singleSignOnService' => array(
// URL Target of the IdP where the Authentication Request Message // URL Target of the IdP where the Authentication Request Message
// will be sent. // will be sent.
'url' => DI::config()->get('saml','sso_url'), 'url' => DI::config()->get('saml', 'sso_url'),
// SAML protocol binding to be used when returning the <Response> // SAML protocol binding to be used when returning the <Response>
// message. OneLogin Toolkit supports the HTTP-Redirect binding // message. OneLogin Toolkit supports the HTTP-Redirect binding
// only for this endpoint. // only for this endpoint.
@ -412,17 +413,17 @@ function saml_settings()
// SLO endpoint info of the IdP. // SLO endpoint info of the IdP.
'singleLogoutService' => array( 'singleLogoutService' => array(
// URL Location of the IdP where SLO Request will be sent. // URL Location of the IdP where SLO Request will be sent.
'url' => DI::config()->get('saml','slo_request_url'), 'url' => DI::config()->get('saml', 'slo_request_url'),
// URL location of the IdP where SLO Response will be sent (ResponseLocation) // URL location of the IdP where SLO Response will be sent (ResponseLocation)
// if not set, url for the SLO Request will be used // if not set, url for the SLO Request will be used
'responseUrl' => DI::config()->get('saml','slo_response_url'), 'responseUrl' => DI::config()->get('saml', 'slo_response_url'),
// SAML protocol binding to be used when returning the <Response> // SAML protocol binding to be used when returning the <Response>
// message. OneLogin Toolkit supports the HTTP-Redirect binding // message. OneLogin Toolkit supports the HTTP-Redirect binding
// only for this endpoint. // only for this endpoint.
'binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect', 'binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
), ),
// Public x509 certificate of the IdP // Public x509 certificate of the IdP
'x509cert' => DI::config()->get('saml','idp_cert'), 'x509cert' => DI::config()->get('saml', 'idp_cert'),
), ),
'security' => array ( 'security' => array (
'wantXMLValidation' => false, 'wantXMLValidation' => false,
@ -444,4 +445,3 @@ function saml_settings()
) )
); );
} }
?>