Security Tutorials系列文章第二章:Forms Authentication概述

Security Tutorials系列文章第二章:Forms Authentication概述

本文英文原版及代码下载:
http://www.asp.net/learn/security/tutorial-02-cs.aspx

导言:

在上一篇文章里,我们探讨了ASP.NET提供了各种不同的authentication, authorization,以及 user account.在本文我们将考察forms authentication的执行.我们在本文构建的web应用程序将在以后逐步完善,从forms authentication扩展到membership 和 roles.

本文我们首先深入的探讨表单认证流程.然后,我们将创建一个ASP.NET站点,通过它来阐述forms authentication的概念.接下来,我们配置该站点使用forms authentication,创建一个简单的登陆页面,看如何写代码判断用户是否通过了认证.要构建一个支持用户帐户并可以通过一个web page来对用户进行认证的ASP.NET应用程序的话,这些都是很重要的:理解表单认证并在一个web应用程序里运用、创建登陆和注销页面.因为这些系列文章都是相互关联的,因此我建议你依次阅读该系列,即使你在以前的项目里对配置表单验证已经很有经验了.

理解表单验证流程

当ASP.NET runtime处理一个对ASP.NET资源——比如ASP.NET page或ASP.NET Web service的请求时,在该请求的生命周期里将引发一系列的事件,贯彻请求的开始和结束。要查阅这些完整的事件列表请参阅《HttpApplication object’s events》HTTP Module是托管类(managed classes),用于处理在请求生命周期里的特定事件.ASP.NET里有多个HTTP Module,用于在后台执行一些基本的任务.其中与本系列尤其相关的2个内置HTTP Module是:

.FormsAuthenticationModule——通过检查表单认证票据(forms authentication ticket)来认证用户.表单认证票据一般是包含在用户的cookies collection里的.如果没有表单认证票据,那么这个用户就是匿名的.


.UrlAuthorizationModule——判断是否授权当前用户访问所请求的URL.该module需要根据应用程序的配置文件指定的授权规则来执行.当然,

ASP.NET里也包含FileAuthorizationModule——它要根据所请求文件的ACLs来决定是否给与权限.


FormsAuthenticationModule在UrlAuthorizationModule(以及FileAuthorizationModule)执行之前运行.如果用户请求未被授权,那么就终止该请求,并返回一个HTTP 401 Unauthorized status.在Windows authentication里,该HTTP 401 status是要返回给浏览器的,使浏览器呈现一个modal对话框,要求用户输入相关认证信息.然而,在forms authentication里,该HTTP 401 Unauthorized status并不会返回给浏览器,因为FormsAuthenticationModule探测到该状态后,(通过HTTP 302 Redirect status)直接将用户导航到登陆页面.

登陆页面负责判断用户是否通过了认证,如果通过了则创建一个表单认证票据,并将用户再返回到他期望访问的那个页面.再以后对页面的请求里,就包含了该表单认证票据,便于FormsAuthenticationModule用来对用户进行甄别.


图1

在页面间导航时保存认证票据(Authentication Ticket)登陆后,每次发送请求时该表单认证票据都要返回给web服务器,这样当用户在浏览站点时他们就处于登陆状态.通常的做法时将认证票据放在用户的cookies collection里.Cookies是存放在客户端电脑上的很小的text文件.每次对站点的请求都将认证票据放在HTTP headers里进行传递.因此,一旦创建了表单认证票据并存储在浏览器的cookies里,随后的请求里就包含了表单认证票据,这样就可以甄别用户了.


使用cookies要注意的一方面是它的有效期,也就是浏览器什么时候销毁cookie.当表单认证票据过期失效后,用户就无法通过认证而变成匿名用户.当用户在公共场所浏览站点时,他们希望关闭浏览器后cookies就过期,然而在家里浏览时,他们希望再次登陆时表单认证票据仍然有效而不必再次登陆.这个问题我们可以通过在登陆页面添加一个“Remember me” checkbox来解决.在第3步里我们将考察如何实现.在后面我们将详细探讨表单认证票据的timeout设置问题.
注意:
    客户端有可能不支持cookies.在这种情况下,ASP.NET也可以使用无cookie的表单认证票据。在这种模式下,将表单认证票据编码进URL.在下一篇文章我们来看在什么时候使用无cookie的表单认证票据,以及如何创建和管理.


The Scope of Forms Authentication

FormsAuthenticationModule是“托管的”,且是ASP.NET runtime的一部分。在IIS7之前的版本,IIS的HTTP pipeline和ASP.NET runtime的pipeline之间有一道鸿沟.简单的说,IIS 6以及更早的版本,当请求是从IIS委托到ASP.NET runtime时,才执行FormsAuthenticationModule.

默认情况下,IIS只处理静态的内容——比如HTML页面、CSS、image文件等.当请求的资源的后缀名为.aspx, .asmx,或.ashx是才将请求转交给ASP.NET runtime处理.

IIS 7则不同,它允许对IIS pipelines和ASP.NET pipelines进行整合.只需少许的配置你就可以使IIS 7对所有的请求都调用FormsAuthenticationModule.此外,使用IIS 7,你可以对任意类型的文件定义URL authorization rules.更多详情请参阅文章《Changes Between IIS6 and IIS7 Security》、《Forms Authentication in IIS7》、《Understanding IIS7 URL Authorization》.简而言之,在IIS 7之前,要想使用forms authentication来保护请求的资源你只能通过ASP.NET runtime,同样也只能通过ASP.NET runtime才能对资源应用URL authorization rules.但在IIS 7里,我们可以将FormsAuthenticationModule 和 UrlAuthorizationModule整合进IIS的HTTP pipeline.

第一步:为本系列文章创建一个ASP.NET Website

为了尽可能的照顾到所有的朋友,我们将用Microsoft Visual Studio 2008的免费版——Visual Web Developer 2008来构建我们的站点,SqlMembershipProvider用户存储使用的是Microsoft SQL Server 2005 Express Edition数据库.如果你使用的是Visual Studio 2005或Visual Studio 2008 或 SQL Server的其它版本,没关系,步骤都差不多,在有差异的地方我们会标注出来.
注意:
    每章的代码都可在每章下载,代码是用Visual Web Developer 2008创建的,面向的是.NET Framework 3.5版本,其Web.config文件包含了额外的3.5-specific配置元素.长话短说,如果您还没有安装.NET 3.5,下载的代码是无法运行的,除非你在Web.config里删除3.5-specific markup.


在配置forms authentication前,我们需要先创建一个ASP.NET站点.启动Visual Web Developer,在File菜单里选New Web Site,这将打开New Web Site对话框.选ASP.NET Web Site模板,在Location下拉列表里选File System,选择一个文件夹来放置该站点,选语言为C#.这就创建了一个包含Default.aspx页面、一个App_Data文件夹和一个Web.config文件.
注意:
   Visual Studio这些2种project管理模式:Web Site Projects 以及 Web Application Projects.其中Web Site Projects没有project文件,

而Web Application Projects则模仿Visual Studio .NET 2002/2003的project体系,包含一个project文件,并将项目的源代码编译进一个装配件,放置在/bin文件夹里.Visual Studio 2005最初只支持Web Site Projects,尽管在Service Pack 1里引入了Web Application Project模式;而Visual Web Developer 2005和2008 版只支持Web Site Projects, 我使用的就是Web Site Project模式,如果你使用的是非Express版本的,且希望使用Web Application Project模式,尽管用吧,只是你看到的画面和本系列的截屏可能有些不太一样,你采取的步骤和本文的要注意区别.


图2


添加一个母版页

接下来在站点的根目录添加一个母版页,名为Site.master.Master page使得页面开发人员定义一个站点模板,以运用到 ASP.NET页面.主要的好处是,可以在定义站点的总体界面,很容易的更新或拼装站点布局.


图3.向站点添加一个名为Site.master的母版页


在母版页定义站点级的布局.你可以在视图模式里添加任何你需要的布局或控件,或直接在源码模式里添加代码来实现.我仿照的是《Working with Data in ASP.NET 2.0 tutorial》系列文章里运用的布局(见图4).母版页使用cascading style sheets来布置,而样式使用的是Style.css文件里定义好的CSS设置(它包含在相关的下载里).


<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="Site" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Forms Authentication, Authorization, and User Accounts</title>
    <link href="Styles.css" _fcksavedurl=""Styles.css"" _fcksavedurl=""Styles.css"" _fcksavedurl=""Styles.css""

rel="stylesheet" type="text/css" />
</head>
<body>
    <div id="wrapper">
        <form id="form1" runat="server">
       
            <div id="header">
                <span class="title">User Account Tutorials</span>
            </div>
            <div id="content">
                <asp:contentplaceholder id="MainContent" runat="server">
                  <!-- Page-specific content will go here... -->
                </asp:contentplaceholder>
            </div>
           
            <div id="navigation">
                TODO: Menu will go here...
            </div>
        </form>
    </div>
</body>
</html>


一个母版页定义了一个静态的页面布局以及一个供使用该母版页的ASP.NET页面编辑的区域.这些区域由ContentPlaceHolder控件来划定,我们的母版页使用的是单独的一个ContentPlaceHolder控件 (MainContent), 实际上母版页可以包含多个ContentPlaceHolders.

输入上述代码后,我们切换到视图模式看母版页的布局。任何运用该母版页的ASP.NET都有统一的布局,且可以在MainContent控件的区域内进行编辑.

图4:视图模式下的母版页


创建内容页面


现在我们有一个Default.aspx页面,但它并没有使用我们刚创建的母版页。虽然我们可以显式地声明代码以使一个web页面使用母版页面.但如果该页面还没有包含任何的内容时,我们可以将其删除再重新添加进来,指定它运用母版页,因此将Default.aspx页面删除.接下来,在资源管理器里的project名称上右键单击选添加一个Web Form,名为Default.aspx.此时,选“Select master page” checkbox,再在下拉列表里选Site.master母版页.


