|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* SimpleSamlPHP authentication layer for Skosmos |
|
5
|
|
|
* |
|
6
|
|
|
* Required variables in your config.ttl: |
|
7
|
|
|
* skosmos:authenticationProvider "SimpleSamlPHP" ; |
|
8
|
|
|
* skosmos:authProviderIncludeDirectory "<SimpleSamlPHP installation path>" ; |
|
9
|
|
|
* skosmos:authProviderAuthEntity "<What authentication entity must be used? For simple testing use 'admin'>" . |
|
10
|
|
|
*/ |
|
11
|
|
|
class SimpleSamlPHP implements BaseAuthInterface { |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @var Model |
|
15
|
|
|
*/ |
|
16
|
|
|
private $model; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Placeholder of the SimpleSamlPHP authentication entity. |
|
20
|
|
|
* |
|
21
|
|
|
* @var string|null |
|
22
|
|
|
*/ |
|
23
|
|
|
private $authEntity; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* The configured application URL |
|
27
|
|
|
* |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
private $baseHref; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param Model $model |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct( Controller $controller ) { |
|
36
|
|
|
$this->model = $controller->model; |
|
37
|
|
|
$this->baseHref = $controller->getBaseHref(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @inheritDoc |
|
42
|
|
|
*/ |
|
43
|
|
|
public function validate(): bool { |
|
44
|
|
|
$authDirectory = $this->model->getConfig()->getLiteral( 'skosmos:authProviderIncludeDirectory' ); |
|
45
|
|
|
if ( !$authDirectory ) { |
|
46
|
|
|
return false; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$authEntity = $this->model->getConfig()->getLiteral( 'skosmos:authProviderAuthEntity' ); |
|
50
|
|
|
if ( !$authEntity ) { |
|
51
|
|
|
return false; |
|
52
|
|
|
} else { |
|
53
|
|
|
$this->authEntity = $authEntity; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$sspAutoloader = $authDirectory . DIRECTORY_SEPARATOR . 'lib/_autoload.php'; |
|
57
|
|
|
if ( !file_exists( $sspAutoloader ) ) { |
|
58
|
|
|
return false; |
|
59
|
|
|
} else { |
|
60
|
|
|
require $sspAutoloader; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return true; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @inheritDoc |
|
68
|
|
|
*/ |
|
69
|
|
|
public function isSignedIn(): bool { |
|
70
|
|
|
return $this->getSessionFromRequest()->isValid( $this->authEntity ); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @inheritDoc |
|
75
|
|
|
*/ |
|
76
|
|
|
public function signIn() { |
|
77
|
|
|
$this->getAuthenticationSource()->requireAuth( [ |
|
78
|
|
|
'ReturnTo' => $this->baseHref |
|
79
|
|
|
] ); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @inheritDoc |
|
84
|
|
|
*/ |
|
85
|
|
|
public function signOut() { |
|
86
|
|
|
$this->getAuthenticationSource()->logout( [ |
|
87
|
|
|
'ReturnTo' => $this->baseHref |
|
88
|
|
|
] ); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @inheritDoc |
|
93
|
|
|
*/ |
|
94
|
|
|
public function getUserAttributes(): array { |
|
95
|
|
|
if ( $this->isSignedIn() ) { |
|
96
|
|
|
return []; |
|
97
|
|
|
} |
|
98
|
|
|
return [ |
|
99
|
|
|
'auth_source' => $this->authEntity, |
|
100
|
|
|
'attributes' => $this->getAuthenticationSource()->getAttributes() |
|
101
|
|
|
]; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @return \SimpleSAML\Auth\Simple |
|
106
|
|
|
*/ |
|
107
|
|
|
private function getAuthenticationSource( ) { |
|
108
|
|
|
return new SimpleSAML\Auth\Simple( $this->authEntity ); |
|
|
|
|
|
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @return SimpleSAML\Session::getSessionFromRequest() |
|
113
|
|
|
*/ |
|
114
|
|
|
private function getSessionFromRequest() { |
|
115
|
|
|
return SimpleSAML\Session::getSessionFromRequest(); |
|
|
|
|
|
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths