2012-07-22 57 views
14

我擁有基本授權的我的maven存儲庫的nginx。具有基本身份驗證的sbt依賴解析器

我build.sbt有:

credentials += Credentials("maven repository", "rep.com", "sbt", "password") 

resolvers ++= Seq(
    "maven repository" at "http://rep.com:8080/" 
) 

但是,SBT無法找到模塊,因爲SBT不使用基本授權。

我nginx的日誌是這樣的:

012/07/22 20:02:21 [error] 3338#0: *14 no user/password was provided for basic authentication, client: 8.32.39.29, server: rep.com, request: "HEAD /some/cool_2.9.1/0.1-SNAPSHOT/cool_2.9.1-0.1-SNAPSHOT.pom HTTP/1.1", host: "rep.com:8080" 

我不想通過nginx的發佈假象。基本身份驗證只需要限制訪問工件。

我如何限制訪問和使用sbt中的存儲庫?

+2

我發現[這個討論](http://comments.gmane.org/gmane.comp.lang.scala.simple-build-tool/4055)可以幫助你,但IMO,它不包含足夠的細節來重現解決方案,因此如果有人會深入研究並提供詳細的答案,那將是非常好的。 – 2012-09-06 19:39:52

+0

你能詳細說明缺少的細節嗎? Harald在那篇文章中的回覆對我來說似乎很簡單:確保領域匹配。來自sebastien的回覆建議使用系統propery'javax.net.debug = all'來找出認證領域。 – 2012-09-12 19:45:56

回答

18

怎麼樣添加以下到〜/ .ivy2/.credentials:

realm=maven repository 
host=rep.com:8080 
user=username 
password=password 

然後用Credentials(Path.userHome/".ivy2"/".credentials")

,你需要確保你的境界配置是否正確:curl http://rep.com:8080 -vv 2>&1 | egrep "realm|host"(我可能是錯的,但「主機」可以對主機進行報頭相匹配,我.e。rep.com:8080,而不僅僅是rep.com)。

心連心

+0

你不需要放在.credentials文件。我主持人不排隊,這是問題。 – jsuereth 2015-01-07 12:38:21

+1

此方法現在已添加到SBT文檔中。 http://www.scala-sbt.org/0.13/docs/Publishing。html – Brett 2015-01-14 08:36:32

+0

grep表達式沒有使用預期的用例: curl http://rep.com:8080 -vv 2>&1 | egrep -i「realm | host」 - >結果預計有兩行: - >主機:nexus.eu - > WWW-Authenticate:BASIC realm =「Sonatype Nexus Repository Manager」 – Sylvain 2017-06-19 10:04:25

-1

不知道它的工作原理,但只是嘗試在URL中添加的基本身份驗證:

resolvers ++= Seq(
    "maven repository" at "http://username:[email protected]:8080/" 
) 
+0

我嘗試過,我得到了java.net.MalformedURLException – 2012-07-22 20:27:09

+0

對不起,這是值得的嘗試... – 2012-07-22 20:30:49

1

我與使用基本身份驗證的SVN倉庫同樣的問題。 這篇文章和上面提到的那篇文章給了我下面我總結的答案。

正如上面提到的所有有關獲取的境界正確的:

在build.sbt設置我的解析如下:

resolvers += { 
Credentials.add("<realm>", "<svnhost?", "<username>", "<password>") 
Resolver.url("name", url("http://<svnhost>/<path>/"))(Resolver.ivyStylePatterns) 
} 

要查找的境界值,它是對證書的第一個參數。新增,我也

curl http://<svn host> -v 

,並用於在WWW-Authenticate頭報道的基本境界值:

WWW-Authenticate: Basic realm="<realm>" 

希望這會有所幫助。