简体   繁体   English

使用HTTP未经授权的couchdb4j api连接到couchdb:“您不是服务器管理员。”

[英]Connect to couchdb using couchdb4j api, HTTP unauthorized: “You are not a server admin.”

I'm using couchdb4j to establish a connection with couchDB, just like the user in the topic: Java couchdb4j DB connection 我正在使用沙发床4j与沙发床建立连接,就像该主题中的用户: Java沙发床4j DB连接一样

So locally I am able to connect to couchdb by just using: 因此,在本地我可以使用以下方法连接到沙发床:

Session LocalSession= new Session("localhost", 5984);

But when I am trying to use my company's couchdb version, it does not function.. and I get this error: ( NB I have the admin role) 但是,当我尝试使用公司的ouchdb版本时,它无法运行..并且出现此错误:( 注意,我具有管理员角色)

 avr. 02, 2015 5:31:04 PM com.fourspaces.couchdb.Session createDatabase
Avertissement: Error creating database: mydatabase
Exception in thread "main" java.lang.NullPointerException
    at filecomparison.DbaseManag.saveFinalDocument(DbaseManag.java:359)
    at filecomparison.DbaseManag.saveEntryQueryLog(DbaseManag.java:247)
    at filecomparison.LoadFiles.loadVirtuosoLog(LoadFiles.java:207)
    at filecomparison.LoadFiles.loadingQueryLog(LoadFiles.java:772)
    at filecomparison.Main.main(Main.java:197)

In the "couchdb4j" library I observed that there were 4 diiferent versions of the Session constructor (but there was not a version which uses the parameter boolean usesAuth ): 在“ couchdb4j”库中,我观察到Session构造函数有4个不同的版本(但是没有使用参数boolean UsesAuth的版本):

public Session(String host, int port, boolean secure) 公共会话(字符串主机,整数端口,布尔安全)

public Session(String host, int port) 公共会话(字符串主机,整数端口)

public Session(String host, int port, String user, String pass, boolean secure) 公共会话(字符串主机,整数端口,字符串用户,字符串通过,布尔安全)

public Session(String host, int port, String user, String pass) 公共会话(字符串主机,整数端口,字符串用户,字符串通过)

Anyway, I tried to use them all but it didn't worked (even if the Session object was created) 无论如何,我尝试全部使用它们,但是没有用(即使创建了Session对象)

I tried also to see what was printed in the Server's log, while I was running my java code, by using the command: 我还尝试通过使用以下命令来查看运行Java代码时在服务器日志中打印的内容:

tail -f /var/log/couchdb/couch.log

And I realized that there was always the same error: 我意识到总是存在相同的错误:

[Tue, 07 Apr 2015 14:07:29 GMT] [debug] [<0.1738.0>] 'DELETE' /mydatabase {1,1} from "127.0.0.1"
Headers: [{'Host',"127.0.0.1:5984"},
          {'User-Agent',"Jakarta Commons-HttpClient/3.1"}]
[Tue, 07 Apr 2015 14:07:29 GMT] [debug] [<0.1738.0>] OAuth Params: []
[Tue, 07 Apr 2015 14:07:29 GMT] [debug] [<0.1738.0>] Minor error in HTTP request: {unauthorized,
                                                   <<"You are not a server admin.">>}

After searching a while I saw some solutions of this authentication issue with use of curl commands , just like this topic open CouchDB session with admin server credential . 经过一会儿的搜索,我看到了使用curl命令解决此身份验证问题的一些方法,就像本主题使用管理服务器凭据打开CouchDB会话一样。 Eg 例如

curl -X DELETE http://username:password@localhost:5984/mydatabase

But has anyone an idea how to solve with my java code? 但是有谁知道如何用我的Java代码解决问题? Should I change the library or it is an issue of couchdb configuration? 我应该更改该库还是它是沙发床配置的问题?

Thanks in advance for any tip! 在此先感谢您的提示!

Regards 问候

Is it an issue of the CouchDB configuration? 这是CouchDB配置的问题吗?

Maybe not 也许不吧

As you have shown with your log line quote - no authentication informations are sent by your java code. 如您的日志行引号所示-Java代码不发送任何身份验证信息。 You can compare these log lines with the log lines that occurring in result of your curl request. 您可以将这些日志行与由于curl请求而出现的日志行进行比较。 There should be eg an Auth or Cookie header present. 应该存在例如Auth或Cookie标头。

Maybe yes 也许是吧

You say that the identical code succeeds/fails depending on the CouchDB target? 您说相同的代码成功/失败取决于CouchDB目标吗? Then it may it worth to compare the authentication handler configuration of both CouchDB installations. 然后可能需要比较两个CouchDB安装的身份验证处理程序配置。 Maybe the authentication method your library is using is not handled in the remote CouchDB. 也许您的库使用的身份验证方法未在远程CouchDB中处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM