单一登录: Active Directory联合身份验证服务开发简介(6)

2012-03-11
浏览
导读:联合身份验证服务代理 安装 ADFS 联合身份验证服务之后,您会在 IIS 管理器中看到一个新的 Web 应用程序,叫做adfs 。在它之下,您还可以看到名为fs和ls的两个子目录,分别代表联合身份验证服务和登录服务 。实际上

联合身份验证服务代理

安装 ADFS 联合身份验证服务之后,您会在 IIS 管理器中看到一个新的 Web 应用程序,叫做“adfs ”。在它之下,您还可以看到名为“fs”和“ls”的两个子目录,分别代表联合身份验证服务和登录服务 。实际上,登录服务仅仅是基于浏览器的 ADFS 前端;如果您仔细浏览 ls 目录的话,就会看到一组 ASPX 页面(顺便说一下,您也可以自定义修改这些页面,所以,花点时间仔细看看它们还是值得的)。 在联合身份验证登录的过程中,浏览器就是被重定向到这里的。在已经发布的有关 ADFS 的文档中,我还 没有发现“登录服务”这个术语,但只要看一下代码,就能知道这个术语的含义。在 fs 目录下,您将会 看到一个名为 FederationServerService.asmx 的文件,这就是作为 ADFS 后端的 Web 服务,技术上也 叫做安全令牌服务 (STS)。

之所以将这些分开,是因为前端(登录服务)的主机可以位于外围网络(通常称为 DMZ),而且可以 通过位于内部网络的 ASMX Web 服务与联合身份验证服务的后端进行通信。在这种配置下,这个前端也叫 做联合身份验证服务代理。

不管您的管理员有没有通过在单独的计算机上使用代理来分割联合身份验证服务,这对您编写应用程 序没什么太大的影响,但是,ADFS 本身的设计能够友好地支持 DMZ,了解这一点还是有好处的。

ADFS — 激活您的 Web 应用程序

如果您承担着构建一个支持 ADFS 登录的 Web 应用程序的任务,那么您需要做这样几件事。您需要掌 握如何设置 web.config 文件来加载并配置 ADFS Web 代理。图 5 显示的是我在本文示例应用程序中所 使用的 web.config 文件。

Figure 5 Sample Web.config

<configuration>
  <configSections>
    <sectionGroup name="system.web">
      <section name="websso" type=
        "System.Web.Security.SingleSignOn.WebSsoConfigurationHandler,
         System.Web.Security.SingleSignOn, Version=1.0.0.0,
         Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null"/>
    </sectionGroup>
  </configSections>
  <system.web>
    <!-- we’re not using any of the standard ASP.NET auth techniques,
         we’re using ADFS! -->
    <authentication mode="None" />
    <customErrors mode="Off"/>
    <sessionState mode="Off" />
    <!-- pull in ADFS assemblies -->
    <compilation debug=‘true’ defaultLanguage=‘c#’>
      <assemblies>
        <add assembly="System.Web.Security.SingleSignOn, Version=1.0.0.0,
                       Culture=neutral, PublicKeyToken=31bf3856ad364e35,
                       Custom=null"/>
        <add assembly="System.Web.Security.SingleSignOn.ClaimTransforms,
                       Version=1.0.0.0, Culture=neutral,
                       PublicKeyToken=31bf3856ad364e35, Custom=null"/>
      </assemblies>
    </compilation>
    <!-- pull in the module containing the ADFS web agent -->
    <httpModules>
      <add name="ADFS Web Agent" type=
          "System.Web.Security.SingleSignOn.WebSsoAuthenticationModule,
           System.Web.Security.SingleSignOn, Version=1.0.0.0,
           Culture=neutral, PublicKeyToken=31bf3856ad364e35,
           Custom=null" />
    </httpModules>
    <!-- the web agent looks here for its configuration -->
    <websso>
      <authenticationrequired />
      <eventloglevel>55</eventloglevel>
      <auditsuccess>2</auditsuccess>
      <urls>
        <returnurl>https://resource.local/web/</returnurl>
      </urls>
      <cookies writecookies="true">
        <path>/web</path>
        <lifetime>240</lifetime>
      </cookies>
      <fs>https://resource.local/adfs/fs/federationserverservice.asmx</fs>
    </websso>
  </system.web>
  <system.diagnostics>
    <switches>
      <!-- enables full debug logging -->
      <add name="WebSsoDebugLevel" value="255" />
    </switches>
    <trace autoflush="true" indentsize="3">
      <listeners>
        <!-- either create a c:\logs directory and grant Network Service
             permission to write to it, or remove this listener -->
        <add name="MyListener" type=
            "System.Web.Security.SingleSignOn.
                 BoundedSizeLogFileTraceListener,
             System.Web.Security.SingleSignOn, Version=1.0.0.0,
             Culture=neutral, PublicKeyToken=31bf3856ad364e35,
             Custom=null"
             initializeData="c:\logs\webagent.log" />
      </listeners>
    </trace>
  </system.diagnostics>
</configuration>

ASP.NET 2.0: 执行Web标准以便更加易于访问

ASP.NET 2.0在SQL Server 2005上自定义分页

ASP.NET 2.0(C#)(8) - DataSourceControl(

ASP.NET 2.0(C#)(7) - Profile(存储用户配

ASP.NET 2.0(C#)(6) - Membership&Role