图5:添加一个新的Default.aspx页面并选择运用母版页

图6:使用Site.master

注意:
    如果你使用的是Web Application Project模式,Add New Item对话框并不包含“Select master page” checkbox.因此,你需要添加一个类型为“Web Content Form”的项,选中“Web Content Form” 选项后,单击Add,Visual Studio就会像图6那样显示一个相同的Select a Master对话框.

该Default.aspx页面的声明代码里包含一个@Page标签,指定了母版页的路径,以及一个Content
控件,如下:

<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default"

Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
</asp:Content>

现在不用管该Default.aspx页面,我们在后面要添加内容.
注意:
     我们的母版页将有一个区域来包含一个菜单,或其它的导航界面.我们将在以后的文章创建该界面


第2步:启用Forms Authentication

创建好站点后,下一步是启用forms authentication.应用程序的authentication配置是在Web.config文件里的<authentication>元素里指定的,该<authentication>元素包含一个名为mode的属性,它指定了应用程序使用的authentication模式,该属性的值可为几种之一:

.Windows——正如前面的文章探讨的那样,当一个应用程序使用Windows authentication时,web server负责对访问者甄别,且通常通过Basic, Digest,或Integrated Windows authentication.

.Forms——用户通过一个web页面里的一个form进行甄别

.Passport——用户通过微软的Passport Network进行甄别.

.None——不采用任何的authentication模式,所有的访问者都是匿名的.

默认情况下,ASP.NET应用程序采用的是Windows authentication. 我们需要将<authentication>元素的mode改为Forms即可.如果你的project并不包含Web.config文件,只需在解决方案管理器里添加一个即可:

图7:添加一个Web.config文件

然后定位到<authentication>元素将其改为使用forms authentication,此时,你的Web.config文件的声明代码看起来和下面的差不多:

<configuration>
    <system.web>
        ... Unrelated configuration settings and comments removed for brevity ...
        <!--
            The <authentication> section enables configuration
            of the security authentication mode used by
            ASP.NET to identify an incoming user.
        -->
        <authentication mode="Forms" />
    </system.web>
</configuration>

注意:由于Web.config是一个XML文件,改为Forms时,务必输入字符“F”.如果你输入“forms”的话, 当你在浏览器里登陆时,你会收到一个配置错误.


该<authentication>元素可能还包含有一个<forms>自元素,包含了与authentication相关的设置.现在我们使用默认的forms authentication设置.我们将在后面的文章里详细的对<forms>子元素进行扩展.


第3步:创建Login Page


为了使我们的站点支持forms authentication,我们需要一个login page,就像在前面的“理解表单验证流程”部分探讨的那样,如果用户未被授权,FormsAuthenticationModule将自动的把用户导航到login page,也有ASP.NET Web控件将展示一个把匿名用户导航到login page的链接,问题是:“login page的URL是多少呢?”.

默认情况下,在forms authentication system里login page为Login.aspx,且位于web应用程序的根目录下.如果你像使用另外一个URL,你可以在Web.config文件里指定.我们将在后面的文章里探讨如何操作.

login page有3个职责:

1.提供一个界面供用户登录
2.判断用户提交的登录信息是否有效
3.通过创建表单验证票据使用户处于登录状态


创建Login Page的用户界面

在站点根目录创建一个新的页面名为Login.aspx,套用Site.master母版页.

图8.添加一个名为Login.aspx的新页面


典型的登录页面由2个textboxes构成,分别用于输入用户名和密码,另外还有一个按钮用于提交表单.通常,还包含一个“Remember me” checkbox,选中它后,以后再次打开浏览器时,先前的票据依然有效.


在Login.aspx页面上添加2个TextBox,分别设其ID为UserName 和 Password,并将Password的TextMode属性设为Password.然后添加一个CheckBox控件,设其ID为RememberMe,设其Text属性为“Remember Me”.接着添加一个名为LoginButton的Button,设其Text属性为“Login”.

最后,添加一个名为InvalidCredentialsMessage的Label控件,其Text属性为 “Your username or password is invalid. Please try again.”, 设其ForeColor属性为Red,Visible属性为False.

这样你的屏幕看起来和图9差不多,页面的声明代码和下面的差不多:

<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"CodeFile="Login.aspx.cs" Inherits="Login" %>
 <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
<h1> Login</h1> <p> Username: <asp:TextBox ID="UserName"
runat="server"></asp:TextBox></p> <p> Password:
<asp:TextBox ID="Password" runat="server"
TextMode="Password"></asp:TextBox></p> <p> <asp:CheckBox
ID="RememberMe" runat="server" Text="Remember Me" /> </p>
<p> <asp:Button ID="LoginButton" runat="server" Text="Login"
OnClick="LoginButton_Click" /> </p> <p> <asp:Label
ID="InvalidCredentialsMessage" runat="server" ForeColor="Red" Text="Your
username or password is invalid. Please try again."
Visible="False"></asp:Label> </p>
</asp:Content>


图9:登录页面包含2个TextBoxes,一个CheckBox,一个Button和一个Label

最后为LoginButton的Click事件创建一个事件处理器,只需在设计模式里双击该按钮即可.


判断提供的登录信息是否有效


现在我们需要在按钮的Click事件里执行第二项任务——判断用户提交的credentials是否有效.为此我们需要有一个user store来存储所有用户的credential.这样我们就可以判定用户提交的credential与任何已知的credential是否匹配.

在ASP.NET 2.0之前,开发人员需要自己负责user stores以及编写代码将用户提供的credentials与存储的credentials进行比较.绝大多数的开发者将user store选为一个数据库,创建一个名为Users的数据表,表的列设计为UserName, Password, Email, LastLoginDate等.一个用户帐户对应一条记录.对用户提供的credentials验证需要调用对数据库的查询,看是否有某条记录的username与用户提交的匹配,如果username匹配再看password是否匹配.


在ASP.NET 2.0里,我们只要使用众多Membership providers中的一个来管理user store,在本系列文章我们使用SqlMembershipProvider,它使用一个SQL Server数据库来作为user store.当使用SqlMembershipProvider的时候我们需要贯彻一个定义好了的数据库构架,该构架包含tables, views,stored procedures.我们在后面的文章《Creating the Membership Schema in SQL Server》里看如何来执行该构架.设置好Membership provider后,要验证用户的credentials只需要调用Membership类的ValidateUser(username, password)方法,该方法返回一个Boolean值,以指明username 和 password是否有效.


用不着花时间设计自定义的Users数据库表,我们在登录页面硬编码验证用户提供的credentials,在LoginButton的Click事件处理器里,添加如下的代码:

