设为首页 收藏本站
查看: 814|回复: 0

[经验分享] SharePoint 2010 Claims-Based Authentication(MemberShip Provider)

[复制链接]
累计签到:21 天
连续签到:1 天
发表于 2015-9-27 07:34:49 | 显示全部楼层 |阅读模式
Create a New SharePoint Application
  Instead of screwing with your existing application, let’s create a new one so we can safely play.  Open Central Administration (make sure that you are running Internet Explorer as Administrator or you will have permissions problems here) and click the “Manage web applications” link.
DSC0000.png
  On the resulting screen, click the ribbon toolbar button to create a new web application.
DSC0001.png
  That will pop open a modal window.  In that dialog, choose “Claims Based Authentication” for the Authentication type.  By default, SharePoint will create a new IIS web site for you.  You can leave the default, or you can rename it as I did to “SharePoint – FBA Demo”.  What’s important to remember here is the port number being used, either something you choose or something SharePoint defaults to.  I accepted the default of “34513”.
DSC0002.png
  Scroll down a bit, and configure the forms based authentication settings.  Check the “Enable Forms Based Authentication” box, and configure the membership provider name as “FBAMembership” and the role provider name as “FBARoles”.
DSC0003.png
  The last thing I configured was to change the identify of the application pool to Network Service.
DSC0004.png
  Scroll to the bottom and click OK, and SharePoint will churn for a moment to create a new application for you (it took about a minute and 15 seconds on my machine to complete).  
  Once complete, you are greeted with the following:
DSC0005.png
  Since you are using Windows authentication in addition to Forms Based Authentication, it’s OK to click the link to create the site collection.  I created a new Team site called “FBA Demo”, specifying a Windows account as the primary administrator.
DSC0006.png

Creating the Membership Store and Adding Users
  You have now created a new application, a site collection, and a top-level site.  The next step is to configure the new application to use FBA.  My friend Ali Mazaheri posted the configuration details on his blog post, “Configuring FBA in SharePoint Server 2010”, but I am sure he won’t mind a second explanation of the settings.  

Create the Database
  Open the Visual Studio 2010 Command Prompt from the start menu and type “aspnet_regsql”.  This will open a new application that lets you create and configure a SQL Server database to use ASP.NET application services.  I accepted all defaults and it created a new database called “aspnetdb” with the following table structure.
DSC0007.png
  The next thing you need to do is to add some users to the database to test your solution.  The easiest way to do this is by leveraging Visual Studio.  Create a new project in Visual Studio 2010 using the &#8220;ASP.NET Empty Web Site&#8221; project template.  Edit the web.config file.  There is an empty element, &#8220;<connectionStrings/>&#8221; that you will edit:
  <connectionStrings>
<clear/>
<add name="AspNetSqlProvider"
connectionString="data source=kirke1; Integrated Security=SSPI;Initial Catalog=aspnetdb;"
providerName="System.Data.SqlClient" />
</connectionStrings>
  Of course, use your own connection string here :)  The next step is to configure a Membership and Role provider.  Right above the </system.web> end tag, add the following markup.  I am using the names &#8220;AspNetSqlMembershipProvider&#8221; and &#8220;AspNetSqlRoleProvider&#8221; here, later when we configure SharePoint I choose the name &#8220;FBAMembership&#8221; and &#8220;FBARoles&#8221;.  The provider&#8217;s name is not important, what is important is the database it points to via the connectionStringName and the applicationName.


   1:  <membership defaultProvider="AspNetSqlMembershipProvider">   2:    <providers>   3:      <clear />   4:      <add name="AspNetSqlMembershipProvider"   5:            connectionStringName="AspNetSqlProvider"                  6:            applicationName="/"   7:            type="System.Web.Security.SqlMembershipProvider, System.Web,    8:            Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />   9:    </providers>  10:  </membership>  11:  <roleManager defaultProvider="AspNetSqlRoleProvider">  12:    <providers>  13:      <clear/>  14:      <add name="AspNetSqlRoleProvider"  15:            connectionStringName="AspNetSqlProvider"  16:            applicationName="/"  17:            description="Stores and retrieves roles data from the local Microsoft SQL Server database"                 18:            type="System.Web.Security.SqlRoleProvider, System.Web,   19:            Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />  20:     21:    </providers>  22:  </roleManager>  NOTE: Remove the line break in the 5-part name for the type attribute in lines 7 and 17.  These are there only for readability.
  What you have done here is told ASP.NET how to authenticate users via membership, and how to authorize them using roles.  For more information on ASP.NET membership, see &#8220;Introduction to Membership&#8221; in the MSDN Library.   Since these providers have been configured, we can now use a tool in Visual Studio that will make it easy for us to add users.  From the menu bar in Visual Studio select &#8220;Website / ASP.NET Configuration&#8221; to bring up the Web Site Administration Tool.

Using the Web Site Administration Tool to Add Users
  By default, your application is configured to use Windows Authentication, we need to change it to use forms authentication.  Click the security tab and choose &#8220;From the internet&#8221; and save your changes.
DSC0008.png
  Behind the scenes, this makes a change in web.config to set the configuration/system.web/authentication node to &#8220;Forms&#8221;, telling ASP.NET we will use Forms Based Authentication.  ASP.NET will see the providers that we have configured in web.config and use them when authenticating users, adding new users, verifying roles, and other membership-related activities.  
  On the security tab, click the &#8220;Enable Roles&#8221; link.  Then click &#8220;Create or Manage Roles&#8221;.  Add a few roles, I chose &#8220;FBAAdministrators&#8221;, &#8220;FBAOwners&#8221;, and &#8220;FBAUsers&#8221;.
DSC0009.png
  Click the &#8220;Create user&#8221; link to add a new user to the database.  Create a user &#8220;adminfba&#8221; and assign the user to the &#8220;FBAAdministrators&#8221; role.
DSC00010.png
  You can create other users and assign them to the various roles.  I created a user &#8220;demofba&#8221; that is in the &#8220;FBAOwners&#8221; role, and &#8220;kirkfba&#8221; that is in the &#8220;FBAUsers&#8221; role.
DSC00011.png
  Note that ASP.NET uses default settings for the membership provider for things like required password length, required non-alphanumeric characters, and the password format.  
DSC00012.png
  The whole reason that we are going through this is really because the password is not stored in the database as clear text, but rather as a hashed value.  This is stored within the aspnet_Membership table, which also contain the salt value used in the hash.  Using the Web Site Administration Tool saved us quite a bit of work.
DSC00013.png
  If you are new to ASP.NET Membership, I strongly recommend you watch &#8220;Understanding ASP.NET Memberships&#8221;.  This is a free 23-minute video that explains a lot of this stuff.
  Now that we have created the Membership database, we can use the same database for our SharePoint application.  We only need to use the same Membership configuration settings that we used in our temporary ASP.NET application.

Granting Access to SQL Server
  When we created the SharePoint web application, we used the Network Service account for the application pool identity.  This is the account that will actually call into SQL Server for authentication and authorization.  I used Network Service here for a quick example, but you probably are going to use some other service account in a real environment.  
  Whatever identity you chose for the application pool needs to have access to SQL Server.  Add a login for SQL Server for the account used in the application pool.
DSC00014.png
  Next, grant permissions to that user by adding them to the appropriate roles.  I added the user to the aspnet_Membership_BasicAccess and  aspnet_Roles_BasicAccess roles.
DSC00015.png
  Remember to do this, otherwise you will receive errors that the security token service is not activated.

Adding Forms Based Membership Providers to SharePoint
  This next section entails 3 basic steps: edit the web.config for your application, edit web.config for Central Administration, and edit web.config for the secure token service application.  We will add the same settings that we used above in the temporary ASP.NET application, with some slight variances.  We could edit this stuff by hand, but we will show how to use the IIS Manager tool for IIS 7 to make this easier and less error-prone.

Add the Connection Strings
  Open the Internet Information Services Manager MMC snap-in.  Expand the &#8220;Sites&#8221; node to reveal the web application we created called &#8220;SharePoint &#8211; FBA Demo&#8221;.
