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
8c94e08c
Commit
8c94e08c
authored
Jul 13, 2012
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved auth settings to request object and updated adapter implementations
parent
69f330de
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
10 deletions
+58
-10
library/Solarium/Client/Adapter/Curl.php
library/Solarium/Client/Adapter/Curl.php
+5
-4
library/Solarium/Client/Adapter/Http.php
library/Solarium/Client/Adapter/Http.php
+3
-2
library/Solarium/Client/Adapter/PeclHttp.php
library/Solarium/Client/Adapter/PeclHttp.php
+5
-0
library/Solarium/Client/Request.php
library/Solarium/Client/Request.php
+28
-0
tests/Solarium/Client/Adapter/HttpTest.php
tests/Solarium/Client/Adapter/HttpTest.php
+1
-4
tests/Solarium/Client/RequestTest.php
tests/Solarium/Client/RequestTest.php
+16
-0
No files found.
library/Solarium/Client/Adapter/Curl.php
View file @
8c94e08c
...
...
@@ -138,8 +138,9 @@ class Solarium_Client_Adapter_Curl extends Solarium_Client_Adapter
$options
[
'headers'
][
'Content-Type'
]
=
'text/xml; charset=utf-8'
;
}
if
(
isset
(
$this
->
_options
[
'username'
])
&&
isset
(
$this
->
_options
[
'password'
]))
{
curl_setopt
(
$handler
,
CURLOPT_USERPWD
,
$this
->
_options
[
'username'
]
.
':'
.
$this
->
_options
[
'password'
]
);
$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/Client/Adapter/Http.php
View file @
8c94e08c
...
...
@@ -111,8 +111,9 @@ class Solarium_Client_Adapter_Http extends Solarium_Client_Adapter
}
}
if
(
isset
(
$this
->
_options
[
'username'
])
&&
isset
(
$this
->
_options
[
'password'
]))
{
$request
->
addHeader
(
'Authorization: Basic '
.
base64_encode
(
$this
->
_options
[
'username'
]
.
':'
.
$this
->
_options
[
'password'
]
));
$authData
=
$request
->
getAuthentication
();
if
(
!
empty
(
$authData
[
'username'
])
&&
!
empty
(
$authData
[
'password'
]))
{
$request
->
addHeader
(
'Authorization: Basic '
.
base64_encode
(
$authData
[
'username'
]
.
':'
.
$authData
[
'password'
]
));
}
$headers
=
$request
->
getHeaders
();
...
...
library/Solarium/Client/Adapter/PeclHttp.php
View file @
8c94e08c
...
...
@@ -137,6 +137,11 @@ class Solarium_Client_Adapter_PeclHttp extends Solarium_Client_Adapter
}
}
$authData
=
$request
->
getAuthentication
();
if
(
!
empty
(
$authData
[
'username'
])
&&
!
empty
(
$authData
[
'password'
]))
{
$headers
[
'Authorization'
]
=
'Basic '
.
base64_encode
(
$authData
[
'username'
]
.
':'
.
$authData
[
'password'
]
);
}
switch
(
$request
->
getMethod
())
{
case
Solarium_Client_Request
::
METHOD_GET
:
$method
=
HTTP_METH_GET
;
...
...
library/Solarium/Client/Request.php
View file @
8c94e08c
...
...
@@ -406,4 +406,32 @@ class Solarium_Client_Request extends Solarium_Configurable
return
$output
;
}
/**
* 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'
),
);
}
}
\ No newline at end of file
tests/Solarium/Client/Adapter/HttpTest.php
View file @
8c94e08c
...
...
@@ -157,11 +157,8 @@ class Solarium_Client_Adapter_HttpTest extends PHPUnit_Framework_TestCase
$request
=
new
Solarium_Client_Request
();
$request
->
setMethod
(
$method
);
$request
->
setAuthentication
(
'someone'
,
'S0M3p455'
);
$this
->
_adapter
->
setOptions
(
array
(
'username'
=>
'someone'
,
'password'
=>
'S0M3p455'
));
$this
->
_adapter
->
setTimeout
(
$timeout
);
$context
=
$this
->
_adapter
->
createContext
(
$request
);
...
...
tests/Solarium/Client/RequestTest.php
View file @
8c94e08c
...
...
@@ -472,4 +472,20 @@ raw data: post data
);
}
public
function
testGetAndSetAuthentication
()
{
$user
=
'someone'
;
$pass
=
'S0M3p455'
;
$this
->
_request
->
setAuthentication
(
$user
,
$pass
);
$this
->
assertEquals
(
array
(
'username'
=>
$user
,
'password'
=>
$pass
,
),
$this
->
_request
->
getAuthentication
()
);
}
}
\ No newline at end of file
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