Completed
Push — master ( d10220...9d4ad8 )
by Tim
03:00 queued 01:16
created

AuthenticationManagerWrapper::getAuthenticators()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
c 1
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * AppserverIo\Psr\Auth\AuthenticationManagerWrapper
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\Application\ApplicationInterface;
24
use AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface;
25
use AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface;
26
27
/**
28
 * The wrapper implementation of a authentication manager.
29
 *
30
 * @author    Tim Wagner <[email protected]>
31
 * @copyright 2016 TechDivision GmbH <[email protected]>
32
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
33
 * @link      https://github.com/appserver-io-psr/auth
34
 * @link      http://www.appserver.io
35
 */
36
class AuthenticationManagerWrapper implements AuthenticationManagerInterface
37
{
38
39
    /**
40
     * The authentication manager instance to be wrapped.
41
     *
42
     * @var \AppserverIo\Psr\Auth\AuthenticationManagerInterface
43
     */
44
    protected $authenticationManager;
45
46
    /**
47
     * Injects the passed authentication manager instance into this wrapper.
48
     *
49
     * @param \AppserverIo\Psr\Auth\AuthenticationManagerInterface $authenticationManager The authentication manager instance used for initialization
50
     *
51
     * @return void
52
     */
53
    public function injectAuthenticationManager(AuthenticationManagerInterface $authenticationManager)
54
    {
55
        $this->authenticationManager = $authenticationManager;
56
    }
57
58
    /**
59
     * Return's the authentication manager instance.
60
     *
61
     * @return \AppserverIo\Psr\Auth\AuthenticationManagerInterface The authentication manager instance
62
     */
63
    public function getAuthenticationManager()
64
    {
65
        return $this->authenticationManager;
66
    }
67
68
    /**
69
     * Handles request in order to authenticate.
70
     *
71
     * @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface  $servletRequest  The request instance
72
     * @param \AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface $servletResponse The response instance
73
     *
74
     * @return boolean TRUE if the authentication has been successful, else FALSE
75
     */
76
    public function handleRequest(HttpServletRequestInterface $servletRequest, HttpServletResponseInterface $servletResponse)
77
    {
78
        return $this->getAuthenticationManager()->handleRequest($servletRequest, $servletResponse);
79
    }
80
81
    /**
82
     * Add's the passed realm the the authentication manager.
83
     *
84
     * @param \AppserverIo\Appserver\ServletEngine\Security\RealmInterface $realm The realm to add
85
     *
86
     * @return void
87
     */
88
    public function addRealm(RealmInterface $realm)
89
    {
90
        $this->getAuthenticationManager()->addRealm($realm);
91
    }
92
93
    /**
94
     * Returns the map with the security domains.
95
     *
96
     * @return \AppserverIo\Collections\MapInterface The security domains
97
     */
98
    public function getRealms()
99
    {
100
        return $this->getAuthenticationManager()->getRealms();
101
    }
102
103
    /**
104
     * Register's the passed authenticator.
105
     *
106
     * @param \AppserverIo\Appserver\ServletEngine\Authenticator\AuthenticatorInterface $authenticator The authenticator to add
107
     *
108
     * @return void
109
     */
110
    public function addAuthenticator(AuthenticatorInterface $authenticator)
111
    {
112
        $this->getAuthenticationManager()->addAuthenticator($authenticator);
113
    }
114
115
    /**
116
     * Returns the configured authenticator for the passed URL pattern authenticator mapping.
117
     *
118
     * @param \AppserverIo\Appserver\ServletEngine\Security\MappingInterface|null $mapping The URL pattern to authenticator mapping
119
     *
120
     * @return \AppserverIo\Storage\StorageInterface The storage with the authentication types
121
     * @throws \AppserverIo\Http\Authentication\AuthenticationException Is thrown if the authenticator with the passed key is not available
122
     */
123
    public function getAuthenticator(MappingInterface $mapping = null)
124
    {
125
        return $this->getAuthenticationManager()->getAuthenticator($mapping);
126
    }
127
128
    /**
129
     * Returns the configured authentication types.
130
     *
131
     * @return \AppserverIo\Storage\StorageInterface The storage with the authentication types
132
     */
133
    public function getAuthenticators()
134
    {
135
        return $this->getAuthenticationManager()->getAuthenticators();
136
    }
137
138
    /**
139
     * Register's a new URL pattern to authentication type mapping.
140
     *
141
     * @param \AppserverIo\Appserver\ServletEngine\Security\MappingInterface $mapping The URL pattern to authenticator mapping
142
     *
143
     * @return void
144
     */
145
    public function addMapping(MappingInterface $mapping)
146
    {
147
        $this->getAuthenticationManager()->addMapping($mapping);
148
    }
149
150
    /**
151
     * Return's the storage for the URL pattern to authenticator mappings.
152
     *
153
     * @return \AppserverIo\Storage\StorageInterface The storage instance
154
     */
155
    public function getMappings()
156
    {
157
        return $this->getAuthenticationManager()->getMappings();
158
    }
159
160
    /**
161
     * Returns the realm with the passed name.
162
     *
163
     * @param string $realmName The name of the requested realm
164
     *
165
     * @return object The requested realm instance
166
     */
167
    public function getRealm($realmName)
168
    {
169
        return $this->getAuthenticationManager()->getRealm($realmName);
170
    }
171
172
    /**
173
     * The managers unique identifier.
174
     *
175
     * @return string The unique identifier
176
     */
177
    public function getIdentifier()
178
    {
179
        return $this->getAuthenticationManager()->getIdentifier();
180
    }
181
182
    /**
183
     * Has been automatically invoked by the container after the application
184
     * instance has been created.
185
     *
186
     * @param \AppserverIo\Psr\Application\ApplicationInterface $application The application instance
187
     *
188
     * @return void
189
     */
190
    public function initialize(ApplicationInterface $application)
191
    {
192
        return $this->getAuthenticationManager()->initialize($application);
193
    }
194
195
    /**
196
     * Returns the value with the passed name from the context.
197
     *
198
     * @param string $key The key of the value to return from the context.
199
     *
200
     * @return mixed The requested attribute
201
     */
202
    public function getAttribute($key)
203
    {
204
        return $this->getAuthenticationManager()->getAttribute($key);
205
    }
206
}
207