Skip to content

Commit

Permalink
add use statements to import SimpleSAML classes
Browse files Browse the repository at this point in the history
  • Loading branch information
briskt committed Jul 10, 2024
1 parent eeb1d92 commit 4841645
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 38 deletions.
3 changes: 1 addition & 2 deletions development/UserPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use SimpleSAML\Error;
use SimpleSAML\Logger;
use SimpleSAML\Module\core\Auth\UserPassBase;
use SimpleSAML\Utils;

/**
* Example authentication source - username & password.
Expand All @@ -23,7 +22,7 @@
*
* @package SimpleSAMLphp
*/
class UserPass extends \SimpleSAML\Module\core\Auth\UserPassBase // GTIS
class UserPass extends UserPassBase // GTIS
{
/**
* Our users, stored in an associative array. The key of the array is "<username>:<password>",
Expand Down
3 changes: 2 additions & 1 deletion dockerbuild/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

use Sil\PhpEnv\Env;
use Sil\PhpEnv\EnvVarNotFoundException;
use SimpleSAML\Utils;

$httpUtils = new \SimpleSAML\Utils\HTTP();
$httpUtils = new Utils\HTTP();

/*
* Get config settings from ENV vars or set defaults
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
use SimpleSAML\Module\silauth\Auth\Source\behaviors\CreatedAtUtcBehavior;
use SimpleSAML\Module\silauth\Auth\Source\http\Request;
use SimpleSAML\Module\silauth\Auth\Source\time\UtcTime;
use SimpleSAML\Module\silauth\Auth\Source\traits\LoggerAwareTrait;
use Yii;
use yii\base\Model;
use yii\helpers\ArrayHelper;
use Yii;

class FailedLoginIpAddress extends FailedLoginIpAddressBase implements LoggerAwareInterface
{
use \SimpleSAML\Module\silauth\Auth\Source\traits\LoggerAwareTrait;
use LoggerAwareTrait;

/**
* @inheritdoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
use SimpleSAML\Module\silauth\Auth\Source\auth\Authenticator;
use SimpleSAML\Module\silauth\Auth\Source\behaviors\CreatedAtUtcBehavior;
use SimpleSAML\Module\silauth\Auth\Source\time\UtcTime;
use SimpleSAML\Module\silauth\Auth\Source\traits\LoggerAwareTrait;
use Yii;
use yii\base\Model;
use yii\helpers\ArrayHelper;
use Yii;

class FailedLoginUsername extends FailedLoginUsernameBase implements LoggerAwareInterface
{
use \SimpleSAML\Module\silauth\Auth\Source\traits\LoggerAwareTrait;
use LoggerAwareTrait;

/**
* @inheritdoc
Expand Down
7 changes: 5 additions & 2 deletions modules/sildisco/public/betatest.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?php

use SimpleSAML\Session;

ini_set('display_errors', 1);

$sessionType = 'sildisco:authentication';
$sessionKey = 'beta_tester';

$session = \SimpleSAML\Session::getSessionFromRequest();
$session->setData($sessionType, $sessionKey, 1, \SimpleSAML\Session::DATA_TIMEOUT_SESSION_END);
$session = Session::getSessionFromRequest();
$session->setData($sessionType, $sessionKey, 1, Session::DATA_TIMEOUT_SESSION_END);

echo "<h1>Start Beta Testing</h1>";
echo "<p>You have been given a cookie to allow you to test beta-enabled IDPs.</p>";
Expand Down
19 changes: 12 additions & 7 deletions modules/sildisco/public/metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
require_once('../public/_include.php');

use SAML2\Constants;
use SimpleSAML\Configuration;
use SimpleSAML\Error;
use SimpleSAML\Metadata\MetaDataStorageHandler;
use SimpleSAML\Metadata\SAMLBuilder;
use SimpleSAML\Metadata\Signer;
use SimpleSAML\Utils;

// load SimpleSAMLphp, configuration and metadata
$config = \SimpleSAML\Configuration::getInstance();
$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
$config = Configuration::getInstance();
$metadata = MetaDataStorageHandler::getMetadataHandler();

if (!$config->getOptionalBoolean('enable.saml20-idp', false)) {
throw new \SimpleSAML\Error\Error('NOACCESS');
throw new Error\Error('NOACCESS');
}

// check if valid local session exists
Expand Down Expand Up @@ -145,7 +150,7 @@
);

if (!$idpmeta->hasValue('OrganizationURL')) {
throw new \SimpleSAML\Error\Exception('If OrganizationName is set, OrganizationURL must also be set.');
throw new Error\Exception('If OrganizationName is set, OrganizationURL must also be set.');
}
$metaArray['OrganizationURL'] = $idpmeta->getLocalizedString('OrganizationURL');
}
Expand Down Expand Up @@ -200,7 +205,7 @@
$metaArray['contacts'][] = $metadataUtils->getContact($techcontact);
}

$metaBuilder = new \SimpleSAML\Metadata\SAMLBuilder($idpentityid);
$metaBuilder = new SAMLBuilder($idpentityid);
$metaBuilder->addMetadataIdP20($metaArray);
$metaBuilder->addOrganizationInfo($metaArray);

Expand All @@ -209,7 +214,7 @@
$metaflat = '$metadata[' . var_export($idpentityid, true) . '] = ' . var_export($metaArray, true) . ';';

// sign the metadata if enabled
$metaxml = \SimpleSAML\Metadata\Signer::sign($metaxml, $idpmeta->toArray(), 'SAML 2 IdP');
$metaxml = Signer::sign($metaxml, $idpmeta->toArray(), 'SAML 2 IdP');

if (array_key_exists('format', $_GET) && $_GET['format'] == 'xml') {
header('Content-Type: application/xml');
Expand All @@ -224,5 +229,5 @@
exit(0);
}
} catch (Exception $exception) {
throw new \SimpleSAML\Error\Error('METADATA', $exception);
throw new Error\Error('METADATA', $exception);
}
14 changes: 8 additions & 6 deletions modules/sildisco/src/Auth/Process/AddIdp2NameId.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace SimpleSAML\Module\sildisco\Auth\Process;

use SAML2\XML\saml\NameID;
use Sil\SspUtils\Metadata;
use SimpleSAML\Auth\ProcessingFilter;
use SimpleSAML\Error;
use SimpleSAML\Logger;

/**
* Attribute filter for appending IDPNamespace to the NameID.
Expand All @@ -17,7 +19,7 @@
* ],
*
*/
class AddIdp2NameId extends \SimpleSAML\Auth\ProcessingFilter
class AddIdp2NameId extends ProcessingFilter
{

const IDP_KEY = "saml:sp:IdP"; // the key that points to the entity id in the state
Expand Down Expand Up @@ -124,7 +126,7 @@ public function process(array &$state): void
$samlIDP = $state[self::IDP_KEY];

if (empty($state[self::SP_NAMEID_ATTR])) {
\SimpleSAML\Logger::warning(
Logger::warning(
self::SP_NAMEID_ATTR . ' attribute not available from ' .
$samlIDP . '.'
);
Expand All @@ -144,19 +146,19 @@ public function process(array &$state): void

// The IDP metadata must have an IDPNamespace entry
if (!isset($idpEntry[self::IDP_CODE_KEY])) {
throw new \SimpleSAML\Error\Exception(self::ERROR_PREFIX . "Missing required metadata entry: " .
throw new Error\Exception(self::ERROR_PREFIX . "Missing required metadata entry: " .
self::IDP_CODE_KEY . ".");
}

// IDPNamespace must be a non-empty string
if (!is_string($idpEntry[self::IDP_CODE_KEY])) {
throw new \SimpleSAML\Error\Exception(self::ERROR_PREFIX . "Required metadata " .
throw new Error\Exception(self::ERROR_PREFIX . "Required metadata " .
"entry, " . self::IDP_CODE_KEY . ", must be a non-empty string.");
}

// IDPNamespace must not have special characters in it
if (!preg_match("/^[A-Za-z0-9_-]+$/", $idpEntry[self::IDP_CODE_KEY])) {
throw new \SimpleSAML\Error\Exception(self::ERROR_PREFIX . "Required metadata " .
throw new Error\Exception(self::ERROR_PREFIX . "Required metadata " .
"entry, " . self::IDP_CODE_KEY . ", must not be empty or contain anything except " .
"letters, numbers, hyphens and underscores.");
}
Expand Down
14 changes: 8 additions & 6 deletions modules/sildisco/src/Auth/Process/LogUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Aws\DynamoDb\Marshaler;
use Aws\Sdk;
use SimpleSAML\Auth\ProcessingFilter;
use SimpleSAML\Logger;

/**
* This Auth Proc logs information about each successful login to an AWS Dynamodb table.
Expand All @@ -16,7 +18,7 @@
* 'DynamoEndpoint' ex. http://dynamo:8000
*
*/
class LogUser extends \SimpleSAML\Auth\ProcessingFilter
class LogUser extends ProcessingFilter
{

const AWS_ACCESS_KEY_ID_ENV = "DYNAMO_ACCESS_KEY_ID";
Expand Down Expand Up @@ -75,12 +77,12 @@ public function process(array &$state): void

$awsKey = getenv(self::AWS_ACCESS_KEY_ID_ENV);
if (!$awsKey) {
\SimpleSAML\Logger::error(self::AWS_ACCESS_KEY_ID_ENV . " environment variable is required for LogUser.");
Logger::error(self::AWS_ACCESS_KEY_ID_ENV . " environment variable is required for LogUser.");
return;
}
$awsSecret = getenv(self::AWS_SECRET_ACCESS_KEY_ENV);
if (!$awsSecret) {
\SimpleSAML\Logger::error(self::AWS_SECRET_ACCESS_KEY_ENV . " environment variable is required for LogUser.");
Logger::error(self::AWS_SECRET_ACCESS_KEY_ENV . " environment variable is required for LogUser.");
return;
}

Expand Down Expand Up @@ -135,7 +137,7 @@ public function process(array &$state): void
try {
$result = $dynamodb->putItem($params);
} catch (\Exception $e) {
\SimpleSAML\Logger::error("Unable to add item: " . $e->getMessage());
Logger::error("Unable to add item: " . $e->getMessage());
}
}

Expand All @@ -144,12 +146,12 @@ private function configsAreValid(): bool
$msg = ' config value not provided to LogUser.';

if (empty($this->dynamoRegion)) {
\SimpleSAML\Logger::error(self::DYNAMO_REGION_KEY . $msg);
Logger::error(self::DYNAMO_REGION_KEY . $msg);
return false;
}

if (empty($this->dynamoLogTable)) {
\SimpleSAML\Logger::error(self::DYNAMO_LOG_TABLE_KEY . $msg);
Logger::error(self::DYNAMO_LOG_TABLE_KEY . $msg);
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions modules/sildisco/src/Auth/Process/TagGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace SimpleSAML\Module\sildisco\Auth\Process;

use Sil\SspUtils\Metadata;
use SimpleSAML\Auth\ProcessingFilter;

/**
* Attribute filter for prefixing group names
*
*/
class TagGroup extends \SimpleSAML\Auth\ProcessingFilter
class TagGroup extends ProcessingFilter
{

const IDP_NAME_KEY = 'name'; // the metadata key for the IDP's name
Expand Down
7 changes: 5 additions & 2 deletions modules/sildisco/src/Auth/Process/TrackIdps.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace SimpleSAML\Module\sildisco\Auth\Process;

use SimpleSAML\Auth\ProcessingFilter;
use SimpleSAML\Session;

/**
* Attribute filter for adding Idps to the session
*
*/
class TrackIdps extends \SimpleSAML\Auth\ProcessingFilter
class TrackIdps extends ProcessingFilter
{

/**
Expand All @@ -17,7 +20,7 @@ class TrackIdps extends \SimpleSAML\Auth\ProcessingFilter
public function process(array &$state): void
{
// get the authenticating Idp and add it to the list of previous ones
$session = \SimpleSAML\Session::getSessionFromRequest();
$session = Session::getSessionFromRequest();
$sessionDataType = "sildisco:authentication";
$sessionKey = "authenticated_idps";

Expand Down
12 changes: 8 additions & 4 deletions modules/sildisco/src/IdPDisco.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
use Sil\SspUtils\DiscoUtils;
use Sil\SspUtils\Metadata;
use SimpleSAML\Auth;
use SimpleSAML\Logger;
use SimpleSAML\Session;
use SimpleSAML\Utils\HTTP;
use SimpleSAML\XHTML\IdPDisco as SSPIdPDisco;
use SimpleSAML\XHTML\Template;

/**
* This class implements a custom IdP discovery service, for use with a ssp hub (proxy)
Expand All @@ -16,7 +20,7 @@
* @author Steve Bagwell SIL GTIS
* @package SimpleSAMLphp
*/
class IdPDisco extends \SimpleSAML\XHTML\IdPDisco
class IdPDisco extends SSPIdPDisco
{

/* The session type for this class */
Expand All @@ -36,7 +40,7 @@ class IdPDisco extends \SimpleSAML\XHTML\IdPDisco
*/
protected function log(string $message): void
{
\SimpleSAML\Logger::info('SildiscoIdPDisco.' . $this->instance . ': ' . $message);
Logger::info('SildiscoIdPDisco.' . $this->instance . ': ' . $message);
}

/* Path to the folder with the SP and IdP metadata */
Expand Down Expand Up @@ -104,7 +108,7 @@ public function handleRequest(): void
$spEntries = Metadata::getSpMetadataEntries($this->getMetadataPath());
$sp = $spEntries[$spEntityId];

$t = new \SimpleSAML\XHTML\Template($this->config, 'selectidp-links', 'disco');
$t = new Template($this->config, 'selectidp-links', 'disco');

// in order to bypass some built-in simplesaml behavior, an extra idp
// might've been added. It's not meant to be displayed.
Expand Down Expand Up @@ -144,7 +148,7 @@ public static function enableBetaEnabled(array $idpList, ?bool $isBetaTester = n
{

if ($isBetaTester === null) {
$session = \SimpleSAML\Session::getSessionFromRequest();
$session = Session::getSessionFromRequest();
$isBetaTester = $session->getData(
self::$sessionType,
self::$betaTesterSessionKey
Expand Down
4 changes: 3 additions & 1 deletion modules/sildisco/tests/AddIdpTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php


use SimpleSAML\Module\sildisco\Auth\Process\AddIdp2NameId;

class AddIdpTest extends PHPUnit_Framework_TestCase
{

Expand Down Expand Up @@ -29,7 +31,7 @@ private static function getNameID($idp)
*/
private static function processAddIdp2NameId(array $config, array $request)
{
$filter = new \SimpleSAML\Module\sildisco\Auth\Process\AddIdp2NameId($config, NULL);
$filter = new AddIdp2NameId($config, NULL);
$filter->process($request);
return $request;
}
Expand Down
3 changes: 2 additions & 1 deletion modules/sildisco/tests/TagGroupTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use SimpleSAML\Module\sildisco\Auth\Process\TagGroup;

class TagGroupTest extends PHPUnit_Framework_TestCase
{
Expand All @@ -12,7 +13,7 @@ class TagGroupTest extends PHPUnit_Framework_TestCase
*/
private static function processTagGroup(array $config, array $request)
{
$filter = new \SimpleSAML\Module\sildisco\Auth\Process\TagGroup($config, NULL);
$filter = new TagGroup($config, NULL);
$filter->process($request);
return $request;
}
Expand Down

0 comments on commit 4841645

Please sign in to comment.