mirror of
https://github.com/bitwarden/server
synced 2026-01-02 08:33:48 +00:00
[PM-1632] Redirect on SsoRequired - return SsoOrganizationIdentifier (#6597)
feat: add SSO request validation and organization identifier lookup - Implement SsoRequestValidator to validate SSO requirements - Add UserSsoOrganizationIdentifierQuery to fetch organization identifiers - Create SsoOrganizationIdentifier custom response for SSO redirects - Add feature flag (RedirectOnSsoRequired) for gradual rollout - Register validators and queries in dependency injection - Create RequestValidationConstants to reduce magic strings - Add comprehensive test coverage for validation logic - Update BaseRequestValidator to consume SsoRequestValidator
This commit is contained in:
38
src/Core/Auth/Sso/UserSsoOrganizationIdentifierQuery.cs
Normal file
38
src/Core/Auth/Sso/UserSsoOrganizationIdentifierQuery.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Repositories;
|
||||
|
||||
namespace Bit.Core.Auth.Sso;
|
||||
|
||||
/// <summary>
|
||||
/// TODO : PM-28846 review data structures as they relate to this query
|
||||
/// Query to retrieve the SSO organization identifier that a user is a confirmed member of.
|
||||
/// </summary>
|
||||
public class UserSsoOrganizationIdentifierQuery(
|
||||
IOrganizationUserRepository _organizationUserRepository,
|
||||
IOrganizationRepository _organizationRepository) : IUserSsoOrganizationIdentifierQuery
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async Task<string?> GetSsoOrganizationIdentifierAsync(Guid userId)
|
||||
{
|
||||
// Get all confirmed organization memberships for the user
|
||||
var organizationUsers = await _organizationUserRepository.GetManyByUserAsync(userId);
|
||||
|
||||
// we can only confidently return the correct SsoOrganizationIdentifier if there is exactly one Organization.
|
||||
// The user must also be in the Confirmed status.
|
||||
var confirmedOrgUsers = organizationUsers.Where(ou => ou.Status == OrganizationUserStatusType.Confirmed);
|
||||
if (confirmedOrgUsers.Count() != 1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var confirmedOrgUser = confirmedOrgUsers.Single();
|
||||
var organization = await _organizationRepository.GetByIdAsync(confirmedOrgUser.OrganizationId);
|
||||
|
||||
if (organization == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return organization.Identifier;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user