INTRODUCTION
This CaseStudy will helps to implement singe-sign on between multiple asp.net web applications & share point web application based on form authentication.
This is been divided into three parts
Login Page IMPLEMENTATION
Add the below one in the Config Sections Tag
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
Add the below lines immediate after the Config Sections tag end
<loggingConfiguration name="Logging Application Block" tracingEnabled="false"
defaultCategory="General" logWarningsWhenNoCategoriesMatch="false">
<listeners>
<add source="Enterprise Library Logging" formatter="Text Formatter"
log="Application" machineName="SSP" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Formatted EventLog TraceListener" />
<add fileName="c:\Test\rolling.log" footer="----------------------------------------"
formatter="Text Formatter" header="----------------------------------------"
rollFileExistsBehavior="Overwrite" rollInterval="None" rollSizeKB="500"
timeStampPattern="yyyy-MM-dd" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Rolling Flat File Trace Listener" />
</listeners>
<formatters>
<add template="Timestamp: {timestamp}
Message: {message}
Category: {category}
Priority: {priority}
EventId: {eventid}
Severity: {severity}
Title:{title}
Machine: {machine}
Application Domain: {appDomain}
Process Id: {processId}
Process Name: {processName}
Win32 Thread Id: {win32ThreadId}
Thread Name: {threadName}
Extended Properties: {dictionary({key} - {value}
)}"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="SSOApp">
<add name="Rolling Flat File Trace Listener" />
</add>
<add switchValue="All" name="General">
<add name="Formatted EventLog TraceListener" />
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings">
</errors>
</specialSources>
</loggingConfiguration>
Find the appSettings tag in the file and add the below lines in the appSettings Tag,
<add key="DefaultURL" value="http://srvssp.com/TechInvo/Home/Home.aspx" />
<add key="ADAttribute" value="wwwHomePage" />
Change the DefaultURL value accordingly to the Environment
Find the “connectionStrings” tag and add the below lines in the “connectionStrings”
If the Users are in the Separate Organizational Unit, add as below
<add name="LocalSqlServer" connectionString="LDAP://srvssp.com/OU=TechInvoUsers,DC=srvssp,DC=com" />
If the Users are in the Users Folder, add as below
<add name="LocalSqlServer" connectionString="LDAP://srvssp.com/CN=Users,DC=srvssp,DC=com" />
srvssp.com is the domain name of the machine, LocalSqlServer is the name of the connection string that should be maintained acroos different tags in web.config like membership provider & role manager. Do the same for all the web applications.
Find the “authentication” tag and replace that tag with below lines
<authentication mode="Forms">
<forms loginUrl="Login/Login.aspx" protection="All" timeout="1000" domain="srvssp.com" name=".ADAuthCookie" path="/" requireSSL="false" slidingExpiration="true" cookieless="UseDeviceProfile" enableCrossAppRedirects="true" />
</authentication>
Find the “authorization” tag and replace that tag with below lines
<authorization>
<deny users="?" />
</authorization>
Add the machineKey tag, after the end of “httpModules” tag and before the end of “System.web” tag. [Take from SharePoint Web Application, where we are going to integrate with SSO]
<machineKey validationKey="508B6F34BD558AD4013FD2A88A7E5D73FF858EAC859E82D1" decryptionKey="A81DBE9EF757D2AD9DAE8D6678B25CF06B065C99D352D592" validation="SHA1" />
Add the “membership” tag after the “machinekey” tag
<membership defaultProvider="MyADMembershipProvider">
<providers>
<clear />
<add applicationName="/TechInvo.SSOWebApplication" connectionStringName="LocalSqlServer" connectionUsername="srvssp\Administrator" connectionPassword="Admin123" name="MyADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</membership>
Change the Application Name, ConnectionUsername and ConnectionPassword accordingly to the Environment
Add the “roleManager” tag below the “membership” tag
<roleManager enabled="true" defaultProvider="ActiveDirRP">
<add applicationName="/TechInvo.SSOWebApplication" name="ActiveDirRP" type="TechInvo.Roles.ADRoleProvider" activeDirectoryConnectionString="LocalSqlServer" groupMode="Additive" groupsToUse="" />
</roleManager>
Web Applications
Here we have the two sub parts as ASP.NET Web Applications and SharePoint Web Application
ASP.NET Web Application IMPLEMENTATION
<loggingConfiguration name="Logging Application Block" tracingEnabled="true"
defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
<add fileName="c:\TechInvoLog\TechInvo.log" footer="----------------------------------------"
<add switchValue="All" name="TechInvo">
<appSettings>
<add key="AccessDeniedPage" value="http://srvssp.com/TechInvo.SSOWebApplication/AccessDenied.aspx" />
<add key="GroupName" value="TechInvo" />
</appSettings>
Change the GroupName as the value accordingly to the Active Directory Role Name
<forms loginUrl="http://srvssp.com/TechInvo.SSOWebApplication/Login/Login.aspx" protection="All" timeout="1000" domain="srvssp.com" name=".ADAuthCookie" path="/" requireSSL="false" slidingExpiration="true" cookieless="UseDeviceProfile" enableCrossAppRedirects="true" defaultUrl="~/Home/Home.aspx" />
Add the machineKey tag, after the end of “httpModules” tag and before the end of “System.web” tag. [Take from SSO Web Application, where we are going to integrate]
<add applicationName="/TechInvo" connectionStringName="LocalSqlServer" connectionUsername="srvssp\Administrator" connectionPassword="Admin123" name="MyADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add applicationName="/TechInvo" name="ActiveDirRP" type="TechInvo.Roles.ADRoleProvider" activeDirectoryConnectionString="LocalSqlServer" groupMode="Additive" groupsToUse="TechInvo" />
Change the groupsToUse value accordingly to the application using.
LOGOUT FUNCTIONALITY
The below will explains the Log Out functionality implemented in Forms Authentication.
LOGOUT IMPLEMENTATION
<asp:Button runat="server" ID="btnLogOut" Text="Log Out"
onclick="btnLogOut_Click"></asp:Button>
protected void btnLogOut_Click(object sender, EventArgs e)
{
FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();
}
The RedirectToLoginPage redirect the user to the page that is given in LoginURL of the Forms tag in web.config.
Role Check
The following steps explain the Role Check functionality implemented in Forms Authentication.
Get the ADRoleProvider.dll from the TechInvo.Roles/bin/debug folder
protected void Application_AuthorizeRequest(object sender, EventArgs e)
string UserName = System.Threading.Thread.CurrentPrincipal.Identity.Name;
if (!String.IsNullOrEmpty(UserName))
UserName = UserName.Split('@')[0];
bool test = Roles.IsUserInRole(UserName, ConfigurationManager.AppSettings["GroupName"]);
if (!test)
Response.Redirect(ConfigurationManager.AppSettings["AccessDeniedPage"]);
SharePoint Web Application IMPLEMENTATION
Find the respective application in C:\Inetpub\wwwroot\wss\VirtualDirectories\[Port Number/Name]
For reference
<add fileName="c:\WebPart\TechInvoSystems.log" footer="----------------------------------------"
<add key="GroupName" value="TechInvo,PricingTool,OMSApp" />
<add key="WebAddress" value="http://srvssp.com/TechInvo/Home/Home.aspx, http://srvssp.com/RepricingTool/Home/Home.aspx ,http://srvssp.com/OMS/Home/Home.aspx" />
<forms loginUrl="http://srvssp.com/TechInvo.SSOWebApplication/Login/Login.aspx" protection="All" timeout="1000" domain="srvssp.com" name=".ADAuthCookie" path="/" requireSSL="false" slidingExpiration="true" cookieless="UseDeviceProfile" enableCrossAppRedirects="true" defaultUrl="http://ssp:22267/default.aspx " />
<add applicationName="/" connectionStringName="LocalSqlServer" connectionUsername="srvssp\Administrator" connectionPassword="Admin123" name="MyADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add name="DemoRoleProvider" connectionStringName="LocalSqlServer" applicationName="/"
type="System.Web.Security.SqlRoleProvider,System.Web, Version=2.0.0.0, Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" />
<add applicationName="/" name="ActiveDirRP" type="TechInvo.Roles.ADRoleProvider, ADRoleProvider"
activeDirectoryConnectionString="LocalSqlServer" groupMode="Additive"
groupsToUse="TechInvo,OMSApp,PricingTool" />
Change the groupsToUse value accordingly to the Active Directory.
Encrypting the Membership and Rolemanager Tags
Configuration files such as the web.config file are often used to hold sensitive information, including user names, passwords, database connection strings, and encryption keys. If we do not protect this information, our application is vulnerable to attackers or malicious users obtaining sensitive information such as account user names and passwords, database names and server names.
Encrypting and decrypting data incurs performance overhead. To keep this overhead to a minimum, encrypt only the sections of your configuration file that store sensitive data.`
The Aspnet_regiis.exe utility tool is located in the following directory:
%WinDir%\Microsoft.NET\Framework\<versionNumber>
If the command is successful, you will see the following output:
Encrypting configuration section...
Succeeded!
Note The DPAPI machine key is stored at the following location:
%windir%\system32\Microsoft\Protect\S-1-5-18
1. Use the aspnet_regiis tool for Encrypting the Membership and Rolemanager tags.
To find aspnet_regiis navigate to the following folder C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727, here you will find the aspnet_regiis.exe tool.
cd C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
aspnet_regiis –pef “system.web/membership” “Web.config file path”
For Eg:- aspnet_regiis –pef “system.web/membership” “C:\Deliverable_25_03_2010\TechInvo.SSO\TechInvo.SSOWebApplication”
Change the Folder name to locate exactly the web.config file
Follow the same procedure for all the other Asp.Net Web applications and SharePoint Web Application where changing the Folder Path respective to the environment.
Use the same tool and type as below
aspnet_regiis –pef “system.web/roleManager” “Web.config file path”
For Eg:- aspnet_regiis –pef “system.web/roleManager” “C:\Deliverable_25_03_2010\TechInvo.SSO\TechInvo.SSOWebApplication”
If need for Decrypting the Tags Please do as below
Use the same aspnet_regiis tool and change the –pef to –pdf and the respective tag needed according to the requirement.
aspnet_regiis –pdf “system.web/roleManager” “Web.config file path”
For Eg:- aspnet_regiis –pdf “system.web/roleManager” “C:\Deliverable_25_03_2010\TechInvo.SSO\TechInvo.SSOWebApplication”
Troubleshooting Points:-
Not able to login with credentials created using ASP.NET application. [SQL membership Provider]
Event Type: Information
Event Source: ASP.NET 2.0.50727.0
Event Category: Web Event
Event ID: 1315
Date: 2/25/2010
Time: 6:36:45 PM
User: N/A
Computer: SSP
Description:
Event code: 4006
Event message: Membership credential verification failed.
Event time: 2/25/2010 6:36:45 PM
Event time (UTC): 2/25/2010 1:06:45 PM
Event ID: 49ac92e0e53d4803a5e6ce7ae7c67e39
Event sequence: 9
Event occurrence: 4
Event detail code: 0
Application information:
Application domain: /LM/W3SVC/1657492262/Root-1-129115762208906250
Trust level: WSS_Minimal
Application Virtual Path: /
Application Path: C:\Inetpub\wwwroot\wss\VirtualDirectories\3377\
Machine name: SSP
Process information:
Process ID: 4084
Process name: w3wp.exe
Account name: NT AUTHORITY\NETWORK SERVICE
Request information:
Request URL: http://ssp:3377/_layouts/login.aspx?ReturnUrl=/
Request path: /_layouts/login.aspx
User host address: 192.168.2.17
User:
Is authenticated: False
Authentication Type:
Thread account name: SRVSSP\IUSR_SSP
Name to authenticate: mossuser1
Custom event details:
For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
Error:-
Action:-
Wrong Credentials. Please retype the UserName and Password
Event Type: Failure Audit
Event Source: MSSQLSERVER
Event Category: (4)
Event ID: 18456
Date: 2/24/2010
Time: 4:43:31 PM
User: NT AUTHORITY\NETWORK SERVICE
Login failed for user 'NT AUTHORITY\NETWORK SERVICE'. [CLIENT: <local machine>]
Action:- Has to give the passowrd correctly.
Error:- In the HomePage Attribute of the Active Directory might be given as www.google.com
Action:- The HomePage Attribute should has to give as http://www.google.com
ASP.NET site with link to a SharePoint site, Both SharePoint and the ASP.NET application are running in the same domain. When a user starts ASP.NET application, they are presented with a logon dialog (windows authentication). When they click the link to the SharePoint, they are presented with the same dialog again.
Error:- :
Error:- As you have enabled the Integrated Windows Authentication (IWA), I suggest you to check your IE configurations to enable automatically logon: