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
ea0232ea
Commit
ea0232ea
authored
Jan 22, 2013
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/endpoint-auth' into develop
parents
82e5539c
97ec474d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
118 additions
and
9 deletions
+118
-9
library/Solarium/Core/Client/Adapter/Curl.php
library/Solarium/Core/Client/Adapter/Curl.php
+4
-1
library/Solarium/Core/Client/Adapter/Http.php
library/Solarium/Core/Client/Adapter/Http.php
+4
-1
library/Solarium/Core/Client/Adapter/PeclHttp.php
library/Solarium/Core/Client/Adapter/PeclHttp.php
+4
-1
library/Solarium/Core/Client/Endpoint.php
library/Solarium/Core/Client/Endpoint.php
+52
-0
library/Solarium/Core/Client/Request.php
library/Solarium/Core/Client/Request.php
+1
-1
tests/Solarium/Tests/Core/Client/EndpointTest.php
tests/Solarium/Tests/Core/Client/EndpointTest.php
+53
-5
No files found.
library/Solarium/Core/Client/Adapter/Curl.php
View file @
ea0232ea
...
...
@@ -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/Adapter/Http.php
View file @
ea0232ea
...
...
@@ -127,7 +127,10 @@ class Http extends Configurable implements AdapterInterface
}
}
$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'
]))
{
$request
->
addHeader
(
'Authorization: Basic '
.
base64_encode
(
$authData
[
'username'
]
.
':'
.
$authData
[
'password'
]
));
}
...
...
library/Solarium/Core/Client/Adapter/PeclHttp.php
View file @
ea0232ea
...
...
@@ -150,7 +150,10 @@ class PeclHttp extends Configurable implements AdapterInterface
}
}
$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'
]))
{
$headers
[
'Authorization'
]
=
'Basic '
.
base64_encode
(
$authData
[
'username'
]
.
':'
.
$authData
[
'password'
]
);
}
...
...
library/Solarium/Core/Client/Endpoint.php
View file @
ea0232ea
...
...
@@ -228,4 +228,56 @@ 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 basic auth settings
*
* @return array
*/
public
function
getAuthentication
()
{
return
array
(
'username'
=>
$this
->
getOption
(
'username'
),
'password'
=>
$this
->
getOption
(
'password'
),
);
}
/**
* Magic method enables a object to be transformed to a string
*
* Get a summary showing significant variables in the object
* note: uri resource is decoded for readability
*
* @return string
*/
public
function
__toString
()
{
$output
=
__CLASS__
.
'::__toString'
.
"
\n
"
.
'base uri: '
.
$this
->
getBaseUri
()
.
"
\n
"
.
'host: '
.
$this
->
getHost
()
.
"
\n
"
.
'port: '
.
$this
->
getPort
()
.
"
\n
"
.
'path: '
.
$this
->
getPath
()
.
"
\n
"
.
'core: '
.
$this
->
getCore
()
.
"
\n
"
.
'timeout: '
.
$this
->
getTimeout
()
.
"
\n
"
.
'authentication: '
.
print_r
(
$this
->
getAuthentication
(),
1
);
return
$output
;
}
}
library/Solarium/Core/Client/Request.php
View file @
ea0232ea
...
...
@@ -473,7 +473,7 @@ class Request extends Configurable
}
/**
* Get HTTP basi
s
auth settings
* Get HTTP basi
c
auth settings
*
* @return array
*/
...
...
tests/Solarium/Tests/Core/Client/EndpointTest.php
View file @
ea0232ea
...
...
@@ -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,50 @@ 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
()
);
}
public
function
testToString
()
{
$options
=
array
(
'host'
=>
'192.168.0.1'
,
'port'
=>
123
,
'path'
=>
'/mysolr/'
,
'core'
=>
'mycore'
,
'timeout'
=>
3
,
'username'
=>
'x'
,
'password'
=>
'y'
);
$this
->
endpoint
->
setOptions
(
$options
);
$this
->
assertEquals
(
'Solarium\Core\Client\Endpoint::__toString
base uri: http://192.168.0.1:123/mysolr/mycore/
host: 192.168.0.1
port: 123
path: /mysolr
core: mycore
timeout: 3
authentication: Array
(
[username] => x
[password] => y
)
'
,
(
string
)
$this
->
endpoint
);
}
}
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