Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
setFirewallName example
/** * @param array $options Options for processing a successful authentication attempt */
public
function
__construct
(
AuthenticationSuccessHandlerInterface
$handler
, array
$options
, string
$firewallName
)
{
$this
->handler =
$handler
;
if
(
method_exists
(
$handler
, 'setOptions'
)
)
{
$this
->handler->
setOptions
(
$options
)
;
}
if
(
method_exists
(
$handler
, 'setFirewallName'
)
)
{
$this
->handler->
setFirewallName
(
$firewallName
)
;
}
}
public
function
onAuthenticationSuccess
(
Request
$request
, TokenInterface
$token
)
: ?Response
{
return
$this
->handler->
onAuthenticationSuccess
(
$request
,
$token
)
;
}
}
/** * @dataProvider getRequestRedirections */
public
function
testRequestRedirections
(
Request
$request
,
$options
,
$redirectedUrl
)
{
$urlGenerator
=
$this
->
createMock
(
UrlGeneratorInterface::
class
)
;
$urlGenerator
->
expects
(
$this
->
any
(
)
)
->
method
(
'generate'
)
->
willReturn
(
'http://localhost/login'
)
;
$httpUtils
=
new
HttpUtils
(
$urlGenerator
)
;
$token
=
$this
->
createMock
(
TokenInterface::
class
)
;
$handler
=
new
DefaultAuthenticationSuccessHandler
(
$httpUtils
,
$options
)
;
if
(
$request
->
hasSession
(
)
)
{
$handler
->
setFirewallName
(
'admin'
)
;
}
$this
->
assertSame
(
'http://localhost'.
$redirectedUrl
,
$handler
->
onAuthenticationSuccess
(
$request
,
$token
)
->
getTargetUrl
(
)
)
;
}
public
function
testRequestRedirectionsWithTargetPathInSessions
(
)
{
$session
=
$this
->
createMock
(
SessionInterface::
class
)
;
$session
->
expects
(
$this
->
once
(
)
)
->
method
(
'get'
)
->
with
(
'_security.admin.target_path'
)
->
willReturn
(
'/admin/dashboard'
)
;
$session
->
expects
(
$this
->
once
(
)
)
->
method
(
'remove'
)
->
with
(
'_security.admin.target_path'
)
;
$requestWithSession
= Request::
create
(
'/'
)
;
$requestWithSession
->
setSession
(
$session
)
;