Readme_Security Extension Sample
This sample works only with SQL Server 2012. It will not work with any version of SQL Server earlier than SQL Server 2012.
The CustomSecurity sample security extension uses Forms Authentication along with SQL Server to provide a custom security model that works with Reporting Services. This sample is not supported on Itanium-based operating systems.
|The security extension sample should not be deployed and tested in a production environment. Reverting back to Windows Authentication after migrating to a different security extension is generally not recommended. If you do, you may experience errors when
you attempt to access items in the report server database that have custom security descriptors, but with no Windows Authentication security descriptors. To revert, you will have to reconfigure Reporting Services with a new set of Report server catalog databases
along with restoring all the modified configuration files back to the initial state. Then manually re-apply any role-based security for your Windows users. Before using this sample, you should back up all your configuration files.
|Samples are provided for educational purposes only. They are not intended to be used in a production environment and have not been tested in a production environment. Microsoft does not provide technical support for these samples. Sample applications and
assemblies should not be connected to or used with your production SQL Server database or your report server without the permission of the system administrator. Microsoft does not provide technical support for these samples.
You should be familiar with Visual Studio and either Visual C# or Visual Basic, and you must have the following applications installed to run the Security Extension sample:
- Microsoft Visual Studio 2010 or later.
- Microsoft .NET Framework 2.0.
- SQL Server 2012 including Reporting Services.
- Reporting Services samples.
- A report server that you have permission to access on your network, if you plan to use the sample extension to add additional data processing functionality to your server.
|SQL Server samples and sample databases must be downloaded and installed before you can view or work with them. For more information, see
Considerations for Installing SQL Server Samples and Sample Databases.
Building the Sample
You must first compile and install the extension. The procedure assumes that you have installed Reporting Services to the default location: C:\Program Files\Microsoft SQL Server\MSRS1050.MSSQLSERVER\Reporting Services. This location will be referred to throughout
the remainder of this topic as <
If you have not already created a strong name key file, generate the key file using the following instructions.
To generate a strong name key file
- Open a Microsoft Visual Studio prompt. Click Start, point to All Programs, point to
Microsoft .NET Framework SDK 2.0, and then click SDK Command Prompt.-- or --Open a Microsoft .NET Framework command prompt. Click
Start, point to All Programs, point to Microsoft .NET Framework SDK 2.0, and then click
SDK Command Prompt.
- Use the change directory command (CD) to change the current directory of the command prompt window to the folder where the samples are installed.
Note: To determine the folder where samples are located, click the Start* button, point to
All Programs, point to Microsoft SQL Server, point to Documentation and Tutorials, and then click
Samples Directory. If the default installation location was used, the samples are located in <system_drive>:\Program Files\Microsoft SQL Server\100\Samples.*
- At the command prompt, run the following command to generate the key file:
sn -k SampleKey.snk Important: For more information about the strong-name key pair, see "Security Briefs: Strong Names and Security in the .NET Framework" in the .NET Development Center on MSDN.
To compile the sample using Visual Studio
- Open CustomSecurity.sln in Microsoft Visual Studio. If you installed the sample to the default location, you can access it at C:\Program Files\Microsoft SQL Server\100\Samples\Reporting Services\Extensions.
- In Solution Explorer, select the CustomSecurity project.
- Look at the CustomSecurity project's references. If you do not see Microsoft.ReportingServices.Interfaces.dll, complete steps the following steps:
- On the Project menu, click Add Reference. The Add References dialog box opens.
- Click the .NET tab.
- Click Browse, and find Microsoft.ReportingServices.Interfaces on your local drive. By default, the assembly is located in the <install>\ReportServer\bin directory. Click OK. The selected reference is added to your project.
- On the Build menu, click Build Solution.
Deploying the Sample
After the sample is compiled, you must copy the DLLs and the ASPX pages to the appropriate subdirectories for your Report Server installation.
To deploy the sample
- Copy Microsoft.Samples.ReportingServices.CustomSecurity.dll and Microsoft.Samples.ReportingServices.CustomSecurity.pdb to the <install>\ReportServer\bin directory.
- Copy Microsoft.Samples.ReportingServices.CustomSecurity.dll and Microsoft.Samples.ReportingServices.CustomSecurity.pdb to the <install>\ReportManager\bin directory. If a PDB file is Not present, it was Not created by the Build step provided
above. Ensure that the Project Properties for Debug/Build is set to generate PDB files.
- Copy the Logon.aspx page to the <install>\ReportServer directory.
- Copy the UILogon.aspx page to the <install>\ReportManager\Pages directory. After the assembly and logon pages are copied to the server, you need to make some modifications to the Report Server configuration file.
|Make backup copies of all of your configuration files before making any changes. Backup and Restore Operations for a Reporting Services Installation can be looked up from MSDN. http://msdn.microsoft.com/en-us/library/ms155814.aspx is its current URL. Configuration
Files (Reporting Services) can be reviewed to get detailed information about the various settings mentioned. Its current URL is http://msdn.microsoft.com/en-us/library/ms155866.aspx.
Files in the ReportServer Folder
To modify the RSReportServer.config file
- Open the RSReportServer.config file with Visual Studio or a simple text editor such as Notepad. RSReportServer.config is located in the <install>\ReportServer directory.
- Locate the <AuthenticationTypes> element and modify the settings as follows:
- Locate the <Security> and <Authentication> elements, within the <Extensions> element, and modify the settings as follows:
</Authentication> . For more information regarding .NET Framework security and Reporting Services, see
Secure Development (Reporting Services)
- Locate the <UI> element and update it as follows:
|If you are running the sample security extension in a development environment that does not have a Secure Sockets Layer (SSL) certificate installed, you must change the value of the
<UseSSL> element to False in the previous configuration entry. We recommend that you always use SSL when combining Reporting Services with Forms Authentication.
You will need to add a code group for your custom security extension that grants FullTrust permission for your extension. You do this by adding the code group to the RSSrvPolicy.config file.
To modify the RSSrvPolicy.config file
- Open the RSSrvPolicy.config file located in the <install>\ReportServer directory.
- Add the following <CodeGroup> element after the existing code group in the security policy file that has a URL membership of $CodeGen as indicated below and then add an entry as follows to RSSrvPolicy.config. Make sure to change the below path according
to your ReportServer installation directory:
Description="Code group for the sample security extension"
Url="C:\Program Files\Microsoft SQL Server\MSRS11.MSSQLSERVER\Reporting Services\ReportServer\bin\Microsoft.Samples.ReportingServices.CustomSecurity.dll"/>
|For simplicity, the Forms Authentication Sample is weak-named and requires a simple URL membership entry in the security policy files. In your production security extension implementation, you should create strong-named assemblies and use the strong name
membership condition when adding security policies for your assembly. For more information about strong-named assemblies, see the
Creating and Using Strong-Named Assemblies topic on MSDN.
To modify the Web.config file for Report Server
- Open the Web.config file in a text editor. By default, the file is located in the <install>\ReportServer directory.
- Locate the <identity> element and set the Impersonate attribute to
false. * <identity impersonate="false" /> *
- Locate the <authentication> element and change the Mode attribute to
- Add the following <forms> element as a child of the <authentication> element and set the
loginUrl, name, timeout, and path attributes as follows:
<forms loginUrl="logon.aspx" name="sqlAuthCookie" timeout="60"
- Add the following <authorization> element directly after the <authentication> element.
<deny users="?" />
This will deny unauthenticated users the right to access the report server. The previously established
attribute of the <authentication
> element will redirect unauthenticated requests to the Logon.aspx page.
Files in the ReportManager Folder
Next, you will need to increase the permissions for the "My Computer" code group in the Report Manager policy file.
To modify the RSMgrPolicy.config file
- Open the Report Manager policy file, RSMgrPolicy.config, located in the <install>\ReportManager directory.
- Locate the following code group in RSMgrPolicy.config and change the PermissionSetName attribute from
Execution to FullTrust as follows:
Description="This code group grants MyComputer code Execution permission. ">
Zone="MyComputer" /> "}*To use Forms Authentication, you need to modify the Web.config files for Report Manager and Report Server.
To modify the Web.config file for Report Manager
- Open the Web.config for Report Manager. It is located in the <install>\ReportManager directory.
- Disable impersonation by locating the section <identity impersonate= "true" /> and changing it to the following:
<identity impersonate="false" />.
- Locate the <authentication> element and change the Mode attribute to Forms.
- Add the following keys to the <appSettings> element.
<add key="ReportServer" value="<Server Name>"/>
<add key="ReportServerInstance" value="RS_<Instance Name>"/>
- Change the <Server Name> value to the name of the report server and the RS_<Instance Name> value to the name of the instance the report server is associated with.
|The <Instance Name> for a default instance is RS_MSSQLSERVER.
Creating the UserAccounts Database
The sample includes a database script, Createuserstore.sql, that enables you to set up a user store for the Forms sample in a SQL Server database.
To create the UserAccounts database
- Open SQL Server Management Studio, and then connect to your local instance of SQL Server.
- Locate the Createuserstore.sql SQL script file. The script file is contained within the sample project files.
- Run the query to create the UserAccounts database.
- Exit SQL Server Management Studio.
Testing the Sample
The following procedure tests the sample extension. You will register an administrator user, which adds the user name, password hash, and salt value to the users table in the UserAccounts database. It also will require you to enter that user name in the Report
Server configuration file. You will then log on the same user to ensure the correct operation of the password verification routines as well as the proper loading of the extension assembly by the report server.
To test the sample
- Restart the Reporting Services service by running the following commands at the command prompt: * net stop "SQL Server Reporting Services (<Instance Name>)"
net start "SQL Server Reporting Services (<Instance Name>)" *
- Open Report Manager. You can do this from the Reporting Services program menu or by accessing the Reports virtual directory from your browser.
- Enter a user name and password and click Register User to add the user to the accounts database.
- Open the RSReportServer.config file. Locate the <Security> element and add the previously registered user name as follows:
- Return to the UILogon.aspx page, re-enter the user name and password, and then click
Logon. You should have access to Report Manager and the report server with no restrictions. The administrator user that you create has equivalent permissions on the report server to those of a built-in administrator account on the local computer. For
the purpose of this sample, you can only have one user designated as an administrator. After you have a built-in administrator account, you can register additional users and assign them roles on the report server.
|You should add your administrator user to the official System Administrator and Content Manager (root folder) roles of your report server. This prevents empty security descriptors from existing in the report server database. For more information about the
System Administrator and Content Manager roles, see Using Predefined Roles.
Using the Web Service with Custom Security
You can use the Web service API with Forms Authentication just as you would with Windows Authentication. However, you must call
LogonUser in your Web service code and pass the credentials of the current user. In addition, your Web service client will not have the benefit of automatic cookie management, which is provided by Internet Explorer or other Web browsers. You will have
to extend the ReportingService2005 proxy class to include cookie management. This can be done by overriding the
GetWebRequest and GetWebResponse methods of the Web service class.
Debugging the Sample Extension
Running the sample extension in the debugger is not only a great way to troubleshoot difficulties you may have, but it is also an effective way to step through the code and see the report server authentication and authorization process as it is happening.
The Microsoft .NET Framework provides several debugging tools that can help you analyze the sample code. The following procedure uses Visual Studio to debug the previous sample.
To debug the Forms Authentication sample code
- Start Visual Studio and open CustomSecurity.sln on your test report server.
- Open Internet Explorer and navigate to Report Manager while leaving the sample code open in Visual Studio.
- Switch to Visual Studio and set some break points in the custom security extension project code.
- With the extension project still the active window, from the Debug menu, click
Process.The Processes dialog opens.
- From the list of processes, select the Aspnet_wp.exe process (or W3wp.exe, if your application is deployed on IIS), and click
- In the Attach to Process dialog, select the Common Language Runtime program type, and then click
OK. For improved debugging performance, make sure that Native is not a selected program type.
- When the sample runs, a logon form appears. Type the user credentials into the logon form and click the
Logon button. Whenever your break points are encountered during processing, the debugger should stop execution at that point.
- Step through your code using the F11 key. For more information about using Visual Studio for debugging, see your Visual Studio documentation.
|Debugging this way requires a lot of resources and processor time. If you run into difficulties, close Visual Studio, reset IIS, and begin again by attaching the CustomSecurity solution to the ASP.NET worker process and logging on to Report Manager.
Removing the Sample Extension
While not generally recommended, it is possible to revert back to Windows Authentication after you have tried out the sample.
To revert to Windows security
Note that reverting back to Windows Authentication after migrating to a different security extension is generally not recommended. If you do, you may experience errors when you attempt to access items in the report server database that have custom security
descriptors, but no Windows Authentication security descriptors.
- Restore the following files from your backup copies: Web.config and RSReportServer.config. This should set the authentication and authorization methods for the report server to the default Windows security. This should also remove any entries you made for
your extension in the Report Server configuration file.
- After the configuration information is removed, your security extension is no longer available to the report server. You should not have to remove any security descriptors that were created while you were running the report server under the sample security
extension. The report server automatically assigns the System Administrator role to the BUILTIN\Administrators group on the computer hosting the report server when Windows Authentication is enabled. However, you will have to manually re-apply any role-based
security for your Windows users.
Reporting Services Samples
Extension Samples (Reporting Services) Implementing a Security Extension
Help and Information
- Getting SQL Server 2008 R2 Assistance* © 2011 Microsoft Corporation. All rights reserved.