Skip to content
Snippets Groups Projects
Commit 468264b6 authored by Valentin Pocotilenco's avatar Valentin Pocotilenco
Browse files

code refactoring

parent a809e63a
No related branches found
No related tags found
No related merge requests found
<?php
namespace App\Constants;
abstract class EarcUtils
{
const COCO_GEANT_NET_URL = "http://www.geant.net/uri/dataprotection-code-of-conduct/v1";
const RS_REFEDS_ORG_URL = "http://refeds.org/category/research-and-scholarship";
const RS_SUPPORT_CATEGORY = "http://macedir.org/entity-category-support";
const RS_CATEGORY = "http://macedir.org/entity-category";
const RELEASE_CHECK_EDUGAIN = "https://release-check.edugain.org/results/";
const EARC_SP = [
'https://rns-ng.example.org/shibboleth',
'https://coco.example.org/shibboleth',
'https://noec.example.org/shibboleth',
// test
'https://rns-ng-earc.aai-dev.grnet.gr/shibboleth',
'https://coco-earc.aai-dev.grnet.gr/shibboleth',
'https://noec-earc.aai-dev.grnet.gr/shibboleth',
];
const EARC_REGIONAL_SP = [
'http://aai.grnet.gr/' => 'https://aai.grnet.gr',
'http://rr.aai.switch.ch/' => 'https://attribute-viewer.aai.switch.ch/interfederation-test/',
'http://taat.edu.ee' => 'https://eitja.taat.edu.ee/',
'http://eduid.hu' => 'https://attributes.eduid.hu',
];
}
\ No newline at end of file
......@@ -15,14 +15,18 @@ class AttrReleaseTestController extends Controller
{
$request->session()->put('test_allowed', true);
if ($request->has('sps')){
if ($request->has('sps'))
{
$sps = $request->input('sps');
$redirect_url = "https://".parse_url($sps[0], PHP_URL_HOST)."/sp";
// Store the other SPs to checked in the session so that they can be retrieved later on
if (count(array_slice($sps,1)) > 0){
if (count(array_slice($sps,1)) > 0)
{
$request->session()->put('remaining_sps', array_slice($sps,1));
}
return redirect($redirect_url);
}
}
......
......@@ -5,7 +5,6 @@ namespace App\Http\Controllers;
use App\IdpResult;
use App\Libraries\EarcUtils;
use App\Http\Controllers\Controller;
use \SimpleSAML_Configuration;
class HomeController extends Controller
{
......@@ -17,12 +16,16 @@ class HomeController extends Controller
public function __invoke()
{
session(['test_allowed' => 'true']);
$sp_entities = EarcUtils::getSpMetadata(null);
$attributemap = EarcUtils::getAttributeMap();
//Get only the latest result for each IdP
$idps = IdpResult::all()->unique('idp_entity_id');
$historical_results = array();
foreach ($idps as $idp){
$historical_results = [];
foreach ($idps as $idp)
{
$historical_results[] = IdpResult::where('idp_entity_id', $idp['idp_entity_id'])
->orderBy('created_at', 'desc')
->first();
......
......@@ -8,6 +8,7 @@ use App\TestResult;
use App\TestAttribute;
use App\Libraries\EarcUtils;
use Illuminate\Http\Request;
use App\Constants\EarcUtils AS EarcConstants;
class ResultsController extends Controller
{
......@@ -18,52 +19,82 @@ class ResultsController extends Controller
{
//Get only the latest result for each IdP
$idps = IdpResult::all()->unique('idp_entity_id');
foreach ($idps as $idp) {
foreach ($idps as $idp)
{
$historical_results[] = IdpResult::where('idp_entity_id', $idp['idp_entity_id'])->orderBy('created_at', 'desc')->first();
}
$idp_result = IdpResult::where('test_id', $test_id)->get();
if (count($idp_result) > 0) {
if (count($idp_result) > 0)
{
$released_attributes = array();
$sp_entities = EarcUtils::getSpMetadata(null);
$test_results = TestResult::where('test_id', $test_id)->get();
$test_attributes = TestAttribute::where('test_id', $test_id)->get();
foreach ($test_results as $result) {
foreach ($test_results as $result)
{
$sp_entities[$result->sp_entityid]['tested'] = true;
if ($result->sp_entityid == env('APP_URL_NOEC') . "/shibboleth") {
if (strpos($result->test_mark, 'F') !== false) {
if ($result->sp_entityid == env('APP_URL_NOEC') . "/shibboleth")
{
if (strpos($result->test_mark, 'F') !== false)
{
$verdict[$result->sp_entityid]['comment'] = 'Good data privacy but bad usability.';
} elseif (strpos($result->test_mark, 'A') !== false) {
}
elseif (strpos($result->test_mark, 'A') !== false)
{
$verdict[$result->sp_entityid]['comment'] = 'Good usability but bad data privacy.';
} else {
}
else
{
$verdict[$result->sp_entityid]['comment'] = $result->test_comment;
}
$verdict[$result->sp_entityid]['mark'] = '';
} else {
}
else
{
$verdict[$result->sp_entityid]['mark'] = $result->test_mark;
$verdict[$result->sp_entityid]['comment'] = $result->test_comment;
}
$released_attributes[$result->sp_entityid] = array();
$released_attributes[$result->sp_entityid] = [];
}
foreach ($test_attributes as $attribute) {
foreach ($test_attributes as $attribute)
{
$released_attributes[$attribute->sp_entityid][$attribute->attr_name] = $attribute->attr_value_multiplicity;
}
foreach ($sp_entities as $sp) {
if (array_key_exists('tested', $sp)) {
if (array_key_exists('attributeNamesRequired', $sp)) {
if (EarcUtils::isRnsIndicated($sp)) {
if (array_key_exists('eduPersonScopedAffiliation', $released_attributes[$sp['entityid']])) {
foreach ($sp_entities as $sp)
{
if (array_key_exists('tested', $sp))
{
if (array_key_exists('attributeNamesRequired', $sp))
{
if (EarcUtils::isRnsIndicated($sp))
{
if (array_key_exists('eduPersonScopedAffiliation', $released_attributes[$sp['entityid']]))
{
$sp['attributeNamesRequired'][] = 'eduPersonScopedAffiliation';
}
if (array_key_exists('eduPersonTargetedID', $released_attributes[$sp['entityid']])) {
if (array_key_exists('eduPersonTargetedID', $released_attributes[$sp['entityid']]))
{
$sp['attributeNamesRequired'][] = 'eduPersonTargetedID';
}
}
$sp_entities[$sp['entityid']]['superfluous_attributes'] = array_diff(array_keys($released_attributes[$sp['entityid']]), $sp['attributeNamesRequired']);
}
}
}
$regional_earc = array_key_exists($idp_result[0]['registration_authority'], config('app.regional_earc'))
? config('app.regional_earc')[$idp_result[0]['registration_authority']]
$regional_earc = array_key_exists($idp_result[0]['registration_authority'], EarcConstants::EARC_REGIONAL_SP)
? EarcConstants::EARC_REGIONAL_SP[$idp_result[0]['registration_authority']]
: null;
return view('results', ['historical_results' => $historical_results,
......@@ -72,38 +103,44 @@ class ResultsController extends Controller
'verdict' => $verdict,
'sp_entities' => $sp_entities,
'released_attributes' => $released_attributes, ]);
} else {
abort(404);
}
}
abort(404);
}
public function getHistoricalResults()
{
$idps = IdpResult::all()->unique('idp_entity_id');
foreach ($idps as $idp) {
foreach ($idps as $idp)
{
$historical_results[] = IdpResult::where('idp_entity_id', $idp['idp_entity_id'])->orderBy('created_at', 'desc')->first();
}
foreach ($historical_results as $key => $result) {
foreach ($historical_results as $key => $result)
{
$historical_results[$key]['test_result'] = TestResult::where('test_id', $result['test_id'])->get();
$historical_results[$key]['result_page'] = 'https://release-check.edugain.org/results/' . $historical_results[$key]['test_id'];
$historical_results[$key]['result_page'] = EarcConstants::RELEASE_CHECK_EDUGAIN . $historical_results[$key]['test_id'];
$historical_results[$key]['date'] = $historical_results[$key]['created_at'];
foreach ($historical_results[$key]['test_result'] as $tkey => $tvalue) {
if ($historical_results[$key]['test_result'][$tkey]['sp_entityid'] == env('APP_URL_NOEC') . "/shibboleth") {
foreach ($historical_results[$key]['test_result'] as $tkey => $tvalue)
{
if ($historical_results[$key]['test_result'][$tkey]['sp_entityid'] == env('APP_URL_NOEC') . "/shibboleth")
{
unset($historical_results[$key]['test_result'][$tkey]);
continue;
}
unset($historical_results[$key]['test_result'][$tkey]['test_comment']);
unset($historical_results[$key]['test_result'][$tkey]['created_at']);
unset($historical_results[$key]['test_result'][$tkey]['updated_at']);
unset($historical_results[$key]['test_result'][$tkey]['id']);
unset($historical_results[$key]['test_result'][$tkey]['test_id']);
}
unset($historical_results[$key]['created_at']);
unset($historical_results[$key]['updated_at']);
unset($historical_results[$key]['id']);
unset($historical_results[$key]['test_id']);
}
return $historical_results;
......@@ -114,15 +151,15 @@ class ResultsController extends Controller
$idp_entity_id = urldecode($idp_entity_id);
$historical_result = IdpResult::where('idp_entity_id', $idp_entity_id)->orderBy('created_at', 'desc')->first();
if (count($historical_result)>0) {
if (count($historical_result)>0)
{
$historical_result['datetime'] = $historical_result['created_at'];
$historical_result['result_page'] = 'https://release-check.edugain.org/results/' . $historical_result['test_id'];
$historical_result['result_page'] = EarcConstants::RELEASE_CHECK_EDUGAIN . $historical_result['test_id'];
unset($historical_result['test_comment']);
unset($historical_result['created_at']);
unset($historical_result['updated_at']);
unset($historical_result['id']);
unset($historical_result['test_id']);
}
return $historical_result;
......
This diff is collapsed.
......@@ -124,31 +124,6 @@ return [
'log_level' => env('APP_LOG_LEVEL', 'debug'),
/*
|---------------------------------------------------------------------------
|EARC specific Configuration
|
|
*/
// XXX Updated using ansible
'earc_sps' => [
'https://rns-ng.example.org/shibboleth',
'https://coco.example.org/shibboleth',
'https://noec.example.org/shibboleth',
],
'regional_earc' => [
'http://aai.grnet.gr/' => 'https://aai.grnet.gr',
'http://rr.aai.switch.ch/' => 'https://attribute-viewer.aai.switch.ch/interfederation-test/',
'http://taat.edu.ee' => 'https://eitja.taat.edu.ee/',
'http://eduid.hu' => 'https://attributes.eduid.hu',
],
'metadata_url' => env('METADATA_URL', ""),
/*
|--------------------------------------------------------------------------
| Autoloaded Service Providers
......
<?php
return [
'metadata_url' => env('METADATA_URL', ""),
'sp_remote_metadata_filename' => 'saml20-sp-remote.php',
'idp_remote_metadata_filename' => 'saml20-idp-remote.php',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment