lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simer P <sime...@gmail.com>
Subject DIGEST authentication with HttpSolrServer not working ... PLEASE HELPPPP !!!
Date Wed, 24 Jul 2013 10:17:36 GMT
Hey Guys,

I was wondering if anyone has successfully been able to connect to SOLR
4.3.1 using DIGEST authentication with HttpSolrServer ?

*How I generated the password*
./digest.sh -a md5 admin:secure:password
admin:secure:password:e430caca84c337d4b820c44c1ebc943a

*I can successfully log in via browser:*
*[image: Inline image 1]
*
*
*
*Tomcat Logs after :*
FINE: Attempting to authenticate user "admin" with realm
"org.apache.catalina.realm.MemoryRealm/1.0"
Jul 24, 2013 7:32:49 PM org.apache.catalina.realm.RealmBase authenticate
FINE: Digest : d085a7ed1747cc5e44748e402f8bfea3 Username:admin
ClientSigest:d085a7ed1747cc5e44748e402f8bfea3
nonce:1374658345333:90ec031d23e72defdeef154de6819b12 nc:0000004f
cnonce:52545941c1d2299c qop:auth
realm:securemd5a2:ea8719b47592cd3b04329611320a94d9 Server
digest:d085a7ed1747cc5e44748e402f8bfea3
Jul 24, 2013 7:32:49 PM org.apache.catalina.realm.CombinedRealm authenticate
FINE: Authenticated user "admin" with realm
"org.apache.catalina.realm.MemoryRealm/1.0"
Jul 24, 2013 7:32:49 PM org.apache.catalina.realm.RealmBase
hasResourcePermission
FINE:   Checking roles GenericPrincipal[admin(admin,manager-script,)]
Jul 24, 2013 7:32:49 PM org.apache.catalina.realm.RealmBase hasRole
FINE: Username admin has role admin
Jul 24, 2013 7:32:49 PM org.apache.catalina.realm.RealmBase
hasResourcePermission
FINE: Role found:  admin

I can also successfully log in connecting using HttpClient directly doing a
HttpGet

HttpResponse response = *null*;
HttpHost targetHost = *new* HttpHost("localhost", 8080, "http");
DefaultHttpClient httpClient = *new* DefaultHttpClient();
AuthScope authScope = *new*
 AuthScope(targetHost.getHostName(), targetHost.getPort(), "secure");
UsernamePasswordCredentials credentials = *new* UsernamePasswordCredentials(
"admin", "password");
httpClient.getCredentialsProvider().setCredentials(authScope, credentials);
HttpGet httpget = *new* HttpGet("http://localhost:8080");
response = httpClient.execute(targetHost, httpget);
System.out.println(response); //Which prints HTTP/1.1 200 OK [Server:
Apache-Coyote/1.1, Cache-Control: private, Expires: Thu, 01 Jan 1970
10:00:00 EST, Content-Type: text/html;charset=UTF-8, Transfer-Encoding:
chunked, Date: Wed, 24 Jul 2013 10:02:37 GMT]


Logs for the above connection:
FINE: Attempting to authenticate user "admin" with realm
"org.apache.catalina.realm.MemoryRealm/1.0"
Jul 24, 2013 7:35:52 PM org.apache.catalina.realm.RealmBase authenticate
FINE: Digest : 85e101cdfbb5585696b557fe55601077 Username:admin
ClientSigest:85e101cdfbb5585696b557fe55601077
nonce:1374658552710:00f1e255052b59840a73f6919d9ada78 nc:00000001
cnonce:37d15b4cfe5167b4 qop:auth
realm:securemd5a2:71998c64aea37ae77020c49c00f73fa8 Server
digest:85e101cdfbb5585696b557fe55601077
Jul 24, 2013 7:35:52 PM org.apache.catalina.realm.CombinedRealm authenticate
FINE: Authenticated user "admin" with realm
"org.apache.catalina.realm.MemoryRealm/1.0"
Jul 24, 2013 7:35:52 PM org.apache.catalina.realm.RealmBase
hasResourcePermission
FINE:   Checking roles GenericPrincipal[admin(admin,manager-script,)]
Jul 24, 2013 7:35:52 PM org.apache.catalina.realm.RealmBase hasRole
FINE: Username admin has role admin
Jul 24, 2013 7:35:52 PM org.apache.catalina.realm.RealmBase
hasResourcePermission
FINE: Role found:  admin

