-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #149 from OpenConext/feature/filter-on-available-g…
…ssp-tokens Filter on all available second factor types
- Loading branch information
Showing
25 changed files
with
433 additions
and
210 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
src/Surfnet/StepupRa/RaBundle/Form/Extension/SecondFactorTypeChoiceList.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright 2018 SURFnet bv | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Surfnet\StepupRa\RaBundle\Form\Extension; | ||
|
||
use Psr\Log\LoggerInterface; | ||
use Surfnet\StepupBundle\Service\SecondFactorTypeService; | ||
use Surfnet\StepupBundle\Service\SecondFactorTypeTranslationService; | ||
|
||
/** | ||
* Used to build a choice list of second factor types | ||
* | ||
* Second factor types are indexed on their identifier. Some examples: 'sms', 'tiqr', 'u2f'. These not very human | ||
* readable keys are linked to a more human readable value which is read from the translator. This results in an | ||
* associative array like this: | ||
* | ||
* [ | ||
* 'sms' => 'SMS', | ||
* 'yubi' => 'Yubikey', | ||
* 'tiqr' => 'Tiqr' | ||
* ] | ||
* | ||
* A message is logged when the second factor type id cannot be translated. Second factor type id's that cannot be | ||
* translated, are not added to the choice list. | ||
*/ | ||
class SecondFactorTypeChoiceList | ||
{ | ||
/** | ||
* @var SecondFactorTypeService | ||
*/ | ||
private $secondFactorTypeService; | ||
|
||
/** | ||
* @var SecondFactorTypeTranslationService | ||
*/ | ||
private $translator; | ||
|
||
/** | ||
* @var LoggerInterface | ||
*/ | ||
private $logger; | ||
|
||
/** | ||
* @param SecondFactorTypeService $service | ||
* @param SecondFactorTypeTranslationService $translator | ||
*/ | ||
public function __construct( | ||
SecondFactorTypeService $service, | ||
SecondFactorTypeTranslationService $translator, | ||
LoggerInterface $logger | ||
) { | ||
$this->secondFactorTypeService = $service; | ||
$this->translator = $translator; | ||
$this->logger = $logger; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function create() | ||
{ | ||
$selectOptions = []; | ||
$collection = $this->secondFactorTypeService->getAvailableSecondFactorTypes(); | ||
|
||
sort($collection); | ||
|
||
foreach ($collection as $sfTypeIdentifier) { | ||
|
||
$translation = $this->translator->translate( | ||
$sfTypeIdentifier, | ||
'ra.form.ra_search_ra_second_factors.choice.type.%s' | ||
); | ||
|
||
// Test if the translator was able to translate the second factor type | ||
if ($sfTypeIdentifier === $translation) { | ||
$this->logger->warning( | ||
sprintf( | ||
'Unable to add a filter option on the second factor type select list for type: "%s"', | ||
$sfTypeIdentifier | ||
) | ||
); | ||
continue; | ||
} | ||
$selectOptions[$sfTypeIdentifier] = $translation; | ||
} | ||
|
||
return $selectOptions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.