atom feed8 messages in org.codehaus.groovy.user[groovy-user] Problem with authentica...
FromSent OnAttachments
Richard OsbaldestonJun 15, 2010 2:27 am 
Thom NicholsJun 15, 2010 2:46 pm 
Richard OsbaldestonJun 15, 2010 3:39 pm 
Samuel DoyleJun 15, 2010 8:35 pm 
Guillaume LaforgeJun 15, 2010 10:40 pm 
Samuel DoyleJun 15, 2010 11:15 pm 
Thom NicholsJun 17, 2010 5:00 am 
Richard OsbaldestonJun 17, 2010 6:27 am 
Subject:[groovy-user] Problem with authentication and CouchDB
From:Richard Osbaldeston (osb@gmail.com)
Date:Jun 15, 2010 2:27:01 am
List:org.codehaus.groovy.user

Hi all, I've been trying to write some test cases with Groovy for out REST interfaces. To setup our test fixture I needed to clearout the CouchDB databases and wrote a simple script to do this, but for some reason I keep getting Unauthorized messages back from CouchDB. The CouchDB instance has the admin user setup, but that's the only deviation from the default configuration i.e. not in 'admin party' mode. Checked the username/password several times. Also tried adding username:password@host to the url - that didn't appear to work either. Annoyingly coping the user:pass@url request from the groovy log and adding 'curl -X ..' all works fine from the cmd line. So it appears there's something going wrong with the Groovy libs.

<pre> @Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.0') import groovyx.net.http.RESTClient import static groovyx.net.http.ContentType.*

RESTClient couchDBRestApi = new RESTClient('http://localhost:5984/') couchDBRestApi.auth.basic 'scott', 'tiger' // def couchDBRestApi = new RESTClient('http://scott:tiger@localhost:5984/')

['vuvuzelas','angrybees'].each { name -> def resp = couchDBRestApi.delete(path:name) assert resp.status == 200 } </pre>

Looking at the logs I'm worried about a couple of entries in particular the empty method list at end of 'WARN DefaultRequestDirector - Authentication error: Unable to respond to any of these challenges: {}' ? and ' DEBUG RESTClient - Response code: 401; found handler: org.codehaus.groovy.runtime.MethodClosure@e2e4d7' ?

Only way I can get this to work is to put CouchDB into 'admin party' where every user is admin - effectively ignoring any auth, which isn't acceptable. To reproduce just needs groovy 1.7.2 and couchdb 0.11 and set the admin user via local.ini or the futon ui.

full log reads: <pre> 2010-06-14 15:19:27,520 DEBUG RESTClient - DELETE http://localhost:5984/vuvuzelas 2010-06-14 15:19:27,522 DEBUG wire -> "DELETE /vuvuzelas HTTP/1.1[EOL]" 2010-06-14 15:19:27,523 DEBUG wire -> "Accept: */*[EOL]" 2010-06-14 15:19:27,523 DEBUG wire -> "Host: localhost:5984[EOL]" 2010-06-14 15:19:27,524 DEBUG wire -> "Connection: Keep-Alive[EOL]" 2010-06-14 15:19:27,525 DEBUG wire -> "User-Agent: Apache-HttpClient/4.0 (java 1.5)[EOL]" 2010-06-14 15:19:27,525 DEBUG wire -> "Accept-Encoding: gzip,deflate[EOL]" 2010-06-14 15:19:27,526 DEBUG wire -> "[EOL]" 2010-06-14 15:19:27,526 DEBUG headers -> DELETE /vuvuzelas HTTP/1.1 2010-06-14 15:19:27,527 DEBUG headers -> Accept: */* 2010-06-14 15:19:27,527 DEBUG headers -> Host: localhost:5984 2010-06-14 15:19:27,528 DEBUG headers -> Connection: Keep-Alive 2010-06-14 15:19:27,528 DEBUG headers -> User-Agent: Apache-HttpClient/4.0 (java 1.5) 2010-06-14 15:19:27,529 DEBUG headers -> Accept-Encoding: gzip,deflate 2010-06-14 15:19:27,543 DEBUG wire <- "HTTP/1.1 401 Unauthorized[EOL]" 2010-06-14 15:19:27,543 DEBUG wire <- "Server: CouchDB/0.11.0 (Erlang OTP/R13B)[EOL]" 2010-06-14 15:19:27,544 DEBUG wire <- "Date: Mon, 14 Jun 2010 14:19:27 GMT[EOL]" 2010-06-14 15:19:27,544 DEBUG wire <- "Content-Type: text/plain;charset=utf-8[EOL]" 2010-06-14 15:19:27,544 DEBUG wire <- "Content-Length: 64[EOL]" 2010-06-14 15:19:27,545 DEBUG wire <- "Cache-Control: must-revalidate[EOL]" 2010-06-14 15:19:27,545 DEBUG wire <- "[EOL]" 2010-06-14 15:19:27,545 DEBUG headers <- HTTP/1.1 401 Unauthorized 2010-06-14 15:19:27,545 DEBUG headers <- Server: CouchDB/0.11.0 (Erlang OTP/R13B) 2010-06-14 15:19:27,546 DEBUG headers <- Date: Mon, 14 Jun 2010 14:19:27 GMT 2010-06-14 15:19:27,546 DEBUG headers <- Content-Type: text/plain;charset=utf-8 2010-06-14 15:19:27,546 DEBUG headers <- Content-Length: 64 2010-06-14 15:19:27,547 DEBUG headers <- Cache-Control: must-revalidate 2010-06-14 15:19:27,548 WARN DefaultRequestDirector - Authentication error: Unable to respond to any of these challenges: {} 2010-06-14 15:19:27,548 DEBUG RESTClient - Response code: 401; found handler: org.codehaus.groovy.runtime.MethodClosure@e2e4d7 2010-06-14 15:19:27,549 DEBUG RESTClient - Parsing response as: text/plain 2010-06-14 15:19:27,549 DEBUG RESTClient - Parsed data to instance of: class java.io.InputStreamReader 2010-06-14 15:19:27,550 DEBUG wire <- "{"error":"unauthorized","reason":"You are not a server admin."}[\n]" </pre>

Any ideas? doing something stupid?

PS No proxies/firewalls/NTLM or anything fancy - all localhost albeit on Windows 7 (development env).

- Richard