Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
getSearchDn example
$presentedPassword
=
$passwordCredentials
->
getPassword
(
)
;
if
(
'' ===
$presentedPassword
)
{
throw
new
BadCredentialsException
(
'The presented password cannot be empty.'
)
;
}
$user
=
$passport
->
getUser
(
)
;
/** @var LdapInterface $ldap */
$ldap
=
$this
->ldapLocator->
get
(
$ldapBadge
->
getLdapServiceId
(
)
)
;
try
{
if
(
$ldapBadge
->
getQueryString
(
)
)
{
if
(
'' !==
$ldapBadge
->
getSearchDn
(
)
&& '' !==
$ldapBadge
->
getSearchPassword
(
)
)
{
try
{
$ldap
->
bind
(
$ldapBadge
->
getSearchDn
(
)
,
$ldapBadge
->
getSearchPassword
(
)
)
;
}
catch
(
InvalidCredentialsException
)
{
throw
new
InvalidSearchCredentialsException
(
)
;
}
}
else
{
throw
new
LogicException
(
'Using the "query_string" config without using a "search_dn" and a "search_password" is not supported.'
)
;
}
$identifier
=
$ldap
->
escape
(
$user
->
getUserIdentifier
(
)
, '', LdapInterface::ESCAPE_FILTER
)
;
$query
=
str_replace
(
'{user_identifier}',
$identifier
,
$ldapBadge
->
getQueryString
(
)
)
;
$result
=
$ldap
->
query
(
$ldapBadge
->
getDnString
(
)
,
$query
)
->
execute
(
)
;