protected void LoginButton_Click(object sender, EventArgs e)
 { // Three valid username/password pairs: Scott/password, Jisun/password, and Sam/password.
string[] users = { "Scott", "Jisun", "Sam" };
string[] passwords = { "password", "password", "password" };
for (int i = 0; i < users.Length; i++)
{ bool validUsername = (string.Compare(UserName.Text, users[i], true) == 0);
  bool validPassword = (string.Compare(Password.Text, passwords[i], false) == 0);
if (validUsername && validPassword) {
// TODO: Log in the user...
// TODO: Redirect them to the appropriate page }
}
// If we reach here, the user's credentials were invalid
InvalidCredentialsMessage.Visible = true; }

如你所见,有3个有效的用户帐户Scott, Jisun,和Sam,它们的密码都是(“password”). 代码对users和passwords数组进行循环处理,以找出一个有效的用户名和密码.如果都有效我们就需要将用户导航到恰当的页面,如果提供的credentials无效,则将名为InvalidCredentialsMessage的Label显示出来.


 当用户输入一个有效的credentials时,我前面提到过要将他们返回到一个“恰当的页面”.那么什么是恰当的页面呢?我们知道,当用户访问一个未被授权的页面时,Forms Authentication自动将其导航到登陆页面,登陆成功后,就在查询字符串里的ReturnUrl参数里包含该请求的URL.那就是说,如果用户试图访问ProtectedPage.aspx页面,但其又未被授权,那么Forms Authentication就会将他导航到

Login.aspx?ReturnUrl=ProtectedPage.aspx

登陆成功后,用户就会被直接返回到ProtectedPage.aspx页面.当然用户可能自己就想访问登陆页面,在这种情况下,登陆后,应该将他们返回到根目录下的Default.aspx页面.


“登陆”用户

如果用户提供的credentials有效,那么我们就应该创建一个表单认证票据以便于用户“登陆”站点.System.Web.Security命名空间的FormsAuthentication类提供了很多通过forms authentication系统登陆和注销的函数.在此我们对3个方法感兴趣:

.GetAuthCookie(username, persistCookie)——为提供的username创建一个表单认证票据,接下来该方法创建并返回一个HttpCookie对象,该对象包含了票据的内容.如果persistCookie为true,则创建一个"持久性"的cookie.

.SetAuthCookie(username, persistCookie)——调用GetAuthCookie(username, persistCookie) 方法来生成表单认证票据.该方法将

GetAuthCookie()方法返回的cookie添加到Cookies collection里(我们假定使用的是基于cookie的forms authentication.不然,该方法将调用一个内部的类来处理无Cookie的票据逻辑)

.RedirectFromLoginPage(username, persistCookie)——该方法调用SetAuthCookie(username, persistCookie),然后将用户再导航到恰当的页面.


如果在cookie清除出Cookies collection之前,你需要对表单认证票据进行修改的话,使用GetAuthCookie方法是很方便的.如果你想创建一个表单认证票据并添加到Cookies collection,但又不想将用户导航到恰当的页面时,SetAuthCookie方法是很有用的.


由于我们希望用户“登陆”并导航到恰当的页面,因此我们使用RedirectFromLoginPage()方法.
在LoginButton按钮的Click事件处理器里,删除那2行TODO注释,添加如下的代码:

FormsAuthentication.RedirectFromLoginPage(UserName.Text, RememberMe.Checked);


创建票据时,我们将ID为UserName的那个TextBox的Text属性作为票据的username参数;将那个“RememberMe”的CheckBox的选中状态作为persistCookie参数.

来测试登陆页面。首先输入一个无效的credentials,比如用户名为“Nope”,密码为“wrong”.点击Login按钮后,将产生一个页面回传,那个ID为InvalidCredentialsMessage的Label控件就显示出来了.

图10:当输入无效的Credentials时,ID为InvalidCredentialsMessage的Label就显示出来了


接下来,输入一个有效的credentials并点Login按钮.此时产生一个页面回传,并创建一个票据,并且自动的将你导航到Default.aspx页面.此时,你已经“登陆”了,只是没有视觉上的提示而已.在第四步,我们将看到如何通过编程判断用户是否已经“登陆”,以及如何对用户进行甄别.

第五步将探讨注销用户的技术

Securing the Login Page

当用户输入credentials并提交时,该credentials——包含了用户密码——将以纯文本的形式通过英特网传递给服务器。这就意味着用户名和密码有可能被黑客截获.为避免这种事情的发生,有必要使用Secure Socket Layers (SSL)来加密处理.这将对credentials(包括正规页面的HTML标记)进行加密.

除非你的站点包含敏感信息,你只需要对登陆页面和那些一纯文本的形式传输密码的页面使用SSL。你不必担心票据的安全性,默认情况下都是经过加密处理了的.关于票据安全性的讨论见后面的文章.
注意:
     很多的金融和医学网站对认证用户可以访问的页面都采用了SSL.如果你正是构建这样的网站,你可以对forms authentication system进行配置,这样票据就只能通过安全的通道进行传输.我们将在下一章《Forms Authentication Configuration and Advanced Topics》里探讨各种不同的forms authentication配置选项.


第四步:Detecting Authenticated Visitors and Determining Their Identity


此时,我们已经启用了forms authentication,并创建了一个基本的登陆页面,但我们还没有考察如何判断用户是通过认证的用户还是匿名用户.在某些情况下我们希望根据访问者是匿名的还是通过认证的来展示不同的数据或信息.此外,我们还常常需要知道认证用户的身份(identity)

让我们对现有的Default.aspx页面进行扩充,以演示这些技术.在Default.aspx页面里添加2个 Panel控件,一个ID为AuthenticatedMessagePanel,另一个为AnonymousMessagePanel.在第一个里面添加一个名为WelcomeBackMessage的Label控件 ,在第二个里面添加一个HyperLink控件,设其Text属性为“Log In”,NavigateUrl属性为“~/Login.aspx”.此时,Default.aspx页面的声明代码看起来应该和下面的差不多:

<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default"

Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
    <asp:Panel runat="server" ID="AuthenticatedMessagePanel">
        <asp:Label runat="server" ID="WelcomeBackMessage"></asp:Label>
    </asp:Panel>
   
    <asp:Panel runat="Server" ID="AnonymousMessagePanel">
        <asp:HyperLink runat="server" ID="lnkLogin" Text="Log In" NavigateUrl="~/Login.aspx"></asp:HyperLink>
    </asp:Panel>
</asp:Content>


你可能已经猜到了,AuthenticatedMessagePanel面向认证用户,AnonymousMessagePanel面向匿名用户.为此,我们需要根据用户是否登陆用户来设置这2个Panels的Visible属性.

Request.IsAuthenticated属性返回一个布尔值,以指出请求是否进过了认证.在Page_Load事件处理器里键入如下的代码:

protected void Page_Load(object sender, EventArgs e)
{
    if (Request.IsAuthenticated)
    {
        WelcomeBackMessage.Text = "Welcome back!";
   
        AuthenticatedMessagePanel.Visible = true;
        AnonymousMessagePanel.Visible = false;
    }
    else
    {
        AuthenticatedMessagePanel.Visible = false;
        AnonymousMessagePanel.Visible = true;
    }
}

有了这些代码,在浏览器里登陆Default.aspx页面.假定你还没有登陆,你将会看到一个到登陆页面的链接(见图11),点该链接,登陆该站点.如我们在第三步所说,输入你的credentials后你将返回到Default.aspx页面,但这次页面显示的是“Welcome back!”消息(见图12).


图11:当匿名访问时,显示一个登陆链接

图12:对认证用户将显示一个“Welcome back!”的消息

我们可以通过HttpContext object的User属性来判断当前登陆用户的身份.HttpContext object对象描述了当前请求的信息,当然它也可以表示这些常见的ASP.NET objects:Response,Request,以及Session等.该User属性描述了当前HTTP request的security context,并且执行IPrincipal接口.

User属性是由FormsAuthenticationModule来设置的.具体来说,当FormsAuthenticationModule在请求里发现了一个票据,它就创建一个新的GenericPrincipal object对象并赋值给该User属性.

Principal objects对象(比如GenericPrincipal)提供了用户身份(identity)以及所属角色的信息。IPrincipal接口定义了2个成员:

.IPrincipal——返回一个布尔值的方法,指出该principal是否属于指定的角色.

.Identity——该属性返回一个执行IIdentity接口的对象.而IIdentity接口定义了3个属性:AuthenticationType, IsAuthenticated,以及Name.

我们可以通过下面的代码判断当前用户的name:

string currentUsersName = User.Identity.Name;

当使用forms authentication时候,将会为GenericPrincipal的Identity属性创建一个FormsIdentity object对象.该FormsIdentity类的AuthenticationType属性总是返回字符串“Forms” ,IsAuthenticated属性总是返回true,而Name属性返回的就是创建票据时指定的username;除了这3个属性外,FormsIdentity还有一个Ticket属性,通过该属性我们可以访问潜在的票据 .该Ticket属性返回的是一个FormsAuthenticationTicket类型的对象.该类型有诸如Expiration, IsPersistent, IssueDate, Name等的属性.

有一点要注意,对FormsAuthentication.GetAuthCookie(username,persistCookie),
FormsAuthentication.SetAuthCookie(username, persistCookie),
以及FormsAuthentication.RedirectFromLoginPage(username, persistCookie)这3个方法里指定的username参数,User.Identity.Name返回的都是一样的值.此外,这些方法创建的票据是可以获取的,方法是将User.Identity转换为一个FormsIdentity object对象,再访问该对象的Ticket属性即可,比如:

FormsIdentity ident = User.Identity as FormsIdentity;

FormsAuthenticationTicket authTicket = ident.Ticket;

让我们在Default.aspx页面里提供一个更具个性化的消息.更改Page_Load事件处理器,将WelcomeBackMessage Label的Text属性设置为“Welcome back, username!”:

WelcomeBackMessage.Text = "Welcome back, " + User.Identity.Name + "!";

如图13,显示的是更改后的效果(当以Scott的名义登陆)

图13:


使用LoginView 和 LoginName控件

接下来,在LoginContent ContentPlaceHolder里的LoginView控件下面再添加一个LoginStatus控件,设置其LogoutAction属性为Redirect;LogoutPageUrl属性为“~/Logout.aspx”,如下:

<div id="navigation">
<asp:ContentPlaceHolder ID="LoginContent" runat="server">
<asp:LoginView ID="LoginView1" runat="server">
<LoggedInTemplate>
 Welcome back, <asp:LoginName ID="LoginName1" runat="server" />.
</LoggedInTemplate>
<AnonymousTemplate> Hello, stranger.
<asp:HyperLink ID="lnkLogin" runat="server" NavigateUrl="~/Login.aspx">Log In</asp:HyperLink>
</AnonymousTemplate>
</asp:LoginView> <br />

<asp:LoginStatus ID="LoginStatus1" runat="server" LogoutAction="Redirect"
LogoutPageUrl="~/Logout.aspx" /> <br /><br />

</asp:ContentPlaceHolder>
TODO: Menu will go here...
</div>

由于LoginStatus位于LoginView控件之外,所以对认证用户和匿名用户而言都是可见的.这没什么不好,因为LoginStatus控件会相应的显示一个“Login”或 “Logout”LinkButton.添加了LoginStatus控件后,AnonymousTemplate模板里的那个 “Log In”链接就显得多余了,因此删除它.

图18显示的是以Jisun的名义访问Default.aspx页面的情形.我们注意到左边显示一条消息Welcome back, Jisun”,以及一个log out的链接.点击该log out LinkButton将导致一个页面回传,将Jisun从系统里注销,并将其导航到Logout.aspx页面.如图19所示,当Jisun抵达Logout.aspx页面时,她已经因被注销而变成匿名用户了.因此,左边的消息变成“Welcome, stranger”,以及一个到登录页面的链接.

图18

图19


注意:
    我建议你对Logout.aspx进行一些处理(就像我们在第四步那样处理的一样).原因是在“Hello, stranger”下面的那个LoginStatus控件将呈现一个“Login” LinkButton,当一个注销了的用户点击该“Login”链接并成功登录后,LoginStatus控件将通过ReturnUrl查询字符串将用户又重新导航回Logout.aspx页面,这样将使用户感到莫名其妙.


结语:
    在本文我们一开始考察了forms authentication流程,然后在一个ASP.NET应用程序里执行forms authentication.我们知道Forms authentication是由FormsAuthenticationModule来驱动的,它主要有2个职责:一个是通过表单认证票据对用户身份进行甄别,另一个是将未授权的用户导航到登录页面.

 .NET Framework的FormsAuthentication类包含了很多创建、检查、销毁表单认证票据的方法.Request.IsAuthenticated属性和User对象都支持编程来判断请求是否是通过了认证,以及关于用户身份的信息.同时,LoginView, LoginStatus以及LoginName控件使开发人员可以快速的、不手写代码的方式来执行很多与登录相关的任务.我们将在以后的文章里更深入的探讨其它一些与登录相关的Web控件.

本文我们对forms authentication做了一个粗略的概述.我们没有探讨其它相关的配置选项,没有探讨无cookie的表单认证票据是如何工作的,以及ASP.NET是如何对表单认证票据的内容进行保护的.这些内容我们将在接下来的文章里探讨.

祝编程愉快!


作者简介:

Scott Mitchell,著有七本ASP/ASP.NET方面的书,是4GuysFromRolla.com的创始人,自1998年以来一直应用 微软Web技术。Scott是个独立的技术咨询顾问,培训师,作家,最近完成了将由Sams出版社出版的新作,24小时内精通ASP.NET 2.0。他的联系电邮为mitchell@4guysfromrolla.com,也可以通过他的博客http://ScottOnWriting.NET与他联系。

转载于:https://www.cnblogs.com/heker2007/archive/2008/03/27/1125703.html

翻译, ====================================== INSTALLING SUBVERSION A Quick Guide ====================================== $LastChangedDate$ Contents: I. INTRODUCTION A. Audience B. Dependency Overview C. Dependencies in Detail D. Documentation II. INSTALLATION A. Building from a Tarball B. Building the Latest Source under Unix C. Building under Unix in Different Directories D. Installing from a Zip or Installer File under Windows E. Building the Latest Source under Windows F. Building using CMake III. BUILDING A SUBVERSION SERVER A. Setting Up Apache Httpd B. Making and Installing the Subversion Apache Server Module C. Configuring Apache Httpd for Subversion D. Running and Testing E. Alternative: 'svnserve' and ra_svn IV. PROGRAMMING LANGUAGE BINDINGS (PYTHON, PERL, RUBY, JAVA) I. INTRODUCTION ============ A. Audience This document is written for people who intend to build Subversion from source code. Normally, the only people who do this are Subversion developers and package maintainers. If neither of these labels fits you, we recommend you find an appropriate binary package of Subversion and install that. While the Subversion project doesn't officially release binary packages, a number of volunteers have made such packages available for different operating systems. Most Linux and BSD distributions already have Subversion packages ready to go via standard packaging channels, and other volunteers have built 'installers' for both Windows and OS X. Visit this page for package links: https://subversion.apache.org/packages.html For those of you who still wish to build from source, Subversion follows the Unix convention of "./configure && make", but it has a number of dependencies. B. Dependency Overview You'll need the following build tools to compile Subversion: * autoconf 2.59 or later (Unix only) * libtool 1.4 or later (Unix only) * a reasonable C compiler (gcc, Visual Studio, etc.) Subversion also depends on the following third-party libraries: * libapr and libapr-util (REQUIRED for client and server) The Apache Portable Runtime (APR) library provides an abstraction of operating-system level services such as file and network I/O, memory management, and so on. It also provides convenience routines for things like hashtables, checksums, and argument processing. While it was originally developed for the Apache HTTP server, APR is a standalone library used by Subversion and other products. It is a critical dependency for all of Subversion; it's the layer that allows Subversion clients and servers to run on different operating systems. * SQLite (REQUIRED for client and server) Subversion uses SQLite to manage some internal databases. * libz (REQUIRED for client and server) Subversion uses zlib for compressing binary differences. These diff streams are used everywhere -- over the network, in the repository, and in the client's working copy. * utf8proc (REQUIRED for client and server) Subversion uses utf8proc for UTF-8 support, including Unicode normalization. * Apache Serf (OPTIONAL for client) The Apache Serf library allows the Subversion client to send HTTP requests. This is necessary if you want your client to access a repository served by the Apache HTTP server. There is an alternate 'svnserve' server as well, though, and clients automatically know how to speak the svnserve protocol. Thus it's not strictly necessary for your client to be able to speak HTTP... though we still recommend that your client be built to speak both HTTP and svnserve protocols. * OpenSSL (OPTIONAL for client and server) OpenSSL enables your client to access SSL-encrypted https:// URLs (using Apache Serf) in addition to unencrypted http:// URLs. To use SSL with Subversion's WebDAV server, Apache needs to be compiled with OpenSSL as well. * Netwide Assembler (OPTIONAL for client and server) The Netwide Assembler (NASM) is used to build the (optional) assembler modules of OpenSSL. As of OpenSSL 1.1.0 NASM is the only supported assembler. * Berkeley DB (DEPRECATED and OPTIONAL for client and server) When you create a repository, you have the option of specifying a storage 'back-end' implementation. Currently, there are two options. The newer and recommended one, known as FSFS, does not require Berkeley DB. FSFS stores data in a flat filesystem. The older implementation, known as BDB, has been deprecated and is not recommended for new repositories, but is still available. BDB stores data in a Berkeley DB database. This back-end will only be available if the BDB libraries are discovered at compile time. * libsasl (OPTIONAL for client and server) If the Cyrus SASL library is detected at compile time, then the svn client (and svnserve server) will be able to utilize SASL to do various forms of authentication when speaking the svnserve protocol. * Python, Perl, Java, Ruby (OPTIONAL) Subversion is mostly a collection of C libraries with well-defined APIs, with a small collection of programs that use the APIs. If you want to build Subversion API bindings for other languages, you need to have those languages available at build time. * py3c (OPTIONAL, but REQUIRED for Python bindings) The Python 3 Compatibility Layer for C Extensions is required to build the Python language bindings. * KDE Framework 5, libsecret, GNOME Keyring (OPTIONAL for client) Subversion contains optional support for storing passwords in KWallet via KDE Framework 5 libraries (preferred) or kdelibs4, and GNOME Keyring via libsecret (preferred) or GNOME APIs. * libmagic (OPTIONAL) If the libmagic library is detected at compile time, it will be used to determine mime-types of binary files which are added to version control. Note that mime-types configured via auto-props or the mime-types-file option take precedence. C. Dependencies in Detail Subversion depends on a number of third party tools and libraries. Some of them are only required to run a Subversion server; others are necessary just for a Subversion client. This section explains what other tools and libraries will be required so that Subversion can be built with the set of features you want. On Unix systems, the './configure' script will tell you if you are missing the correct version of any of the required libraries or tools, so if you are in a real hurry to get building, you can skip straight to section II. If you want to gather the pieces you will need before starting out, however, you should read the following. If you're just installing a Subversion client, the Subversion team has created a script that downloads the minimal prerequisite libraries (Apache Portable Runtime, Sqlite, and Zlib). The script, 'get-deps.sh', is available in the same directory as this file. When run, it will place 'apr', 'apr-util', 'serf', 'zlib', and 'sqlite-amalgamation' directories directly into your unpacked Subversion distribution. With the exception of sqlite-amalgamation, they will still need to be configured, built and installed explicitly, and Subversion's own configure script may need to be told where to find them, if they were not installed in standard system locations. Note: there are optional dependencies (such as OpenSSL, swig, and httpd) which get-deps.sh does not download. Note: Because previous builds of Subversion may have installed older versions of these libraries, you may want to run some of the cleanup commands described in section II.B before installing the following. 1. Apache Portable Runtime 1.4 or newer (REQUIRED) Whenever you want to build any part of Subversion, you need the Apache Portable Runtime (APR) and the APR Utility (APR-util) libraries. If you do not have a pre-installed APR and APR-util, you will need to get these yourself: https://apr.apache.org/download.cgi On Unix systems, if you already have the APR libraries compiled and do not wish to regenerate them from source code, then Subversion needs to be able to find them. There are a couple of options to "./configure" that tell it where to look for the APR and APR-util libraries. By default it will try to locate the libraries using apr-config and apu-config scripts. These scripts provide all the relevant information for the APR and APR-util installations. If you want to specify the location of the APR library, you can use the "--with-apr=" option of "./configure". It should be able to find the apr-config script in the standard location under that directory (e.g. ${prefix}/bin). Similarly, you can specify the location of APR-util using the "--with-apr-util=" option to "./configure". It will look for the apu-config script relative to that directory. For example, if you want to use the APR libraries you built with the Apache httpd server, you could run: $ ./configure --with-apr=/usr/local/apache2 \ --with-apr-util=/usr/local/apache2 ... Notes on Windows platforms: * Do not use APR version 1.7.3 as that release contains a bug that makes it impossible for Subversion to use it properly. This issue only affects APR builds on Windows. This issue was fixed in APR version 1.7.4. See: https://lists.apache.org/thread/xd5t922jvb9423ph4j84rsp5fxks1k0z * If you check out APR and APR-util sources from their Subversion repository, be sure to use a native Windows SVN client (as opposed to Cygwin's version) so that the .dsp files get carriage-returns at the ends of their lines. Otherwise Visual Studio will complain that it doesn't recognize the .dsp files. Notes on Unix platforms: * If you check out APR and APR-util sources from their Subversion repository, you need to run the 'buildconf' script in each library's directory to regenerate the configure scripts and other files required for compiling the libraries. Afterwards, configure, build, and install both libraries before running Subversion's configure script. For example: $ cd apr $ ./buildconf $ ./configure <options...> $ make $ make install $ cd .. $ cd apr-util $ ./buildconf $ ./configure <options...> $ make $ make install $ cd .. 2. SQLite (REQUIRED) Subversion requires SQLite version 3.24.0 or above. You can meet this dependency several ways: * Use an SQLite amalgamation file. * Specify an SQLite installation to use. * Let Subversion find an installed SQLite. To use an SQLite-provided amalgamation, just drop sqlite3.c into Subversion's sqlite-amalgamation/ directory, or point to it with the --with-sqlite configure option. This file also ships with the Subversion dependencies distribution, or you can download it from SQLite: https://www.sqlite.org/download.html 3. Zlib (REQUIRED) Subversion's binary-differencing engine depends on zlib for compression. Most Unix systems have libz pre-installed, but if you need it, you can get it from http://www.zlib.net/ 4. utf8proc (REQUIRED) Subversion uses utf8proc for UTF-8 support. Configure will attempt to locate utf8proc by default using pkg-config and known paths. If it is installed in a non-standard location, then use: --with-utf8proc=/path/to/libutf8proc Alternatively, a copy of utf8proc comes bundled with the Subversion sources. If configure should use the bundled copy, use: --with-utf8proc=internal 5. autoconf 2.59 or newer (Unix only) This is required only if you plan to build from the latest source (see section II.B). Generally only developers would be doing this. 6. libtool 1.4 or newer (Unix only) This is required only if you plan to build from the latest source (see section II.B). Note: Some systems (Solaris, for example) require libtool 1.4.3 or newer. The autogen.sh script knows about that. 7. Apache Serf library 1.3.4 or newer (OPTIONAL) If you want your client to be able to speak to an Apache server (via a http:// or https:// URL), you must link against Apache Serf. Though optional, we strongly recommend this. In order to use ra_serf, you must install serf, and run Subversion's ./configure with the argument --with-serf. If serf is installed in a non-standard place, you should use --with-serf=/path/to/serf/install instead. Apache Serf can be obtained via your system's package distribution system or directly from https://serf.apache.org/. For more information on Apache Serf and Subversion's ra_serf, see the file subversion/libsvn_ra_serf/README. 8. OpenSSL (OPTIONAL) ### needs some updates. I think Apache Serf automagically handles ### finding OpenSSL, but we may need more docco here. and w.r.t ### zlib. The Apache Serf library has support for SSL encryption by relying on the OpenSSL library. a. Using OpenSSL on the client through Apache Serf On Unix systems, to build Apache Serf with OpenSSL, you need OpenSSL installed on your system, and you must add "--with-ssl" as a "./configure" parameter. If your OpenSSL installation is hard for Apache Serf to find, you may need to use "--with-libs=/path/to/lib" in addition. In particular, on Red Hat (but not Fedora Core) it is necessary to specify "--with-libs=/usr/kerberos" for OpenSSL to be found. You can also specify a path to the zlib library using "--with-libs". Under Windows, you can specify the paths to these libraries by passing the options --with-zlib and --with-openssl to gen-make.py. b. Using OpenSSL on the Apache server You can also add support for these features to an Apache httpd server to be used for Subversion using the same support libraries. The Subversion build system will not provide them, however. You add them by specifying parameters to the "./configure" script of the Apache Server instead. For getting SSL on your server, you would add the "--enable-ssl" or "--with-ssl=/path/to/lib" option to Apache's "./configure" script. Apache enables zlib support by default, but you can specify a nonstandard location for the library with the "--with-z=/path/to/dir" option. Consult the Apache documentation for more details, and for other modules you may wish to install to enhance your Subversion server. If you don't already have it, you can get a copy of OpenSSL, including instructions for building and packaging on both Unix systems and Windows, at: https://www.openssl.org/ 9. Berkeley DB 4.X (DEPRECATED and OPTIONAL) You need the Berkeley DB libraries only if you are building a Subversion server that supports the older BDB repository storage back-end, or a Subversion client that can access local BDB repositories via the file:// URI scheme. The BDB back-end has been deprecated and is not recommended for new repositories. BDB may be removed in Subversion 2.0. We recommend the newer FSFS back-end for all new repositories. FSFS does not require the Berkeley DB libraries. If in doubt, the 'svnadmin info' command, added in Subversion 1.9, can identify whether an existing repository uses BDB or FSFS. The current recommended version of Berkeley DB is 4.4.20 or newer, which brings auto-recovery functionality to the Berkeley DB database environment. If you must use an older version of Berkeley DB, we *strongly* recommend using 4.3 or 4.2 over the 4.1 or 4.0 versions. Not only are these significantly faster and more stable, but they also enable Subversion repositories to automatically clean up database journal files to save disk space. You'll need Berkeley DB installed on your system. You can get it from: http://www.oracle.com/technetwork/database/database-technologies/berkeleydb/overview/index.html If you have Berkeley DB installed in a place not searched by default for includes and libraries, add something like this: --with-berkeley-db=db.h:/usr/local/include/db4.7:/usr/local/lib/db4.7:db-4.7 to your `configure' switches, and the build process will use the Berkeley DB header and library in the named directories. You may need to use a different path, of course. Note that in order for the detection to succeed, the dynamic linker must be able to find the libraries at configure time. 10. Cyrus SASL library (OPTIONAL) If the Simple Authentication and Security Layer (SASL) library is detected on your system, then the Subversion client and svnserve server can utilize its abilities for various forms of authentication. To learn more about SASL or to get the source code, visit: http://freshmeat.net/projects/cyrussasl/ 11. Apache Web Server 2.2.X or newer (OPTIONAL) (https://httpd.apache.org/download.cgi) The Apache httpd server is one of two methods to make your Subversion repository available over a network - the other is a custom server program called svnserve, which requires no extra software packages. Building Subversion, the Apache server, and the modules that Apache needs to communicate with Subversion are complicated enough that there is a whole section at the end of this document that describes how it is done: See section III for details. 12. Python 3.x or newer (https://www.python.org/) (OPTIONAL) Subversion does not require Python for its basic operation. However, Python is required for building and testing Subversion and for using Subversion's SWIG Python bindings or hook scripts coded in Python. The majority of Subversion's test suite is written in Python, as is part of Subversion's build system. In more detail, Python is required to do any of the following: * Use the SWIG Python bindings. * Use the ctypes Python bindings. * Use hook scripts coded in Python. * Build Subversion from a tarball on Unix-like systems and run Subversion's test suite as described in section II.B. * Build Subversion on Windows as described in section II.E. * Build Subversion from a working copy checked out from Subversion's own repository (whether or not running the test suite). * Build the SWIG Python bindings. * Build the ctypes Python bindings. * Testing as described in section III.D. The Python bindings are used by: * Third-party programs (e.g., ViewVC) * Scripts distributed with Subversion itself in the tools/ subdirectory. * Any in-house scripts you may have. Python is NOT required to do any of the following: * Use the core command-line binaries (svn, svnadmin, svnsync, etc.) * Use Subversion's C libraries. * Use any of Subversion's other language bindings. * Build Subversion from a tarball on Unix-like systems without running Subversion's test suite Although this section calls for Python 3.x, Subversion still technically works with Python 2.7. However, Support for Python 2.7 is being phased out. As of 1 January 2020, Python 2.7 has reached end of life. All users are strongly encouraged to move to Python 3. Note: If you are using a Subversion distribution tarball and want to build the Python bindings for Python 2, you should rebuild the build environment in non-release mode by running 'sh autogen.sh' before running the ./configure script; see section II.B for more about autogen.sh. 13. Perl 5.8 or newer (Windows only) (OPTIONAL) To build Subversion under any of the MS Windows platforms, you will also need Perl 5.8 or newer to run apr-util's w32locatedb.pl script. 14. pkg-config (Unix only, OPTIONAL) Subversion uses pkg-config to find appropriate options used at build time. 15. D-Bus (Unix only, OPTIONAL) D-Bus is a message bus system. D-Bus is required for support for KWallet and GNOME Keyring. pkg-config is needed to find D-Bus headers and library. 16. Qt 5 or Qt 4 (Unix only, OPTIONAL) Qt is a cross-platform application framework. QtCore, QtDBus and QtGui modules are required for support for KWallet. pkg-config is needed to find Qt headers and libraries. 17. KDE 5 Framework libraries or KDELibs 4 (Unix only, OPTIONAL) Subversion contains optional support for storing passwords in KWallet. Subversion will look for KF5Wallet, KF5CoreAddons, KF5I18n APIs by default, and needs kf5-config to find them. The KDELibs 4 api is also supported. KDELibs contains core KDE libraries. Subversion uses libkdecore and libkdeui libraries when support for KWallet is enabled. kde4-config is used to get some necessary options. pkg-config, D-Bus and Qt 4 are also required. If you want to build support for KWallet, then pass the '--with-kwallet' option to `configure`. If KDE is installed in a non-standard prefix, then use: --with-kwallet=/path/to/KDE/prefix 18. GLib 2 (Unix only, OPTIONAL) GLib is a general-purpose utility library. GLib is required for support for GNOME Keyring. pkg-config is needed to find GLib headers and library. 19. GNOME Keyring (Unix only, OPTIONAL) Subversion contains optional support for storing passwords in GNOME Keyring. pkg-config is needed to find GNOME Keyring headers and library. D-Bus and GLib are also required. If you want to build support for GNOME Keyring, then pass the '--with-gnome-keyring' option to `configure`. 20. Ctypesgen (OPTIONAL) Ctypesgen is Python wrapper generator for ctypes. It is used to generate a part of Subversion Ctypes Python bindings (CSVN). If you want to build CSVN, then pass the '--with-ctypesgen' option to `configure`. If ctypesgen.py is installed in a non-standard place, then use: --with-ctypesgen=/path/to/ctypesgen.py For more information on CSVN, see subversion/bindings/ctypes-python/README. 21. libmagic (OPTIONAL) Subversion's configure script attempts to find libmagic automatically. If it is installed in a non-standard location, then use: --with-libmagic=/path/to/libmagic/prefix The files include/magic.h and lib/libmagic.so.1.0 (or similar) are expected beneath this prefix directory. If they cannot be found Subversion will be compiled without support for libmagic. If libmagic is installed but support for it should not be compiled in, then use: --with-libmagic=no If configure should fail when libmagic is not present, but only the default locations should be searched, then use: --with-libmagic 22. LZ4 (OPTIONAL) Subversion uses LZ4 compression library version r129 or above. Configure will attempt to locate the system library by default using pkg-config and known paths. If it is installed in a non-standard location, then use: --with-lz4=/path/to/liblz4 If configure should use the version bundled with the sources, use: --with-lz4=internal 23. py3c (OPTIONAL) Subversion uses the Python 3 Compatibility Layer for C Extensions (py3c) library when building the Python language bindings. As py3c is a header-only library, it is needed only to build the bindings, not to use them. Configure will attempt to locate py3c by default using pkg-config and known paths. If it is installed in a non-standard location, then use: --with-py3c=/path/to/py3c/prefix The library can be downloaded from GitHub: https://github.com/encukou/py3c On Unix systems, you can also use the provided get-deps.sh script to download py3c and several other dependencies; see the top of section I.C for more about get-deps.sh. D. Documentation The primary documentation for Subversion is the free book "Version Control with Subversion", a.k.a. "The Subversion Book", obtainable from https://svnbook.red-bean.com/. Various additional documentation exists in the doc/ subdirectory of the Subversion source. See the file doc/README for more information. II. INSTALLATION ============ Subversion support three different build systems: - Autoconf/make, for Unix builds - Visual Studio vcproj, for Windows builds - CMake, for both Unix and Windows The first two have been in use since 2001. Sections A-E below describe the classic build system. The CMake build system was created in 2024 and is still under development. It will be included in Subversion 1.15 and is expected to be the default build system starting with Subversion 1.16. Section F below describes the CMake build system. A. Building from a Tarball ------------------------------ 1. Building from a Tarball Download the most recent distribution tarball from: https://subversion.apache.org/download/ Unpack it, and use the standard GNU procedure to compile: $ ./configure $ make # make install You can also run the full test suite by running 'make check'. Even in successful runs, some tests will report XFAIL; that is normal. Failed runs are indicated by FAIL or XPASS results, or a non-zero exit code from "make check". B. Building the Latest Source under Unix ------------------------------------- These instructions assume you have already installed Subversion and checked out a working copy of Subversion's own code -- either the latest /trunk code, or some branch or tag. You also need to have already installed whatever prerequisites that version of Subversion requires (if you haven't, the ./configure step should complain). You can discard the directory created by the tarball; you're about to build the latest, greatest Subversion client. This is the procedure Subversion developers use. First off, if you have any Subversion libraries lying around from previous 'make installs', clean them up first! # rm -f /usr/local/lib/libsvn* # rm -f /usr/local/lib/libapr* # rm -f /usr/local/lib/libserf* Start the process by running "autogen.sh": $ sh ./autogen.sh This script will make sure you have all the necessary components available to build Subversion. If any are missing, you will be told where to get them from. (See the 'Dependency Overview' in section I.) Note: if the command "autoconf" on your machine does not run autoconf 2.59 or later, but you do have a new enough autoconf available, then you can specify the correct one with the AUTOCONF variable. (The AUTOHEADER variable is similar.) This may be required on Debian GNU/Linux, where "autoconf" is actually a Perl script that attempts to guess which version is required -- because of the interaction between Subversion's and APR's configuration systems, the Perl script may get it wrong. So for example, you might need to do: $ AUTOCONF=autoconf2.59 sh ./autogen.sh Once you've prepared the working copy by running autogen.sh, just follow the usual configuration and build procedure: $ ./configure $ make # make install (Optionally, you might want to pass --enable-maintainer-mode to the ./configure script. This enables debugging symbols in your binaries (among other things) and most Subversion developers use it.) Since the resulting binary depends on shared libraries, the destination library directory must be identified in your operating system's library search path. That is in either /etc/ld.so.conf or $LD_LIBRARY_PATH for Linux systems and in /etc/rc.conf for FreeBSD, followed by a run of the 'ldconfig' program. Check your system documentation for details. By identifying the destination directory, Subversion will be able to dynamically load repository access plugins. If you try to do a checkout and see an error like: subversion/libsvn_ra/ra_loader.c:209: (apr_err=170000) svn: Unrecognized URL scheme 'https://svn.apache.org/repos/asf/subversion/trunk' It probably means that the dynamic loader/linker can't find all of the libsvn_* libraries. C. Building under Unix in Different Directories -------------------------------------------- It is possible to configure and build Subversion on Unix in a directory other than the working copy. For example $ svn co https://svn.apache.org/repos/asf/subversion/trunk svn $ cd svn $ # get SQLite amalgamation if required $ chmod +x autogen.sh $ ./autogen.sh $ mkdir ../obj $ cd ../obj $ ../svn/configure [...with options as appropriate...] $ make puts the Subversion working copy in the directory svn and builds it in a separate, parallel directory obj. Why would you want to do this? Well there are a number of reasons... * You may prefer to avoid "polluting" the working copy with files generated during the build. * You may want to put the build directory and the working copy on different physical disks to improve performance. * You may want to separate source and object code and only backup the source. * You may want to remote mount the working copy on multiple machines, and build for different machines from the same working copy. * You may want to build multiple configurations from the same working copy. The last reason above is possibly the most useful. For instance you can have separate debug and optimized builds each using the same working copy. Or you may want a client-only build and a client-server build. Using multiple build directories you can rebuild any or all configurations after an edit without the need to either clean and reconfigure, or identify and copy changes into another working copy. D. Installing from a Zip or Installer File under Windows ----------------------------------------------------- Of all the ways of getting a Subversion client, this is the easiest. Download a Zip or self-extracting installer via: https://subversion.apache.org/packages.html#windows For a Zip file extract the DLLs and EXEs to a directory of your choice. Included in the download are among other tools the SVN client, the SVNADMIN administration tool and the SVNLOOK reporting tool. You may want to add the bin directory in the Subversion folder to your PATH environment variable so as to not have to use the full path when running Subversion commands. To test the installation, open a DOS box (run either "cmd" or "command" from the Start menu's "Run..." menu option), change to the directory you installed the executables into, and run: C:\test>svn co https://svn.apache.org/repos/asf/subversion/trunk svn This will get the latest Subversion sources and put them into the "svn" subdirectory. If using a self-extracting .exe file, just run it instead of unzipping it, to install Subversion. E. Building the Latest Source under Windows ---------------------------------------- E.1 Prerequisites * Microsoft Visual Studio. Any recent (2005+) version containing the Visual C++ component will work (E.g. Professional, Express, Community Edition). Make sure you enable C++ support during setup. * Python 2.7 or higher, downloaded from https://www.python.org/ which is used to generate the project files. * Perl 5.8 or higher from https://www.perl.org/get.html * Awk is needed to compile Apache. Source code is available in tools\dev\awk, run the buildwin.bat program to compile. * Apache apr, apr-util, and optionally apr-iconv libraries, version 1.4 or later (1.2 for apr-iconv). If you are building from a Subversion checkout and have not downloaded Apache 2, then get these 3 libraries from https://www.apache.org/dist/apr/. * SQLite 3.24.0 or higher from https://www.sqlite.org/download.html (3.39.4 or higher recommended) * ZLib 1.2 or higher is required and can be obtained from http://www.zlib.net/ * Either a Subversion client binary from https://subversion.apache.org/packages.html to do the initial checkout of the Subversion source or the zip file source distribution. Additional Options * [Optional] Apache Httpd 2 source, downloaded from https://httpd.apache.org/download.cgi, these instructions assume version 2.0.58. This is only needed for building the Subversion server Apache modules. ### FIXME Apache 2.2 or greater required. * [Optional] Berkeley DB for backend support of the server components are available from http://www.oracle.com/technetwork/database/database-technologies/berkeleydb/downloads/index-082944.html (Version 4.4.20 or in specific cases some higher version recommended) For more information see Section I.C.9. * [Optional] Openssl can be obtained from https://www.openssl.org/source/ * [Optional] NASM can be obtained from http://www.nasm.us/ * [Optional] A modified version of GNU libintl, called svn-win32-libintl.zip, can be used for displaying localized messages. Available at: http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=2627 * [Optional] GNU gettext for generating message catalog (.mo) files from message translations. You can get the latest binaries from http://gnuwin32.sourceforge.net/. You'll need the binaries (gettext-0.14.1-bin.zip) and dependencies (gettext-0.14.1-dep.zip). E.2 Notes The Apache Serf library supports secure connections with OpenSSL and on-the-wire compression with zlib. If you want to use the secure connections feature, you should pass the option "--with-openssl" to the gen-make.py script. See Section I.C.7 for more details. E.3 Preparation This section describes how to unpack the files to make a build tree. * Make a directory SVN and cd into it. * Either checkout Subversion: svn co https://svn.apache.org/repos/asf/subversion/trunk src-trunk or unpack the zip file distribution and rename the directory to src-trunk. * Install Visual Studio Environment. You either have to tell the installer to register environment variables or run VCVARS32.BAT before building anything. If you are using a newer Visual Studio, use the 'Visual Studio 20xx Command Prompt' on the Start menu. * Install Python and add it to your path * Install Perl (it should add itself to the path) ### Subversion doesn't need perl. Only some dependencies need it (OpenSSL and some apr scripts) * Copy AWK (awk95.exe) to awk.exe (e.g. SVN\awk\awk.exe) and add the directory containing it (e.g. SVN\awk) to the path. ### Subversion doesn't need awk. Only some dependencies need it (some apr scripts) * [Optional] Install NASM and add it to your path ### Subversion doesn't need NASM. Only some dependencies need it optionally (OpenSSL) * [Optional] If you checked out Subversion from the repository and want to build Subversion with http/https access support then install the Apache Serf sources into SVN\src-trunk\serf. * [Optional] If you want BDB backend support, extract the Berkeley DB files into SVN\src-trunk\db4-win32. It's a good idea to add SVN\src-trunk\db4-win32\bin to your PATH, so that Subversion can find the Berkeley DB DLLs. [NOTE: This binary package of Berkeley DB is provided for convenience only. Please don't address questions about Berkeley DB that aren't directly related to using Subversion to the project mailing list.] If you build Berkeley DB from the source, you will have to copy the file db-x.x.x\build_win32\db.h to SVN\src-trunk\db4-win32\include, and all the import libraries to SVN\src-trunk\db4-win32\lib. Again, the DLLs should be somewhere in your path. ### Just use --with-serf instead of the hardcoded path * [Optional] If you want to build the server modules, extract Apache source into SVN\httpd-2.x.x. * If you are building from a checkout of Subversion, and you are NOT building Apache, then you will need the APR libraries. Depending on how you got your version of APR, either: - Extract the APR, APR-util and APR-iconv source distributions into SVN\apr, SVN\apr-util, and SVN\apr-iconv respectively. Or: - Extract the apr, apr-util and apr-iconv directories from the srclib folder in the Apache httpd source into SVN\apr, SVN\apr-util, and SVN\apr-iconv respectively. ### Just use --with-apr, etc. instead of the hardcoded paths * Extract the ZLib sources into SVN\zlib if you are not using the zlib included in the dependencies zip file. ### Just use --with-zlib instead of the hardcoded path * [Optional] If you want secure connection (https) client support extract OpenSSL into SVN\openssl ### And pass the path to both serf and gen-make.py * [Optional] If you want localized message support, extract svn-win32-libintl.zip into SVN\svn-win32-libintl and extract gettext-x.x.x-bin.zip and gettext-x.x.x-dep.zip into SVN\gettext-x.x.x-bin. Add SVN\gettext-x.x.x-bin\bin to your path. * Download the SQLite amalgamation from https://www.sqlite.org/download.html and extract it into SVN\sqlite-amalgamation. See I.C.12 for alternatives to using the amalgamation package. E.4 Building the Binaries To build the binaries either follow these instructions. Start in the SVN directory you created. Set up the environment (commands should be one line even if wrapped here). C:>set VER=trunk C:>set DIR=trunk C:>set BUILD_ROOT=C:\SVN C:>set PYTHONDIR=C:\Python27 C:>set AWKDIR=C:\SVN\Awk C:>set ASMDIR=C:\SVN\asm C:>set SDKINC="C:\Program Files\Microsoft SDK\include" C:>set SDKLIB="C:\Program Files\Microsoft SDK\lib" C:>set GETTEXTBIN=C:\SVN\gettext-0.14.1-bin\bin C:>PATH=%PATH%;%BUILD_ROOT%\src-%DIR%\db4-win32;%ASMDIR%; %PYTHONDIR%;%AWKDIR%;%GETTEXTBIN% C:>set INCLUDE=%SDKINC%;%INCLUDE% C:>set LIB=%SDKLIB%;%LIB% OpenSSL < 1.1.0 C:>cd openssl C:>perl Configure VC-WIN32 [*] C:>call ms\do_masm C:>nmake -f ms\ntdll.mak C:>cd out32dll C:>call ..\ms\test C:>cd ..\.. *Note: Use "call ms\do_nasm" if you have nasm instead of MASM, or "call ms\do_ms" if you don't have an assembler. Also if you are using OpenSSL >= 1.0.0 masm is no longer supported. You will have to use do_nasm or do_ms in this case. OpenSSL >= 1.1.0 C:>cd openssl C:>perl Configure VC-WIN32 C:>nmake C:>nmake test C:>cd .. Apache 2 This step is only required for building the server dso modules. ### FIXME Apache 2.2 or greater required. Old build instructions for VC6. C:>set APACHEDIR=C:\Program Files\Apache Group\Apache2 C:>msdev httpd-2.0.58\apache.dsw /MAKE "BuildBin - Win32 Release" APR If you downloaded APR / APR-UTIL / APR_ICONV by source, you will have to build these libraries first. Building these libraries on Windows is straight forward and in most cases as simple as issuing these two commands: C:>nmake -f Makefile.win C:>nmake -f Makefile.win install Please refer to the build instructions provided by the library source for actual build instructions. ZLib If you downloaded the zlib source, you will have to build ZLib first. Building ZLib using Visual Studio should be quite simple. Just open the appropriate solution and build the project zlibstat using the IDE. Please refer to the build instructions provided by the library source for actual build instructions. Note that you'd make sure to define ZLIB_WINAPI in the ZLib config header and move the lib-file into the zlib root-directory. Please note that you MUST NOT build ZLib with the included assembler optimized code. It is known to be buggy, see for example the discussion https://svn.haxx.se/dev/archive-2013-10/0109.shtml. This means that you must not define ASMV or ASMINF. Note that the VS projects in contrib\visualstudio define these in the Debug configuration. Apache Serf ### Section about Apache Serf might be required/useful to add. ### scons is required too and Apache Serf needs to be configured prior to ### be able to build Subversion using: ### scons APR=[PATH_TO_APR] APU=[PATH_TO_APU] OPENSSL=[PATH_TO_OPENSSL] ### ZLIB=[PATH_TO_ZLIB] PREFIX=[PATH_TO_SERF_DEST] ### scons check ### scons install Subversion Things to note: * If you don't want to build mod_dav_svn, omit the --with-httpd option. The zip file source distribution contains apr, apr-util and apr-iconv in the default build location. If you have downloaded the apr files yourself you will have to tell the generator where to find the APR libraries; the options are --with-apr, --with-apr-util and --with-apr-iconv. * If you would like a debug build substitute Debug for Release in the msbuild command. * There have been rumors that Subversion on Win32 can be built using the latest cygwin, you probably don't want the zip file source distribution though. ymmv. * You will also have to distribute the C runtime dll with the binaries. Also, since Apache/APR do not provide .vcproj files, you will need to convert the Apache/APR .dsp files to .vcproj files with Visual Studio before building -- just open the Apache .dsw file and answer 'Yes To All' when the conversion dialog pops up, or you can open the individual .dsp files and convert them one at a time. The Apache/APR projects required by Subversion are: apr-util\libaprutil.dsp, apr\libapr.dsp, apr-iconv\libapriconv.dsp, apr-util\xml\expat\lib\xml.dsp, apr-iconv\ccs\libapriconv_ccs_modules.dsp, and apr-iconv\ces\libapriconv_ces_modules.dsp. * If the server dso modules are being built and tested Apache must not be running or the copy of the dso modules will fail. C:>cd src-%DIR% If Apache 2 has been built and the server modules are required then gen-make.py will already have been run. If the source is from the zip file, Apache 2 has not been built so gen-make.py must be run: C:>python gen-make.py --vsnet-version=20xx --with-berkeley-db=db4-win32 --with-openssl=..\openssl --with-zlib=..\zlib --with-libintl=..\svn-win32-libintl Then build subversion: C:>msbuild subversion_vcnet.sln /t:__MORE__ /p:Configuration=Release C:>cd .. The binaries have now been built. E.5 Packaging the binaries You now need to copy the binaries ready to make the release zip file. You also need to do this to run the tests as the new binaries need to be in your path. You can use the build/win32/make_dist.py script in the Subversion source directory to do that. [TBD: Describe how to do this. Note dependencies on zip, jar, doxygen.] E.6 Testing the Binaries [TBD: It's been a long, long while since it was necessary to move binaries around for testing. win-tests.py does that automagically. Fix this section accordingly, and probably reorder, putting the packaging at the end.] The build process creates the binary test programs but it does not copy the client tests into the release test area. C:>cd src-%DIR% C:>mkdir Release\subversion\tests\cmdline C:>xcopy /S /Y subversion\tests\cmdline Release\subversion\tests\cmdline If the server dso modules have been built then copy the dso files and dlls into the Apache modules directory. C:>copy Release\subversion\mod_dav_svn\mod_dav_svn.so "%APACHEDIR%"\modules C:>copy Release\subversion\mod_authz_svn\mod_authz_svn.so "%APACHEDIR%"\modules C:>copy svn-win32-%VER%\bin\intl.dll "%APACHEDIR%\bin" C:>copy svn-win32-%VER%\bin\iconv.dll "%APACHEDIR%\bin" C:>copy svn-win32-%VER%\bin\libdb42.dll "%APACHEDIR%\bin" C:>cd .. Put the svn-win32-trunk\bin directory at the start of your path so you run the newly built binaries and not another version you might have installed. Then run the client tests: C:>PATH=%BUILD_ROOT%\svn-win32-%VER%\bin;%PATH% C:>cd src-%DIR% C:>python win-tests.py -c -r -v If the server dso modules were built configure Apache to use the mod_dav_svn and mod_authz_svn modules by making sure these lines appear uncommented in httpd.conf: LoadModule dav_module modules/mod_dav.so LoadModule dav_fs_module modules/mod_dav_fs.so LoadModule dav_svn_module modules/mod_dav_svn.so LoadModule authz_svn_module modules/mod_authz_svn.so And further down the file add location directives to point to the test repositories. Change the paths to the SVN directory you created (paths should be on one line even if wrapped here): <Location /svn-test-work/repositories> DAV svn SVNParentPath C:/SVN/src-trunk/Release/subversion/tests/cmdline/ svn-test-work/repositories </Location> <Location /svn-test-work/local_tmp/repos> DAV svn SVNPath c:/SVN/src-trunk/Release/subversion/tests/cmdline/ svn-test-work/local_tmp/repos </Location> Then restart Apache and run the tests: C:>python win-tests.py -c -r -v -u http://localhost C:>cd .. F. Building using CMake -------------------- Get the sources, either a release tarball or by checking out the official repository. The CMake build system currently only exists in /trunk and it will be included in the 1.15 release. The process for building on Unix and Windows is the same. $ python gen-make.py -t cmake $ cmake -B out [build options] $ cmake --build out "out" in the commands above is the build directory used by CMake. Build options can be added, for example: $ cmake -B out -DCMAKE_INSTALL_PREFIX=/usr/local/subversion -DSVN_ENABLE_RA_SERF=ON Build options can be listed using: $ cmake -LH Windows tricks: - Modern versions of Microsoft Visual Studio provide support for CMake projects out-of-box, including intellisense, integrated options editor, test explorer, and more. In order to use it for Subversion, open the source directory with Visual Studio, and the configuration should start automatically. For editing the cache (options), do right-click to the CMakeLists.txt file and clicking `CMake Settings for Subversion` will open the editor. After the required settings are configured, hit `F7` in order to build. For more info, check the article bellow: https://learn.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio - There is a useful tool for bootstrapping the dependencies, vcpkg. It provides ports for the most of the Subversion's dependencies, which then could be installed via a single command. To start using it, download the registry from GitHub, bootstrap vcpkg, and install the dependencies: $ git clone https://github.com/microsoft/vcpkg $ cd vcpkg && .\bootstrap-vcpkg.bat -disableMetrics $ .\vcpkg install apr apr-util expat zlib sqlite3 [any other dependency] After this is done, vcpkg can be integrated into CMake by passing the vcpkg toolchain to CMAKE_TOOLCHAIN_FILE option. In order to do it with Visual Studio, open the CMake cache editor as explained in the previous step, and put the following into `CMake toolchain file` field, where VCPKG_ROOT is the path to vcpkg registry: <VCPKG_ROOT>/scripts/buildsystems/vcpkg.cmake III. BUILDING A SUBVERSION SERVER ============================ Subversion has two servers you can choose from: svnserve and Apache. svnserve is a small, lightweight server program that is automatically compiled when you build Subversion's source. Apache is a more heavyweight HTTP server, but tends to have more features. This section primarily focuses on how to build Apache and the accompanying mod_dav_svn server module for it. If you plan to use svnserve instead, jump right to section E for a quick explanation. A. Setting Up Apache Httpd ----------------------- 1. Obtaining and Installing Apache Httpd 2 Subversion tries to compile against the latest released version of Apache httpd 2.2+. The easiest thing for you to do is download a source tarball of the latest release and unpack that. If you have questions about the Apache httpd 2.2 build, please consult the httpd install documentation: https://httpd.apache.org/docs-2.2/install.html At the top of the httpd tree: $ ./buildconf $ ./configure --enable-dav --enable-so --enable-maintainer-mode The first arg says to build mod_dav. The second arg says to enable shared module support which is needed for a typical compile of mod_dav_svn (see below). The third arg says to include debugging information. If you built Subversion with --enable-maintainer-mode, then you should do the same for Apache; there can be problems if one was compiled with debugging and the other without. Note: if you have multiple db versions installed on your system, Apache might link to a different one than Subversion, causing failures when accessing the repository through Apache. To prevent this from happening, you have to tell Apache which db version to use and where to find db. Add --with-dbm=db4 and --with-berkeley-db=/usr/local/BerkeleyDB.4.2 to the configure line. Make sure this is the same db as the one Subversion uses. This note assumes you have installed Berkeley DB 4.2.52 at its default locations. For more info about the db requirement, see section I.C.9. You may also want to include other modules in your build. Add --enable-ssl to turn on SSL support, and --enable-deflate to turn on compression support, for example. Consult the Apache documentation for more details. All instructions below assume you configured Apache to install in its default location, /usr/local/apache2/; substitute appropriately if you chose some other location. Compile and install apache: $ make && make install B. Making and Installing the Subversion Apache Server Module --------------------------------------------------------- Go back into your subversion working copy and run ./autogen.sh if you need to. Then, assuming Apache httpd 2.2 is installed in the standard location, run: $ ./configure Note: do *not* configure subversion with "--disable-shared"! mod_dav_svn *must* be built as a shared library, and it will look for other libsvn_*.so libraries on your system. If you see a warning message that the build of mod_dav_svn is being skipped, this may be because you have Apache httpd 2.x installed in a non-standard location. You can use the "--with-apxs=" option to locate the apxs script: $ ./configure --with-apxs=/usr/local/apache2/bin/apxs Note: it *is* possible to build mod_dav_svn as a static library and link it directly into Apache. Possible, but painful. Stick with the shared library for now; if you can't, then ask. $ rm /usr/local/lib/libsvn* If you have old subversion libraries sitting on your system, libtool will link them instead of the `fresh' ones in your tree. Remove them before building subversion. $ make clean && make && make install After the make install, the Subversion shared libraries are in /usr/local/lib/. mod_dav_svn.so should be installed in /usr/local/libexec/ (or elsewhere, such as /usr/local/apache2/modules/, if you passed --with-apache-libexecdir to configure). Section II.E explains how to build the server on Windows. C. Configuring Apache Httpd for Subversion --------------------------------------- The following section is an abbreviated version of the information in the Subversion Book (https://svnbook.red-bean.com). Please read chapter 6 for more details. The following assumes you have already created a repository. For documentation on how to do that, see README. The following also assumes that you have modified /usr/local/apache2/conf/httpd.conf to reflect your setup. At a minimum you should look at the User, Group and ServerName directives. Full details on setting up apache can be found at: https://httpd.apache.org/docs-2.2/ First, your httpd.conf needs to load the mod_dav_svn module. If you pass --enable-mod-activation to Subversion's configure, 'make install' target should automatically add this line for you. In any case, if Apache HTTPD gives you an error like "Unknown DAV provider: svn", then you may want to verify that this line exists in your httpd.conf: LoadModule dav_svn_module modules/mod_dav_svn.so NOTE: if you built mod_dav as a dynamic module as well, make sure the above line appears after the one that loads mod_dav.so. Next, add this to the *bottom* of your httpd.conf: <Location /svn/repos> DAV svn SVNPath /absolute/path/to/repository </Location> This will give anyone unrestricted access to the repository. If you want limited access, read or write, you add these lines to the Location block: AuthType Basic AuthName "Subversion repository" AuthUserFile /my/svn/user/passwd/file And: a) For a read/write restricted repository: Require valid-user b) For a write restricted repository: <LimitExcept GET PROPFIND OPTIONS REPORT> Require valid-user </LimitExcept> c) For separate restricted read and write access: AuthGroupFile /my/svn/group/file <LimitExcept GET PROPFIND OPTIONS REPORT> Require group svn_committers </LimitExcept> <Limit GET PROPFIND OPTIONS REPORT> Require group svn_committers Require group svn_readers </Limit> ### FIXME Tutorials section refers to old 2.0 docs These are only a few simple examples. For a complete tutorial on Apache access control, please consider taking a look at the tutorials found under "Security" on the following page: https://httpd.apache.org/docs-2.0/misc/tutorials.html In order for 'svn cp' to work (which is actually implemented as a DAV COPY command), mod_dav needs to be able to determine the hostname of the server. A standard way of doing this is to use Apache's ServerName directive to set the server's hostname. Edit your /usr/local/apache2/conf/httpd.conf to include: ServerName svn.myserver.org If you are using virtual hosting through Apache's NameVirtualHost directive, you may need to use the ServerAlias directive to specify additional names that your server is known by. If you have configured mod_deflate to be in the server, you can enable compression support for your repository by adding the following line to your Location block: SetOutputFilter DEFLATE NOTE: If you are unfamiliar with an Apache directive, or not exactly sure about what it does, don't hesitate to look it up in the documentation: https://httpd.apache.org/docs-2.2/mod/directives.html. NOTE: Make sure that the user 'nobody' (or whatever UID the httpd process runs as) has permission to read and write the Berkeley DB files! This is a very common problem. D. Running and Testing ------------------- Fire up apache 2: $ /usr/local/apache2/bin/apachectl stop $ /usr/local/apache2/bin/apachectl start Check /usr/local/apache2/logs/error_log to make sure it started up okay. Try doing a network checkout from the repository: $ svn co http://localhost/svn/repos wc The most common reason this might fail is permission problems reading the repository db files. If the checkout fails, make sure that the httpd process has permission to read and write to the repository. You can see all of mod_dav_svn's complaints in the Apache error logfile, /usr/local/apache2/logs/error_log. To run the regression test suite for networked Subversion, see the instructions in subversion/tests/cmdline/README. For advice about tracing problems, see "Debugging the server" in https://subversion.apache.org/docs/community-guide/. E. Alternative: 'svnserve' and ra_svn ----------------------------------- An alternative network layer is libsvn_ra_svn (on the client side) and the 'svnserve' process on the server. This is a simple network layer that speaks a custom protocol over plain TCP (documented in libsvn_ra_svn/protocol): $ svnserve -d # becomes a background daemon $ svn checkout svn://localhost/usr/local/svn/repository You can use the "-r" option to svnserve to set a logical root for repositories, and the "-R" option to restrict connections to read-only access. ("Read-only" is a logical term here; svnserve still needs write access to the database in this mode, but will not allow commits or revprop changes.) 'svnserve' has built-in CRAM-MD5 authentication (so you can use non-system accounts), and can also be tunneled over SSH (so you can use existing system accounts). It's also capable of using Cyrus SASL if libsasl2 is detected at ./configure time. Please read chapter 6 in the Subversion Book (https://svnbook.red-bean.com) for details on these features. IV. PROGRAMMING LANGUAGE BINDINGS (PYTHON, PERL, RUBY, JAVA) ======================================================== For Python, Perl and Ruby bindings, see the file ./subversion/bindings/swig/INSTALL For Java bindings, see the file ./subversion/bindings/javahl/README
最新发布
06-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值