mirror of
https://github.com/bitwarden/server
synced 2026-01-05 01:53:17 +00:00
Revert filescoped (#2227)
* Revert "Add git blame entry (#2226)" This reverts commit239286737d. * Revert "Turn on file scoped namespaces (#2225)" This reverts commit34fb4cca2a.
This commit is contained in:
@@ -1,35 +1,36 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Core.Models.Business.Tokenables;
|
||||
|
||||
public class EmergencyAccessInviteTokenable : Tokens.ExpiringTokenable
|
||||
namespace Bit.Core.Models.Business.Tokenables
|
||||
{
|
||||
public const string ClearTextPrefix = "";
|
||||
public const string DataProtectorPurpose = "EmergencyAccessServiceDataProtector";
|
||||
public const string TokenIdentifier = "EmergencyAccessInvite";
|
||||
public string Identifier { get; set; } = TokenIdentifier;
|
||||
public Guid Id { get; set; }
|
||||
public string Email { get; set; }
|
||||
|
||||
[JsonConstructor]
|
||||
public EmergencyAccessInviteTokenable(DateTime expirationDate)
|
||||
public class EmergencyAccessInviteTokenable : Tokens.ExpiringTokenable
|
||||
{
|
||||
ExpirationDate = expirationDate;
|
||||
}
|
||||
public const string ClearTextPrefix = "";
|
||||
public const string DataProtectorPurpose = "EmergencyAccessServiceDataProtector";
|
||||
public const string TokenIdentifier = "EmergencyAccessInvite";
|
||||
public string Identifier { get; set; } = TokenIdentifier;
|
||||
public Guid Id { get; set; }
|
||||
public string Email { get; set; }
|
||||
|
||||
public EmergencyAccessInviteTokenable(EmergencyAccess user, int hoursTillExpiration)
|
||||
{
|
||||
Id = user.Id;
|
||||
Email = user.Email;
|
||||
ExpirationDate = DateTime.UtcNow.AddHours(hoursTillExpiration);
|
||||
}
|
||||
[JsonConstructor]
|
||||
public EmergencyAccessInviteTokenable(DateTime expirationDate)
|
||||
{
|
||||
ExpirationDate = expirationDate;
|
||||
}
|
||||
|
||||
public bool IsValid(Guid id, string email)
|
||||
{
|
||||
return Id == id &&
|
||||
Email.Equals(email, StringComparison.InvariantCultureIgnoreCase);
|
||||
}
|
||||
public EmergencyAccessInviteTokenable(EmergencyAccess user, int hoursTillExpiration)
|
||||
{
|
||||
Id = user.Id;
|
||||
Email = user.Email;
|
||||
ExpirationDate = DateTime.UtcNow.AddHours(hoursTillExpiration);
|
||||
}
|
||||
|
||||
protected override bool TokenIsValid() => Identifier == TokenIdentifier && Id != default && !string.IsNullOrWhiteSpace(Email);
|
||||
public bool IsValid(Guid id, string email)
|
||||
{
|
||||
return Id == id &&
|
||||
Email.Equals(email, StringComparison.InvariantCultureIgnoreCase);
|
||||
}
|
||||
|
||||
protected override bool TokenIsValid() => Identifier == TokenIdentifier && Id != default && !string.IsNullOrWhiteSpace(Email);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,42 +2,43 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Tokens;
|
||||
|
||||
namespace Bit.Core.Models.Business.Tokenables;
|
||||
|
||||
public class HCaptchaTokenable : ExpiringTokenable
|
||||
namespace Bit.Core.Models.Business.Tokenables
|
||||
{
|
||||
private const double _tokenLifetimeInHours = (double)5 / 60; // 5 minutes
|
||||
public const string ClearTextPrefix = "BWCaptchaBypass_";
|
||||
public const string DataProtectorPurpose = "CaptchaServiceDataProtector";
|
||||
public const string TokenIdentifier = "CaptchaBypassToken";
|
||||
|
||||
public string Identifier { get; set; } = TokenIdentifier;
|
||||
public Guid Id { get; set; }
|
||||
public string Email { get; set; }
|
||||
|
||||
[JsonConstructor]
|
||||
public HCaptchaTokenable()
|
||||
public class HCaptchaTokenable : ExpiringTokenable
|
||||
{
|
||||
ExpirationDate = DateTime.UtcNow.AddHours(_tokenLifetimeInHours);
|
||||
}
|
||||
private const double _tokenLifetimeInHours = (double)5 / 60; // 5 minutes
|
||||
public const string ClearTextPrefix = "BWCaptchaBypass_";
|
||||
public const string DataProtectorPurpose = "CaptchaServiceDataProtector";
|
||||
public const string TokenIdentifier = "CaptchaBypassToken";
|
||||
|
||||
public HCaptchaTokenable(User user) : this()
|
||||
{
|
||||
Id = user?.Id ?? default;
|
||||
Email = user?.Email;
|
||||
}
|
||||
public string Identifier { get; set; } = TokenIdentifier;
|
||||
public Guid Id { get; set; }
|
||||
public string Email { get; set; }
|
||||
|
||||
public bool TokenIsValid(User user)
|
||||
{
|
||||
if (Id == default || Email == default || user == null)
|
||||
[JsonConstructor]
|
||||
public HCaptchaTokenable()
|
||||
{
|
||||
return false;
|
||||
ExpirationDate = DateTime.UtcNow.AddHours(_tokenLifetimeInHours);
|
||||
}
|
||||
|
||||
return Id == user.Id &&
|
||||
Email.Equals(user.Email, StringComparison.InvariantCultureIgnoreCase);
|
||||
}
|
||||
public HCaptchaTokenable(User user) : this()
|
||||
{
|
||||
Id = user?.Id ?? default;
|
||||
Email = user?.Email;
|
||||
}
|
||||
|
||||
// Validates deserialized
|
||||
protected override bool TokenIsValid() => Identifier == TokenIdentifier && Id != default && !string.IsNullOrWhiteSpace(Email);
|
||||
public bool TokenIsValid(User user)
|
||||
{
|
||||
if (Id == default || Email == default || user == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return Id == user.Id &&
|
||||
Email.Equals(user.Email, StringComparison.InvariantCultureIgnoreCase);
|
||||
}
|
||||
|
||||
// Validates deserialized
|
||||
protected override bool TokenIsValid() => Identifier == TokenIdentifier && Id != default && !string.IsNullOrWhiteSpace(Email);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,54 +3,55 @@ using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Tokens;
|
||||
|
||||
namespace Bit.Core.Models.Business.Tokenables;
|
||||
|
||||
public class OrganizationSponsorshipOfferTokenable : Tokenable
|
||||
namespace Bit.Core.Models.Business.Tokenables
|
||||
{
|
||||
public const string ClearTextPrefix = "BWOrganizationSponsorship_";
|
||||
public const string DataProtectorPurpose = "OrganizationSponsorshipDataProtector";
|
||||
public const string TokenIdentifier = "OrganizationSponsorshipOfferToken";
|
||||
public string Identifier { get; set; } = TokenIdentifier;
|
||||
public Guid Id { get; set; }
|
||||
public PlanSponsorshipType SponsorshipType { get; set; }
|
||||
public string Email { get; set; }
|
||||
|
||||
public override bool Valid => !string.IsNullOrWhiteSpace(Email) &&
|
||||
Identifier == TokenIdentifier &&
|
||||
Id != default;
|
||||
|
||||
|
||||
[JsonConstructor]
|
||||
public OrganizationSponsorshipOfferTokenable() { }
|
||||
|
||||
public OrganizationSponsorshipOfferTokenable(OrganizationSponsorship sponsorship)
|
||||
public class OrganizationSponsorshipOfferTokenable : Tokenable
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(sponsorship.OfferedToEmail))
|
||||
{
|
||||
throw new ArgumentException("Invalid OrganizationSponsorship to create a token, OfferedToEmail is required", nameof(sponsorship));
|
||||
}
|
||||
Email = sponsorship.OfferedToEmail;
|
||||
public const string ClearTextPrefix = "BWOrganizationSponsorship_";
|
||||
public const string DataProtectorPurpose = "OrganizationSponsorshipDataProtector";
|
||||
public const string TokenIdentifier = "OrganizationSponsorshipOfferToken";
|
||||
public string Identifier { get; set; } = TokenIdentifier;
|
||||
public Guid Id { get; set; }
|
||||
public PlanSponsorshipType SponsorshipType { get; set; }
|
||||
public string Email { get; set; }
|
||||
|
||||
if (!sponsorship.PlanSponsorshipType.HasValue)
|
||||
{
|
||||
throw new ArgumentException("Invalid OrganizationSponsorship to create a token, PlanSponsorshipType is required", nameof(sponsorship));
|
||||
}
|
||||
SponsorshipType = sponsorship.PlanSponsorshipType.Value;
|
||||
public override bool Valid => !string.IsNullOrWhiteSpace(Email) &&
|
||||
Identifier == TokenIdentifier &&
|
||||
Id != default;
|
||||
|
||||
if (sponsorship.Id == default)
|
||||
|
||||
[JsonConstructor]
|
||||
public OrganizationSponsorshipOfferTokenable() { }
|
||||
|
||||
public OrganizationSponsorshipOfferTokenable(OrganizationSponsorship sponsorship)
|
||||
{
|
||||
throw new ArgumentException("Invalid OrganizationSponsorship to create a token, Id is required", nameof(sponsorship));
|
||||
if (string.IsNullOrWhiteSpace(sponsorship.OfferedToEmail))
|
||||
{
|
||||
throw new ArgumentException("Invalid OrganizationSponsorship to create a token, OfferedToEmail is required", nameof(sponsorship));
|
||||
}
|
||||
Email = sponsorship.OfferedToEmail;
|
||||
|
||||
if (!sponsorship.PlanSponsorshipType.HasValue)
|
||||
{
|
||||
throw new ArgumentException("Invalid OrganizationSponsorship to create a token, PlanSponsorshipType is required", nameof(sponsorship));
|
||||
}
|
||||
SponsorshipType = sponsorship.PlanSponsorshipType.Value;
|
||||
|
||||
if (sponsorship.Id == default)
|
||||
{
|
||||
throw new ArgumentException("Invalid OrganizationSponsorship to create a token, Id is required", nameof(sponsorship));
|
||||
}
|
||||
Id = sponsorship.Id;
|
||||
}
|
||||
Id = sponsorship.Id;
|
||||
|
||||
public bool IsValid(OrganizationSponsorship sponsorship, string currentUserEmail) =>
|
||||
sponsorship != null &&
|
||||
sponsorship.PlanSponsorshipType.HasValue &&
|
||||
SponsorshipType == sponsorship.PlanSponsorshipType.Value &&
|
||||
Id == sponsorship.Id &&
|
||||
!string.IsNullOrWhiteSpace(sponsorship.OfferedToEmail) &&
|
||||
Email.Equals(currentUserEmail, StringComparison.InvariantCultureIgnoreCase) &&
|
||||
Email.Equals(sponsorship.OfferedToEmail, StringComparison.InvariantCultureIgnoreCase);
|
||||
|
||||
}
|
||||
|
||||
public bool IsValid(OrganizationSponsorship sponsorship, string currentUserEmail) =>
|
||||
sponsorship != null &&
|
||||
sponsorship.PlanSponsorshipType.HasValue &&
|
||||
SponsorshipType == sponsorship.PlanSponsorshipType.Value &&
|
||||
Id == sponsorship.Id &&
|
||||
!string.IsNullOrWhiteSpace(sponsorship.OfferedToEmail) &&
|
||||
Email.Equals(currentUserEmail, StringComparison.InvariantCultureIgnoreCase) &&
|
||||
Email.Equals(sponsorship.OfferedToEmail, StringComparison.InvariantCultureIgnoreCase);
|
||||
|
||||
}
|
||||
|
||||
@@ -2,42 +2,43 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Tokens;
|
||||
|
||||
namespace Bit.Core.Models.Business.Tokenables;
|
||||
|
||||
public class SsoTokenable : ExpiringTokenable
|
||||
namespace Bit.Core.Models.Business.Tokenables
|
||||
{
|
||||
public const string ClearTextPrefix = "BWUserPrefix_";
|
||||
public const string DataProtectorPurpose = "SsoTokenDataProtector";
|
||||
public const string TokenIdentifier = "ssoToken";
|
||||
|
||||
public Guid OrganizationId { get; set; }
|
||||
public string DomainHint { get; set; }
|
||||
public string Identifier { get; set; } = TokenIdentifier;
|
||||
|
||||
[JsonConstructor]
|
||||
public SsoTokenable() { }
|
||||
|
||||
public SsoTokenable(Organization organization, double tokenLifetimeInSeconds) : this()
|
||||
public class SsoTokenable : ExpiringTokenable
|
||||
{
|
||||
OrganizationId = organization?.Id ?? default;
|
||||
DomainHint = organization?.Identifier;
|
||||
ExpirationDate = DateTime.UtcNow.AddSeconds(tokenLifetimeInSeconds);
|
||||
}
|
||||
public const string ClearTextPrefix = "BWUserPrefix_";
|
||||
public const string DataProtectorPurpose = "SsoTokenDataProtector";
|
||||
public const string TokenIdentifier = "ssoToken";
|
||||
|
||||
public bool TokenIsValid(Organization organization)
|
||||
{
|
||||
if (OrganizationId == default || DomainHint == default || organization == null || !Valid)
|
||||
public Guid OrganizationId { get; set; }
|
||||
public string DomainHint { get; set; }
|
||||
public string Identifier { get; set; } = TokenIdentifier;
|
||||
|
||||
[JsonConstructor]
|
||||
public SsoTokenable() { }
|
||||
|
||||
public SsoTokenable(Organization organization, double tokenLifetimeInSeconds) : this()
|
||||
{
|
||||
return false;
|
||||
OrganizationId = organization?.Id ?? default;
|
||||
DomainHint = organization?.Identifier;
|
||||
ExpirationDate = DateTime.UtcNow.AddSeconds(tokenLifetimeInSeconds);
|
||||
}
|
||||
|
||||
return organization.Identifier.Equals(DomainHint, StringComparison.InvariantCultureIgnoreCase)
|
||||
&& organization.Id.Equals(OrganizationId);
|
||||
}
|
||||
public bool TokenIsValid(Organization organization)
|
||||
{
|
||||
if (OrganizationId == default || DomainHint == default || organization == null || !Valid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validates deserialized
|
||||
protected override bool TokenIsValid() =>
|
||||
Identifier == TokenIdentifier
|
||||
&& OrganizationId != default
|
||||
&& !string.IsNullOrWhiteSpace(DomainHint);
|
||||
return organization.Identifier.Equals(DomainHint, StringComparison.InvariantCultureIgnoreCase)
|
||||
&& organization.Id.Equals(OrganizationId);
|
||||
}
|
||||
|
||||
// Validates deserialized
|
||||
protected override bool TokenIsValid() =>
|
||||
Identifier == TokenIdentifier
|
||||
&& OrganizationId != default
|
||||
&& !string.IsNullOrWhiteSpace(DomainHint);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user