DSC00016.png
  Double-click the Connection Strings feature, and under Actions choose Add.  Add a new connection string called AspNetSqlProvider (this is case-sensitive) and click OK.
DSC00017.png
  Behind the scenes, that created a new connection string in the following file:
  C:\inetpub\wwwroot\wss\VirtualDirectories\34513\web.config
  The new entry will look like this:


   1:    <connectionStrings>   2:      <add name="AspNetSqlProvider"   3:           connectionString="data source=kirke1; Integrated Security=SSPI;Initial Catalog=aspnetdb;"   4:           providerName="System.Data.SqlClient" />   5:    </connectionStrings>  Now, click on the &#8220;SharePoint Central Administration v4&#8221; node in IIS Manager.
DSC00018.png
  Double-click on Connection Strings and add a new connection string like you did in the previous step, making sure that you are adding the connection string to the Central Administration application this time.
DSC00019.png
  Now, expand the &#8220;SharePoint Web Services&#8221; node in IIS Manager and choose the &#8220;SecurityTokenServiceApplication&#8221; node.  Double-click on the connection strings feature and add a connection string just like before.
DSC00020.png

Add Membership and Role Providers
  In the IIS Manager, click on the &#8220;SharePoint &#8211; FBA Demo&#8221; node again to reveal the list of features for the web application.  Double-click on the &#8220;Providers&#8221; feature.
  Add a new role provider called &#8220;FBARoles&#8221;.  Specify the type as &#8220;SqlRoleProvider&#8221;, the ApplicationName as &#8220;/&#8221;, and the connection string name as &#8220;AspNetSqlProvider&#8221; (available in a drop-down to reduce the likelihood of fat-fingering this).
DSC00021.png
  Add a new membership provider called &#8220;FBAMembership&#8221;.  The type is SqlMembershipProvider, connection string name is &#8220;AspNetSqlProvider&#8221;, and the application name is &#8220;/&#8221;.
DSC00022.png   
  The result looks like this:
<membership defaultProvider="i">
<providers>
<add name="i"
type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthMembershipProvider, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
<add name="FBAMembership"
type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
applicationName="/"
connectionStringName="AspNetSqlProvider"
enablePasswordReset="false"
enablePasswordRetrieval="false"
passwordFormat="Clear"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false" />
</providers>
</membership>
<roleManager defaultProvider="c"
enabled="true"
cacheRolesInCookie="false">
<providers>
<add name="c"
type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthRoleProvider, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
<add name="FBARoles"
type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
applicationName="/"
connectionStringName="AspNetSqlProvider" />
</providers>
</roleManager>
  Click the &#8220;SharePoint Central Administration v4&#8221; node and make the same edits to its configuration, adding the FBAMembership and FBARoles providers as described above.
  Expand the &#8220;SharePoint Web Services&#8221; node, select the &#8220;SecurityTokenServiceApplication&#8221; node, and add the FBAMembership and FBARoles providers.

Edit Web.Config for Central Administration
  In the previous section, we added configuration for connection string, membership, and roles to our web application.  We also need to add these settings for Central Administration so that we can add our forms-based authentication users as site collection owners (among other settings).  
  We need to make a few small tweaks to the configuration for Central Administration because there isn&#8217;t a way (that I could find, anyway) to do this using the MMC console:


  • The defaultProvider for the role section must be AspNetWindowsTokenRoleProvider.
  • The defaultProvider for the membership section must be our new membership provider, &#8220;FBAMembership&#8221;.
<roleManager defaultProvider="AspNetWindowsTokenRoleProvider"
enabled="true">
<providers>
<clear />
<add applicationName="/"
name="AspNetWindowsTokenRoleProvider"
type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add name="FBARoles"
type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
applicationName="/"
connectionStringName="AspNetSqlProvider" />
</providers>
</roleManager>
<membership defaultProvider="FBAMembership">
<providers>
<clear />
<add name="FBAMembership"
type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
applicationName="/"
connectionStringName="AspNetSqlProvider"
enablePasswordReset="false"
enablePasswordRetrieval="false"
passwordFormat="Clear"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false" />
</providers>
</membership>
  While we are editing the web.config for Central Administration, there&#8217;s one more thing that we need to be sure to add.  We need to enable wildcard searches for our users when using the People Picker control.  This section is located under configuration/SharePoint/PeoplePickerWildcards.
    <PeoplePickerWildcards>
