在文章《 Subversion 詳細說明 》中,我們曾經建立了一個版本控制倉庫,現在打開這個版本控制倉庫,讓我們來看看這個目錄結構,
我們會在目錄結構中找到一個叫做conf的文件夾,打開這個文件夾,你會看到三個文件,分別叫做authz,passwd,svnserve.conf。
下面我們就來介紹一下這三個文件的作用格式什么。
首先,我們介紹passwd這個文件。
用你習慣的文本編輯器打開這個文件,你會看到一些使用“#”注釋掉的說明,其中關鍵的就是在[users]下面,有
# harry = harryssecret
# sally = sallyssecret
樣的樣板代碼,意思就是有兩個用戶,其中一個的用戶名叫“harry”,密碼為“harryssecret”,而另一個用戶名為“sally”,密碼為“sallyssecret”。我們接下來為我們的測試下面添加一些用戶,這樣方便我們下面的說明。比如,我要添加三個用戶,一個叫做“nicholas”,密碼為“nicholas”,第二個用戶名為“friend”,密碼為“friend”,第三個為“stranger”,密碼為“strangers”。
代碼如下:
nicholas = nicholas
friend = friend
???????? stranger = stranger
這樣,我們就添加好了三個認證用戶。
### This file is an example password file for svnserve.
### Its format is similar to that of svnserve.conf. As shown in the
### example below it contains one section labelled [users].
### The name and password for each user follow, one account per line.
?
[users]
# harry = harryssecret
# sally = sallyssecret
nicholas = nicholas
friend = friend
stranger = stranger
|
?
??????
下面,我們來介紹authz這個文件,這個文件是控制
權限
的關鍵。
同樣打開這個文件,你會看到一些注釋掉的語句,
# [groups]
# [/foo/bar]
# [repository:/baz/fuz]
??????
下面,我們介紹一下用戶組的概念。所謂用戶組,顧名思義,就是一個成員組,一般情況下,在同一個成員組的人員享有同樣的權力,比如讀,寫權。
Subversion
為我們提供了一個很好的用戶組應用。
在之前,我們一共建立三個用戶,nicholas,friend和stranger,我們現在設想一下我們的組情況,假設我們希望nicholas和friend在開發組中,這兩個用戶具有讀和寫的權力,而用戶stranger在測試組中,只具備讀的權力。那么我們該如何來控制這個
權限
呢?看看下面的代碼:
我們先在[groups]標記下面,輸入組的名稱:
?????? dev_group = nicholas, friend
?????? test_group = stranger
到目前為止,我們已經為三個用戶分好了用戶組,其中nicholas和friend在dev_group中,而stranger則在test_group中。
下面,我們為兩個組來分配
權限
。
首先我們要為這兩個組所能訪問的工程做一個規定,正如在之前的文章《
Eclipse
中使用
Subversion
進行版本控制
》中,曾經向版本參考提交了一個名為“TestSVNProj”的項目,下面我就假設剛剛建立的兩個用戶組都需要最這個工程進行操作。
我們在authz文件中,寫下[TestSVNProj],這個是指定我們下面將對TestSVNProj項目進行定義。
我們使用如下代碼:
@dev_group = rw
@test_group = r
這就定義了,對TestSVNProj項目,dev_group用戶組可以進行讀,寫操作,而test_group用戶組則只具備讀的
權限
。
為了阻止其他用戶組對這個文件有讀的權力,我們可以再添加一句:
* =
這個語句就是指定其他的用戶組的權力為空,也就是沒有權力。
### This file is an example authorization file for svnserve.
### Its format is identical to that of mod_authz_svn authorization
### files.
### As shown below each section defines authorizations for the path and
### (optional) repository specified by the section name.
### The authorizations follow. An authorization line can refer to a
### single user, to a group of users defined in a special [groups]
### section, or to anyone using the '*' wildcard.?Each definition can
### grant read ('r') access, read-write ('rw') access, or no access
### ('').
?
[groups]
# harry_and_sally = harry,sally
?
dev_group = nicholas,friend
test_group = stranger
?
# [/foo/bar]
# harry = rw
# * =
?
# [repository:/baz/fuz]
# @harry_and_sally = rw
# * = r
?
[/TestSVNProj]
@dev_group = rw
@test_group = r
* =
|
?
最后,我們在來說說這個svnserve.conf文件,打開這個文件,我們就可以看出這個是
Subversion
權限
配置的主文件,類似于讀取相關信息的樞紐。
為了讓我們剛剛配置的兩個文件(passwd和authz)起作用,我們需要去掉password-db = passwd和authz-db = authz前面的注釋符“#”,讓
Subversion
知道要從上面兩個文件中讀取相關信息。
當然,你也可以指定其他的認證文件,寫法如下:
??????? password-db = ..\..\passwd
authz-db = ..\..\authz
以此類推。
??????
在實戰過程中,處于安全的考慮,我們往往要限制對匿名用戶的訪問
權限
,所以我們可以將anon-access = read前面的“#”去掉,并將read參數修改為none,表明禁止匿名用戶對版本控制庫的訪問。
### This file controls the configuration of the svnserve daemon, if you
### use it to allow access to this repository.?(If you only allow
### access through http: and/or file: URLs, then this file is
### irrelevant.)
?
### Visit http://
subversion
.tigris.org/ for more information.
?
[general]
### These options control access to the repository for unauthenticated
### and authenticated users.?Valid values are "write", "read",
### and "none".?The sample settings below are the defaults.
anon-access = none
# auth-access = write
### The password-db option controls the location of the password
### database file.?Unless you specify a path starting with a /,
### the file's location is relative to the conf directory.
### Uncomment the line below to use the default password file.
password-db = passwd
### The authz-db option controls the location of the authorization
### rules for path-based access control.?Unless you specify a path
### starting with a /, the file's location is relative to the conf
### directory.?If you don't specify an authz-db, no path-based access
### control is done.
### Uncomment the line below to use the default authorization file.
authz-db = authz
### This option specifies the authentication realm of the repository.
### If two repositories have the same authentication realm, they should
### have the same password database, and vice versa.?The default realm
### is repository's uuid.
# realm = My First Repository
|
?
??????
至此,你可以控制你的項目,對其進行訪問
權限
的控制了。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
