Setting CredentialRetrievalEnum on DataSourceDefinition

Jan 10, 2012 at 10:48 PM

Hello!  I've got this tool working well except for one problem.  We don't store login credentials in our data sources on our report server, and we don't use Windows Authentication.  I need to be able to set data sources to prompt the user for credentials.  I don't see how to do this with this tool.  I only see options for providing Windows credentials to store in the data source.  Can someone enlighten me on how to set data sources to prompt for credentials using this tool?  I'd really appreciate it! 

Thanks!

Jan 10, 2012 at 11:08 PM

After looking at the source code, it looks like this isn't possible without a modification.  In the GetDataSourceDefinition method of NativeDeploymentManager.cs it appears that the only CredentialRetrievalEnum values that are used are 'Store' and 'Integrated.'  We need to be able to set this to 'Prompt' and specify a text prompt for the user.  Are there any plans to make the 'Prompt' and 'None' CredentialRetrievalEnum values available?  I'd be happy to make this change and send it to you if it's not something you're interested in doing.  Thanks!

/// <summary>
        /// Gets the data source definition.
        /// </summary>
        /// <param name="dataSource">
        /// The data source.
        /// </param>
        /// <param name="sqlConStringBuilder">
        /// The SQL con string builder.
        /// </param>
        /// <returns>
        /// DataSourceDefinition with default setting created.
        /// </returns>
        private DataSourceDefinition GetDataSourceDefinition(
            ReportServerDataSource dataSource, SqlConnectionStringBuilder sqlConStringBuilder)
        {
            // create a data source definition and apply default settings
            DataSourceDefinition definition = new DataSourceDefinition();
            this.SetDefaultDefinition(definition);

            // setting the conection string bas up the type
            switch (dataSource.Provider)
            {
                case DataProviderEnum.SQL:
                    definition.Extension = "SQL";
                    break;
                case DataProviderEnum.OLEDBMD:
                    definition.Extension = "OLEDB-MD";
                    break;
            }

            // get the Data Source and Catalogs 
            definition.ConnectString = string.Format(
                "Data Source={0};Initial Catalog={1}", 
                sqlConStringBuilder.DataSource, 
                sqlConStringBuilder.InitialCatalog);

            // check to if windows security is used or in the provicer is AS
            if (sqlConStringBuilder.IntegratedSecurity || dataSource.Provider == DataProviderEnum.OLEDBMD)
            {
                definition.WindowsCredentials = true;

                // checking to see if the impersonation needs to be set.
                if (dataSource.WindowCredentials != null)
                {
                    // set impersonation details of the windows user
                    definition.UserName = dataSource.WindowCredentials.UserName;
                    definition.Password = dataSource.WindowCredentials.PassWord;
                    definition.CredentialRetrieval = CredentialRetrievalEnum.Store;
                }
                else
                {
                    // user standard windows / Kebross security
                    definition.CredentialRetrieval = CredentialRetrievalEnum.Integrated;
                }
            }
            else
            {
                // llse use SQL Server security
                definition.UserName = sqlConStringBuilder.UserID;
                definition.Password = sqlConStringBuilder.Password;
                definition.CredentialRetrieval = CredentialRetrievalEnum.Store;
            }

            return definition;
        }
 

Jan 11, 2012 at 1:09 AM

Ok, I made a few source changes, recompiled, and I've got this working.  The changes I made are as follows:

Added a property to the ReportServerDataSource.cs class:

/// <summary>
        /// Gets or sets the prompt displayed to the user when asking for security credentials.
        /// </summary>
        /// <value>A string containing the text to use to prompt the user for credentials.</value>
        public string CredentialsPrompt { get; set; }

 

Added the following code to the Execute method in CreateReportingDataSource.cs:

if (!String.IsNullOrEmpty(this.DataSources[index].GetMetadata("Prompt")))
                    {
                        reportServerDataSources[index].CredentialsPrompt = this.DataSources[index].GetMetadata("Prompt");
                    }

Modified the GetDataSourceDefinition method in NativeDeploymentManager.cs as follows:

/// <summary>
        /// Gets the data source definition.
        /// </summary>
        /// <param name="dataSource">
        /// The data source.
        /// </param>
        /// <param name="sqlConStringBuilder">
        /// The SQL con string builder.
        /// </param>
        /// <returns>
        /// DataSourceDefinition with default setting created.
        /// </returns>
        private DataSourceDefinition GetDataSourceDefinition(
            ReportServerDataSource dataSource, SqlConnectionStringBuilder sqlConStringBuilder)
        {
            // create a data source definition and apply default settings
            DataSourceDefinition definition = new DataSourceDefinition();
            this.SetDefaultDefinition(definition);

            // setting the conection string bas up the type
            switch (dataSource.Provider)
            {
                case DataProviderEnum.SQL:
                    definition.Extension = "SQL";
                    break;
                case DataProviderEnum.OLEDBMD:
                    definition.Extension = "OLEDB-MD";
                    break;
            }

            // get the Data Source and Catalogs 
            definition.ConnectString = string.Format(
                "Data Source={0};Initial Catalog={1}", 
                sqlConStringBuilder.DataSource, 
                sqlConStringBuilder.InitialCatalog);

            // check to if windows security is used or in the provicer is AS
            if (sqlConStringBuilder.IntegratedSecurity || dataSource.Provider == DataProviderEnum.OLEDBMD)
            {
                definition.WindowsCredentials = true;

                // checking to see if the impersonation needs to be set.
                if (dataSource.WindowCredentials != null)
                {
                    // set impersonation details of the windows user
                    definition.UserName = dataSource.WindowCredentials.UserName;
                    definition.Password = dataSource.WindowCredentials.PassWord;
                    definition.CredentialRetrieval = CredentialRetrievalEnum.Store;
                }
                else
                {
                    // user standard windows / Kebross security
                    definition.CredentialRetrieval = CredentialRetrievalEnum.Integrated;
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(sqlConStringBuilder.UserID))
                {
                    // llse use SQL Server security
                    definition.UserName = sqlConStringBuilder.UserID;
                    definition.Password = sqlConStringBuilder.Password;
                    definition.CredentialRetrieval = CredentialRetrievalEnum.Store;
                }
                else
                {
                    if (!string.IsNullOrEmpty(dataSource.CredentialsPrompt))
                    {
                        // Prompt the user for security credentials
                        definition.Prompt = dataSource.CredentialsPrompt;
                        definition.CredentialRetrieval = CredentialRetrievalEnum.Prompt;
                    }
                    else
                    {
                        // No security credentials required
                        definition.CredentialRetrieval = CredentialRetrievalEnum.None;
                    }
                }
            }

            return definition;
        }

 

So, I've got it working now.  It would be great if something along these lines was added to the project if it's still being maintained.  Anyway, hope that helps somebody.

Coordinator
Jan 11, 2012 at 10:42 AM

Hi

   Thank you for using the tasks and updating them.  I have just updated the task to add support for schedules I am in the middle of testing. I will add the changes into this release.

Regards

Steve Wright

Jan 14, 2012 at 12:08 AM

Fantastic!  Thank you!

Coordinator
Feb 1, 2012 at 9:47 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.