<clear />
<add key="FBAMembership"
value="%" />
</PeoplePickerWildcards>
Edit Web.Config for the Secure Token Service Application
  Just like we did with Central Administration, we need to set the default providers for the Secure Token Service Application.  Open the web.config file at:
  C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\WebServices\SecurityToken\web.config
  You will need to add your connectionStrings section and a web.config section.  A partial listing showing the configuration that needs to be added:
<membership defaultProvider="FBAMembership">
<providers>
<add name="FBAMembership"
connectionStringName="AspNetSqlProvider"
applicationName ="/"            
type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0,  Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</membership>
<roleManager enabled="true"
defaultProvider="FBARoles">
<providers>
<add name="FBARoles"
connectionStringName="AspNetSqlProvider"
applicationName="/"                          
type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</roleManager>
Verifying Our Changes
  Open SharePoint Central Administration.  Under Application Management click &#8220;Manage web applications" and click the &#8220;SharePoint &#8211; FBA Demo&#8221; item. That will light up the &#8220;User Policy&#8221; ribbon toolbar item.  Click the User Policy ribbon button.
DSC00023.png
  Click Add Users.  You are then asked what zone to configure users for, choose &#8220;Default&#8221; and click Next.  In the Choose Users section, you should be able to enter &#8220;adminfba&#8221; and the name will resolve.  Alternatively, you can click the phone book icon to search for users in the address book.  Enter &#8220;a&#8221; and you will see something like the following, showing our Forms Auth user.
DSC00024.png
  Select the adminfba user and give that user full control.
DSC00025.png
  The result in the policy window shows our user with the user name &#8220;i:0#.f|fbamembership|adminfba&#8221;.
DSC00026.png
  Open up your new web site, you will see the following screen:
DSC00027.png
  Choose Forms Authentication, then sign in as adminfba.
DSC00028.png
  You are now logged into your site as adminfba, with site administrator privileges (note the Site Actions menu contains privileged capabilities).
DSC00029.png
  We gave the adminfba user full control of the application, so we can set things like security groups up.  You can add the FBAAdministrators group into the &#8220;FBA Demo Owners&#8221; group as site owners.
DSC00030.png
  You can also add the FBAUsers group into the &#8220;FBA Demo Visitors&#8221; group.
DSC00031.png
  Once you have done that, log out and log back in as &#8220;kirkfba&#8221;, recalling that &#8220;kirkfba&#8221; is in the FBAUsers role, which we added to the &#8220;FBA Demo Visitors&#8221; group in SharePoint.  As you can see, this user has limited capabilities, such as less capabilities in the &#8220;Site Actions&#8221; menu.
DSC00032.png

Wrapping It Up
  There is a lot of verbiage and quite a few screen shots in this post.  If you think I missed a step or need to elaborate further, please leave a comment!  As it turns out, there really is not that much work to this after you walk through it the first time.  The steps are:


  • Create the database using aspnet_regsql
  • Add users and roles using the Web Site Administration Tool
  • Add connection strings in the web.config for:

    • Your application
    • Central Administration
    • Secure Token Service Application

  • Add membership and role providers for:

    • Your application
    • Central Administration
    • Secure Token Service Application

  • Edit web.config for Central Administration

    • Set the default provider for roles as AspNetWindowsTokenRoleProvider
    • Set the default provider for membership as your new membership provider
    • Add the PeoplePickerWildcards entry

  • Edit web.config for the Secure Token Service Application

    • Set the default provider for roles as your provider
    • Set the default provider for membership as your provider

  • Add the FBA administration user to Central Administration
  • Add FBA roles to SharePoint groups
  Reference :http://blogs.msdn.com/b/kaevans/archive/2010/07/09/sql-server-provider-for-claims-based-authentication-in-sharepoint-2010.aspx

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-119240-1-1.html 上篇帖子: 《Office SharePoint Server2007开发入门指南》预订! 下篇帖子: sharepoint 文档 下载申请流程控制
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表