|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* AppserverIo\Authenticator\Utils\SingleSignOnFormPageUtil |
|
5
|
|
|
* |
|
6
|
|
|
* NOTICE OF LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
9
|
|
|
* that is available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* PHP version 5 |
|
13
|
|
|
* |
|
14
|
|
|
* @author Tim Wagner <[email protected]> |
|
15
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
17
|
|
|
* @link https://github.com/appserver-io/authenticator |
|
18
|
|
|
* @link http://www.appserver.io |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace AppserverIo\Authenticator\Utils; |
|
22
|
|
|
|
|
23
|
|
|
use AppserverIo\Psr\Security\SecurityException; |
|
24
|
|
|
use AppserverIo\Psr\Auth\LoginConfigurationInterface; |
|
25
|
|
|
use AppserverIo\Psr\Auth\AuthenticationManagerInterface; |
|
26
|
|
|
use AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface; |
|
27
|
|
|
use AppserverIo\Psr\Application\ManagerConfigurationInterface; |
|
28
|
|
|
use AppserverIo\Authenticator\Utils\ParamKeys; |
|
29
|
|
|
use AppserverIo\Server\Dictionaries\ServerVars; |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Utility class that helps to read the login form page configuration. |
|
33
|
|
|
* |
|
34
|
|
|
* @author Tim Wagner <[email protected]> |
|
35
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
36
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
37
|
|
|
* @link https://github.com/appserver-io/authenticator |
|
38
|
|
|
* @link http://www.appserver.io |
|
39
|
|
|
*/ |
|
40
|
|
|
class SingleSignOnFormPageUtil implements FormPageUtilInterface |
|
41
|
|
|
{ |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* The general form page utility instance. |
|
45
|
|
|
* |
|
46
|
|
|
* @var \AppserverIo\Authenticator\Utils\FormPageUtilInterface |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $formPageUtil; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Initializes the utiltiy with the general form page utility instance. |
|
52
|
|
|
* |
|
53
|
|
|
* @param \AppserverIo\Authenticator\Utils\FormPageUtilInterface $formPageUtil the general form page utility instance |
|
54
|
|
|
*/ |
|
55
|
|
|
public function __construct(FormPageUtilInterface $formPageUtil) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->formPageUtil = $formPageUtil; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Return's the location for the redirect to the login page configured in the `web.xml` file. |
|
62
|
|
|
* |
|
63
|
|
|
* @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface $servletRequest The servlet request instance |
|
64
|
|
|
* @param \AppserverIo\Psr\Auth\LoginConfigurationInterface $configData The login configuration in the `web.xml` |
|
65
|
|
|
* @param \AppserverIo\Psr\Auth\AuthenticationManagerInterface|null $authenticationManager The authentication manager instance |
|
66
|
|
|
* |
|
67
|
|
|
* @return string The location for the redirect to the login page |
|
68
|
|
|
* @throws \AppserverIo\Psr\Security\SecurityException Is thrown, if the appropriate form configuration in the `web.xml` is missing |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getLoginPage( |
|
71
|
|
|
HttpServletRequestInterface $servletRequest, |
|
72
|
|
|
LoginConfigurationInterface $configData, |
|
73
|
|
|
AuthenticationManagerInterface $authenticationManager = null |
|
74
|
|
|
) { |
|
75
|
|
|
|
|
76
|
|
|
// we need an authentication manager instance here |
|
77
|
|
|
if ($authenticationManager === null) { |
|
78
|
|
|
throw new SecurityException('Can\'t find mandatory authentication manager instance as 3rd method param'); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
// load the manager configuration from the authentication manager |
|
82
|
|
|
/** @var \AppserverIo\Psr\Application\ManagerConfigurationInterface $managerConfiguration */ |
|
83
|
|
|
$managerConfiguration = $authenticationManager->getManagerConfiguration(); |
|
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
// load the URL of the identity provider and the authorization path |
|
86
|
|
|
$identityUrl = $managerConfiguration->getParam(ParamKeys::IDENTITY_URL); |
|
|
|
|
|
|
87
|
|
|
$authorizePath = $managerConfiguration->getParam(ParamKeys::AUTHORIZATION_PATH); |
|
88
|
|
|
|
|
89
|
|
|
// create the location with the redirect URI to use |
|
90
|
|
|
$location = sprintf('%s%s', $identityUrl, $authorizePath); |
|
91
|
|
|
|
|
92
|
|
|
// prepare the redirect URK with the actual scheme HTTP/HTTPS and the server name |
|
93
|
|
|
$redirectUri = sprintf( |
|
94
|
|
|
'%s://%s', |
|
95
|
|
|
$servletRequest->getServerVar(ServerVars::REQUEST_SCHEME), |
|
96
|
|
|
$servletRequest->getServerVar(ServerVars::SERVER_NAME) |
|
97
|
|
|
); |
|
98
|
|
|
|
|
99
|
|
|
// load the actual server port, because by default and in local |
|
100
|
|
|
// environments we often use 9080/9443 instead of 80/443 |
|
101
|
|
|
$serverPort = (int) $servletRequest->getServerVar(ServerVars::SERVER_PORT); |
|
102
|
|
|
|
|
103
|
|
|
// query whether or not a custom server port, e. g. in context of containerized |
|
104
|
|
|
// environment, has been specified in the manager configuration |
|
105
|
|
|
if ($customServerPort = $managerConfiguration->getParam(ParamKeys::SERVER_PORT)) { |
|
106
|
|
|
$serverPort = $customServerPort; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
// append the port, if we do NOT have one of the default ports |
|
110
|
|
|
$redirectUri = in_array($serverPort, [80, 443]) ? $redirectUri : sprintf('%s:%d', $redirectUri, $serverPort); |
|
111
|
|
|
|
|
112
|
|
|
// append the path from the `web.xml` we've to to redirect to |
|
113
|
|
|
$redirectUri = sprintf('%s%s', $redirectUri, $this->formPageUtil->getLoginPage($servletRequest, $configData)); |
|
114
|
|
|
|
|
115
|
|
|
// create the location with the redirect URI to use and return it |
|
116
|
|
|
return sprintf($location, $redirectUri); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
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