/* * dbMango * * Copyright 2025 Deutsche Bank AG * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using MongoDB.Bson; using Rms.Risk.Mango.Pivot.Core; using Rms.Risk.Mango.Pivot.Core.MongoDb; using Microsoft.AspNetCore.Authorization; using Rms.Service.Bootstrap.Security; namespace Rms.Risk.Mango.Interfaces; /// /// Interface representing a user session, providing access to user-related services, database configurations, /// and MongoDB services. /// public interface IUserSession { /// /// Gets the user service for the current session. /// UserService User { get; } /// /// Gets or sets the task number associated with the session. /// string? TaskNumber { get; set; } /// /// Gets the error message, if any, related to task checks. /// string? TaskCheckError { get; } /// /// Gets or sets the name of the database being used in the session. /// string Database { get; set; } /// /// Gets a value indicating whether database instance selection is allowed. /// bool IsDatabaseInstanceSelectionAllowed { get; } /// /// Gets or sets the name of the collection being used in the session. /// string Collection { get; set; } /// /// Gets or sets the database instance being used in the session. /// string DatabaseInstance { get; set; } /// /// Gets the MongoDB service for interacting with the database. /// IMongoDbService MongoDb { get; } /// /// Gets the MongoDB admin service for managing the database. /// IMongoDbDatabaseAdminService MongoDbAdmin { get; } /// /// Gets the MongoDB admin service for managing the admin database. /// IMongoDbDatabaseAdminService MongoDbAdminForAdminDatabase { get; } /// /// Gets the pivot table data source for the session. /// IPivotTableDataSource PivotDataSource { get; } /// /// Gets the audit service for logging and tracking changes. /// IAuditService Audit { get; } /// /// Gets the configuration record for the database. /// MongoDbConfigRecord DatabaseConfig { get; } /// /// Gets the LDAP groups configuration for the session. /// DatabasesConfig.DatabaseConfig.LdapGroups LdapGroups { get; } /// /// Checks if the session has a valid task. /// /// A task that resolves to true if the task is valid; otherwise, false. Task HasValidTask(); /// /// Determines if the user can access a specific resource based on the provided policy and database name. /// /// The authorization service. /// The name of the policy to check. /// The name of the database to check access for. /// A task that resolves to true if access is allowed; otherwise, false. Task CanAccess(IAuthorizationService auth, string policyName, string databaseName); /// /// Determines if instance selection is allowed for the specified database. /// /// The name of the database. /// True if instance selection is allowed; otherwise, false. bool IsInstanceSelectionAllowed(string database); /// /// Event triggered when the database changes. /// event Action? DatabaseChanged; /// /// Gets a custom MongoDB admin service for the specified database and instance. /// /// The name of the database. /// The name of the database instance. /// The custom MongoDB admin service. IMongoDbDatabaseAdminService GetCustomAdmin(string databaseName, string databaseInstance); /// /// Gets a shard connection for the specified host and port. /// /// The host of the shard. /// The port of the shard. /// The MongoDB admin service for the shard connection. IMongoDbDatabaseAdminService GetShardConnection(string host, int port); }