100165432.htm

来自「C#高级编程(第三版),顶死你们。。 。up」· HTM 代码 · 共 75 行

HTM
75
字号


<!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><title>
	
        14.3.1  Principal
</title></head>
<body>
    <div class="area">

        

        <div class="col1">
            <div class="lineBlue">
            </div>
            <!-- title -->
            <div class="arcTitle">
                <h1>
                    <a href="../16">
                        C#高级编程(第3版)【全文连载】
                    </a>
                </h1>
                <div style="text-align: center; font-size: 15px">
                    <a href="100165432.htm">
                        14.3.1  Principal
                    </a>
                </div>
                <div style="text-align: center; font-size: 15px">
                    <a class="url" href="../../default.htm">http://book.csdn.net/</a>
                    2006-10-13 14:41:00
                </div>
                <div style="margin: 0px auto; width: 700px; border: solid 1px #0b5f98;">
                    <div style="float: left; width: 16px; background-color: #0b5f98; color: White; padding: 1px;">
                        图书导读
                    </div>
                    <div style="float: right; width: 670px; text-align: left; line-height: 16pt; padding-left: 2px">
                        <!--导读-->
                        <h1 id="divCurrentNode" style="color: #b83507; width: 100%; text-align: left; font-size: 12px; padding-left: 2px">当前章节:<a href='100165432.htm'><font color='red'>14.3.1  Principal</font></a></h1>
                        <div id="divRelateNode" style="padding-left: 2px">
                        <div style='float:left;width:49%'>·<a href='100165429.htm'>14.2.6  创建代码访问权限</a></div><div style='float:right;width:49%'>·<a href='100165430.htm'>14.2.7  声明的安全性</a></div><div style='float:left;width:49%'>·<a href='100165431.htm'>14.3  基于角色的安全性</a></div><div style='float:right;width:49%'>·<a href='100165433.htm'>14.3.2  Windows Principal</a></div><div style='float:left;width:49%'>·<a href='100165434.htm'>14.3.3  角色</a></div><div style='float:right;width:49%'>·<a href='100165435.htm'>14.3.4  声明基于角色的安全性</a></div></div>
                    </div>
                </div>
                </div>
            <!-- main -->
            <div id="main">
                <div id="text"> <link href="css.css" rel="stylesheet" type="text/css" /><h3 style="MARGIN-TOP: 8.15pt; MARGIN-LEFT: 0cm; MARGIN-RIGHT: 0cm; FTEL: 8.15pt"><a ftel="_Toc507815612"><span lang="EN-US">14.3.1&nbsp; Principal</span></a></h3>
