Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/66037 #456

Merged
merged 8 commits into from
Aug 6, 2024
4 changes: 4 additions & 0 deletions common/ASC.Api.Core/Model/EmployeeFullDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ public class EmployeeFullDto : EmployeeDto
/// <type>System.Boolean, System</type>
public bool? IsCustomQuota { get; set; }

/// <summary>Current login event ID</summary>
/// <type>System.Int32, System</type>
public int? LoginEventId { get; set; }

public static new EmployeeFullDto GetSample()
{
return new EmployeeFullDto
Expand Down
4 changes: 3 additions & 1 deletion common/ASC.Core.Common/Data/DbLoginEventsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,15 @@ public async Task LogOutAllActiveConnectionsForTenantAsync(int tenantId)
await InnerLogOutAsync(loginEventContext, loginEvents);
}

public async Task LogOutAllActiveConnectionsExceptThisAsync(int loginEventId, int tenantId, Guid userId)
public async Task<List<DbLoginEvent>> LogOutAllActiveConnectionsExceptThisAsync(int loginEventId, int tenantId, Guid userId)
{
await using var loginEventContext = await dbContextFactory.CreateDbContextAsync();

var loginEvents = await loginEventContext.LoginEventsExceptThisAsync(tenantId, userId, loginEventId).ToListAsync();

await InnerLogOutAsync(loginEventContext, loginEvents);

return loginEvents;
}

private async Task InnerLogOutAsync(MessagesContext loginEventContext, List<DbLoginEvent> loginEvents)
Expand Down
7 changes: 7 additions & 0 deletions common/ASC.Core.Common/Quota/QuotaSocketManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ public async Task ChangeInvitationLimitValue(int value)
await MakeRequest("change-invitation-limit-value", new { room, value });
}

public async Task LogoutSession(Guid userId, int loginEventId = 0)
{
var tenantId = await _tenantManager.GetCurrentTenantIdAsync();

await MakeRequest("logout-session", new { room = $"{tenantId}-{userId}", loginEventId });
}

private async Task<string> GetQuotaRoom()
{
var tenantId = await _tenantManager.GetCurrentTenantIdAsync();
Expand Down
5 changes: 5 additions & 0 deletions common/ASC.Socket.IO/app/controllers/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,10 @@ module.exports = (files) => {
res.end();
});

router.post("/logout-session", (req, res) => {
files.logoutSession(req.body);
res.end();
});

return router;
};
10 changes: 8 additions & 2 deletions common/ASC.Socket.IO/app/hubs/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,17 @@ module.exports = (io) => {
logger.info(`changed user invitation limit in room ${room}, value ${value}`);
filesIO.to(room).emit("s:change-invitation-limit-value", value);
}

function updateHistory({ room, id, type } = {}) {
logger.info(`update ${type} history ${id} in room ${room}`);
filesIO.to(room).emit("s:update-history", { id, type });
}


function logoutSession({ room, loginEventId } = {}) {
logger.info(`logout user ${room} session ${loginEventId}`);
filesIO.to(room).emit("s:logout-session", loginEventId);
}

return {
startEdit,
stopEdit,
Expand All @@ -354,5 +359,6 @@ module.exports = (io) => {
markAsNewFolders,
changeInvitationLimitValue,
updateHistory,
logoutSession
};
};
4 changes: 4 additions & 0 deletions products/ASC.People/Server/Api/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

using ASC.AuditTrail.Repositories;
using ASC.AuditTrail.Types;
using ASC.Core.Security.Authentication;

namespace ASC.People.Api;

Expand All @@ -34,6 +35,7 @@ public class UserController(
ICache cache,
TenantManager tenantManager,
CookiesManager cookiesManager,
CookieStorage cookieStorage,
CustomNamingPeople customNamingPeople,
EmployeeDtoHelper employeeDtoHelper,
EmployeeFullDtoHelper employeeFullDtoHelper,
Expand Down Expand Up @@ -1023,6 +1025,8 @@ public async Task<EmployeeFullDto> SelfAsync()

result.Theme = (await settingsManager.LoadForCurrentUserAsync<DarkThemeSettings>()).Theme;

result.LoginEventId = cookieStorage.GetLoginEventIdFromCookie(cookiesManager.GetCookies(CookiesType.AuthKey));

return result;
}

Expand Down
2 changes: 2 additions & 0 deletions web/ASC.Web.Api/Api/AuthenticationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class AuthenticationController(
ApiContext apiContext,
AuthContext authContext,
CookieStorage cookieStorage,
QuotaSocketManager quotaSocketManager,
DbLoginEventsManager dbLoginEventsManager,
BruteForceLoginManager bruteForceLoginManager,
TfaAppAuthSettingsHelper tfaAppAuthSettingsHelper,
Expand Down Expand Up @@ -295,6 +296,7 @@ public async Task<object> LogoutAsync()
var loginEventId = cookieStorage.GetLoginEventIdFromCookie(cookie);
var tenantId = await tenantManager.GetCurrentTenantIdAsync();
await dbLoginEventsManager.LogOutEventAsync(tenantId, loginEventId);
await quotaSocketManager.LogoutSession(securityContext.CurrentAccount.ID, loginEventId);

var user = await userManager.GetUsersAsync(securityContext.CurrentAccount.ID);
var loginName = user.DisplayUserName(false, displayUserSettingsHelper);
Expand Down
15 changes: 14 additions & 1 deletion web/ASC.Web.Api/Api/ConnectionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class ConnectionsController(
MessageService messageService,
CookiesManager cookiesManager,
CookieStorage cookieStorage,
QuotaSocketManager quotaSocketManager,
GeolocationHelper geolocationHelper,
ApiDateTimeHelper apiDateTimeHelper)
: ControllerBase
Expand Down Expand Up @@ -223,7 +224,12 @@ public async Task<object> LogOutAllExceptThisConnection()
var userName = user.DisplayUserName(false, displayUserSettingsHelper);
var loginEventFromCookie = GetLoginEventIdFromCookie();

await dbLoginEventsManager.LogOutAllActiveConnectionsExceptThisAsync(loginEventFromCookie, user.TenantId, user.Id);
var loginEvents = await dbLoginEventsManager.LogOutAllActiveConnectionsExceptThisAsync(loginEventFromCookie, user.TenantId, user.Id);

foreach (var loginEvent in loginEvents)
{
await quotaSocketManager.LogoutSession(user.Id, loginEvent.Id);
}

await messageService.SendAsync(MessageAction.UserLogoutActiveConnections, userName);
return userName;
Expand Down Expand Up @@ -270,6 +276,11 @@ public async Task<bool> LogOutActiveConnection(int loginEventId)

await dbLoginEventsManager.LogOutEventAsync(loginEvent.TenantId, loginEvent.Id);

if (loginEvent.UserId.HasValue)
{
await quotaSocketManager.LogoutSession(loginEvent.UserId.Value, loginEvent.Id);
}

await messageService.SendAsync(MessageAction.UserLogoutActiveConnection, userName);
return true;
}
Expand All @@ -289,6 +300,8 @@ private async Task LogOutAllActiveConnections(Guid? userId = null)

await messageService.SendAsync(currentUserId.Equals(user.Id) ? MessageAction.UserLogoutActiveConnections : MessageAction.UserLogoutActiveConnectionsForUser, MessageTarget.Create(user.Id), auditEventDate, userName);
await cookiesManager.ResetUserCookieAsync(user.Id);

await quotaSocketManager.LogoutSession(user.Id);
}

private int GetLoginEventIdFromCookie()
Expand Down
Loading