Skip to content
Snippets Groups Projects

Code style

Merged Pavel Břoušek requested to merge github/fork/BaranekD/codeStyle into master
4 files
+ 266
32
Compare changes
  • Side-by-side
  • Inline
Files
4
<?php
namespace SimpleSAML\Module\remoteuserssl\Auth\Source;
use SimpleSAML\Module\ldap\ConfigHelper;
use SimpleSAML\Auth\Source;
use SimpleSAML\Configuration;
use SimpleSAML\XHTML\Template;
use SimpleSAML\Utils\HTTP;
use SimpleSAML\Error\ErrorCodes;
use SimpleSAML\Logger;
/**
* Getting user's identity either from REMOTE_USER or SSL_CLIENT_S_DN. The code of the module has been inspired by module authX509 from Emmanuel Dreyfus <manu@netbsd.org>.
* Getting user's identity either from REMOTE_USER or SSL_CLIENT_S_DN. The code of the module has been inspired
* by module authX509 from Emmanuel Dreyfus <manu@netbsd.org>.
*
* @author Michal Prochazka, <michalp@ics.muni.cz>
*
* @package SimpleSAMLphp
*/
class sspmod_remoteUserSSL_Auth_Source_RemoteUserSSL extends SimpleSAML_Auth_Source {
class RemoteUserSSL extends \SimpleSAML\Auth\Source
{
/**
* LDAPConfigHelper object
@@ -16,19 +29,20 @@ class sspmod_remoteUserSSL_Auth_Source_RemoteUserSSL extends SimpleSAML_Auth_Sou
/**
* Constructor for this authentication source.
*
* @param array $info Information about this authentication source.
* @param array $config Configuration.
* @param array $info Information about this authentication source.
* @param array $config Configuration.
*/
public function __construct($info, $config) {
public function __construct($info, $config)
{
assert('is_array($info)');
assert('is_array($config)');
// Call the parent constructor first, as required by the interface
parent::__construct($info, $config);
$this->ldapcf = new sspmod_ldap_ConfigHelper(
$this->ldapcf = new ConfigHelper(
$config,
'Authentication source '.var_export($this->authId, true)
'Authentication source ' . var_export($this->authId, true)
);
return;
@@ -37,12 +51,14 @@ class sspmod_remoteUserSSL_Auth_Source_RemoteUserSSL extends SimpleSAML_Auth_Sou
/**
* Get REMOTE_USER or SSL_CLIENT_S_DN
*
* This function just gets value from REMOTE_USER and if it is empty it tries SSL_CLIENT_S_DN. If any of two is filled, then it let user in.
* This function just gets value from REMOTE_USER and if it is empty it tries SSL_CLIENT_S_DN. If any of two is
* filled, then it let user in.
*
* @param array &$state Information about the current authentication.
*/
public function authenticate(&$state) {
assert(is_array($state));
public function authenticate(&$state)
{
assert(is_array($state));
$login = null;
if (isset($_SERVER['SSL_CLIENT_S_DN'])) {
@@ -51,7 +67,9 @@ class sspmod_remoteUserSSL_Auth_Source_RemoteUserSSL extends SimpleSAML_Auth_Sou
$login = preg_replace('/^([^@]*).*/', '\1', $_SERVER['REMOTE_USER']);
} else {
// Both variables were empty, this shouldn't happen if the web server is properly configured
\SimpleSAML\Logger::error('remoteUserSSL: user entered protected area without being properly authenticated');
Logger::error(
'remoteUserSSL: user entered protected area without being properly authenticated'
);
$state['remoteUserSSL.error'] = "AUTHERROR";
$this->authFailed($state);
@@ -61,19 +79,19 @@ class sspmod_remoteUserSSL_Auth_Source_RemoteUserSSL extends SimpleSAML_Auth_Sou
$dn = $this->ldapcf->searchfordn(null, $login, true);
if ($dn === null) {
\SimpleSAML\Logger::warning('remoteuserssl: no matching user found in LDAP for login='.$login);
Logger::warning('remoteuserssl: no matching user found in LDAP for login=' . $login);
$this->authFailed($state);
assert(false); // should never be reached
return;
}
\SimpleSAML\Logger::info('remoteuserssl: '.$dn);
$attributes = $this->ldapcf->getAttributes($dn);
Logger::info('remoteuserssl: ' . $dn);
$attributes = $this->ldapcf->getAttributes($dn);
assert(is_array($attributes));
$state['Attributes'] = $attributes;
$this->authSuccesful($state);
$this->authSuccesful($state);
assert(false); // should never be reached
return;
@@ -86,11 +104,12 @@ class sspmod_remoteUserSSL_Auth_Source_RemoteUserSSL extends SimpleSAML_Auth_Sou
*
* @param array &$state Information about the current authentication.
*/
public function authSuccesful(&$state) {
SimpleSAML_Auth_Source::completeAuth($state);
public function authSuccesful(&$state)
{
Source::completeAuth($state);
assert(false); // should never be reached
return;
return;
}
/**
@@ -100,19 +119,19 @@ class sspmod_remoteUserSSL_Auth_Source_RemoteUserSSL extends SimpleSAML_Auth_Sou
*
* @param array &$state Information about the current authentication.
*/
public function authFailed(&$state) {
$config = SimpleSAML_Configuration::getInstance();
$t = new SimpleSAML_XHTML_Template($config, 'remoteuserssl:RemoteUserSSLerror.php');
$t->data['loginurl'] = \SimpleSAML\Utils\HTTP::getSelfURL();
public function authFailed(&$state)
{
$config = Configuration::getInstance();
$t = new Template($config, 'remoteuserssl:RemoteUserSSLerror.php');
$t->data['loginurl'] = HTTP::getSelfURL();
if (isset($state['remoteUserSSL.error'])) {
$t->data['errorcode'] = $state['remoteUserSSL.error'];
}
$t->data['errorcodes'] = \SimpleSAML\Error\ErrorCodes::getAllErrorCodeMessages();
$t->data['errorcodes'] = ErrorCodes::getAllErrorCodeMessages();
$t->show();
exit();
}
}
Loading