January 20, 2011

Implement Form Based Authentication in MOSS 2007

oI have came so far travelling sharepoint ship. But still did not know how to implement form based authentication in MOSS(SP2007). So i decided to give it a try.
There are so many blogs which explain implementing form based authentication, but still i faced some problem following them. So here i am explaining it step to step

Requirment = You must have
1. MOSS 2007
2. SQL Server 20005/2008
3. .Net framework(obviously it will be there, if you have above two component)

Now let us start,

1. In this article, we will be using the SQL Server membership provider to authenticate users, but you can use any membership provider that you so choose.

Before you can use the SQL Server membership provider, you have to set up the database that the provider uses to store member and role information. Microsoft ships a handy tool named the ASP.NET SQL Server Setup Wizard along with the .NET Framework, which will guide you through the process of creating the table structure and stored procedures required for the provider. You can launch the wizard by running aspnet_regsql.exe from the .NET Framework folder, which is normally found in the following location:

\Microsoft.NET\Framework\\aspnet_regsql.exe

C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe

When you launch the wizard, the "Welcome" screen appears and tells you all sorts of useful things about what the wizard does and the command line parameters you can use to get more options. It makes for great reading. When you've satisfied your literary pallet, click the Next button to display the "Select a Setup Option" screen (Figure 1).





Figure 1 – ASP.NET SQL Server Setup Wizard – Select a Setup Option screen
From the "Select a Setup Option" screen, choose the "Configure SQL Server for application services" option button. This lets the wizard know you want to add new tables and stored procedures to a membership database. You can also use the wizard to remove the table structure and delete all data in the database, but we don't need to deal with that right now. If you accidentally add the structure to the wrong dataset, you may have to deal with it later. Click "Next" to move to the "Select the Server and Database" screen (Figure 2).




Figure 2 – ASP.NET SQL Server Setup Wizard – Select the Server and Database screen

Enter the name of your database server in the Server textbox to let the wizard know which SQL Server it needs to access. Then enter or select a database name in the Database combo box. The combo box displays a drop down containing a list of existing databases. If you want to add the tables and stored procedures for the provider to an existing database, select the database from the list. If you want to create a new database, then just type the name of the new database directly in the combo box and the wizard will create the database automatically. You may also need to enter SQL Server authentication credentials if you connect to the database using SQL Server authentication instead of Windows authentication. These credentials are not used outside of the wizard, so it won't affect your SharePoint configuration one way or the other. Click the Next button to continue to the "Confirm Your Settings" screen.

The "Confirm Your Settings" screen displays a summary of the epoch-defining choices you've made thus far in the wizard. In other words, the server and database name. If you're feeling hesitant about either, then this is your chance to back out. When you've got your courage built up, click the Next button.

In about a second, or about one and half seconds if you're using a Virtual PC image (like me), the wizard creates all of the tables and stored procedures required by the membership provider. If it takes longer than that, you've entered a setting incorrectly and the wizard is waiting to time out (or you have a really slow machine). The wizard then displays a final status screen indicating success or failure. If the wizard fails, it details the reasons why so you can fix the problem. There are only six settings in the entire wizard (if you count option buttons as "settings") so you should have a sporting chance at troubleshooting the problem. The success screen just tells you that everything worked and to click the Finish button.

At this point, the database you selected is populated with the proper table structure and stored procedures required by the provider, so now you can add a user to the membership database. Refer Below Figure


Now add some users to the databse using inbuilt STORED PROCEDURE

e.g

declare @now datetime
set @now= GETDATE()
exec aspnet_Membership_CreateUser 'appName', 'userName','password','','email@something.com','','',1,@now,@now,0,0,null

Now create role using stored procedure

e.g.
declare @now datetime
set @now= GETDATE()
exec aspnet_Roles_CreateRole 'appName', 'roleName'

Now add above created user to the role above created
e.g.
declare @now datetime
set @now= GETDATE()
exec aspnet_UsersInRoles_AddUsersToRoles 'appName','userName', 'roleName',@now

So now we are done with database membership provider, you can add any number of user to this databse to have access to the site

There are some other methods also for adding membership data provider like. creating asp.net web application and then adding aso web configuration, but i relly like it (yes i know it will be easier to make entries to databse). So i willng ahead.

Now

Enable Forms Authentication on the SharePoint site

You enable Forms Authentication for SharePoint sites using SharePoint Central Administration. Navigate to the Central Admin site using your browser. You can normally find a shortcut to the site in the Start menu:

Programs > Office Server 2007 > SharePoint 3.0 Central Administration Once the Central Administration Home page is loaded, click on the Application Management link on the left hand navigation bar. You are taken to the Application Management page, which displays a variety of administration links. Click on the Authentication Providers link under the Application Security section on the right hand column of the page. The Authentication Providers page loads, as shown in Figure 3.



Figure 3 – Authentication Providers screen

When working in SharePoint Central Administration website, make sure the correct Web Application is selected when you are about to change configuration settings; otherwise you'll be applying changes to the wrong site. There's a small light-blue bar in the content pane of the page that displays the current Web Application URL. Make sure it's the web application on which you want to enable Forms authentication. If it's not, click the little down-arrow next to the URL and choose "Change Web Application" from the drop down list. SharePoint then displays a popup window with a list of web application from which you may choose.

Once you have the right web application selected, the Authentication Providers page displays a list of the zones in that application. Click on the name of the zone in which you want to enable Forms authentication. The Edit Authentication page displays (Figure 4).


In the Edit Authentication page, choose the "Forms" option for Authentication Type. The page refreshes and displays the Membership provider and Role manager sections. Enter DemoMembershipProvider in the Membership provider name textbox, and DemoRoleProvider in the Role manager name textbox, then click the Save button. You are taken back to the Authentication Providers screen, but your zone should now say DemoMembershipProvider under the Membership Provider Name column. Forms authentication is now enabled on the site.

Now, 

Open web.cofig file of central administration.

Make below shown highlighted  entry after </sharepoint> tag


 
Next is , make entries immediatly after <system.web>



Now make similar entries in the web.config file of the web application where you have enabled form based authentication.

IMPORTNAT: Please verify that values you put in figure 4 for "Membership provider name" and "Role manager name" matches with those values put in web.config files.

Now just browse to your site collection where you have enabled FBA.


Put here the user name which you had added in SQL databse.

You will be presented with your site collection.

Feel free to ask, if you did not get any step.
!!!. Cheeeers........

1 comment: