在文章《
Subversion詳細(xì)說明》中,我們?cè)?jīng)建立了一個(gè)版本控制倉(cāng)庫,現(xiàn)在打開這個(gè)版本控制倉(cāng)庫,讓我們來看看這個(gè)目錄結(jié)構(gòu),
我們會(huì)在目錄結(jié)構(gòu)中找到一個(gè)叫做conf的文件夾,打開這個(gè)文件夾,你會(huì)看到三個(gè)文件,分別叫做authz,passwd,svnserve.conf。
下面我們就來介紹一下這三個(gè)文件的作用格式什么。
首先,我們介紹passwd這個(gè)文件。
用你習(xí)慣的文本編輯器打開這個(gè)文件,你會(huì)看到一些使用“#”注釋掉的說明,其中關(guān)鍵的就是在[users]下面,有
# harry = harryssecret
# sally = sallyssecret
樣的樣板代碼,意思就是有兩個(gè)用戶,其中一個(gè)的用戶名叫“harry”,密碼為“harryssecret”,而另一個(gè)用戶名為“sally”,密碼為“sallyssecret”。我們接下來為我們的測(cè)試下面添加一些用戶,這樣方便我們下面的說明。比如,我要添加三個(gè)用戶,一個(gè)叫做“nicholas”,密碼為“nicholas”,第二個(gè)用戶名為“friend”,密碼為“friend”,第三個(gè)為“stranger”,密碼為“strangers”。
代碼如下:
nicholas = nicholas
friend = friend
stranger = stranger
這樣,我們就添加好了三個(gè)認(rèn)證用戶。
### 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這個(gè)文件,這個(gè)文件是控制權(quán)限的關(guān)鍵。
同樣打開這個(gè)文件,你會(huì)看到一些注釋掉的語句,
# [groups]
# [/foo/bar]
# [repository:/baz/fuz]
下面,我們介紹一下用戶組的概念。所謂用戶組,顧名思義,就是一個(gè)成員組,一般情況下,在同一個(gè)成員組的人員享有同樣的權(quán)力,比如讀,寫權(quán)。Subversion為我們提供了一個(gè)很好的用戶組應(yīng)用。
在之前,我們一共建立三個(gè)用戶,nicholas,friend和stranger,我們現(xiàn)在設(shè)想一下我們的組情況,假設(shè)我們希望nicholas和friend在開發(fā)組中,這兩個(gè)用戶具有讀和寫的權(quán)力,而用戶stranger在測(cè)試組中,只具備讀的權(quán)力。那么我們?cè)撊绾蝸砜刂七@個(gè)權(quán)限呢?看看下面的代碼:
我們先在[groups]標(biāo)記下面,輸入組的名稱:
dev_group = nicholas, friend
test_group = stranger
到目前為止,我們已經(jīng)為三個(gè)用戶分好了用戶組,其中nicholas和friend在dev_group中,而stranger則在test_group中。
下面,我們?yōu)閮蓚€(gè)組來分配權(quán)限。
首先我們要為這兩個(gè)組所能訪問的工程做一個(gè)規(guī)定,正如在之前的文章《Eclipse中使用Subversion進(jìn)行版本控制》中,曾經(jīng)向版本參考提交了一個(gè)名為“TestSVNProj”的項(xiàng)目,下面我就假設(shè)剛剛建立的兩個(gè)用戶組都需要最這個(gè)工程進(jìn)行操作。
我們?cè)赼uthz文件中,寫下[TestSVNProj],這個(gè)是指定我們下面將對(duì)TestSVNProj項(xiàng)目進(jìn)行定義。
我們使用如下代碼:
@dev_group = rw
@test_group = r
這就定義了,對(duì)TestSVNProj項(xiàng)目,dev_group用戶組可以進(jìn)行讀,寫操作,而test_group用戶組則只具備讀的權(quán)限。
為了阻止其他用戶組對(duì)這個(gè)文件有讀的權(quán)力,我們可以再添加一句:
* =
這個(gè)語句就是指定其他的用戶組的權(quán)力為空,也就是沒有權(quán)力。
### 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
* =
最后,我們?cè)趤碚f說這個(gè)svnserve.conf文件,打開這個(gè)文件,我們就可以看出這個(gè)是Subversion權(quán)限配置的主文件,類似于讀取相關(guān)信息的樞紐。
為了讓我們剛剛配置的兩個(gè)文件(passwd和authz)起作用,我們需要去掉password-db = passwd和authz-db = authz前面的注釋符“#”,讓Subversion知道要從上面兩個(gè)文件中讀取相關(guān)信息。
當(dāng)然,你也可以指定其他的認(rèn)證文件,寫法如下:
password-db = ..\..\passwd
authz-db = ..\..\authz
以此類推。
在實(shí)戰(zhàn)過程中,處于安全的考慮,我們往往要限制對(duì)匿名用戶的訪問權(quán)限,所以我們可以將anon-access = read前面的“#”去掉,并將read參數(shù)修改為none,表明禁止匿名用戶對(duì)版本控制庫的訪問。
### 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
至此,你可以控制你的項(xiàng)目,對(duì)其進(jìn)行訪問權(quán)限的控制了。