*It's just that when I request using HttpSolrServer I get unauthorized error
*
org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException:
Server at http://localhost:8080/p<http://localhost:8080/cmrsearchengine/primary>rimary
returned non ok status:401, message:Unauthorized
*
*
Here is how I'm connecting to SOLR using HttpSolrServer

HttpResponse response = *null*;
HttpHost targetHost = *new* HttpHost("localhost", 8080, "http");
DefaultHttpClient httpClient = *new* DefaultHttpClient();
httpClient.addRequestInterceptor(*new* PreemptiveAuthInterceptor(), 0);
AuthScope authScope = *new*
 AuthScope(targetHost.getHostName(), targetHost.getPort(), "secure");
UsernamePasswordCredentials credentials = *new* UsernamePasswordCredentials(
"admin", "password");
httpClient.getCredentialsProvider().setCredentials(authScope, credentials);

HttpSolrServer primary = *new* HttpSolrServer("http://localhost:8080" +
"\" + PRIMARY, httpClient);
primary.add(*new* SolrInputDocument(), 20);


And my Interceptor being

*public* *class* PreemptiveAuthInterceptor *implements*
 HttpRequestInterceptor {

    *public* *void* process(HttpRequest hr, HttpContext context) *throws*
 HttpException, IOException {
        AuthState authState = (AuthState)
context.getAttribute(ClientContext.TARGET_AUTH_STATE);
        *if* (authState.getAuthScheme() == *null*) {
            CredentialsProvider credsProvider = (CredentialsProvider)
context.getAttribute(ClientContext.CREDS_PROVIDER);
            HttpHost targetHost = (HttpHost)
context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
            AuthScope authScope = *new*
 AuthScope(targetHost.getHostName(), targetHost.getPort(), "secure");
            credsProvider.setCredentials(authScope, *new*
 UsernamePasswordCredentials("admin", "password"));

            DigestScheme digestAuth = *new*
 DigestScheme(ChallengeState.TARGET);
            digestAuth.overrideParamter("algorithm", "MD5");
            digestAuth.overrideParamter("realm", "secure");
            digestAuth.overrideParamter("nonce", Long.toString(*new*
 Random().nextLong(), 36));
            digestAuth.overrideParamter("qop", "auth");//   not effective
            digestAuth.overrideParamter("nc", "\" + 1);//nt effective
            digestAuth.overrideParamter("cnonce"
, DigestScheme.createCnonce());
            digestAuth.overrideParamter("opaque", "ba897c2f0f3de9c6f52d");
            digestAuth.overrideParamter("username", "admin");
            authState.update(digestAuth,
credsProvider.getCredentials(authScope));
        }
    }
}

Has any successfully been able to use HttpSolrServer with DIGEST
authentication ? Basic Authentication works but not DIGEST.

I've been struggling with this for two days. Please help.

If I don't use the interceptor I get NonRepeatableRequestException error.

Caused by: org.apache.http.client.ClientProtocolException
at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:909)
at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)
at
org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:352)
... 43 more
Caused by: org.apache.http.client.NonRepeatableRequestException: Cannot
retry request with a non-repeatable request entity.
at
org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:695)
at
org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:522)
at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
... 46 more
Java Result: 1

*web.xml*
[image: Inline image 1]

Thanks in advance

Mime
  • Unnamed multipart/related (inline, None, 0 bytes)
View raw message