Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
solarium
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
solarium
Commits
c4a8b6ad
Commit
c4a8b6ad
authored
Jan 22, 2013
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added authentication support to endpoint
parent
82e5539c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
6 deletions
+56
-6
library/Solarium/Core/Client/Adapter/Curl.php
library/Solarium/Core/Client/Adapter/Curl.php
+4
-1
library/Solarium/Core/Client/Endpoint.php
library/Solarium/Core/Client/Endpoint.php
+30
-0
tests/Solarium/Tests/Core/Client/EndpointTest.php
tests/Solarium/Tests/Core/Client/EndpointTest.php
+22
-5
No files found.
library/Solarium/Core/Client/Adapter/Curl.php
View file @
c4a8b6ad
...
...
@@ -156,7 +156,10 @@ class Curl extends Configurable implements AdapterInterface
$options
[
'headers'
][
'Content-Type'
]
=
'text/xml; charset=utf-8'
;
}
$authData
=
$request
->
getAuthentication
();
// Try endpoint authentication first, fallback to request for backwards compatibility
$authData
=
$endpoint
->
getAuthentication
();
if
(
empty
(
$authData
[
'username'
]))
$authData
=
$request
->
getAuthentication
();
if
(
!
empty
(
$authData
[
'username'
])
&&
!
empty
(
$authData
[
'password'
]))
{
curl_setopt
(
$handler
,
CURLOPT_USERPWD
,
$authData
[
'username'
]
.
':'
.
$authData
[
'password'
]
);
curl_setopt
(
$handler
,
CURLOPT_HTTPAUTH
,
CURLAUTH_BASIC
);
...
...
library/Solarium/Core/Client/Endpoint.php
View file @
c4a8b6ad
...
...
@@ -228,4 +228,34 @@ class Endpoint extends Configurable
return
$uri
;
}
/**
* Set HTTP basic auth settings
*
* If one or both values are NULL authentication will be disabled
*
* @param string $username
* @param string $password
* @return self Provides fluent interface
*/
public
function
setAuthentication
(
$username
,
$password
)
{
$this
->
setOption
(
'username'
,
$username
);
$this
->
setOption
(
'password'
,
$password
);
return
$this
;
}
/**
* Get HTTP basis auth settings
*
* @return array
*/
public
function
getAuthentication
()
{
return
array
(
'username'
=>
$this
->
getOption
(
'username'
),
'password'
=>
$this
->
getOption
(
'password'
),
);
}
}
tests/Solarium/Tests/Core/Client/EndpointTest.php
View file @
c4a8b6ad
...
...
@@ -47,11 +47,13 @@ class EndpointTest extends \PHPUnit_Framework_TestCase
public
function
testConfigMode
()
{
$options
=
array
(
'host'
=>
'192.168.0.1'
,
'port'
=>
123
,
'path'
=>
'/mysolr/'
,
'core'
=>
'mycore'
,
'timeout'
=>
3
,
'host'
=>
'192.168.0.1'
,
'port'
=>
123
,
'path'
=>
'/mysolr/'
,
'core'
=>
'mycore'
,
'timeout'
=>
3
,
'username'
=>
'x'
,
'password'
=>
'y'
);
$this
->
endpoint
->
setOptions
(
$options
);
...
...
@@ -110,4 +112,19 @@ class EndpointTest extends \PHPUnit_Framework_TestCase
$this
->
assertEquals
(
'http://myserver:123/mypath/mycore/'
,
$this
->
endpoint
->
getBaseUri
());
}
public
function
testGetAndSetAuthentication
()
{
$user
=
'someone'
;
$pass
=
'S0M3p455'
;
$this
->
endpoint
->
setAuthentication
(
$user
,
$pass
);
$this
->
assertEquals
(
array
(
'username'
=>
$user
,
'password'
=>
$pass
,
),
$this
->
endpoint
->
getAuthentication
()
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment