From user-return-10338-apmail-couchdb-user-archive=couchdb.apache.org@couchdb.apache.org Sat May 01 22:49:55 2010 Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 19046 invoked from network); 1 May 2010 22:49:55 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 1 May 2010 22:49:55 -0000 Received: (qmail 7796 invoked by uid 500); 1 May 2010 22:49:54 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 7728 invoked by uid 500); 1 May 2010 22:49:54 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 7720 invoked by uid 99); 1 May 2010 22:49:54 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 May 2010 22:49:54 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of bharat.kjsce@gmail.com designates 209.85.221.191 as permitted sender) Received: from [209.85.221.191] (HELO mail-qy0-f191.google.com) (209.85.221.191) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 May 2010 22:49:46 +0000 Received: by qyk29 with SMTP id 29so1997325qyk.14 for ; Sat, 01 May 2010 15:49:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type; bh=J6Gg0U6v7lKXsUEjpBDtS8DmkWRqNbws61QGqab2ZLM=; b=HPxa6tRWMtyYNowsEC9lzJj0mB6o0IN7e8StKPSKcIkf+ImlXL3OPWhmGl+uO9l5/E S2RyJDmXm3nu95bZcayu5mmZwXxopoXQcdcqaD9PjZNSzDGULuk14gYz4BRTJ9ZykfuA RZcexv0iX1LYQbw8RQpBUr6y7AqVTl49asP00= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=gkOOrC6uK3YWUQn8Z6sfJk4FUfJZ+zT6/RAxrHk5kc/6T/Bi0i0xRsRZ4a0j0V8jmJ eZQhYw8GRqgAEldTuKsjPeUMQouBAQFhJ8Z09SmHtR58P7P9sDgIlh0qOswMYnUM4GFW kzP2FFiAwYxfL0CqUdl0WEvSoZxji2OFWL8ho= MIME-Version: 1.0 Received: by 10.229.227.10 with SMTP id iy10mr1028391qcb.55.1272754165632; Sat, 01 May 2010 15:49:25 -0700 (PDT) Received: by 10.229.229.66 with HTTP; Sat, 1 May 2010 15:49:25 -0700 (PDT) In-Reply-To: <93C1C60B-DCF8-4534-8A70-C0D88F8E35A4@apache.org> References: <20100428200008.GC28028@translab.its.uci.edu> <93C1C60B-DCF8-4534-8A70-C0D88F8E35A4@apache.org> Date: Sat, 1 May 2010 15:49:25 -0700 Message-ID: Subject: Re: jcouchdb anyone? From: Bharat To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=00163631023dedd10a0485902be7 X-Virus-Checked: Checked by ClamAV on apache.org --00163631023dedd10a0485902be7 Content-Type: text/plain; charset=ISO-8859-1 Hi Adam, yes if you specify username and password in the source and target, it works fine. replicate(http://username:pass@localhost :5984/sourceDB, http://username:pass@localhost:5984/targetDB, false); My question was, why it doesnt work by just setting "setCredentials" method like I am doing for all get, put etc methods? Shouldnt it take care of auth so we dont have to pass usr/pass again in the post body? Because if I use above approach, I have to specify URls along with source and target DB which causes replication to slow down(which I can get around by using pull replication though). Thanks! On Sat, May 1, 2010 at 6:21 AM, Adam Kocoloski wrote: > Hi Bharat, if your source or target DB requires authorization and is > specified using a URL, you need to include the credentials in the POST body. > Is that the problem? > > Adam > > On Apr 30, 2010, at 7:35 PM, Bharat wrote: > > > back to this. > > > > Looks like authentication works for mostly all other requests but not > > replication which is using a HttpPost object. Anyone seeing this > behavior? > > Again pretty striaght fwd code, using the same auth (after killing my > login > > ServerImpl instance): > > > > ServerImpl service = new ServerImpl(sourceUrl); > > Credentials credentials = new > > UsernamePasswordCredentials("username", "password"); > > AuthScope authScope = new AuthScope(sourceUrl, port, > "_admin"); > > service.setCredentials(authScope, credentials); > > > > ReplicationInfo repInfo = service.replicate(sourceDbName, > > targetDbName, false); > > ---------------------- > > > > I see this in the logs: > > > > [debug] [<0.2228.0>] 'POST' /_replicate {1,1} > > Headers: [{'Connection',"Keep-Alive"}, > > {'Content-Encoding',"UTF-8"}, > > {'Content-Length',"44"}, > > {'Content-Type',"application/json"}, > > {'Host',"localhost:5984"}] > > [debug] [<0.2228.0>] OAuth Params: [] > > [debug] [<0.2246.0>] Not a reader: UserCtx {user_ctx,null,[],undefined} > vs > > Names [<<"username">>] Roles [<<"_admin">>] > > [error] [<0.2246.0>] {error_report,<0.30.0>, > > {<0.2246.0>,crash_report, > > [[{initial_call,{couch_rep,init,['Argument__1']}}, > > {pid,<0.2246.0>}, > > {registered_name,[]}, > > {error_info, > > {exit, > > {bad_return_value, > > {unauthorized, > > <<"You are not authorized to access this db.">>}}, > > [{gen_server,init_it,6},{proc_lib,init_p_do_apply,3}]}}, > > {ancestors, > > > > [couch_rep_sup,couch_primary_services,couch_server_sup,<0.31.0>]}, > > {messages,[]}, > > {links,[<0.80.0>]}, > > {dictionary,[]}, > > {trap_exit,true}, > > {status,running}, > > {heap_size,987}, > > {stack_size,24}, > > {reductions,326}], > > []]}} > > > > =CRASH REPORT==== 30-Apr-2010::16:28:14 === > > crasher: > > initial call: couch_rep:init/1 > > pid: <0.2246.0> > > registered_name: [] > > exception exit: {bad_return_value, > > {unauthorized, > > <<"You are not authorized to access this > > db.">>}} > > in function gen_server:init_it/6 > > ancestors: [couch_rep_sup,couch_primary_services,couch_server_sup, > > <0.31.0>] > > messages: [] > > links: [<0.80.0>] > > dictionary: [] > > trap_exit: true > > status: running > > heap_size: 987 > > stack_size: 24 > > reductions: 326 > > neighbours: > > [error] [<0.2228.0>] Uncaught error in HTTP request: {error, > > {case_clause, > > {error, > > {bad_return_value, > > {unauthorized, > > <<"You are not authorized to access > > this db.">>}}}}} > > [info] [<0.2228.0>] Stacktrace: [{couch_rep,start_replication_server,1}, > > {couch_rep,replicate,2}, > > {couch_httpd_misc_handlers,handle_replicate_req,1}, > > {couch_httpd,handle_request_int,5}, > > {mochiweb_http,headers,5}, > > {proc_lib,init_p_do_apply,3}] > > [info] [<0.2228.0>] 127.0.0.1 - - 'POST' /_replicate 500 > > [debug] [<0.2228.0>] httpd 500 error response: > > {"error":"case_clause","reason":"{error,\n {bad_return_value,\n > > {unauthorized,<<\"You are not authorized to access this db.\">>}}}"} > > ------------------------------------ > > > > On Wed, Apr 28, 2010 at 1:09 PM, Bharat wrote: > > > >> Perfect James. > >> Thats what I was missing. Uncommenting WWW-authenticate and passing that > as > >> a realm, works. > >> > >> Thanks guys. > >> > >> On Wed, Apr 28, 2010 at 1:00 PM, James Marca < > jmarca@translab.its.uci.edu>wrote: > >> > >>> Perhaps try passing the "authority" key when setting the AuthScope? > >>> > >>> Example: > >>> > >>> my /etc/couchdb/local.ini has: > >>> > >>> ... > >>> [httpd] > >>> ; Uncomment next line to trigger basic-auth popup on unauthorized > >>> requests. > >>> WWW-Authenticate = Basic realm="administrator" > >>> ... > >>> > >>> > >>> My code in a test case looks as follows: > >>> > >>> > >>> ... > >>> private static final String TESTDB_AUTHORITY = "administrator"; > >>> ... > >>> > >>> @Before > >>> public void setUp() throws Exception { > >>> // load couchdb properties > >>> > >>> > props.load(getClass().getClassLoader().getResource(DB_PROPERTIES).openStream()); > >>> > >>> ... > >>> > >>> dbname =props.getProperty("couchdb.db.dbname",TESTDB_NAME); > >>> user =props.getProperty("couchdb.db.user"); > >>> pass =props.getProperty("couchdb.db.password"); > >>> authority > >>> =props.getProperty("couchdb.db.authority",TESTDB_AUTHORITY); > >>> > >>> ... > >>> } > >>> > >>> > >>> > >>> then later, I create dbs as follows...note the authority in AuthScope > new > >>> call > >>> > >>> public static Database createDatabaseForTest() > >>> { > >>> // Load couchdb properties > >>> Server server = new ServerImpl(host,port); > >>> if(user != null && pass !=null) { > >>> AuthScope as = new AuthScope(host, port, authority); > >>> Credentials c = new UsernamePasswordCredentials(user, pass); > >>> server.setCredentials(as,c); > >>> } > >>> > >>> List databases = server.listDatabases(); > >>> > >>> log.debug("databases = " + databases); > >>> > >>> ... > >>> > >>> } > >>> > >>> Hope that helps, > >>> James > >>> > >>> > >>> > >>> On Wed, Apr 28, 2010 at 10:33:31AM -0700, Bharat wrote: > >>>> I am trying to use jcouchdb api for authenticating against my couchdb > >>>> instance(0.11). I have set the admin usr/pass in futon and in addition > >>>> specified ADMIN and READER on the DB I am trying to access so only > >>> people > >>>> with correct credentials can access/view the DB. > >>>> > >>>> My code is pretty simple and directly using ServerImpl and its > >>>> setCredentials and get method: > >>>> > >>>> ------------------------- > >>>> ServerImpl service = new ServerImpl("localhost"); > >>>> Credentials credentials = > >>>> new UsernamePasswordCredentials(, ); > >>>> AuthScope authScope = new AuthScope("http://localhost", 5984); > >>>> > >>>> service.setCredentials(authScope, credentials); > >>>> > >>>> Response res = service.get(/); > >>>> ----------------------------- > >>>> > >>>> But everytime I do this, I keep getting http 401 in my response. Is > >>> there > >>>> something I am missing or not setting correctly? > >>>> > >>>> I know its not exactly a couchdb question but there is very little to > no > >>>> documentation available so thought I ll try here. > >>>> > >>>> Thanks! > >>> > >>> -- > >>> This message has been scanned for viruses and > >>> dangerous content by MailScanner, and is > >>> believed to be clean. > >>> > >>> > >> > > --00163631023dedd10a0485902be7--