108 return databaseContext
111 .Where(
x =>
ids.Contains(
x.Id!.Value))
134 .Where(
x =>
userIds.Contains(
x.User!.Id!.Value))
137 return list.ToLookup(
139 x =>
new GraphQL.Types.OAuth.OAuthConnection(
x.ExternalUserId!,
x.Provider));
161 .Where(
x =>
userIds.Contains(
x.User!.Id!.Value))
164 return list.ToLookup(
166 x =>
new GraphQL.Types.OAuth.OidcConnection(
x.ExternalUserId!,
x.SchemeKey!));
349#pragma warning disable CA1506
354#pragma warning restore CA1506
357 async authorizationService =>
388 Logger.LogTrace(
ex,
"System identities not implemented!");
423#pragma warning disable CA1502
424#pragma warning disable CA1506
426#pragma warning restore CA1502
427#pragma warning restore CA1506
434 if (
model.OidcConnections !=
null ||
model.OAuthConnections !=
null)
448 else if (
model.Enabled.HasValue
449 ||
model.Group !=
null
450 ||
model.Name !=
null
451 ||
model.PermissionSet !=
null)
456 async authorizationService =>
460 if (!
model.Id.HasValue ||
model.OAuthConnections?.Any(
x =>
x ==
null) ==
true)
463 if (
model.Group !=
null &&
model.PermissionSet !=
null)
470 .Include(
x =>
x.CreatedBy)
471 .Include(
x =>
x.OAuthConnections)
472 .Include(
x =>
x.OidcConnections)
473 .Include(
x =>
x.Group!)
474 .ThenInclude(
x =>
x.PermissionSet)
475 .Include(
x =>
x.PermissionSet)
491 Logger.LogDebug(
"System user ID {userId}'s PasswordHash is polluted, updating database.",
originalUser.Id);
500 if (
model.Password !=
null)
515 if (
model.OAuthConnections !=
null
517 || !
model.OAuthConnections.All(
x =>
originalUser.OAuthConnections.Any(
y =>
y.Provider ==
x.Provider &&
y.ExternalUserId ==
x.ExternalUserId))))
532 originalUser.OAuthConnections.Add(
new Models.OAuthConnection
534 Provider = updatedConnection.Provider,
535 ExternalUserId = updatedConnection.ExternalUserId,
539 if (
model.OidcConnections !=
null
541 || !
model.OidcConnections.All(
x =>
originalUser.OidcConnections.Any(
y =>
y.SchemeKey ==
x.SchemeKey &&
y.ExternalUserId ==
x.ExternalUserId))))
555 originalUser.OidcConnections.Add(
new Models.OidcConnection
557 SchemeKey = updatedConnection.SchemeKey,
558 ExternalUserId = updatedConnection.ExternalUserId,
562 if (
model.Group !=
null)
570 .Where(
x =>
x.Id ==
model.Group.Id)
571 .Include(
x =>
x.PermissionSet)
580 Logger.LogInformation(
"Deleting permission set {permissionSetId}...",
originalUser.PermissionSet.Id);
585 else if (
model.PermissionSet !=
null)
592 Logger.LogTrace(
"Creating new permission set...");
609 if (
model.Enabled.HasValue)
677 Security.IAuthorizationService authorizationService,
684 || (
await authorizationService.AuthorizeAsync(
701 GraphQL.Subscriptions.UserSubscriptions.UserUpdatedTopics(
702 user.Require(
x =>
x.Id))
706 CancellationToken.None)));
727 .Include(
x =>
x.CreatedBy)
728 .Include(
x =>
x.OAuthConnections)
729 .Include(
x =>
x.OidcConnections)
730 .Include(
x =>
x.Group!)
731 .ThenInclude(
x =>
x.PermissionSet)
732 .Include(
x =>
x.PermissionSet);
745 Models.PermissionSet? permissionSet =
null;
747 if (
model.Group !=
null)
751 .Where(
x =>
x.Id ==
model.Group.Id)
752 .Include(
x =>
x.PermissionSet)
776 CreatedAt = DateTimeOffset.UtcNow,
782 SystemIdentifier =
model.SystemIdentifier,
785 ?.Select(
x =>
new Models.OAuthConnection
787 Provider = x.Provider,
788 ExternalUserId = x.ExternalUserId,
791 ??
new List<Models.OAuthConnection>(),
794 ?.
Select(
x =>
new Models.OidcConnection
796 SchemeKey =
x.SchemeKey,
797 ExternalUserId =
x.ExternalUserId,
800 ??
new List<Models.OidcConnection>(),
814 if (
newPassword.Length < generalConfigurationOptions.Value.MinimumPasswordLength)
818 AdditionalData = $
"Required password length: {generalConfigurationOptions.Value.MinimumPasswordLength}",
Represents initial credentials used by the server.
static readonly string AdminUserName
The name of the default admin user.
Represents a valid OAuth connection.
Represents a valid OIDC connection.
Represents a set of server permissions.
AdministrationRights? AdministrationRights
The Rights.AdministrationRights for the user.
For editing a given user.
Represents an error message returned by the server.
Extension methods for the ValueTask and ValueTask<TResult> classes.
static async ValueTask WhenAll(IEnumerable< ValueTask > tasks)
Fully await a given list of tasks .
Base implementation of IAuthority.
ILogger< AuthorityBase > Logger
Gets the ILogger for the AuthorityBase.
Represents a response from an authority.
Evaluates a set of IAuthorizationRequirements to be checked before executing a response.
readonly ISessionInvalidationTracker sessionInvalidationTracker
The ISessionInvalidationTracker for the UserAuthority.
readonly ITopicEventSender topicEventSender
The ITopicEventSender for the UserAuthority.
RequirementsGated< AuthorityResponse< GraphQL.Types.OAuth.OidcConnection[]> > OidcConnections(long userId, CancellationToken cancellationToken)
Gets the GraphQL.Types.OAuth.OidcConnections for the User with a given userId .A RequirementsGated<TR...
readonly IPermissionsUpdateNotifyee permissionsUpdateNotifyee
The IPermissionsUpdateNotifyee for the UserAuthority.
static ? AuthorityResponse< UpdatedUser > CheckValidName(UserUpdateRequest model, bool newUser)
Check if a given model has a valid UserName.Name specified.
AuthorityResponse< UpdatedUser >? TrySetPassword(User dbUser, string newPassword, bool newUser)
Attempt to change the password of a given dbUser .
static Task< Dictionary< long, User > > GetUsers(IReadOnlyList< long > ids, IDatabaseContext databaseContext, CancellationToken cancellationToken)
Implements the usersDataLoader.
readonly IClaimsPrincipalAccessor claimsPrincipalAccessor
The IClaimsPrincipalAccessor for the UserAuthority.
UserAuthority(IDatabaseContext databaseContext, ILogger< UserAuthority > logger, IUsersDataLoader usersDataLoader, IOAuthConnectionsDataLoader oAuthConnectionsDataLoader, IOidcConnectionsDataLoader oidcConnectionsDataLoader, ISystemIdentityFactory systemIdentityFactory, IPermissionsUpdateNotifyee permissionsUpdateNotifyee, ICryptographySuite cryptographySuite, ISessionInvalidationTracker sessionInvalidationTracker, ITopicEventSender topicEventSender, IClaimsPrincipalAccessor claimsPrincipalAccessor, IOptionsSnapshot< GeneralConfiguration > generalConfigurationOptions, IOptions< SecurityConfiguration > securityConfigurationOptions)
Initializes a new instance of the UserAuthority class.
async ValueTask< AuthorityResponse< User > > GetIdImpl(long id, bool includeJoins, bool allowSystemUser, CancellationToken cancellationToken)
Implementation of retrieving a User by ID.
RequirementsGated< AuthorityResponse< User > > Read(CancellationToken cancellationToken)
Gets the currently authenticated user.A RequirementsGated<TResult> User AuthorityResponse<TResult>.
readonly ISystemIdentityFactory systemIdentityFactory
The ISystemIdentityFactory for the UserAuthority.
RequirementsGated< AuthorityResponse< User > > GetId(long id, bool includeJoins, bool allowSystemUser, CancellationToken cancellationToken)
Gets the User with a given id .A RequirementsGated<TResult> User AuthorityResponse<TResult>.
readonly IOptions< SecurityConfiguration > securityConfigurationOptions
The IOptions<TOptions> of SecurityConfiguration for the UserAuthority.
readonly IOptionsSnapshot< GeneralConfiguration > generalConfigurationOptions
The IOptionsSnapshot<TOptions> of GeneralConfiguration for the UserAuthority.
RequirementsGated< IQueryable< User > > Queryable(bool includeJoins)
Gets all registered Users.A RequirementsGated<TResult> IQueryable<T> of Users.
IQueryable< User > Queryable(bool includeJoins, bool allowSystemUser)
Gets all registered Users.
async ValueTask< User > CreateNewUserFromModel(Api.Models.Internal.UserApiBase model, CancellationToken cancellationToken)
Creates a new User from a given model .
RequirementsGated< AuthorityResponse< GraphQL.Types.OAuth.OAuthConnection[]> > OAuthConnections(long userId, CancellationToken cancellationToken)
Gets the GraphQL.Types.OAuth.OAuthConnections for the User with a given userId .A RequirementsGated<T...
static async ValueTask< ILookup< long, GraphQL.Types.OAuth.OAuthConnection > > GetOAuthConnections(IReadOnlyList< long > userIds, IDatabaseContext databaseContext, CancellationToken cancellationToken)
Implements the oAuthConnectionsDataLoader.
static async ValueTask< ILookup< long, GraphQL.Types.OAuth.OidcConnection > > GetOidcConnections(IReadOnlyList< long > userIds, IDatabaseContext databaseContext, CancellationToken cancellationToken)
Implements the oidcConnectionsDataLoader.
RequirementsGated< AuthorityResponse< UpdatedUser > > Create(UserCreateRequest createRequest, bool? needZeroLengthPasswordWithOAuthConnections, CancellationToken cancellationToken)
Creates a User.A RequirementsGated<TResult> AuthorityResponse<TResult> for the created UpdatedUser.
static bool BadCreateRequestChecks(UserCreateRequest createRequest, bool? needZeroLengthPasswordWithOAuthConnections, [NotNullWhen(true)] out AuthorityResponse< UpdatedUser >? failResponse)
Checks if a createRequest should return a bad request AuthorityResponse<TResult>.
readonly IOidcConnectionsDataLoader oidcConnectionsDataLoader
The IOidcConnectionsDataLoader for the UserAuthority.
async ValueTask< AuthorityResponse< UpdatedUser > > UpdatedUserResponse(Security.IAuthorizationService authorizationService, User user, HttpSuccessResponse successResponse)
Create the AuthorityResponse<TResult> for an UpdatedUser.
readonly ICryptographySuite cryptographySuite
The ICryptographySuite for the UserAuthority.
ValueTask SendUserUpdatedTopics(User user)
Send topics through the topicEventSender indicating a given user was created or updated.
readonly IUsersDataLoader usersDataLoader
The IUsersDataLoader for the UserAuthority.
RequirementsGated< AuthorityResponse< UpdatedUser > > Update(UserUpdateRequest model, CancellationToken cancellationToken)
Updates a User.A RequirementsGated<TResult> AuthorityResponse<TResult> for the created UpdatedUser.
readonly IOAuthConnectionsDataLoader oAuthConnectionsDataLoader
The IOAuthConnectionsDataLoader for the UserAuthority.
Backend abstract implementation of IDatabaseContext.
DbSet< OAuthConnection > OAuthConnections
The OAuthConnections in the DatabaseContext.
DbSet< PermissionSet > PermissionSets
The PermissionSets in the DatabaseContext.
Task Save(CancellationToken cancellationToken)
Saves changes made to the IDatabaseContext.A Task representing the running operation.
DbSet< User > Users
The Users in the DatabaseContext.
DbSet< OidcConnection > OidcConnections
The OidcConnections in the DatabaseContext.
DbSet< UserGroup > Groups
The UserGroups in the DatabaseContext.
Represents a User that has been updated.
Represents a group of Users.
const string TgsSystemUserName
Username used when creating jobs automatically.
static string CanonicalizeName(string name)
Change a UserName.Name into a CanonicalName.
string? CanonicalName
The uppercase invariant of UserName.Name.
An conditional expression of TRights .
IAuthority for managing Users.
IDatabaseCollection< OidcConnection > OidcConnections
The DbSet<TEntity> for OidcConnections.
IDatabaseCollection< User > Users
The Users in the IDatabaseContext.
IDatabaseCollection< OAuthConnection > OAuthConnections
The DbSet<TEntity> for OAuthConnections.
Interface for accessing the current request's ClaimsPrincipal.
ClaimsPrincipal User
Get the current ClaimsPrincipal.
Contains various cryptographic functions.
Receives notifications about permissions updates.
ValueTask UserDisabled(User user, CancellationToken cancellationToken)
Called when a given User is successfully disabled.
Handles invalidating user sessions.
void UserModifiedInvalidateSessions(User user)
Invalidate all sessions for a given user .
Factory for ISystemIdentitys.
Task< ISystemIdentity?> CreateSystemIdentity(User user, CancellationToken cancellationToken)
Create a ISystemIdentity for a given user .
ErrorCode
Types of Response.ErrorMessageResponses that the API may return.
@ List
User may list files if the Models.Instance allows it.
InstanceManagerRights
Rights for managing Models.Instances.
AdministrationRights
Administration rights for the server.
@ Api
The ApiHeaders.ApiVersionHeader header is missing or invalid.
HttpFailureResponse
Indicates the type of HTTP status code an failing AuthorityResponse should generate.
HttpSuccessResponse
Indicates the type of HTTP status code a successful AuthorityResponse<TResult> should generate.
@ Enabled
The OAuth Gateway is enabled.