1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-05 10:02:47 -05:00

Turn on file scoped namespaces (#2225)

This commit is contained in:
Justin Baur
2022-08-29 14:53:16 -04:00
committed by GitHub
parent 7c4521e0b4
commit 34fb4cca2a
1206 changed files with 73816 additions and 75022 deletions

View File

@ -1,12 +1,11 @@
using Bit.Core.Entities;
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public class AttachmentResponseData
{
public class AttachmentResponseData
{
public string Id { get; set; }
public CipherAttachment.MetaData Data { get; set; }
public Cipher Cipher { get; set; }
public string Url { get; set; }
}
public string Id { get; set; }
public CipherAttachment.MetaData Data { get; set; }
public Cipher Cipher { get; set; }
public string Url { get; set; }
}

View File

@ -1,36 +1,35 @@
using System.Text.Json.Serialization;
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public class CipherAttachment
{
public class CipherAttachment
public Guid Id { get; set; }
public Guid? UserId { get; set; }
public Guid? OrganizationId { get; set; }
public string AttachmentId { get; set; }
public string AttachmentData { get; set; }
public class MetaData
{
public Guid Id { get; set; }
public Guid? UserId { get; set; }
public Guid? OrganizationId { get; set; }
public string AttachmentId { get; set; }
public string AttachmentData { get; set; }
private long _size;
public class MetaData
// We serialize Size as a string since JSON (or Javascript) doesn't support full precision for long numbers
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString)]
public long Size
{
private long _size;
// We serialize Size as a string since JSON (or Javascript) doesn't support full precision for long numbers
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString)]
public long Size
{
get { return _size; }
set { _size = value; }
}
public string FileName { get; set; }
public string Key { get; set; }
public string ContainerName { get; set; } = "attachments";
public bool Validated { get; set; } = true;
// This is stored alongside metadata as an identifier. It does not need repeating in serialization
[JsonIgnore]
public string AttachmentId { get; set; }
get { return _size; }
set { _size = value; }
}
public string FileName { get; set; }
public string Key { get; set; }
public string ContainerName { get; set; } = "attachments";
public bool Validated { get; set; } = true;
// This is stored alongside metadata as an identifier. It does not need repeating in serialization
[JsonIgnore]
public string AttachmentId { get; set; }
}
}

View File

