1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* AppserverIo\Authenticator\Utils\FormPageUtil |
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
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Utility class that helps to read the login form page configuration. |
31
|
|
|
* |
32
|
|
|
* @author Tim Wagner <[email protected]> |
33
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
34
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
35
|
|
|
* @link https://github.com/appserver-io/authenticator |
36
|
|
|
* @link http://www.appserver.io |
37
|
|
|
*/ |
38
|
|
|
class FormPageUtil implements FormPageUtilInterface |
39
|
|
|
{ |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Return's the location for the redirect to the login page configured in the `web.xml` file. |
43
|
|
|
* |
44
|
|
|
* @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface $servletRequest The servlet request instance |
45
|
|
|
* @param \AppserverIo\Psr\Auth\LoginConfigurationInterface $configData The login configuration in the `web.xml` |
46
|
|
|
* |
47
|
|
|
* @return string The location for the redirect to the login page |
48
|
|
|
* @throws \AppserverIo\Psr\Security\SecurityException Is thrown, if the appropriate form configuration in the `web.xml` is missing |
49
|
|
|
*/ |
50
|
|
|
public function getLoginPage( |
51
|
|
|
HttpServletRequestInterface $servletRequest, |
52
|
|
|
LoginConfigurationInterface $configData |
53
|
|
|
) { |
54
|
|
|
|
55
|
|
|
// query whether or not we've a valid form login configuration |
56
|
|
|
if ($formLoginConfig = $configData->getFormLoginConfig()) { |
57
|
|
|
if ($formLoginPage = $formLoginConfig->getFormLoginPage()) { |
58
|
|
|
// initialize the location to redirect to |
59
|
|
|
$location = $formLoginPage->__toString(); |
60
|
|
|
if ($baseModifier = $servletRequest->getBaseModifier()) { |
61
|
|
|
$location = $baseModifier . $location; |
62
|
|
|
} |
63
|
|
|
// return the location |
64
|
|
|
return $location; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
// throw an exception because we need |
69
|
|
|
// the appropriate configuration |
70
|
|
|
throw new SecurityException( |
71
|
|
|
'Please configure a form-login-page when using auth-method \'Form\' in the login-config of your application\'s web.xml' |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|