<p class="MsoNormal"><span lang="EN-US" style="COLOR: black">.NET</span><span style="COLOR: black; FONT-FAMILY: 宋体">使当前的线程很容易访问应用程序的用户,当前的线程把应用程序用户作为</span><span lang="EN-US" style="COLOR: black">Principal(</span><span style="COLOR: black; FONT-FAMILY: 宋体">身份</span><span lang="EN-US" style="COLOR: black">)</span><span style="COLOR: black; FONT-FAMILY: 宋体">来引用。</span><span lang="EN-US" style="COLOR: black">Principal</span><span style="COLOR: black; FONT-FAMILY: 宋体">是</span><span lang="EN-US" style="COLOR: black">.NET</span><span style="COLOR: black; FONT-FAMILY: 宋体">提供的基于角色的安全性的核心,通过它可以访问用户的身份,该身份通常用于映射下列类型的用户账户:</span></p>
<p class="1" style="MARGIN-LEFT: 37.55pt; FTEL: -16.1pt"><span lang="EN-US">●<span style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="EN-US">Windows</span><span style="FONT-FAMILY: 宋体">账户</span></p>
<p class="1" style="MARGIN-LEFT: 37.55pt; FTEL: -16.1pt"><span lang="EN-US">●<span style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="EN-US">Passport</span><span style="FONT-FAMILY: 宋体">账户</span></p>
<p class="1" style="MARGIN-LEFT: 37.55pt; FTEL: -16.1pt"><span lang="EN-US" style="COLOR: black">●<span style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="EN-US" style="COLOR: black">ASP.NETcookie</span><span style="COLOR: black; FONT-FAMILY: 宋体">已确认用户</span></p>
<p class="MsoNormal"><span style="COLOR: black; FONT-FAMILY: 宋体">在</span><span lang="EN-US" style="COLOR: black">.NET</span><span style="COLOR: black; FONT-FAMILY: 宋体">中,基于角色的安全性的另一个优点是:通过执行</span><span lang="EN-US" style="COLOR: black">IPrincipal</span><span style="COLOR: black; FONT-FAMILY: 宋体">接口,可以创建自己的</span><span lang="EN-US" style="COLOR: black">Principal</span><span style="COLOR: black; FONT-FAMILY: 宋体">。如果不想依赖</span><span lang="EN-US" style="COLOR: black">Windows</span><span style="COLOR: black; FONT-FAMILY: 宋体">验证、</span><span lang="EN-US" style="COLOR: black">Passport</span><span style="COLOR: black; FONT-FAMILY: 宋体">或简单的</span><span lang="EN-US" style="COLOR: black">cookie</span><span style="COLOR: black; FONT-FAMILY: 宋体">验证,可以使用定制的</span><span lang="EN-US" style="COLOR: black">principal</span><span style="COLOR: black; FONT-FAMILY: 宋体">类创建自己的验证策略。</span></p>
<p class="MsoNormal"><span style="COLOR: black; FONT-FAMILY: 宋体">至于对</span><span lang="EN-US" style="COLOR: black">principal</span><span style="COLOR: black; FONT-FAMILY: 宋体">的访问,可以根据它的身份和角色进行安全决定。角色是具有相同安全权限的用户集合,它是用户管理的单元。例如,如果使用</span><span lang="EN-US" style="COLOR: black">Windows</span><span style="COLOR: black; FONT-FAMILY: 宋体">验证策略验证用户,就把</span><span lang="EN-US" style="COLOR: black">WindowsIdentity</span><span style="COLOR: black; FONT-FAMILY: 宋体">类型用作身份。可以使用</span><span lang="EN-US" style="COLOR: black">WindowsIdentity</span><span style="COLOR: black; FONT-FAMILY: 宋体">类型去查明用户是否是某一</span><span lang="EN-US" style="COLOR: black">Windows</span><span style="COLOR: black; FONT-FAMILY: 宋体">用户</span><span style="FONT-FAMILY: 宋体">账<span style="COLOR: black">户组的成员,然后,使用得到的信息决定是否把代码和资源的访问权赋予用户。</span></span></p>
<p class="MsoNormal"><span style="FONT-FAMILY: 宋体">通常,如果以角色</span><span lang="EN-US">(</span><span style="FONT-FAMILY: 宋体">而不是单个用户</span><span lang="EN-US">)</span><span style="FONT-FAMILY: 宋体">为基础对资源和功能进行访问,则安全性的管理就会更加容易。设想有三个方法,对方法的访问都必须进行严格的控制,确保只有被授权的人员才能访问它们。如果应用程序有四个用户,很容易指定哪一个用户可以访问哪一个方法,哪一个用户不能访问哪一个方法。但是,如果将来方法的数目增加到九个,则允许新增用户访问某个方法将需要修改这九个方法中的每一个。更糟糕的是,当用户在公司中的角色改变时,就必须对代码进行改动。如果执行的是使用角色的系统,就可以在角色中添加用户或从角色中删除用户,而不是在应用程序中添加单个用户或从应用程序中删除单个用户。这样做可以大大简化应用程序,至于每一个方法,则可以请求让用户成为某一角色的成员。此外,由于管理员</span><span lang="EN-US">(</span><span style="FONT-FAMILY: 宋体">而不是应用程序的开发人员</span><span lang="EN-US">)</span><span style="FONT-FAMILY: 宋体">可以进行角色的管理,也大大简化了角色的管理。简言之,开发人员应关心的是,让管理员而不是秘书能访问某个方法。</span></p>
<p class="MsoNormal"><span lang="EN-US" style="COLOR: black">.NET</span><span style="COLOR: black; FONT-FAMILY: 宋体">基于角色的安全性建立在</span><span lang="EN-US" style="COLOR: black">MTS</span><span style="COLOR: black; FONT-FAMILY: 宋体">和</span><span lang="EN-US" style="COLOR: black">COM+</span><span style="COLOR: black; FONT-FAMILY: 宋体">提供的安全性之上,</span><span lang="EN-US" style="COLOR: black">.NET</span><span style="COLOR: black; FONT-FAMILY: 宋体">基于角色的安全性还提供了一个灵活的构架,该构架可以对应用程序中需要保护的代码段进行保护。如果</span><span lang="EN-US" style="COLOR: black">COM+</span><span style="COLOR: black; FONT-FAMILY: 宋体">已安装在机器上,其基于角色的安全性将能够与</span><span lang="EN-US" style="COLOR: black">.NET</span><span style="COLOR: black; FONT-FAMILY: 宋体">基于角色的安全性进行相互操作,但是对于</span><span lang="EN-US" style="COLOR: black">.NET</span><span style="COLOR: black; FONT-FAMILY: 宋体">基于角色的安全性而言,</span><span lang="EN-US" style="COLOR: black">COM</span><span style="COLOR: black; FONT-FAMILY: 宋体">并不是必需的。</span></p></div>
                <!-- page -->
                <div class="page" style="text-align: center">
                    <a href="100165431.htm">上一页</a>&nbsp;&nbsp;&nbsp;<a href="index.html">首页</a>&nbsp;&nbsp;&nbsp;<a href="100165433.htm">下一页</a>
                </div>
                <div style="margin: 0px auto; width: 700px; border: solid 1px #0b5f98;">
                    <div style="float: left; width: 16px; background-color: #0b5f98; color: White; padding: 1px;">
                        图书导读
                    </div>
                    <div style="float: right; width: 670px; text-align: left; line-height: 16pt; padding-left: 2px">
                        <!--导读-->
                        <h1 id="divCurrentNode2" style="color: #b83507; width: 100%; text-align: left; font-size: 12px; padding-left: 2px">当前章节:<a href='100165432.htm'><font color='red'>14.3.1  Principal</font></a></h1>
                        <div id="divRealteNod2" style="padding-left: 2px">
                        <div style='float:left;width:49%'>·<a href='100165429.htm'>14.2.6  创建代码访问权限</a></div><div style='float:right;width:49%'>·<a href='100165430.htm'>14.2.7  声明的安全性</a></div><div style='float:left;width:49%'>·<a href='100165431.htm'>14.3  基于角色的安全性</a></div><div style='float:right;width:49%'>·<a href='100165433.htm'>14.3.2  Windows Principal</a></div><div style='float:left;width:49%'>·<a href='100165434.htm'>14.3.3  角色</a></div><div style='float:right;width:49%'>·<a href='100165435.htm'>14.3.4  声明基于角色的安全性</a></div></div>
                    </div>
                </div>
                </div>
        </div>
</body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?