@ -1,14 +1,13 @@
namespace Bit.Core.Models.Data
{
public class CipherCardData : CipherData
{
public CipherCardData() { }
namespace Bit.Core.Models.Data;
public string CardholderName { get; set; }
public string Brand { get; set; }
public string Number { get; set; }
public string ExpMonth { get; set; }
public string ExpYear { get; set; }
public string Code { get; set; }
}
public class CipherCardData : CipherData
{
public CipherCardData() { }
public string CardholderName { get; set; }
public string Brand { get; set; }
public string Number { get; set; }
public string ExpMonth { get; set; }
public string ExpYear { get; set; }
public string Code { get; set; }
}

View File

@ -1,12 +1,11 @@
namespace Bit.Core.Models.Data
{
public abstract class CipherData
{
public CipherData() { }
namespace Bit.Core.Models.Data;
public string Name { get; set; }
public string Notes { get; set; }
public IEnumerable<CipherFieldData> Fields { get; set; }
public IEnumerable<CipherPasswordHistoryData> PasswordHistory { get; set; }
}
public abstract class CipherData
{
public CipherData() { }
public string Name { get; set; }
public string Notes { get; set; }
public IEnumerable<CipherFieldData> Fields { get; set; }
public IEnumerable<CipherPasswordHistoryData> PasswordHistory { get; set; }
}

View File

@ -1,10 +1,9 @@
namespace Core.Models.Data
namespace Core.Models.Data;
public class CipherDetails : CipherOrganizationDetails
{
public class CipherDetails : CipherOrganizationDetails
{
public Guid? FolderId { get; set; }
public bool Favorite { get; set; }
public bool Edit { get; set; }
public bool ViewPassword { get; set; }
}
public Guid? FolderId { get; set; }
public bool Favorite { get; set; }
public bool Edit { get; set; }
public bool ViewPassword { get; set; }
}

View File

@ -1,14 +1,13 @@
using Bit.Core.Enums;
namespace Bit.Core.Models.Data
{
public class CipherFieldData
{
public CipherFieldData() { }
namespace Bit.Core.Models.Data;
public FieldType Type { get; set; }
public string Name { get; set; }
public string Value { get; set; }
public int? LinkedId { get; set; }
}
public class CipherFieldData
{
public CipherFieldData() { }
public FieldType Type { get; set; }
public string Name { get; set; }
public string Value { get; set; }
public int? LinkedId { get; set; }
}

View File

@ -1,26 +1,25 @@
namespace Bit.Core.Models.Data
{
public class CipherIdentityData : CipherData
{
public CipherIdentityData() { }
namespace Bit.Core.Models.Data;
public string Title { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string Address3 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string PostalCode { get; set; }
public string Country { get; set; }
public string Company { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public string SSN { get; set; }
public string Username { get; set; }
public string PassportNumber { get; set; }
public string LicenseNumber { get; set; }
}
public class CipherIdentityData : CipherData
{
public CipherIdentityData() { }
public string Title { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string Address3 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string PostalCode { get; set; }
public string Country { get; set; }
public string Company { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public string SSN { get; set; }
public string Username { get; set; }
public string PassportNumber { get; set; }
public string LicenseNumber { get; set; }
}

View File

@ -1,31 +1,30 @@
using Bit.Core.Enums;
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public class CipherLoginData : CipherData
{
public class CipherLoginData : CipherData
private string _uri;
public CipherLoginData() { }
public string Uri
{
private string _uri;
get => Uris?.FirstOrDefault()?.Uri ?? _uri;
set { _uri = value; }
}
public IEnumerable<CipherLoginUriData> Uris { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public DateTime? PasswordRevisionDate { get; set; }
public string Totp { get; set; }
public bool? AutofillOnPageLoad { get; set; }
public CipherLoginData() { }
public class CipherLoginUriData
{
public CipherLoginUriData() { }
public string Uri
{
get => Uris?.FirstOrDefault()?.Uri ?? _uri;
set { _uri = value; }
}
public IEnumerable<CipherLoginUriData> Uris { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public DateTime? PasswordRevisionDate { get; set; }
public string Totp { get; set; }
public bool? AutofillOnPageLoad { get; set; }
public class CipherLoginUriData
{
public CipherLoginUriData() { }
public string Uri { get; set; }
public UriMatchType? Match { get; set; } = null;
}
public string Uri { get; set; }
public UriMatchType? Match { get; set; } = null;
}
}

View File

@ -1,9 +1,8 @@
using Bit.Core.Entities;
namespace Core.Models.Data
namespace Core.Models.Data;
public class CipherOrganizationDetails : Cipher
{
public class CipherOrganizationDetails : Cipher
{
public bool OrganizationUseTotp { get; set; }
}
public bool OrganizationUseTotp { get; set; }
}

View File

@ -1,10 +1,9 @@
namespace Bit.Core.Models.Data
{
public class CipherPasswordHistoryData
{
public CipherPasswordHistoryData() { }
namespace Bit.Core.Models.Data;
public string Password { get; set; }
public DateTime LastUsedDate { get; set; }
}
public class CipherPasswordHistoryData
{
public CipherPasswordHistoryData() { }
public string Password { get; set; }
public DateTime LastUsedDate { get; set; }
}

View File

@ -1,11 +1,10 @@
using Bit.Core.Enums;
namespace Bit.Core.Models.Data
{
public class CipherSecureNoteData : CipherData
{
public CipherSecureNoteData() { }
namespace Bit.Core.Models.Data;
public SecureNoteType Type { get; set; }
}
public class CipherSecureNoteData : CipherData
{
public CipherSecureNoteData() { }
public SecureNoteType Type { get; set; }
}

View File

@ -1,10 +1,9 @@
using Bit.Core.Entities;
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public class CollectionDetails : Collection
{
public class CollectionDetails : Collection
{
public bool ReadOnly { get; set; }
public bool HidePasswords { get; set; }
}
public bool ReadOnly { get; set; }
public bool HidePasswords { get; set; }
}

View File

@ -1,135 +1,134 @@
using System.Collections;
using Microsoft.Azure.Cosmos.Table;
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public class DictionaryEntity : TableEntity, IDictionary<string, EntityProperty>
{
public class DictionaryEntity : TableEntity, IDictionary<string, EntityProperty>
private IDictionary<string, EntityProperty> _properties = new Dictionary<string, EntityProperty>();
public ICollection<EntityProperty> Values => _properties.Values;
public EntityProperty this[string key]
{
private IDictionary<string, EntityProperty> _properties = new Dictionary<string, EntityProperty>();
get => _properties[key];
set => _properties[key] = value;
}
public ICollection<EntityProperty> Values => _properties.Values;
public int Count => _properties.Count;
public EntityProperty this[string key]
{
get => _properties[key];
set => _properties[key] = value;
}
public bool IsReadOnly => _properties.IsReadOnly;
public int Count => _properties.Count;
public ICollection<string> Keys => _properties.Keys;
public bool IsReadOnly => _properties.IsReadOnly;
public override void ReadEntity(IDictionary<string, EntityProperty> properties,
OperationContext operationContext)
{
_properties = properties;
}
public ICollection<string> Keys => _properties.Keys;
public override IDictionary<string, EntityProperty> WriteEntity(OperationContext operationContext)
{
return _properties;
}
public override void ReadEntity(IDictionary<string, EntityProperty> properties,
OperationContext operationContext)
{
_properties = properties;
}
public void Add(string key, EntityProperty value)
{
_properties.Add(key, value);
}
public override IDictionary<string, EntityProperty> WriteEntity(OperationContext operationContext)
{
return _properties;
}
public void Add(string key, bool value)
{
_properties.Add(key, new EntityProperty(value));
}
public void Add(string key, EntityProperty value)
{
_properties.Add(key, value);
}
public void Add(string key, byte[] value)
{
_properties.Add(key, new EntityProperty(value));
}
public void Add(string key, bool value)
{
_properties.Add(key, new EntityProperty(value));
}
public void Add(string key, DateTime? value)
{
_properties.Add(key, new EntityProperty(value));
}
public void Add(string key, byte[] value)
{
_properties.Add(key, new EntityProperty(value));
}
public void Add(string key, DateTimeOffset? value)
{
_properties.Add(key, new EntityProperty(value));
}
public void Add(string key, DateTime? value)
{
_properties.Add(key, new EntityProperty(value));
}
public void Add(string key, double value)
{
_properties.Add(key, new EntityProperty(value));
}
public void Add(string key, DateTimeOffset? value)
{
_properties.Add(key, new EntityProperty(value));
}
public void Add(string key, Guid value)
{
_properties.Add(key, new EntityProperty(value));
}
public void Add(string key, double value)
{
_properties.Add(key, new EntityProperty(value));
}
public void Add(string key, int value)
{
_properties.Add(key, new EntityProperty(value));
}
public void Add(string key, Guid value)
{
_properties.Add(key, new EntityProperty(value));
}
public void Add(string key, long value)
{
_properties.Add(key, new EntityProperty(value));
}
public void Add(string key, int value)
{
_properties.Add(key, new EntityProperty(value));
}
public void Add(string key, string value)
{
_properties.Add(key, new EntityProperty(value));
}
public void Add(string key, long value)
{
_properties.Add(key, new EntityProperty(value));
}
public void Add(KeyValuePair<string, EntityProperty> item)
{
_properties.Add(item);
}
public void Add(string key, string value)
{
_properties.Add(key, new EntityProperty(value));
}
public bool ContainsKey(string key)
{
return _properties.ContainsKey(key);
}
public void Add(KeyValuePair<string, EntityProperty> item)
{
_properties.Add(item);
}
public bool Remove(string key)
{
return _properties.Remove(key);
}
public bool ContainsKey(string key)
{
return _properties.ContainsKey(key);
}
public bool TryGetValue(string key, out EntityProperty value)
{
return _properties.TryGetValue(key, out value);
}
public bool Remove(string key)
{
return _properties.Remove(key);
}
public void Clear()
{
_properties.Clear();
}
public bool TryGetValue(string key, out EntityProperty value)
{
return _properties.TryGetValue(key, out value);
}
public bool Contains(KeyValuePair<string, EntityProperty> item)
{
return _properties.Contains(item);
}
public void Clear()
{
_properties.Clear();
}
public void CopyTo(KeyValuePair<string, EntityProperty>[] array, int arrayIndex)
{
_properties.CopyTo(array, arrayIndex);
}
public bool Contains(KeyValuePair<string, EntityProperty> item)
{
return _properties.Contains(item);
}
public bool Remove(KeyValuePair<string, EntityProperty> item)
{
return _properties.Remove(item);
}
public void CopyTo(KeyValuePair<string, EntityProperty>[] array, int arrayIndex)
{
_properties.CopyTo(array, arrayIndex);
}
public IEnumerator<KeyValuePair<string, EntityProperty>> GetEnumerator()
{
return _properties.GetEnumerator();
}
public bool Remove(KeyValuePair<string, EntityProperty> item)
{
return _properties.Remove(item);
}
public IEnumerator<KeyValuePair<string, EntityProperty>> GetEnumerator()
{
return _properties.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return _properties.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return _properties.GetEnumerator();
}
}

View File

@ -1,12 +1,11 @@
using Bit.Core.Entities;
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public class EmergencyAccessDetails : EmergencyAccess
{
public class EmergencyAccessDetails : EmergencyAccess
{
public string GranteeName { get; set; }
public string GranteeEmail { get; set; }
public string GrantorName { get; set; }
public string GrantorEmail { get; set; }
}
public string GranteeName { get; set; }
public string GranteeEmail { get; set; }
public string GrantorName { get; set; }
public string GrantorEmail { get; set; }
}

View File

@ -1,11 +1,10 @@
using Bit.Core.Entities;
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public class EmergencyAccessNotify : EmergencyAccess
{
public class EmergencyAccessNotify : EmergencyAccess
{
public string GrantorEmail { get; set; }
public string GranteeName { get; set; }
public string GranteeEmail { get; set; }
}
public string GrantorEmail { get; set; }
public string GranteeName { get; set; }
public string GranteeEmail { get; set; }
}

View File

@ -1,11 +1,10 @@
using Bit.Core.Entities;
using Core.Models.Data;
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public class EmergencyAccessViewData
{
public class EmergencyAccessViewData
{
public EmergencyAccess EmergencyAccess { get; set; }
public IEnumerable<CipherDetails> Ciphers { get; set; }
}
public EmergencyAccess EmergencyAccess { get; set; }
public IEnumerable<CipherDetails> Ciphers { get; set; }
}

View File

@ -1,35 +1,34 @@
using Bit.Core.Context;
using Bit.Core.Enums;
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public class EventMessage : IEvent
{
public class EventMessage : IEvent
public EventMessage() { }
public EventMessage(ICurrentContext currentContext)
: base()
{
public EventMessage() { }
public EventMessage(ICurrentContext currentContext)
: base()
{
IpAddress = currentContext.IpAddress;
DeviceType = currentContext.DeviceType;
}
public DateTime Date { get; set; }
public EventType Type { get; set; }
public Guid? UserId { get; set; }
public Guid? OrganizationId { get; set; }
public Guid? InstallationId { get; set; }
public Guid? ProviderId { get; set; }
public Guid? CipherId { get; set; }
public Guid? CollectionId { get; set; }
public Guid? GroupId { get; set; }
public Guid? PolicyId { get; set; }
public Guid? OrganizationUserId { get; set; }
public Guid? ProviderUserId { get; set; }
public Guid? ProviderOrganizationId { get; set; }
public Guid? ActingUserId { get; set; }
public DeviceType? DeviceType { get; set; }
public string IpAddress { get; set; }
public Guid? IdempotencyId { get; private set; } = Guid.NewGuid();
IpAddress = currentContext.IpAddress;
DeviceType = currentContext.DeviceType;
}
public DateTime Date { get; set; }
public EventType Type { get; set; }
public Guid? UserId { get; set; }
public Guid? OrganizationId { get; set; }
public Guid? InstallationId { get; set; }
public Guid? ProviderId { get; set; }
public Guid? CipherId { get; set; }
public Guid? CollectionId { get; set; }
public Guid? GroupId { get; set; }
public Guid? PolicyId { get; set; }
public Guid? OrganizationUserId { get; set; }
public Guid? ProviderUserId { get; set; }
public Guid? ProviderOrganizationId { get; set; }
public Guid? ActingUserId { get; set; }
public DeviceType? DeviceType { get; set; }
public string IpAddress { get; set; }
public Guid? IdempotencyId { get; private set; } = Guid.NewGuid();
}

View File

@ -2,154 +2,153 @@
using Bit.Core.Utilities;
using Microsoft.Azure.Cosmos.Table;
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public class EventTableEntity : TableEntity, IEvent
{
public class EventTableEntity : TableEntity, IEvent
public EventTableEntity() { }
private EventTableEntity(IEvent e)
{
public EventTableEntity() { }
Date = e.Date;
Type = e.Type;
UserId = e.UserId;
OrganizationId = e.OrganizationId;
InstallationId = e.InstallationId;
ProviderId = e.ProviderId;
CipherId = e.CipherId;
CollectionId = e.CollectionId;
PolicyId = e.PolicyId;
GroupId = e.GroupId;
OrganizationUserId = e.OrganizationUserId;
ProviderUserId = e.ProviderUserId;
ProviderOrganizationId = e.ProviderOrganizationId;
DeviceType = e.DeviceType;
IpAddress = e.IpAddress;
ActingUserId = e.ActingUserId;
}
private EventTableEntity(IEvent e)
public DateTime Date { get; set; }
public EventType Type { get; set; }
public Guid? UserId { get; set; }
public Guid? OrganizationId { get; set; }
public Guid? InstallationId { get; set; }
public Guid? ProviderId { get; set; }
public Guid? CipherId { get; set; }
public Guid? CollectionId { get; set; }
public Guid? PolicyId { get; set; }
public Guid? GroupId { get; set; }
public Guid? OrganizationUserId { get; set; }
public Guid? ProviderUserId { get; set; }
public Guid? ProviderOrganizationId { get; set; }
public DeviceType? DeviceType { get; set; }
public string IpAddress { get; set; }
public Guid? ActingUserId { get; set; }
public override IDictionary<string, EntityProperty> WriteEntity(OperationContext operationContext)
{
var result = base.WriteEntity(operationContext);
var typeName = nameof(Type);
if (result.ContainsKey(typeName))
{
Date = e.Date;
Type = e.Type;
UserId = e.UserId;
OrganizationId = e.OrganizationId;
InstallationId = e.InstallationId;
ProviderId = e.ProviderId;
CipherId = e.CipherId;
CollectionId = e.CollectionId;
PolicyId = e.PolicyId;
GroupId = e.GroupId;
OrganizationUserId = e.OrganizationUserId;
ProviderUserId = e.ProviderUserId;
ProviderOrganizationId = e.ProviderOrganizationId;
DeviceType = e.DeviceType;
IpAddress = e.IpAddress;
ActingUserId = e.ActingUserId;
result[typeName] = new EntityProperty((int)Type);
}
else
{
result.Add(typeName, new EntityProperty((int)Type));
}
public DateTime Date { get; set; }
public EventType Type { get; set; }
public Guid? UserId { get; set; }
public Guid? OrganizationId { get; set; }
public Guid? InstallationId { get; set; }
public Guid? ProviderId { get; set; }
public Guid? CipherId { get; set; }
public Guid? CollectionId { get; set; }
public Guid? PolicyId { get; set; }
public Guid? GroupId { get; set; }
public Guid? OrganizationUserId { get; set; }
public Guid? ProviderUserId { get; set; }
public Guid? ProviderOrganizationId { get; set; }
public DeviceType? DeviceType { get; set; }
public string IpAddress { get; set; }
public Guid? ActingUserId { get; set; }
public override IDictionary<string, EntityProperty> WriteEntity(OperationContext operationContext)
var deviceTypeName = nameof(DeviceType);
if (result.ContainsKey(deviceTypeName))
{
var result = base.WriteEntity(operationContext);
var typeName = nameof(Type);
if (result.ContainsKey(typeName))
{
result[typeName] = new EntityProperty((int)Type);
}
else
{
result.Add(typeName, new EntityProperty((int)Type));
}
var deviceTypeName = nameof(DeviceType);
if (result.ContainsKey(deviceTypeName))
{
result[deviceTypeName] = new EntityProperty((int?)DeviceType);
}
else
{
result.Add(deviceTypeName, new EntityProperty((int?)DeviceType));
}
return result;
result[deviceTypeName] = new EntityProperty((int?)DeviceType);
}
else
{
result.Add(deviceTypeName, new EntityProperty((int?)DeviceType));
}
public override void ReadEntity(IDictionary<string, EntityProperty> properties,
OperationContext operationContext)
return result;
}
public override void ReadEntity(IDictionary<string, EntityProperty> properties,
OperationContext operationContext)
{
base.ReadEntity(properties, operationContext);
var typeName = nameof(Type);
if (properties.ContainsKey(typeName) && properties[typeName].Int32Value.HasValue)
{
base.ReadEntity(properties, operationContext);
var typeName = nameof(Type);
if (properties.ContainsKey(typeName) && properties[typeName].Int32Value.HasValue)
{
Type = (EventType)properties[typeName].Int32Value.Value;
}
var deviceTypeName = nameof(DeviceType);
if (properties.ContainsKey(deviceTypeName) && properties[deviceTypeName].Int32Value.HasValue)
{
DeviceType = (DeviceType)properties[deviceTypeName].Int32Value.Value;
}
Type = (EventType)properties[typeName].Int32Value.Value;
}
public static List<EventTableEntity> IndexEvent(EventMessage e)
var deviceTypeName = nameof(DeviceType);
if (properties.ContainsKey(deviceTypeName) && properties[deviceTypeName].Int32Value.HasValue)
{
var uniquifier = e.IdempotencyId.GetValueOrDefault(Guid.NewGuid());
var pKey = GetPartitionKey(e);
var dateKey = CoreHelpers.DateTimeToTableStorageKey(e.Date);
var entities = new List<EventTableEntity>
{
new EventTableEntity(e)
{
PartitionKey = pKey,
RowKey = $"Date={dateKey}__Uniquifier={uniquifier}"
}
};
if (e.OrganizationId.HasValue && e.ActingUserId.HasValue)
{
entities.Add(new EventTableEntity(e)
{
PartitionKey = pKey,
RowKey = $"ActingUserId={e.ActingUserId}__Date={dateKey}__Uniquifier={uniquifier}"
});
}
if (!e.OrganizationId.HasValue && e.ProviderId.HasValue && e.ActingUserId.HasValue)
{
entities.Add(new EventTableEntity(e)
{
PartitionKey = pKey,
RowKey = $"ActingUserId={e.ActingUserId}__Date={dateKey}__Uniquifier={uniquifier}"
});
}
if (e.CipherId.HasValue)
{
entities.Add(new EventTableEntity(e)
{
PartitionKey = pKey,
RowKey = $"CipherId={e.CipherId}__Date={dateKey}__Uniquifier={uniquifier}"
});
}
return entities;
}
private static string GetPartitionKey(EventMessage e)
{
if (e.OrganizationId.HasValue)
{
return $"OrganizationId={e.OrganizationId}";
}
if (e.ProviderId.HasValue)
{
return $"ProviderId={e.ProviderId}";
}
return $"UserId={e.UserId}";
DeviceType = (DeviceType)properties[deviceTypeName].Int32Value.Value;
}
}
public static List<EventTableEntity> IndexEvent(EventMessage e)
{
var uniquifier = e.IdempotencyId.GetValueOrDefault(Guid.NewGuid());
var pKey = GetPartitionKey(e);
var dateKey = CoreHelpers.DateTimeToTableStorageKey(e.Date);
var entities = new List<EventTableEntity>
{
new EventTableEntity(e)
{
PartitionKey = pKey,
RowKey = $"Date={dateKey}__Uniquifier={uniquifier}"
}
};
if (e.OrganizationId.HasValue && e.ActingUserId.HasValue)
{
entities.Add(new EventTableEntity(e)
{
PartitionKey = pKey,
RowKey = $"ActingUserId={e.ActingUserId}__Date={dateKey}__Uniquifier={uniquifier}"
});
}
if (!e.OrganizationId.HasValue && e.ProviderId.HasValue && e.ActingUserId.HasValue)
{
entities.Add(new EventTableEntity(e)
{
PartitionKey = pKey,
RowKey = $"ActingUserId={e.ActingUserId}__Date={dateKey}__Uniquifier={uniquifier}"
});
}
if (e.CipherId.HasValue)
{
entities.Add(new EventTableEntity(e)
{
PartitionKey = pKey,
RowKey = $"CipherId={e.CipherId}__Date={dateKey}__Uniquifier={uniquifier}"
});
}
return entities;
}
private static string GetPartitionKey(EventMessage e)
{
if (e.OrganizationId.HasValue)
{
return $"OrganizationId={e.OrganizationId}";
}
if (e.ProviderId.HasValue)
{
return $"ProviderId={e.ProviderId}";
}
return $"UserId={e.UserId}";
}
}

View File

@ -1,10 +1,9 @@
using System.Data;
using Bit.Core.Entities;
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public class GroupWithCollections : Group
{
public class GroupWithCollections : Group
{
public DataTable Collections { get; set; }
}
public DataTable Collections { get; set; }
}

View File

@ -1,24 +1,23 @@
using Bit.Core.Enums;
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public interface IEvent
{
public interface IEvent
{
EventType Type { get; set; }
Guid? UserId { get; set; }
Guid? OrganizationId { get; set; }
Guid? InstallationId { get; set; }
Guid? ProviderId { get; set; }
Guid? CipherId { get; set; }
Guid? CollectionId { get; set; }
Guid? GroupId { get; set; }
Guid? PolicyId { get; set; }
Guid? OrganizationUserId { get; set; }
Guid? ProviderUserId { get; set; }
Guid? ProviderOrganizationId { get; set; }
Guid? ActingUserId { get; set; }
DeviceType? DeviceType { get; set; }
string IpAddress { get; set; }
DateTime Date { get; set; }
}
EventType Type { get; set; }
Guid? UserId { get; set; }
Guid? OrganizationId { get; set; }
Guid? InstallationId { get; set; }
Guid? ProviderId { get; set; }
Guid? CipherId { get; set; }
Guid? CollectionId { get; set; }
Guid? GroupId { get; set; }
Guid? PolicyId { get; set; }
Guid? OrganizationUserId { get; set; }
Guid? ProviderUserId { get; set; }
Guid? ProviderOrganizationId { get; set; }
Guid? ActingUserId { get; set; }
DeviceType? DeviceType { get; set; }
string IpAddress { get; set; }
DateTime Date { get; set; }
}

View File

@ -1,35 +1,34 @@
using Microsoft.Azure.Cosmos.Table;
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public class InstallationDeviceEntity : TableEntity
{
public class InstallationDeviceEntity : TableEntity
public InstallationDeviceEntity() { }
public InstallationDeviceEntity(Guid installationId, Guid deviceId)
{
public InstallationDeviceEntity() { }
PartitionKey = installationId.ToString();
RowKey = deviceId.ToString();
}
public InstallationDeviceEntity(Guid installationId, Guid deviceId)
public InstallationDeviceEntity(string prefixedDeviceId)
{
var parts = prefixedDeviceId.Split("_");
if (parts.Length < 2)
{
PartitionKey = installationId.ToString();
RowKey = deviceId.ToString();
throw new ArgumentException("Not enough parts.");
}
if (!Guid.TryParse(parts[0], out var installationId) || !Guid.TryParse(parts[1], out var deviceId))
{
throw new ArgumentException("Could not parse parts.");
}
PartitionKey = parts[0];
RowKey = parts[1];
}
public InstallationDeviceEntity(string prefixedDeviceId)
{
var parts = prefixedDeviceId.Split("_");
if (parts.Length < 2)
{
throw new ArgumentException("Not enough parts.");
}
if (!Guid.TryParse(parts[0], out var installationId) || !Guid.TryParse(parts[1], out var deviceId))
{
throw new ArgumentException("Could not parse parts.");
}
PartitionKey = parts[0];
RowKey = parts[1];
}
public static bool IsInstallationDeviceId(string deviceId)
{
return deviceId != null && deviceId.Length == 73 && deviceId[36] == '_';
}
public static bool IsInstallationDeviceId(string deviceId)
{
return deviceId != null && deviceId.Length == 73 && deviceId[36] == '_';
}
}

View File

@ -1,35 +1,34 @@
using Bit.Core.Entities;
namespace Bit.Core.Models.Data.Organizations
namespace Bit.Core.Models.Data.Organizations;
public class OrganizationAbility
{
public class OrganizationAbility
public OrganizationAbility() { }
public OrganizationAbility(Organization organization)
{
public OrganizationAbility() { }
public OrganizationAbility(Organization organization)
{
Id = organization.Id;
UseEvents = organization.UseEvents;
Use2fa = organization.Use2fa;
Using2fa = organization.Use2fa && organization.TwoFactorProviders != null &&
organization.TwoFactorProviders != "{}";
UsersGetPremium = organization.UsersGetPremium;
Enabled = organization.Enabled;
UseSso = organization.UseSso;
UseKeyConnector = organization.UseKeyConnector;
UseScim = organization.UseScim;
UseResetPassword = organization.UseResetPassword;
}
public Guid Id { get; set; }
public bool UseEvents { get; set; }
public bool Use2fa { get; set; }
public bool Using2fa { get; set; }
public bool UsersGetPremium { get; set; }
public bool Enabled { get; set; }
public bool UseSso { get; set; }
public bool UseKeyConnector { get; set; }
public bool UseScim { get; set; }
public bool UseResetPassword { get; set; }
Id = organization.Id;
UseEvents = organization.UseEvents;
Use2fa = organization.Use2fa;
Using2fa = organization.Use2fa && organization.TwoFactorProviders != null &&
organization.TwoFactorProviders != "{}";
UsersGetPremium = organization.UsersGetPremium;
Enabled = organization.Enabled;
UseSso = organization.UseSso;
UseKeyConnector = organization.UseKeyConnector;
UseScim = organization.UseScim;
UseResetPassword = organization.UseResetPassword;
}
public Guid Id { get; set; }
public bool UseEvents { get; set; }
public bool Use2fa { get; set; }
public bool Using2fa { get; set; }
public bool UsersGetPremium { get; set; }
public bool Enabled { get; set; }
public bool UseSso { get; set; }
public bool UseKeyConnector { get; set; }
public bool UseScim { get; set; }
public bool UseResetPassword { get; set; }
}

View File

@ -1,32 +1,31 @@
using Bit.Core.Entities;
using Bit.Core.Enums;
namespace Bit.Core.Models.Data.Organizations.OrganizationConnections
namespace Bit.Core.Models.Data.Organizations.OrganizationConnections;
public class OrganizationConnectionData<T> where T : new()
{
public class OrganizationConnectionData<T> where T : new()
public Guid? Id { get; set; }
public OrganizationConnectionType Type { get; set; }
public Guid OrganizationId { get; set; }
public bool Enabled { get; set; }
public T Config { get; set; }
public OrganizationConnection ToEntity()
{
public Guid? Id { get; set; }
public OrganizationConnectionType Type { get; set; }
public Guid OrganizationId { get; set; }
public bool Enabled { get; set; }
public T Config { get; set; }
public OrganizationConnection ToEntity()
var result = new OrganizationConnection()
{
var result = new OrganizationConnection()
{
Type = Type,
OrganizationId = OrganizationId,
Enabled = Enabled,
};
result.SetConfig(Config);
Type = Type,
OrganizationId = OrganizationId,
Enabled = Enabled,
};
result.SetConfig(Config);
if (Id.HasValue)
{
result.Id = Id.Value;
}
return result;
if (Id.HasValue)
{
result.Id = Id.Value;
}
return result;
}
}

View File

@ -1,31 +1,30 @@
using Bit.Core.Entities;
using Bit.Core.Enums;
namespace Bit.Core.Models.Data.Organizations.OrganizationSponsorships
{
public class OrganizationSponsorshipData
{
public OrganizationSponsorshipData() { }
public OrganizationSponsorshipData(OrganizationSponsorship sponsorship)
{
SponsoringOrganizationUserId = sponsorship.SponsoringOrganizationUserId;
SponsoredOrganizationId = sponsorship.SponsoredOrganizationId;
FriendlyName = sponsorship.FriendlyName;
OfferedToEmail = sponsorship.OfferedToEmail;
PlanSponsorshipType = sponsorship.PlanSponsorshipType.GetValueOrDefault();
LastSyncDate = sponsorship.LastSyncDate;
ValidUntil = sponsorship.ValidUntil;
ToDelete = sponsorship.ToDelete;
}
public Guid SponsoringOrganizationUserId { get; set; }
public Guid? SponsoredOrganizationId { get; set; }
public string FriendlyName { get; set; }
public string OfferedToEmail { get; set; }
public PlanSponsorshipType PlanSponsorshipType { get; set; }
public DateTime? LastSyncDate { get; set; }
public DateTime? ValidUntil { get; set; }
public bool ToDelete { get; set; }
namespace Bit.Core.Models.Data.Organizations.OrganizationSponsorships;
public bool CloudSponsorshipRemoved { get; set; }
public class OrganizationSponsorshipData
{
public OrganizationSponsorshipData() { }
public OrganizationSponsorshipData(OrganizationSponsorship sponsorship)
{
SponsoringOrganizationUserId = sponsorship.SponsoringOrganizationUserId;
SponsoredOrganizationId = sponsorship.SponsoredOrganizationId;
FriendlyName = sponsorship.FriendlyName;
OfferedToEmail = sponsorship.OfferedToEmail;
PlanSponsorshipType = sponsorship.PlanSponsorshipType.GetValueOrDefault();
LastSyncDate = sponsorship.LastSyncDate;
ValidUntil = sponsorship.ValidUntil;
ToDelete = sponsorship.ToDelete;
}
public Guid SponsoringOrganizationUserId { get; set; }
public Guid? SponsoredOrganizationId { get; set; }
public string FriendlyName { get; set; }
public string OfferedToEmail { get; set; }
public PlanSponsorshipType PlanSponsorshipType { get; set; }
public DateTime? LastSyncDate { get; set; }
public DateTime? ValidUntil { get; set; }
public bool ToDelete { get; set; }
public bool CloudSponsorshipRemoved { get; set; }
}

View File

@ -1,9 +1,8 @@
namespace Bit.Core.Models.Data.Organizations.OrganizationSponsorships
namespace Bit.Core.Models.Data.Organizations.OrganizationSponsorships;
public class OrganizationSponsorshipSyncData
{
public class OrganizationSponsorshipSyncData
{
public string BillingSyncKey { get; set; }
public Guid SponsoringOrganizationCloudId { get; set; }
public IEnumerable<OrganizationSponsorshipData> SponsorshipsBatch { get; set; }
}
public string BillingSyncKey { get; set; }
public Guid SponsoringOrganizationCloudId { get; set; }
public IEnumerable<OrganizationSponsorshipData> SponsorshipsBatch { get; set; }
}

View File

@ -1,13 +1,12 @@
using Bit.Core.Enums;
namespace Bit.Core.Models.Data.Organizations.OrganizationUsers
namespace Bit.Core.Models.Data.Organizations.OrganizationUsers;
public class OrganizationUserInviteData
{
public class OrganizationUserInviteData
{
public IEnumerable<string> Emails { get; set; }
public OrganizationUserType? Type { get; set; }
public bool AccessAll { get; set; }
public IEnumerable<SelectionReadOnly> Collections { get; set; }
public Permissions Permissions { get; set; }
}
public IEnumerable<string> Emails { get; set; }
public OrganizationUserType? Type { get; set; }
public bool AccessAll { get; set; }
public IEnumerable<SelectionReadOnly> Collections { get; set; }
public Permissions Permissions { get; set; }
}

View File

@ -1,43 +1,42 @@
namespace Bit.Core.Models.Data.Organizations.OrganizationUsers
namespace Bit.Core.Models.Data.Organizations.OrganizationUsers;
public class OrganizationUserOrganizationDetails
{
public class OrganizationUserOrganizationDetails
{
public Guid OrganizationId { get; set; }
public Guid? UserId { get; set; }
public string Name { get; set; }
public bool UsePolicies { get; set; }
public bool UseSso { get; set; }
public bool UseKeyConnector { get; set; }
public bool UseScim { get; set; }
public bool UseGroups { get; set; }
public bool UseDirectory { get; set; }
public bool UseEvents { get; set; }
public bool UseTotp { get; set; }
public bool Use2fa { get; set; }
public bool UseApi { get; set; }
public bool UseResetPassword { get; set; }
public bool SelfHost { get; set; }
public bool UsersGetPremium { get; set; }
public int? Seats { get; set; }
public short? MaxCollections { get; set; }
public short? MaxStorageGb { get; set; }
public string Key { get; set; }
public Enums.OrganizationUserStatusType Status { get; set; }
public Enums.OrganizationUserType Type { get; set; }
public bool Enabled { get; set; }
public Enums.PlanType PlanType { get; set; }
public string SsoExternalId { get; set; }
public string Identifier { get; set; }
public string Permissions { get; set; }
public string ResetPasswordKey { get; set; }
public string PublicKey { get; set; }
public string PrivateKey { get; set; }
public Guid? ProviderId { get; set; }
public string ProviderName { get; set; }
public string FamilySponsorshipFriendlyName { get; set; }
public string SsoConfig { get; set; }
public DateTime? FamilySponsorshipLastSyncDate { get; set; }
public DateTime? FamilySponsorshipValidUntil { get; set; }
public bool? FamilySponsorshipToDelete { get; set; }
}
public Guid OrganizationId { get; set; }
public Guid? UserId { get; set; }
public string Name { get; set; }
public bool UsePolicies { get; set; }
public bool UseSso { get; set; }
public bool UseKeyConnector { get; set; }
public bool UseScim { get; set; }
public bool UseGroups { get; set; }
public bool UseDirectory { get; set; }
public bool UseEvents { get; set; }
public bool UseTotp { get; set; }
public bool Use2fa { get; set; }
public bool UseApi { get; set; }
public bool UseResetPassword { get; set; }
public bool SelfHost { get; set; }
public bool UsersGetPremium { get; set; }
public int? Seats { get; set; }
public short? MaxCollections { get; set; }
public short? MaxStorageGb { get; set; }
public string Key { get; set; }
public Enums.OrganizationUserStatusType Status { get; set; }
public Enums.OrganizationUserType Type { get; set; }
public bool Enabled { get; set; }
public Enums.PlanType PlanType { get; set; }
public string SsoExternalId { get; set; }
public string Identifier { get; set; }
public string Permissions { get; set; }
public string ResetPasswordKey { get; set; }
public string PublicKey { get; set; }
public string PrivateKey { get; set; }
public Guid? ProviderId { get; set; }
public string ProviderName { get; set; }
public string FamilySponsorshipFriendlyName { get; set; }
public string SsoConfig { get; set; }
public DateTime? FamilySponsorshipLastSyncDate { get; set; }
public DateTime? FamilySponsorshipValidUntil { get; set; }
public bool? FamilySponsorshipToDelete { get; set; }
}

View File

@ -1,9 +1,8 @@
namespace Bit.Core.Models.Data.Organizations.OrganizationUsers
namespace Bit.Core.Models.Data.Organizations.OrganizationUsers;
public class OrganizationUserPublicKey
{
public class OrganizationUserPublicKey
{
public Guid Id { get; set; }
public Guid UserId { get; set; }
public string PublicKey { get; set; }
}
public Guid Id { get; set; }
public Guid UserId { get; set; }
public string PublicKey { get; set; }
}

View File

@ -1,35 +1,34 @@
using Bit.Core.Entities;
using Bit.Core.Enums;
namespace Bit.Core.Models.Data.Organizations.OrganizationUsers
namespace Bit.Core.Models.Data.Organizations.OrganizationUsers;
public class OrganizationUserResetPasswordDetails
{
public class OrganizationUserResetPasswordDetails
public OrganizationUserResetPasswordDetails(OrganizationUser orgUser, User user, Organization org)
{
public OrganizationUserResetPasswordDetails(OrganizationUser orgUser, User user, Organization org)
if (orgUser == null)
{
if (orgUser == null)
{
throw new ArgumentNullException(nameof(orgUser));
}
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}
if (org == null)
{
throw new ArgumentNullException(nameof(org));
}
Kdf = user.Kdf;
KdfIterations = user.KdfIterations;
ResetPasswordKey = orgUser.ResetPasswordKey;
EncryptedPrivateKey = org.PrivateKey;
throw new ArgumentNullException(nameof(orgUser));
}
public KdfType Kdf { get; set; }
public int KdfIterations { get; set; }
public string ResetPasswordKey { get; set; }
public string EncryptedPrivateKey { get; set; }
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}
if (org == null)
{
throw new ArgumentNullException(nameof(org));
}
Kdf = user.Kdf;
KdfIterations = user.KdfIterations;
ResetPasswordKey = orgUser.ResetPasswordKey;
EncryptedPrivateKey = org.PrivateKey;
}
public KdfType Kdf { get; set; }
public int KdfIterations { get; set; }
public string ResetPasswordKey { get; set; }
public string EncryptedPrivateKey { get; set; }
}

View File

@ -1,60 +1,59 @@
using Bit.Core.Enums;
using Bit.Core.Utilities;
namespace Bit.Core.Models.Data.Organizations.OrganizationUsers
namespace Bit.Core.Models.Data.Organizations.OrganizationUsers;
public class OrganizationUserUserDetails : IExternal, ITwoFactorProvidersUser
{
public class OrganizationUserUserDetails : IExternal, ITwoFactorProvidersUser
private Dictionary<TwoFactorProviderType, TwoFactorProvider> _twoFactorProviders;
public Guid Id { get; set; }
public Guid OrganizationId { get; set; }
public Guid? UserId { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string TwoFactorProviders { get; set; }
public bool? Premium { get; set; }
public OrganizationUserStatusType Status { get; set; }
public OrganizationUserType Type { get; set; }
public bool AccessAll { get; set; }
public string ExternalId { get; set; }
public string SsoExternalId { get; set; }
public string Permissions { get; set; }
public string ResetPasswordKey { get; set; }
public bool UsesKeyConnector { get; set; }
public Dictionary<TwoFactorProviderType, TwoFactorProvider> GetTwoFactorProviders()
{
private Dictionary<TwoFactorProviderType, TwoFactorProvider> _twoFactorProviders;
public Guid Id { get; set; }
public Guid OrganizationId { get; set; }
public Guid? UserId { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string TwoFactorProviders { get; set; }
public bool? Premium { get; set; }
public OrganizationUserStatusType Status { get; set; }
public OrganizationUserType Type { get; set; }
public bool AccessAll { get; set; }
public string ExternalId { get; set; }
public string SsoExternalId { get; set; }
public string Permissions { get; set; }
public string ResetPasswordKey { get; set; }
public bool UsesKeyConnector { get; set; }
public Dictionary<TwoFactorProviderType, TwoFactorProvider> GetTwoFactorProviders()
if (string.IsNullOrWhiteSpace(TwoFactorProviders))
{
if (string.IsNullOrWhiteSpace(TwoFactorProviders))
{
return null;
}
try
{
if (_twoFactorProviders == null)
{
_twoFactorProviders =
JsonHelpers.LegacyDeserialize<Dictionary<TwoFactorProviderType, TwoFactorProvider>>(
TwoFactorProviders);
}
return _twoFactorProviders;
}
catch (Newtonsoft.Json.JsonException)
{
return null;
}
return null;
}
public Guid? GetUserId()
try
{
return UserId;
}
if (_twoFactorProviders == null)
{
_twoFactorProviders =
JsonHelpers.LegacyDeserialize<Dictionary<TwoFactorProviderType, TwoFactorProvider>>(
TwoFactorProviders);
}
public bool GetPremium()
return _twoFactorProviders;
}
catch (Newtonsoft.Json.JsonException)
{
return Premium.GetValueOrDefault(false);
return null;
}
}
public Guid? GetUserId()
{
return UserId;
}
public bool GetPremium()
{
return Premium.GetValueOrDefault(false);
}
}

View File

@ -1,10 +1,9 @@
using System.Data;
using Bit.Core.Entities;
namespace Bit.Core.Models.Data.Organizations.OrganizationUsers
namespace Bit.Core.Models.Data.Organizations.OrganizationUsers;
public class OrganizationUserWithCollections : OrganizationUser
{
public class OrganizationUserWithCollections : OrganizationUser
{
public DataTable Collections { get; set; }
}
public DataTable Collections { get; set; }
}

View File

@ -1,6 +1,5 @@
namespace Bit.Core.Models.Data.Organizations.Policies
namespace Bit.Core.Models.Data.Organizations.Policies;
public interface IPolicyDataModel
{
public interface IPolicyDataModel
{
}
}

View File

@ -1,10 +1,9 @@
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.Models.Data.Organizations.Policies
namespace Bit.Core.Models.Data.Organizations.Policies;
public class ResetPasswordDataModel : IPolicyDataModel
{
public class ResetPasswordDataModel : IPolicyDataModel
{
[Display(Name = "ResetPasswordAutoEnrollCheckbox")]
public bool AutoEnrollEnabled { get; set; }
}
[Display(Name = "ResetPasswordAutoEnrollCheckbox")]
public bool AutoEnrollEnabled { get; set; }
}

View File

@ -1,10 +1,9 @@
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.Models.Data.Organizations.Policies
namespace Bit.Core.Models.Data.Organizations.Policies;
public class SendOptionsPolicyData : IPolicyDataModel
{
public class SendOptionsPolicyData : IPolicyDataModel
{
[Display(Name = "DisableHideEmail")]
public bool DisableHideEmail { get; set; }
}
[Display(Name = "DisableHideEmail")]
public bool DisableHideEmail { get; set; }
}

View File

@ -1,8 +1,7 @@
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public class PageOptions
{
public class PageOptions
{
public string ContinuationToken { get; set; }
public int PageSize { get; set; } = 50;
}
public string ContinuationToken { get; set; }
public int PageSize { get; set; } = 50;
}

View File

@ -1,8 +1,7 @@
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public class PagedResult<T>
{
public class PagedResult<T>
{
public List<T> Data { get; set; } = new List<T>();
public string ContinuationToken { get; set; }
}
public List<T> Data { get; set; } = new List<T>();
public string ContinuationToken { get; set; }
}

View File

@ -1,45 +1,44 @@
using System.Text.Json.Serialization;
namespace Bit.Core.Models.Data
{
public class Permissions
{
public bool AccessEventLogs { get; set; }
public bool AccessImportExport { get; set; }
public bool AccessReports { get; set; }
[Obsolete("This permission exists for client backwards-compatibility. It should not be used to determine permissions in this repository", true)]
public bool ManageAllCollections => CreateNewCollections && EditAnyCollection && DeleteAnyCollection;
public bool CreateNewCollections { get; set; }
public bool EditAnyCollection { get; set; }
public bool DeleteAnyCollection { get; set; }
[Obsolete("This permission exists for client backwards-compatibility. It should not be used to determine permissions in this repository", true)]
public bool ManageAssignedCollections => EditAssignedCollections && DeleteAssignedCollections;
public bool EditAssignedCollections { get; set; }
public bool DeleteAssignedCollections { get; set; }
public bool ManageGroups { get; set; }
public bool ManagePolicies { get; set; }
public bool ManageSso { get; set; }
public bool ManageUsers { get; set; }
public bool ManageResetPassword { get; set; }
public bool ManageScim { get; set; }
namespace Bit.Core.Models.Data;
[JsonIgnore]
public List<(bool Permission, string ClaimName)> ClaimsMap => new()
{
(AccessEventLogs, "accesseventlogs"),
(AccessImportExport, "accessimportexport"),
(AccessReports, "accessreports"),
(CreateNewCollections, "createnewcollections"),
(EditAnyCollection, "editanycollection"),
(DeleteAnyCollection, "deleteanycollection"),
(EditAssignedCollections, "editassignedcollections"),
(DeleteAssignedCollections, "deleteassignedcollections"),
(ManageGroups, "managegroups"),
(ManagePolicies, "managepolicies"),
(ManageSso, "managesso"),
(ManageUsers, "manageusers"),
(ManageResetPassword, "manageresetpassword"),
(ManageScim, "managescim"),
};
}
public class Permissions
{
public bool AccessEventLogs { get; set; }
public bool AccessImportExport { get; set; }
public bool AccessReports { get; set; }
[Obsolete("This permission exists for client backwards-compatibility. It should not be used to determine permissions in this repository", true)]
public bool ManageAllCollections => CreateNewCollections && EditAnyCollection && DeleteAnyCollection;
public bool CreateNewCollections { get; set; }
public bool EditAnyCollection { get; set; }
public bool DeleteAnyCollection { get; set; }
[Obsolete("This permission exists for client backwards-compatibility. It should not be used to determine permissions in this repository", true)]
public bool ManageAssignedCollections => EditAssignedCollections && DeleteAssignedCollections;
public bool EditAssignedCollections { get; set; }
public bool DeleteAssignedCollections { get; set; }
public bool ManageGroups { get; set; }
public bool ManagePolicies { get; set; }
public bool ManageSso { get; set; }
public bool ManageUsers { get; set; }
public bool ManageResetPassword { get; set; }
public bool ManageScim { get; set; }
[JsonIgnore]
public List<(bool Permission, string ClaimName)> ClaimsMap => new()
{
(AccessEventLogs, "accesseventlogs"),
(AccessImportExport, "accessimportexport"),
(AccessReports, "accessreports"),
(CreateNewCollections, "createnewcollections"),
(EditAnyCollection, "editanycollection"),
(DeleteAnyCollection, "deleteanycollection"),
(EditAssignedCollections, "editassignedcollections"),
(DeleteAssignedCollections, "deleteassignedcollections"),
(ManageGroups, "managegroups"),
(ManagePolicies, "managepolicies"),
(ManageSso, "managesso"),
(ManageUsers, "manageusers"),
(ManageResetPassword, "manageresetpassword"),
(ManageScim, "managescim"),
};
}

View File

@ -1,20 +1,19 @@
using Bit.Core.Entities.Provider;
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public class ProviderAbility
{
public class ProviderAbility
public ProviderAbility() { }
public ProviderAbility(Provider provider)
{
public ProviderAbility() { }
public ProviderAbility(Provider provider)
{
Id = provider.Id;
UseEvents = provider.UseEvents;
Enabled = provider.Enabled;
}
public Guid Id { get; set; }
public bool UseEvents { get; set; }
public bool Enabled { get; set; }
Id = provider.Id;
UseEvents = provider.UseEvents;
Enabled = provider.Enabled;
}
public Guid Id { get; set; }
public bool UseEvents { get; set; }
public bool Enabled { get; set; }
}

View File

@ -1,17 +1,16 @@
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public class ProviderOrganizationOrganizationDetails
{
public class ProviderOrganizationOrganizationDetails
{
public Guid Id { get; set; }
public Guid ProviderId { get; set; }
public Guid OrganizationId { get; set; }
public string OrganizationName { get; set; }
public string Key { get; set; }
public string Settings { get; set; }
public DateTime CreationDate { get; set; }
public DateTime RevisionDate { get; set; }
public int UserCount { get; set; }
public int? Seats { get; set; }
public string Plan { get; set; }
}
public Guid Id { get; set; }
public Guid ProviderId { get; set; }
public Guid OrganizationId { get; set; }
public string OrganizationName { get; set; }
public string Key { get; set; }
public string Settings { get; set; }
public DateTime CreationDate { get; set; }
public DateTime RevisionDate { get; set; }
public int UserCount { get; set; }
public int? Seats { get; set; }
public string Plan { get; set; }
}

View File

@ -1,37 +1,36 @@
using Bit.Core.Enums.Provider;
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public class ProviderUserOrganizationDetails
{
public class ProviderUserOrganizationDetails
{
public Guid OrganizationId { get; set; }
public Guid? UserId { get; set; }
public string Name { get; set; }
public bool UsePolicies { get; set; }
public bool UseSso { get; set; }
public bool UseKeyConnector { get; set; }
public bool UseScim { get; set; }
public bool UseGroups { get; set; }
public bool UseDirectory { get; set; }
public bool UseEvents { get; set; }
public bool UseTotp { get; set; }
public bool Use2fa { get; set; }
public bool UseApi { get; set; }
public bool UseResetPassword { get; set; }
public bool SelfHost { get; set; }
public bool UsersGetPremium { get; set; }
public int? Seats { get; set; }
public short? MaxCollections { get; set; }
public short? MaxStorageGb { get; set; }
public string Key { get; set; }
public ProviderUserStatusType Status { get; set; }
public ProviderUserType Type { get; set; }
public bool Enabled { get; set; }
public string Identifier { get; set; }
public string PublicKey { get; set; }
public string PrivateKey { get; set; }
public Guid? ProviderId { get; set; }
public Guid? ProviderUserId { get; set; }
public string ProviderName { get; set; }
}
public Guid OrganizationId { get; set; }
public Guid? UserId { get; set; }
public string Name { get; set; }
public bool UsePolicies { get; set; }
public bool UseSso { get; set; }
public bool UseKeyConnector { get; set; }
public bool UseScim { get; set; }
public bool UseGroups { get; set; }
public bool UseDirectory { get; set; }
public bool UseEvents { get; set; }
public bool UseTotp { get; set; }
public bool Use2fa { get; set; }
public bool UseApi { get; set; }
public bool UseResetPassword { get; set; }
public bool SelfHost { get; set; }
public bool UsersGetPremium { get; set; }
public int? Seats { get; set; }
public short? MaxCollections { get; set; }
public short? MaxStorageGb { get; set; }
public string Key { get; set; }
public ProviderUserStatusType Status { get; set; }
public ProviderUserType Type { get; set; }
public bool Enabled { get; set; }
public string Identifier { get; set; }
public string PublicKey { get; set; }
public string PrivateKey { get; set; }
public Guid? ProviderId { get; set; }
public Guid? ProviderUserId { get; set; }
public string ProviderName { get; set; }
}

View File

@ -1,18 +1,17 @@
using Bit.Core.Enums.Provider;
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public class ProviderUserProviderDetails
{
public class ProviderUserProviderDetails
{
public Guid ProviderId { get; set; }
public Guid? UserId { get; set; }
public string Name { get; set; }
public string Key { get; set; }
public ProviderUserStatusType Status { get; set; }
public ProviderUserType Type { get; set; }
public bool Enabled { get; set; }
public string Permissions { get; set; }
public bool UseEvents { get; set; }
public ProviderStatusType ProviderStatus { get; set; }
}
public Guid ProviderId { get; set; }
public Guid? UserId { get; set; }
public string Name { get; set; }
public string Key { get; set; }
public ProviderUserStatusType Status { get; set; }
public ProviderUserType Type { get; set; }
public bool Enabled { get; set; }
public string Permissions { get; set; }
public bool UseEvents { get; set; }
public ProviderStatusType ProviderStatus { get; set; }
}

View File

@ -1,9 +1,8 @@
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public class ProviderUserPublicKey
{
public class ProviderUserPublicKey
{
public Guid Id { get; set; }
public Guid UserId { get; set; }
public string PublicKey { get; set; }
}
public Guid Id { get; set; }
public Guid UserId { get; set; }
public string PublicKey { get; set; }
}

View File

@ -1,16 +1,15 @@
using Bit.Core.Enums.Provider;
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public class ProviderUserUserDetails
{
public class ProviderUserUserDetails
{
public Guid Id { get; set; }
public Guid ProviderId { get; set; }
public Guid? UserId { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public ProviderUserStatusType Status { get; set; }
public ProviderUserType Type { get; set; }
public string Permissions { get; set; }
}
public Guid Id { get; set; }
public Guid ProviderId { get; set; }
public Guid? UserId { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public ProviderUserStatusType Status { get; set; }
public ProviderUserType Type { get; set; }
public string Permissions { get; set; }
}

View File

@ -1,9 +1,8 @@
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public class SelectionReadOnly
{
public class SelectionReadOnly
{
public Guid Id { get; set; }
public bool ReadOnly { get; set; }
public bool HidePasswords { get; set; }
}
public Guid Id { get; set; }
public bool ReadOnly { get; set; }
public bool HidePasswords { get; set; }
}

View File

@ -1,16 +1,15 @@
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public abstract class SendData
{
public abstract class SendData
public SendData() { }
public SendData(string name, string notes)
{
public SendData() { }
public SendData(string name, string notes)
{
Name = name;
Notes = notes;
}
public string Name { get; set; }
public string Notes { get; set; }
Name = name;
Notes = notes;
}
public string Name { get; set; }
public string Notes { get; set; }
}

View File

@ -1,23 +1,22 @@
using System.Text.Json.Serialization;
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public class SendFileData : SendData
{
public class SendFileData : SendData
public SendFileData() { }
public SendFileData(string name, string notes, string fileName)
: base(name, notes)
{
public SendFileData() { }
public SendFileData(string name, string notes, string fileName)
: base(name, notes)
{
FileName = fileName;
}
// We serialize Size as a string since JSON (or Javascript) doesn't support full precision for long numbers
[JsonNumberHandling(JsonNumberHandling.WriteAsString | JsonNumberHandling.AllowReadingFromString)]
public long Size { get; set; }
public string Id { get; set; }
public string FileName { get; set; }
public bool Validated { get; set; } = true;
FileName = fileName;
}
// We serialize Size as a string since JSON (or Javascript) doesn't support full precision for long numbers
[JsonNumberHandling(JsonNumberHandling.WriteAsString | JsonNumberHandling.AllowReadingFromString)]
public long Size { get; set; }
public string Id { get; set; }
public string FileName { get; set; }
public bool Validated { get; set; } = true;
}

View File

@ -1,17 +1,16 @@
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public class SendTextData : SendData
{
public class SendTextData : SendData
public SendTextData() { }
public SendTextData(string name, string notes, string text, bool hidden)
: base(name, notes)
{
public SendTextData() { }
public SendTextData(string name, string notes, string text, bool hidden)
: base(name, notes)
{
Text = text;
Hidden = hidden;
}
public string Text { get; set; }
public bool Hidden { get; set; }
Text = text;
Hidden = hidden;
}
public string Text { get; set; }
public bool Hidden { get; set; }
}

View File

@ -2,125 +2,124 @@
using Bit.Core.Utilities;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public class SsoConfigurationData
{
public class SsoConfigurationData
private static string _oidcSigninPath = "/oidc-signin";
private static string _oidcSignedOutPath = "/oidc-signedout";
private static string _saml2ModulePath = "/saml2";
public static SsoConfigurationData Deserialize(string data)
{
private static string _oidcSigninPath = "/oidc-signin";
private static string _oidcSignedOutPath = "/oidc-signedout";
private static string _saml2ModulePath = "/saml2";
return CoreHelpers.LoadClassFromJsonData<SsoConfigurationData>(data);
}
public static SsoConfigurationData Deserialize(string data)
public string Serialize()
{
return CoreHelpers.ClassToJsonData(this);
}
public SsoType ConfigType { get; set; }
public bool KeyConnectorEnabled { get; set; }
public string KeyConnectorUrl { get; set; }
// OIDC
public string Authority { get; set; }
public string ClientId { get; set; }
public string ClientSecret { get; set; }
public string MetadataAddress { get; set; }
public OpenIdConnectRedirectBehavior RedirectBehavior { get; set; }
public bool GetClaimsFromUserInfoEndpoint { get; set; }
public string AdditionalScopes { get; set; }
public string AdditionalUserIdClaimTypes { get; set; }
public string AdditionalEmailClaimTypes { get; set; }
public string AdditionalNameClaimTypes { get; set; }
public string AcrValues { get; set; }
public string ExpectedReturnAcrValue { get; set; }
// SAML2 IDP
public string IdpEntityId { get; set; }
public string IdpSingleSignOnServiceUrl { get; set; }
public string IdpSingleLogoutServiceUrl { get; set; }
public string IdpX509PublicCert { get; set; }
public Saml2BindingType IdpBindingType { get; set; }
public bool IdpAllowUnsolicitedAuthnResponse { get; set; }
public string IdpArtifactResolutionServiceUrl { get => null; set { /*IGNORE*/ } }
public bool IdpDisableOutboundLogoutRequests { get; set; }
public string IdpOutboundSigningAlgorithm { get; set; }
public bool IdpWantAuthnRequestsSigned { get; set; }
// SAML2 SP
public Saml2NameIdFormat SpNameIdFormat { get; set; }
public string SpOutboundSigningAlgorithm { get; set; }
public Saml2SigningBehavior SpSigningBehavior { get; set; }
public bool SpWantAssertionsSigned { get; set; }
public bool SpValidateCertificates { get; set; }
public string SpMinIncomingSigningAlgorithm { get; set; }
public static string BuildCallbackPath(string ssoUri = null)
{
return BuildSsoUrl(_oidcSigninPath, ssoUri);
}
public static string BuildSignedOutCallbackPath(string ssoUri = null)
{
return BuildSsoUrl(_oidcSignedOutPath, ssoUri);
}
public static string BuildSaml2ModulePath(string ssoUri = null, string scheme = null)
{
return string.Concat(BuildSsoUrl(_saml2ModulePath, ssoUri),
string.IsNullOrWhiteSpace(scheme) ? string.Empty : $"/{scheme}");
}
public static string BuildSaml2AcsUrl(string ssoUri = null, string scheme = null)
{
return string.Concat(BuildSaml2ModulePath(ssoUri, scheme), "/Acs");
}
public static string BuildSaml2MetadataUrl(string ssoUri = null, string scheme = null)
{
return BuildSaml2ModulePath(ssoUri, scheme);
}
public IEnumerable<string> GetAdditionalScopes() => AdditionalScopes?
.Split(',')?
.Where(c => !string.IsNullOrWhiteSpace(c))?
.Select(c => c.Trim()) ??
Array.Empty<string>();
public IEnumerable<string> GetAdditionalUserIdClaimTypes() => AdditionalUserIdClaimTypes?
.Split(',')?
.Where(c => !string.IsNullOrWhiteSpace(c))?
.Select(c => c.Trim()) ??
Array.Empty<string>();
public IEnumerable<string> GetAdditionalEmailClaimTypes() => AdditionalEmailClaimTypes?
.Split(',')?
.Where(c => !string.IsNullOrWhiteSpace(c))?
.Select(c => c.Trim()) ??
Array.Empty<string>();
public IEnumerable<string> GetAdditionalNameClaimTypes() => AdditionalNameClaimTypes?
.Split(',')?
.Where(c => !string.IsNullOrWhiteSpace(c))?
.Select(c => c.Trim()) ??
Array.Empty<string>();
private static string BuildSsoUrl(string relativePath, string ssoUri)
{
if (string.IsNullOrWhiteSpace(ssoUri) ||
!Uri.IsWellFormedUriString(ssoUri, UriKind.Absolute))
{
return CoreHelpers.LoadClassFromJsonData<SsoConfigurationData>(data);
}
public string Serialize()
{
return CoreHelpers.ClassToJsonData(this);
}
public SsoType ConfigType { get; set; }
public bool KeyConnectorEnabled { get; set; }
public string KeyConnectorUrl { get; set; }
// OIDC
public string Authority { get; set; }
public string ClientId { get; set; }
public string ClientSecret { get; set; }
public string MetadataAddress { get; set; }
public OpenIdConnectRedirectBehavior RedirectBehavior { get; set; }
public bool GetClaimsFromUserInfoEndpoint { get; set; }
public string AdditionalScopes { get; set; }
public string AdditionalUserIdClaimTypes { get; set; }
public string AdditionalEmailClaimTypes { get; set; }
public string AdditionalNameClaimTypes { get; set; }
public string AcrValues { get; set; }
public string ExpectedReturnAcrValue { get; set; }
// SAML2 IDP
public string IdpEntityId { get; set; }
public string IdpSingleSignOnServiceUrl { get; set; }
public string IdpSingleLogoutServiceUrl { get; set; }
public string IdpX509PublicCert { get; set; }
public Saml2BindingType IdpBindingType { get; set; }
public bool IdpAllowUnsolicitedAuthnResponse { get; set; }
public string IdpArtifactResolutionServiceUrl { get => null; set { /*IGNORE*/ } }
public bool IdpDisableOutboundLogoutRequests { get; set; }
public string IdpOutboundSigningAlgorithm { get; set; }
public bool IdpWantAuthnRequestsSigned { get; set; }
// SAML2 SP
public Saml2NameIdFormat SpNameIdFormat { get; set; }
public string SpOutboundSigningAlgorithm { get; set; }
public Saml2SigningBehavior SpSigningBehavior { get; set; }
public bool SpWantAssertionsSigned { get; set; }
public bool SpValidateCertificates { get; set; }
public string SpMinIncomingSigningAlgorithm { get; set; }
public static string BuildCallbackPath(string ssoUri = null)
{
return BuildSsoUrl(_oidcSigninPath, ssoUri);
}
public static string BuildSignedOutCallbackPath(string ssoUri = null)
{
return BuildSsoUrl(_oidcSignedOutPath, ssoUri);
}
public static string BuildSaml2ModulePath(string ssoUri = null, string scheme = null)
{
return string.Concat(BuildSsoUrl(_saml2ModulePath, ssoUri),
string.IsNullOrWhiteSpace(scheme) ? string.Empty : $"/{scheme}");
}
public static string BuildSaml2AcsUrl(string ssoUri = null, string scheme = null)
{
return string.Concat(BuildSaml2ModulePath(ssoUri, scheme), "/Acs");
}
public static string BuildSaml2MetadataUrl(string ssoUri = null, string scheme = null)
{
return BuildSaml2ModulePath(ssoUri, scheme);
}
public IEnumerable<string> GetAdditionalScopes() => AdditionalScopes?
.Split(',')?
.Where(c => !string.IsNullOrWhiteSpace(c))?
.Select(c => c.Trim()) ??
Array.Empty<string>();
public IEnumerable<string> GetAdditionalUserIdClaimTypes() => AdditionalUserIdClaimTypes?
.Split(',')?
.Where(c => !string.IsNullOrWhiteSpace(c))?
.Select(c => c.Trim()) ??
Array.Empty<string>();
public IEnumerable<string> GetAdditionalEmailClaimTypes() => AdditionalEmailClaimTypes?
.Split(',')?
.Where(c => !string.IsNullOrWhiteSpace(c))?
.Select(c => c.Trim()) ??
Array.Empty<string>();
public IEnumerable<string> GetAdditionalNameClaimTypes() => AdditionalNameClaimTypes?
.Split(',')?
.Where(c => !string.IsNullOrWhiteSpace(c))?
.Select(c => c.Trim()) ??
Array.Empty<string>();
private static string BuildSsoUrl(string relativePath, string ssoUri)
{
if (string.IsNullOrWhiteSpace(ssoUri) ||
!Uri.IsWellFormedUriString(ssoUri, UriKind.Absolute))
{
return relativePath;
}
if (Uri.TryCreate(string.Concat(ssoUri.TrimEnd('/'), relativePath), UriKind.Absolute, out var newUri))
{
return newUri.ToString();
}
return relativePath;
}
if (Uri.TryCreate(string.Concat(ssoUri.TrimEnd('/'), relativePath), UriKind.Absolute, out var newUri))
{
return newUri.ToString();
}
return relativePath;
}
}

View File

@ -1,10 +1,9 @@
using Bit.Core.Enums;
namespace Bit.Core.Models.Data
namespace Bit.Core.Models.Data;
public class UserKdfInformation
{
public class UserKdfInformation
{
public KdfType Kdf { get; set; }
public int KdfIterations { get; set; }
}
public KdfType Kdf { get; set; }
public int KdfIterations { get; set; }
}