|
24 | 24 | using System.Security.Cryptography.X509Certificates; |
25 | 25 | using System.Text; |
26 | 26 | using System.Text.Json; |
| 27 | +using System.Text.Json.Nodes; |
27 | 28 | using System.Web; |
28 | 29 | using AasSecurity.Exceptions; |
29 | 30 | using AasSecurity.Models; |
|
40 | 41 | using Microsoft.IdentityModel.JsonWebTokens; |
41 | 42 | using Microsoft.IdentityModel.Tokens; |
42 | 43 | using Namotion.Reflection; |
| 44 | +using Newtonsoft.Json; |
43 | 45 | using Newtonsoft.Json.Linq; |
44 | 46 | using static QRCoder.PayloadGenerator; |
45 | 47 | using File = AasCore.Aas3_0.File; |
@@ -238,12 +240,58 @@ public void parseAccessRuleFile() |
238 | 240 | if (claim.StartsWith("token:")) |
239 | 241 | { |
240 | 242 | var value = tokenClaims?.Where(tc => tc.Type == claim).FirstOrDefault()?.Value; |
241 | | - condition[c.Key] = conditionValue.Replace($"CLAIM({claim})", $"\"{value}\""); |
| 243 | + if (value.StartsWith("{")) |
| 244 | + { |
| 245 | + var dict = JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(value); |
| 246 | + |
| 247 | + var key = dict.Keys.First(); |
| 248 | + |
| 249 | + if (dict != null && dict.TryGetValue(key, out var roles)) |
| 250 | + { |
| 251 | + var valueBuildString = new StringBuilder(""); |
| 252 | + |
| 253 | + foreach (var role in roles) |
| 254 | + { |
| 255 | + valueBuildString = valueBuildString.Append($"{key}:{role}"); |
| 256 | + |
| 257 | + if (roles.IndexOf(role) < roles.Count - 1) |
| 258 | + { |
| 259 | + valueBuildString.Append(" "); |
| 260 | + } |
| 261 | + } |
| 262 | + value = valueBuildString.ToString(); |
| 263 | + } |
| 264 | + } |
| 265 | + var replaced = conditionValue.Replace($"CLAIM({claim})", $"\"{value}\""); |
| 266 | + condition[c.Key] = replaced; |
242 | 267 | } |
243 | 268 | if (claim == accessRole) |
244 | 269 | { |
245 | 270 | var value = tokenClaims?.Where(tc => tc.Type == claim).FirstOrDefault()?.Value; |
246 | | - condition[c.Key] = conditionValue.Replace($"CLAIM({accessRole})", $"\"{value}\""); |
| 271 | + if (value.StartsWith("{")) |
| 272 | + { |
| 273 | + var dict = JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(value); |
| 274 | + |
| 275 | + var key = dict.Keys.First(); |
| 276 | + |
| 277 | + if (dict != null && dict.TryGetValue(key, out var roles)) |
| 278 | + { |
| 279 | + var valueBuildString = new StringBuilder(""); |
| 280 | + |
| 281 | + foreach (var role in roles) |
| 282 | + { |
| 283 | + valueBuildString = valueBuildString.Append($"{role}"); |
| 284 | + |
| 285 | + if (roles.IndexOf(role) < roles.Count - 1) |
| 286 | + { |
| 287 | + valueBuildString.Append(" "); |
| 288 | + } |
| 289 | + } |
| 290 | + value = valueBuildString.ToString(); |
| 291 | + } |
| 292 | + } |
| 293 | + var replaced = conditionValue.Replace($"CLAIM({claim})", $"\"{value}\""); |
| 294 | + condition[c.Key] = replaced; |
247 | 295 | } |
248 | 296 | } |
249 | 297 | } |
|
0 commit comments