|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* AppserverIo\Psr\Auth\AuthenticatorWrapper |
|
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-psr/auth |
|
18
|
|
|
* @link http://www.appserver.io |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace AppserverIo\Psr\Auth; |
|
22
|
|
|
|
|
23
|
|
|
use AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface; |
|
24
|
|
|
use AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Wrapper for a authentication type implementation. |
|
28
|
|
|
* |
|
29
|
|
|
* @author Tim Wagner <[email protected]> |
|
30
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
31
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
32
|
|
|
* @link https://github.com/appserver-io-psr/auth |
|
33
|
|
|
* @link http://www.appserver.io |
|
34
|
|
|
*/ |
|
35
|
|
|
class AuthenticatorWrapper implements AuthenticatorInterface |
|
36
|
|
|
{ |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* The authenticator instance to be wrapped. |
|
40
|
|
|
* |
|
41
|
|
|
* @var \AppserverIo\Psr\Auth\AuthenticatorInterface |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $authenticator; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Injects the passed authenticator instance into this wrapper. |
|
47
|
|
|
* |
|
48
|
|
|
* @param \AppserverIo\Psr\Auth\AuthenticatorInterface $authenticator The authenticator instance used for initialization |
|
49
|
|
|
* |
|
50
|
|
|
* @return void |
|
51
|
|
|
*/ |
|
52
|
|
|
public function injectAuthenticator(AuthenticatorInterface $authenticator) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->authenticator = $authenticator; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Return's the authenticator instance. |
|
59
|
|
|
* |
|
60
|
|
|
* @return \AppserverIo\Psr\Auth\AuthenticatorInterface The authenticator instance |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getAuthenticator() |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->authenticator; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Returns the configuration data given for authentication type. |
|
69
|
|
|
* |
|
70
|
|
|
* @return object The configuration data |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getConfigData() |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->getAuthenticator()->getConfigData(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Return's the authentication manager instance. |
|
79
|
|
|
* |
|
80
|
|
|
* @return \AppserverIo\Psr\Auth\AuthenticationManagerInterface The authentication manager instance |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getAuthenticationManager() |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->getAuthenticator()->getAuthenticationManager(); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Returns the authentication type token. |
|
89
|
|
|
* |
|
90
|
|
|
* @return string The auth type |
|
91
|
|
|
*/ |
|
92
|
|
|
public function getAuthType() |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->getAuthenticator()->getType(); |
|
|
|
|
|
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Try to authenticate against the configured adapter. |
|
99
|
|
|
* |
|
100
|
|
|
* @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface $servletRequest The servlet request instance |
|
101
|
|
|
* @param \AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface $servletResponse The servlet response instance |
|
102
|
|
|
* |
|
103
|
|
|
* @return boolean TRUE if authentication has already been processed on a request before, else FALSE |
|
104
|
|
|
* @throws \AppserverIo\Http\Authentication\AuthenticationException Is thrown if the request can't be authenticated |
|
105
|
|
|
*/ |
|
106
|
|
|
public function authenticate(HttpServletRequestInterface $servletRequest, HttpServletResponseInterface $servletResponse) |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->getAuthenticator()->authenticate($servletRequest, $servletResponse); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Returns the password parsed from the request. |
|
113
|
|
|
* |
|
114
|
|
|
* @return string|null The password |
|
115
|
|
|
*/ |
|
116
|
|
|
public function getPassword() |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->getAuthenticator()->getPassword(); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Returns the username parsed from the request. |
|
123
|
|
|
* |
|
124
|
|
|
* @return string|null The username |
|
125
|
|
|
*/ |
|
126
|
|
|
public function getUsername() |
|
127
|
|
|
{ |
|
128
|
|
|
return $this->getAuthenticator()->getUsername(); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Mark's the authenticator as the default one. |
|
133
|
|
|
* |
|
134
|
|
|
* @return void |
|
135
|
|
|
*/ |
|
136
|
|
|
public function setDefaultAuthenticator() |
|
137
|
|
|
{ |
|
138
|
|
|
$this->getAuthenticator()->setDefaultAuthenticator(); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Query whether or not this is the default authenticator. |
|
143
|
|
|
* |
|
144
|
|
|
* @return boolean TRUE if this is the default authenticator, else FALSE |
|
145
|
|
|
*/ |
|
146
|
|
|
public function isDefaultAuthenticator() |
|
147
|
|
|
{ |
|
148
|
|
|
return $this->getAuthenticator()->isDefaultAuthenticator(); |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.