23 Feb 2015

SSRS: Configure User Authentication with ReportCredentials

Many times I found that the Reporting service is configured to access as "Anonymous Access", so any user having URL can access reports from external world. Ideally it should be access by only users/application. For that SQL SERVER Reporting service should not be  accessed by "Anonymous Access". It also prevents Report server from unauthorized access.
NOTE: In shared hosting, Hosting provider provides username/password and only those users can get access to the reports for that specific user.
Today, I am going to explain to how to send user credentials from Report application, so Reporting service can authenticate user and allow to get reports. Only users having correct credentials can access the reports from the server. We are going to configure application to send credentials, so application can get access to the reports.
To configure application to get access reports from Shared hosting/Domain, we need to do following:
1. Get credentials from shared hosting/Domain controller to access the reports
2. Configure Application to Authenticate (.Net)
1. Get credentials
Whenever we need to deploy/access report from the Report Server, we should have following information:
    Report Server URL
  • UserName/Password to access the reports
This information will be provided by Shared hosting provider/Domain controller. Information like:
To check this information, Type Report URL in browser. It will ask for Username and password (if anonymous access is disabled). Enter given credentials, if Credentials are correct then Reporting service allow you to access the URL.
2. Configure Application to Authenticate (.Net)
As we get Basic information in step #1, now we need to build application that pass credentials to the Report server, so Report server authenticate the request and allow application to access the reports.
To authenticate request to Report server we need to implement IReportServerCredentials to send Report Credential to Report Server.
  • Create a class to implement IReportServerCredentials
SSRS ReportCredentials (2)
Please find VB code here:
01.Public Class ReportCredentials
02.Implements Microsoft.Reporting.WebForms.IReportServerCredentials
03. 
04.Private _userName As String, _password As String, _domain As String
05. 
06.Public Sub New(ByVal userName As String, ByVal password As String, ByVal domain As String)
07._userName = userName
08._password = password
09._domain = domain
10.End Sub
11.Public ReadOnly Property ImpersonationUser() As System.Security.Principal.WindowsIdentity _
12.Implements Microsoft.Reporting.WebForms.IReportServerCredentials.ImpersonationUser
13.Get
14.Return Nothing
15.End Get
16.End Property
17. 
18.Public ReadOnly Property NetworkCredentials() As System.Net.ICredentials _
19.Implements Microsoft.Reporting.WebForms.IReportServerCredentials.NetworkCredentials
20.Get
21.Return New System.Net.NetworkCredential(_userName, _password, _domain)
22.End Get
23.End Property
24. 
25.Public Function GetFormsCredentials(ByRef authCoki As System.Net.Cookie,
26.ByRef userName As String,  
27.ByRef password As String, _
28.ByRef authority As String) As Boolean _
29.Implements Microsoft.Reporting.WebForms.IReportServerCredentials.GetFormsCredentials
30.userName = _userName
31.password = _password
32.authority = _domain
33.authCoki = New System.Net.Cookie(".ASPXAUTH", ".ASPXAUTH", "/", "Domain")
34. 
35.Return True
36.End Function
37. 
38.End Class
Now we have created "ReportCredentials" class, now we need to use this class object to send credential info via Report Viewer Control as follows:
SSRS ReportCredentials 2
Please find VB code here:
01.Imports Microsoft.Reporting.WebForms
02. 
03.Partial Class Report
04.Inherits System.Web.UI.Page
05. 
06.Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
07.Handles Me.Load
08. 
09.If Not IsPostBack Then
10.Dim ReportServerUrl As String = "https://<;url>/ReportServer"
11.Dim ReportDataSourceName As String = "/My Reports/"
12.With Me.ReportViewer
13..ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote
14.With .ServerReport
15..ReportServerUrl = New Uri(ReportServerUrl)
16..ReportPath = ReportDataSourceName + "ReportName"
17..ReportServerCredentials = New _
18.ReportCredentials("Domain", "UserName", "Password")
19..Refresh()
20.End With
21.End With
22.Page.Title = "Reports - " + Request.Params("Report")
23.If Request.Params("HideOptions") = 1 Then
24.ReportViewer.ShowParameterPrompts = False
25.End If
26.End If
27.End Sub
28.End Class</url>

That's it, now you can access your reports deployed at Shared Hosting/Domain from application, 
Report server allows to access if credentials are correct. 

Let me know if you have any question/problem in deploying/accessing reports from Shared Hosting/Domain.