Skip to content

Commit

Permalink
Merge 1191d6c into df88c21
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Sep 25, 2019
2 parents df88c21 + 1191d6c commit e5f31da
Show file tree
Hide file tree
Showing 116 changed files with 850 additions and 715 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"symfony/dependency-injection": "^3.4 || ^4.0",
"symfony/yaml": "^3.4 || ^4.0",
"twig/twig": "~1.0 || ~2.0",
"webmozart/assert": "~1.4",
"whitehat101/apr1-md5": "~1.0"
},
"require-dev": {
Expand Down
39 changes: 20 additions & 19 deletions lib/SimpleSAML/Auth/ProcessingChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use SimpleSAML\Logger;
use SimpleSAML\Module;
use SimpleSAML\Utils;
use Webmozart\Assert\Assert;

/**
* Class for implementing authentication processing chains for IdPs.
Expand Down Expand Up @@ -56,8 +57,8 @@ class ProcessingChain
*/
public function __construct($idpMetadata, $spMetadata, $mode = 'idp')
{
assert(is_array($idpMetadata));
assert(is_array($spMetadata));
Assert::isArray($idpMetadata);
Assert::isArray($spMetadata);

$this->filters = [];

Expand Down Expand Up @@ -95,8 +96,8 @@ public function __construct($idpMetadata, $spMetadata, $mode = 'idp')
*/
private static function addFilters(&$target, $src)
{
assert(is_array($target));
assert(is_array($src));
Assert::isArray($target);
Assert::isArray($src);

foreach ($src as $filter) {
$fp = $filter->priority;
Expand All @@ -122,7 +123,7 @@ private static function addFilters(&$target, $src)
*/
private static function parseFilterList($filterSrc)
{
assert(is_array($filterSrc));
Assert::isArray($filterSrc);

$parsedFilters = [];

Expand Down Expand Up @@ -153,7 +154,7 @@ private static function parseFilterList($filterSrc)
*/
private static function parseFilter($config, $priority)
{
assert(is_array($config));
Assert::isArray($config);

if (!array_key_exists('class', $config)) {
throw new \Exception('Authentication processing filter without name given.');
Expand Down Expand Up @@ -197,9 +198,9 @@ private static function parseFilter($config, $priority)
*/
public function processState(&$state)
{
assert(is_array($state));
assert(array_key_exists('ReturnURL', $state) || array_key_exists('ReturnCall', $state));
assert(!array_key_exists('ReturnURL', $state) || !array_key_exists('ReturnCall', $state));
Assert::isArray($state);
Assert::true(array_key_exists('ReturnURL', $state) || array_key_exists('ReturnCall', $state));
Assert::true(!array_key_exists('ReturnURL', $state) || !array_key_exists('ReturnCall', $state));

$state[self::FILTERS_INDEX] = $this->filters;

Expand Down Expand Up @@ -243,7 +244,7 @@ public function processState(&$state)
*/
public static function resumeProcessing($state)
{
assert(is_array($state));
Assert::isArray($state);

while (count($state[self::FILTERS_INDEX]) > 0) {
$filter = array_shift($state[self::FILTERS_INDEX]);
Expand All @@ -259,8 +260,8 @@ public static function resumeProcessing($state)

// Completed

assert(array_key_exists('ReturnURL', $state) || array_key_exists('ReturnCall', $state));
assert(!array_key_exists('ReturnURL', $state) || !array_key_exists('ReturnCall', $state));
Assert::true(array_key_exists('ReturnURL', $state) || array_key_exists('ReturnCall', $state));
Assert::true(!array_key_exists('ReturnURL', $state) || !array_key_exists('ReturnCall', $state));


if (array_key_exists('ReturnURL', $state)) {
Expand All @@ -277,10 +278,10 @@ public static function resumeProcessing($state)
State::deleteState($state);

$func = $state['ReturnCall'];
assert(is_callable($func));
Assert::isCallable($func);

call_user_func($func, $state);
assert(false);
Assert::true(false);
}
}

Expand All @@ -298,9 +299,9 @@ public static function resumeProcessing($state)
*/
public function processStatePassive(&$state)
{
assert(is_array($state));
Assert::isArray($state);
// Should not be set when calling this method
assert(!array_key_exists('ReturnURL', $state));
Assert::keyNotExists($state, 'ReturnURL');

// Notify filters about passive request
$state['isPassive'] = true;
Expand Down Expand Up @@ -335,7 +336,7 @@ public function processStatePassive(&$state)
*/
public static function fetchProcessedState($id)
{
assert(is_string($id));
Assert::string($id);

return State::loadState($id, self::COMPLETED_STAGE);
}
Expand All @@ -348,8 +349,8 @@ public static function fetchProcessedState($id)
*/
private static function addUserID(&$state)
{
assert(is_array($state));
assert(array_key_exists('Attributes', $state));
Assert::isArray($state);
Assert::keyExists($state, 'Attributes');

if (isset($state['Destination']['userid.attribute'])) {
$attributeName = $state['Destination']['userid.attribute'];
Expand Down
4 changes: 3 additions & 1 deletion lib/SimpleSAML/Auth/ProcessingFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace SimpleSAML\Auth;

use Webmozart\Assert\Assert;

/**
* Base class for authentication processing filters.
*
Expand Down Expand Up @@ -45,7 +47,7 @@ abstract class ProcessingFilter
*/
public function __construct(&$config, $reserved)
{
assert(is_array($config));
Assert::isArray($config);

if (array_key_exists('%priority', $config)) {
$this->priority = $config['%priority'];
Expand Down
37 changes: 19 additions & 18 deletions lib/SimpleSAML/Auth/Simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

namespace SimpleSAML\Auth;

use \SimpleSAML\Configuration;
use \SimpleSAML\Error;
use \SimpleSAML\Module;
use \SimpleSAML\Session;
use \SimpleSAML\Utils;
use SimpleSAML\Configuration;
use SimpleSAML\Error;
use SimpleSAML\Module;
use SimpleSAML\Session;
use SimpleSAML\Utils;
use Webmozart\Assert\Assert;

/**
* Helper class for simple authentication applications.
Expand Down Expand Up @@ -39,7 +40,7 @@ class Simple
*/
public function __construct($authSource, Configuration $config = null, Session $session = null)
{
assert(is_string($authSource));
Assert::string($authSource);

if ($config === null) {
$config = Configuration::getInstance();
Expand Down Expand Up @@ -165,7 +166,7 @@ public function login(array $params = [])

$as = $this->getAuthSource();
$as->initLogin($returnTo, $errorURL, $params);
assert(false);
Assert::true(false);
}


Expand All @@ -187,7 +188,7 @@ public function login(array $params = [])
*/
public function logout($params = null)
{
assert(is_array($params) || is_string($params) || $params === null);
Assert::true(is_array($params) || is_string($params) || $params === null);

if ($params === null) {
$params = Utils\HTTP::getSelfURL();
Expand All @@ -199,11 +200,11 @@ public function logout($params = null)
];
}

assert(is_array($params));
assert(isset($params['ReturnTo']) || isset($params['ReturnCallback']));
Assert::isArray($params);
Assert::true(isset($params['ReturnTo']) || isset($params['ReturnCallback']));

if (isset($params['ReturnStateParam']) || isset($params['ReturnStateStage'])) {
assert(isset($params['ReturnStateParam'], $params['ReturnStateStage']));
Assert::true(isset($params['ReturnStateParam'], $params['ReturnStateStage']));
}

if ($this->session->isValid($this->authSource)) {
Expand Down Expand Up @@ -236,16 +237,16 @@ public function logout($params = null)
*/
public static function logoutCompleted($state)
{
assert(is_array($state));
assert(isset($state['ReturnTo']) || isset($state['ReturnCallback']));
Assert::isArray($state);
Assert::true(isset($state['ReturnTo']) || isset($state['ReturnCallback']));

if (isset($state['ReturnCallback'])) {
call_user_func($state['ReturnCallback'], $state);
assert(false);
Assert::true(false);
} else {
$params = [];
if (isset($state['ReturnStateParam']) || isset($state['ReturnStateStage'])) {
assert(isset($state['ReturnStateParam'], $state['ReturnStateStage']));
Assert::true(isset($state['ReturnStateParam'], $state['ReturnStateStage']));
$stateID = State::saveState($state, $state['ReturnStateStage']);
$params[$state['ReturnStateParam']] = $stateID;
}
Expand Down Expand Up @@ -283,7 +284,7 @@ public function getAttributes()
*/
public function getAuthData($name)
{
assert(is_string($name));
Assert::string($name);

if (!$this->isAuthenticated()) {
return null;
Expand Down Expand Up @@ -318,7 +319,7 @@ public function getAuthDataArray()
*/
public function getLoginURL($returnTo = null)
{
assert($returnTo === null || is_string($returnTo));
Assert::nullOrString($returnTo);

if ($returnTo === null) {
$returnTo = Utils\HTTP::getSelfURL();
Expand All @@ -343,7 +344,7 @@ public function getLoginURL($returnTo = null)
*/
public function getLogoutURL($returnTo = null)
{
assert($returnTo === null || is_string($returnTo));
Assert::nullOrString($returnTo);

if ($returnTo === null) {
$returnTo = Utils\HTTP::getSelfURL();
Expand Down

0 comments on commit e5f31da

Please sign in to comment.