public async Task Update(IAccessPermissionCollection accessPermissions)
        {
            // NOTE: this is temporary quick solution
            // Normally it should be replaced with an implementation of partial updates based on MS Sync Framework
            var biometricInfo = await _listUsersBiometricRequest.Request(ListCommand.WithoutParameters);

            var biometricInfoMap            = biometricInfo.Users.ToDictionary(x => x.UserName);
            Func <string, UserHash> getHash = x =>
            {
                var hash = biometricInfoMap.ContainsKey(x) ? biometricInfoMap[x].BiometricHash : null;
                return(new UserHash(x, hash));
            };

            // add user permissions
            var accessRights = await _listAccessRightsRequest.Request(ListCommand.WithoutParameters);

            foreach (var userAccessRights in accessRights.UserAccessRights)
            {
                var userName = userAccessRights.UserName;
                var userHash = getHash(userName);

                userAccessRights.PermanentAccessRules.ForEach(
                    rule =>
                {
                    var permission = new PermanentUserAccess(rule.AccessPointId, userHash);
                    accessPermissions.AddOrUpdatePermission(permission);
                });

                userAccessRights.ScheduledAccessRules.ForEach(
                    rule =>
                {
                    var permission = new ScheduledUserAccess(rule.AccessPointId, userHash, WeeklySchedule.Convert(rule.WeeklySchedule));
                    accessPermissions.AddOrUpdatePermission(permission);
                });
            }

            // add user group permissions
            foreach (var groupRights in accessRights.UserGroupAccessRights)
            {
                var groupName          = groupRights.UserGroupName;
                var usersInGroupResult = await _listUsersInGroupRequest.Request(ListCommand.ListUsersInGroup(groupName));

                var userHashes = usersInGroupResult.Users.Select(x => getHash(x.UserName)).ToArray();

                groupRights.PermanentAccessRules.ForEach(
                    rule =>
                {
                    var permission = new PermanentGroupAccess(rule.AccessPointId, groupName, userHashes);
                    accessPermissions.AddOrUpdatePermission(permission);
                });

                groupRights.ScheduledAccessRules.ForEach(
                    rule =>
                {
                    var permission = new ScheduledGroupAccess(rule.AccessPointId, groupName, userHashes, WeeklySchedule.Convert(rule.WeeklySchedule));
                    accessPermissions.AddOrUpdatePermission(permission);
                });
            }
        }
Пример #2
0
        public Task Consume(ConsumeContext <IScheduledUserAccessAllowed> context)
        {
            var hash       = new UserHash(context.Message.UserName, context.Message.BiometricHash);
            var permission = new ScheduledUserAccess(context.Message.AccessPointId, hash, WeeklySchedule.Convert(context.Message.WeeklySchedule));

            _accessPermissions.AddOrUpdatePermission(permission);
            _service.Save(_accessPermissions);
            return(Task.FromResult(true));
        }
Пример #3
0
        public void Visit(ScheduledUserAccess permission)
        {
            if (!string.Equals(permission.UserHash.UserName, _userName))
            {
                return;
            }

            var replacement = new ScheduledUserAccess(
                permission.AccessPointId,
                new UserHash(permission.UserHash.UserName, _newHash),
                permission.WeeklySchedule);

            _accessPermissions.AddOrUpdatePermission(replacement);
        }