Skip to content

Expose SSPI context provider as public#2494

Open
twsouthwick wants to merge 15 commits intodotnet:mainfrom
twsouthwick:public
Open

Expose SSPI context provider as public#2494
twsouthwick wants to merge 15 commits intodotnet:mainfrom
twsouthwick:public

Conversation

@twsouthwick
Copy link
Member

@twsouthwick twsouthwick commented May 8, 2024

This change:

  • Adds a property to SqlConnection to allow setting a provider
  • Plumbs that property into the TdsParser so that it can be used if set

Fixes #2253

@twsouthwick twsouthwick changed the title Expose SSPI context provider as public Expose SSPI context provider as public May 8, 2024
@twsouthwick twsouthwick force-pushed the public branch 3 times, most recently from e16f2c8 to cfcf164 Compare March 3, 2025 19:42
@codecov
Copy link

codecov bot commented Mar 3, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.07%. Comparing base (d05100e) to head (77cab44).
⚠️ Report is 110 commits behind head on main.

❗ There is a different number of reports uploaded between BASE (d05100e) and HEAD (77cab44). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (d05100e) HEAD (77cab44)
addons 1 0
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2494      +/-   ##
==========================================
- Coverage   77.23%   70.07%   -7.17%     
==========================================
  Files         274      266       -8     
  Lines       45671    43873    -1798     
==========================================
- Hits        35273    30742    -4531     
- Misses      10398    13131    +2733     
Flag Coverage Δ
addons ?
netcore 70.09% <ø> (-7.08%) ⬇️
netfx 69.44% <ø> (-6.98%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@benrr101 benrr101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, really like the goal and implementation. Most of my comments are style related, since I'm sure my colleagues have tackled the bigger questions.

Copy link
Contributor

@paulmedynski paulmedynski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made an initial pass, and came up with some questions/comments.

@paulmedynski paulmedynski self-assigned this Apr 2, 2025
@twsouthwick twsouthwick force-pushed the public branch 6 times, most recently from 380e896 to 2039bd9 Compare May 1, 2025 19:37
Copy link
Contributor

@paulmedynski paulmedynski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Factory vs instance in the netfx code, and a few questions about docs.

@twsouthwick twsouthwick force-pushed the public branch 4 times, most recently from 5bb128f to 8937cb7 Compare May 13, 2025 14:58
@twsouthwick twsouthwick marked this pull request as ready for review May 13, 2025 18:40
Copy link

@nhart12 nhart12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latest package still works for our use-case

@0xced
Copy link
Contributor

0xced commented Feb 12, 2026

I understand why stale bots exist, still, I hate them.

Copilot AI review requested due to automatic review settings February 12, 2026 19:41
@mdaigle
Copy link
Contributor

mdaigle commented Feb 12, 2026

Security review is complete. Waiting for builds to pass, then we'll get this final review and approval.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Comments suppressed due to low confidence (1)

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnection.cs:807

  • The SspiContextProvider property setter is missing validation to prevent setting the property after a connection has been opened or is connecting. This validation is present in similar properties like Credential, AccessToken, and AccessTokenCallback which check InnerConnection.AllowSetConnectionString and throw ADP.OpenConnectionPropertySet if the connection state doesn't allow changes. Add the same check here for consistency and to prevent unexpected behavior.
        public SspiContextProvider SspiContextProvider
        {
            get { return _sspiContextProvider; }
            set
            {
                ConnectionString_Set(new SqlConnectionPoolKey(_connectionString, credential: _credential, accessToken: null, accessTokenCallback: null, sspiContextProvider: value));
                _sspiContextProvider = value;
            }
        }

@paulmedynski paulmedynski modified the milestones: 7.0.0-preview5, 7.0.0-preview4 Feb 12, 2026
mdaigle
mdaigle previously approved these changes Feb 12, 2026
Copilot AI review requested due to automatic review settings February 12, 2026 23:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.

Comments suppressed due to low confidence (1)

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnection.cs:807

  • The SspiContextProvider property setter is missing critical validation that exists in other similar properties (Credential, AccessToken, AccessTokenCallback). Since this property affects the connection pool key, it must validate that the connection is not already open or opening before allowing the value to be changed.

Add the following validation at the start of the setter:

if (!InnerConnection.AllowSetConnectionString)
{
    throw ADP.OpenConnectionPropertySet(nameof(SspiContextProvider), InnerConnection.State);
}

This prevents runtime errors when users attempt to change the SSPI provider on an active connection and maintains consistency with the established pattern for pool-key-affecting properties.

        public SspiContextProvider SspiContextProvider
        {
            get { return _sspiContextProvider; }
            set
            {
                ConnectionString_Set(new SqlConnectionPoolKey(_connectionString, credential: _credential, accessToken: null, accessTokenCallback: null, sspiContextProvider: value));
                _sspiContextProvider = value;
            }
        }

@github-actions github-actions bot removed the Stale The Issue or PR has become stale and will be automatically closed shortly if no activity occurs. label Feb 13, 2026
Copilot AI review requested due to automatic review settings February 13, 2026 19:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnection.cs:806

  • The SspiContextProvider property setter is missing validation that prevents modification after the connection is opened. Connection-level properties that affect the pool key (Credential, AccessToken, AccessTokenCallback) must validate InnerConnection.AllowSetConnectionString and throw ADP.OpenConnectionPropertySet if false. The documentation at line 2145 explicitly states "The SspiContextProvider is a part of the connection pool key", so it must follow the same pattern. Add the validation check at the start of the setter, similar to the AccessTokenCallback property at lines 782-784.
        public SspiContextProvider SspiContextProvider
        {
            get { return _sspiContextProvider; }
            set
            {
                ConnectionString_Set(new SqlConnectionPoolKey(_connectionString, credential: _credential, accessToken: null, accessTokenCallback: null, sspiContextProvider: value));
                _sspiContextProvider = value;
            }

Copilot AI review requested due to automatic review settings February 13, 2026 21:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Partner Approval Needed 🤝 Issues/PRs that require approval/feedback from partner teams Public API 🆕 Issues/PRs that introduce new APIs to the driver.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add hook for custom SSPI context for SqlConnection instances

8 participants