|
1 | 1 | using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
2 | 4 |
|
3 | 5 | namespace MultiFactor.Radius.Adapter.Configuration |
4 | 6 | { |
5 | 7 | public class AuthenticatedClientCacheConfig |
6 | 8 | { |
7 | 9 | public TimeSpan Lifetime { get; } |
8 | 10 | public bool Enabled => Lifetime != TimeSpan.Zero; |
| 11 | + public IReadOnlyCollection<string> AuthenticationCacheGroups { get; } |
9 | 12 |
|
10 | | - public AuthenticatedClientCacheConfig(TimeSpan lifetime) |
| 13 | + public AuthenticatedClientCacheConfig(TimeSpan lifetime, IReadOnlyCollection<string> authenticationCacheGroups = null) |
11 | 14 | { |
12 | 15 | Lifetime = lifetime; |
| 16 | + AuthenticationCacheGroups = authenticationCacheGroups?.Select(x => x.ToLower()).ToArray() ?? Array.Empty<string>(); |
13 | 17 | } |
14 | 18 |
|
15 | | - public static AuthenticatedClientCacheConfig CreateFromTimeSpan(string value) |
| 19 | + public static AuthenticatedClientCacheConfig CreateFromTimeSpan(string value, string authenticationCacheGroups = null) |
16 | 20 | { |
17 | 21 | if (string.IsNullOrWhiteSpace(value)) return new AuthenticatedClientCacheConfig(TimeSpan.Zero); |
18 | | - return new AuthenticatedClientCacheConfig(TimeSpan.ParseExact(value, @"hh\:mm\:ss", null, System.Globalization.TimeSpanStyles.None)); |
| 22 | + var cacheGroups = SplitCacheGroup(authenticationCacheGroups); |
| 23 | + return new AuthenticatedClientCacheConfig(TimeSpan.ParseExact(value, @"hh\:mm\:ss", null, System.Globalization.TimeSpanStyles.None), cacheGroups); |
19 | 24 | } |
20 | 25 |
|
21 | | - public static AuthenticatedClientCacheConfig CreateFromMinutes(string value) |
| 26 | + public static AuthenticatedClientCacheConfig CreateFromMinutes(string value, string authenticationCacheGroups = null) |
22 | 27 | { |
23 | 28 | if (string.IsNullOrWhiteSpace(value)) return new AuthenticatedClientCacheConfig(TimeSpan.Zero); |
24 | | - return new AuthenticatedClientCacheConfig(TimeSpan.FromMinutes(int.Parse(value))); |
| 29 | + var cacheGroups = SplitCacheGroup(authenticationCacheGroups); |
| 30 | + return new AuthenticatedClientCacheConfig(TimeSpan.FromMinutes(int.Parse(value)), cacheGroups); |
| 31 | + } |
| 32 | + |
| 33 | + private static string[] SplitCacheGroup(string cacheGroup) |
| 34 | + { |
| 35 | + return cacheGroup |
| 36 | + ?.Split(new[] {';'}, StringSplitOptions.RemoveEmptyEntries) |
| 37 | + .Select(x => x.ToLower().Trim()) |
| 38 | + .Where(x => !string.IsNullOrWhiteSpace(x)) |
| 39 | + .Distinct() |
| 40 | + .ToArray() ?? Array.Empty<string>(); |
25 | 41 | } |
26 | 42 | } |
27 | 43 | } |
0 commit comments