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 <[email protected]>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<String> 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(<usr>, <pass>); > > AuthScope authScope = new AuthScope("http://localhost", 5984); > > > > service.setCredentials(authScope, credentials); > > > > Response res = service.get(/<database>); > > ----------------------------- > > > > 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. > >
