|
| 1 | +using System.Collections.Generic; |
| 2 | + |
| 3 | +namespace Cyaim.WebSocketServer.Infrastructure.AccessControl |
| 4 | +{ |
| 5 | + /// <summary> |
| 6 | + /// Access control policy for IP and geographic location filtering |
| 7 | + /// IP 和地理位置访问控制策略 |
| 8 | + /// </summary> |
| 9 | + public class AccessControlPolicy |
| 10 | + { |
| 11 | + /// <summary> |
| 12 | + /// Enable access control / 启用访问控制 |
| 13 | + /// </summary> |
| 14 | + public bool Enabled { get; set; } = false; |
| 15 | + |
| 16 | + /// <summary> |
| 17 | + /// IP whitelist / IP 白名单 |
| 18 | + /// Supports CIDR notation (e.g., "192.168.1.0/24") / 支持 CIDR 表示法(例如:"192.168.1.0/24") |
| 19 | + /// </summary> |
| 20 | + public List<string> IpWhitelist { get; set; } = new List<string>(); |
| 21 | + |
| 22 | + /// <summary> |
| 23 | + /// IP blacklist / IP 黑名单 |
| 24 | + /// Supports CIDR notation (e.g., "10.0.0.0/8") / 支持 CIDR 表示法(例如:"10.0.0.0/8") |
| 25 | + /// </summary> |
| 26 | + public List<string> IpBlacklist { get; set; } = new List<string>(); |
| 27 | + |
| 28 | + /// <summary> |
| 29 | + /// Country whitelist (ISO 3166-1 alpha-2 country codes, e.g., "CN", "US") / 国家白名单(ISO 3166-1 alpha-2 国家代码,例如:"CN", "US") |
| 30 | + /// </summary> |
| 31 | + public List<string> CountryWhitelist { get; set; } = new List<string>(); |
| 32 | + |
| 33 | + /// <summary> |
| 34 | + /// Country blacklist (ISO 3166-1 alpha-2 country codes) / 国家黑名单(ISO 3166-1 alpha-2 国家代码) |
| 35 | + /// </summary> |
| 36 | + public List<string> CountryBlacklist { get; set; } = new List<string>(); |
| 37 | + |
| 38 | + /// <summary> |
| 39 | + /// City whitelist (format: "CountryCode:CityName", e.g., "CN:Beijing", "US:New York") / 城市白名单(格式:"CountryCode:CityName",例如:"CN:Beijing", "US:New York") |
| 40 | + /// </summary> |
| 41 | + public List<string> CityWhitelist { get; set; } = new List<string>(); |
| 42 | + |
| 43 | + /// <summary> |
| 44 | + /// City blacklist (format: "CountryCode:CityName") / 城市黑名单(格式:"CountryCode:CityName") |
| 45 | + /// </summary> |
| 46 | + public List<string> CityBlacklist { get; set; } = new List<string>(); |
| 47 | + |
| 48 | + /// <summary> |
| 49 | + /// Region whitelist (format: "CountryCode:RegionName", e.g., "CN:Beijing", "US:California") / 地区白名单(格式:"CountryCode:RegionName",例如:"CN:Beijing", "US:California") |
| 50 | + /// </summary> |
| 51 | + public List<string> RegionWhitelist { get; set; } = new List<string>(); |
| 52 | + |
| 53 | + /// <summary> |
| 54 | + /// Region blacklist (format: "CountryCode:RegionName") / 地区黑名单(格式:"CountryCode:RegionName") |
| 55 | + /// </summary> |
| 56 | + public List<string> RegionBlacklist { get; set; } = new List<string>(); |
| 57 | + |
| 58 | + /// <summary> |
| 59 | + /// Action when access is denied / 拒绝访问时的操作 |
| 60 | + /// </summary> |
| 61 | + public AccessDeniedAction DeniedAction { get; set; } = AccessDeniedAction.CloseConnection; |
| 62 | + |
| 63 | + /// <summary> |
| 64 | + /// Custom denial message / 自定义拒绝消息 |
| 65 | + /// </summary> |
| 66 | + public string DenialMessage { get; set; } = "Access denied"; |
| 67 | + |
| 68 | + /// <summary> |
| 69 | + /// Enable geographic location lookup / 启用地理位置查询 |
| 70 | + /// </summary> |
| 71 | + public bool EnableGeoLocationLookup { get; set; } = true; |
| 72 | + |
| 73 | + /// <summary> |
| 74 | + /// Cache geographic location results (in seconds) / 缓存地理位置查询结果(秒) |
| 75 | + /// </summary> |
| 76 | + public int GeoLocationCacheSeconds { get; set; } = 3600; // 1 hour |
| 77 | + } |
| 78 | + |
| 79 | + /// <summary> |
| 80 | + /// Action to take when access is denied / 拒绝访问时的操作 |
| 81 | + /// </summary> |
| 82 | + public enum AccessDeniedAction |
| 83 | + { |
| 84 | + /// <summary> |
| 85 | + /// Close connection immediately / 立即关闭连接 |
| 86 | + /// </summary> |
| 87 | + CloseConnection, |
| 88 | + |
| 89 | + /// <summary> |
| 90 | + /// Return HTTP 403 Forbidden / 返回 HTTP 403 Forbidden |
| 91 | + /// </summary> |
| 92 | + ReturnForbidden, |
| 93 | + |
| 94 | + /// <summary> |
| 95 | + /// Return HTTP 401 Unauthorized / 返回 HTTP 401 Unauthorized |
| 96 | + /// </summary> |
| 97 | + ReturnUnauthorized |
| 98 | + } |
| 99 | +} |
| 100 | + |
0 commit comments