Skip to content

Commit 27d0032

Browse files
committed
Allow token without accessRole
1 parent 87e0888 commit 27d0032

File tree

9 files changed

+171
-23
lines changed

9 files changed

+171
-23
lines changed

src/AasSecurity/ISecurityService.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* SPDX-License-Identifier: Apache-2.0
1212
********************************************************************************/
1313

14+
using System.Security.Claims;
1415
using AasSecurity.Models;
1516
using Microsoft.AspNetCore.Authentication;
1617
using Microsoft.AspNetCore.Http;
@@ -29,7 +30,9 @@ bool AuthorizeRequest(string accessRole,
2930
out string? getPolicy,
3031
string objPath = null,
3132
string? aasResourceType = null,
32-
IClass? aasResource = null, string? policy = null);
33+
IClass? aasResource = null,
34+
string? policy = null,
35+
List<Claim> tokenClaims = null);
3336

3437
string GetSecurityRules(out List<Dictionary<string, string>> condition);
3538
}

src/AasSecurity/SecurityService.cs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using System.Linq.Expressions;
1919
using System.Net;
2020
using System.Net.Http.Headers;
21+
using System.Security.AccessControl;
2122
using System.Security.Claims;
2223
using System.Security.Cryptography;
2324
using System.Security.Cryptography.X509Certificates;
@@ -88,12 +89,14 @@ public void parseAccessRuleFile()
8889
}
8990
}
9091

91-
public List<AccessPermissionRule>? GetAccessRules(string accessRole, string neededRightsClaim, string? httpRoute = null, List<Claim>? tokenClaims = null)
92+
public List<AccessPermissionRule>? GetAccessRules(string accessRole, string neededRightsClaim, string? httpRoute = null,
93+
List<Claim>? tokenClaims = null)
9294
{
9395
return GetAccessRulesStatic(accessRole, neededRightsClaim, httpRoute, tokenClaims);
9496
}
9597

96-
public static List<AccessPermissionRule>? GetAccessRulesStatic(string accessRole, string neededRightsClaim, string? httpRoute = null, List<Claim>? tokenClaims = null)
98+
public static List<AccessPermissionRule>? GetAccessRulesStatic(string accessRole, string neededRightsClaim, string? httpRoute = null,
99+
List<Claim>? tokenClaims = null)
97100
{
98101
if (_accessRules != null)
99102
{
@@ -124,7 +127,7 @@ public void parseAccessRuleFile()
124127
a.ItemType == "CLAIM" &&
125128
(
126129
(accessRole != null && a.Value == accessRole) ||
127-
(tokenClaims != null && tokenClaims.Any(t => t.ValueType == "token:" + a.Value))
130+
(tokenClaims != null && tokenClaims.Any(t => t.Type == a.Value))
128131
)
129132
) &&
130133
(
@@ -147,7 +150,7 @@ public void parseAccessRuleFile()
147150
}
148151
public Dictionary<string, string>? GetCondition(string accessRole, string neededRightsClaim, string? httpRoute = null, List<Claim>? tokenClaims = null)
149152
{
150-
var rules = GetAccessRules(accessRole, neededRightsClaim);
153+
var rules = GetAccessRules(accessRole, neededRightsClaim, tokenClaims: tokenClaims);
151154

152155
if (rules == null)
153156
{
@@ -315,7 +318,7 @@ public void AddSecurityRule(string name, string access, string right, string obj
315318
}
316319

317320
var accessRole = GetAccessRole(queries, headers, out var policy, out var policyRequestedResource, out var tokenClaims);
318-
if (string.IsNullOrEmpty(accessRole))
321+
if (string.IsNullOrEmpty(accessRole) && tokenClaims.Count == 0)
319322
{
320323
_logger.LogDebug($"Access Role found null. Hence setting the access role as isNotAuthenticated.");
321324
accessRole = "isNotAuthenticated";
@@ -807,22 +810,24 @@ private string CheckUserPW(string userPW64, out string userName, out string pass
807810

808811
public bool AuthorizeRequest(string accessRole, string httpRoute, AccessRights neededRights,
809812
out string error, out bool withAllow, out string? getPolicy, string objPath = null, string? aasResourceType = null,
810-
IClass? aasResource = null, string? policy = null)
813+
IClass? aasResource = null, string? policy = null, List<Claim>? tokenClaims = null)
811814
{
812-
return CheckAccessRights(accessRole, httpRoute, neededRights, out error, out withAllow, out getPolicy, objPath, aasResourceType, aasResource, policy: policy);
815+
return CheckAccessRights(accessRole, httpRoute, neededRights, out error, out withAllow, out getPolicy,
816+
objPath, aasResourceType, aasResource, policy: policy, tokenClaims: tokenClaims);
813817
}
814818

815819
private static bool CheckAccessRights(string currentRole, string operation, AccessRights neededRights, out string error, out bool withAllow, out string? getPolicy,
816-
string objPath = "", string? aasResourceType = null, IClass? aasResource = null, bool testOnly = false, string? policy = null)
820+
string objPath = "", string? aasResourceType = null, IClass? aasResource = null, bool testOnly = false, string? policy = null,
821+
List<Claim>? tokenClaims = null)
817822
{
818823
withAllow = false;
819824
return CheckAccessRightsWithAllow(currentRole, operation, neededRights, out error, out withAllow, out getPolicy,
820-
objPath, aasResourceType, aasResource, testOnly, policy);
825+
objPath, aasResourceType, aasResource, testOnly, policy, tokenClaims);
821826
}
822827

823828
private static bool CheckAccessRightsWithAllow(string currentRole, string operation, AccessRights neededRights, out string error, out bool withAllow, out string? getPolicy,
824829
string objPath = "", string? aasResourceType = null, IClass? aasResource = null, bool testOnly = false,
825-
string? policy = null)
830+
string? policy = null, List<Claim>? tokenClaims = null)
826831
{
827832
error = "Access not allowed";
828833
withAllow = false;
@@ -837,7 +842,7 @@ private static bool CheckAccessRightsWithAllow(string currentRole, string operat
837842
// TODO (jtikekar, 2023-09-04): uncomment
838843
if (CheckAccessLevelWithError(
839844
out error, currentRole, operation, neededRights, out withAllow, out getPolicy,
840-
objPath, aasResourceType, aasResource, policy))
845+
objPath, aasResourceType, aasResource, policy, tokenClaims))
841846
return true;
842847
}
843848

@@ -852,7 +857,8 @@ private static bool CheckAccessRightsWithAllow(string currentRole, string operat
852857
}
853858

854859
private static bool CheckAccessLevelWithError(out string error, string currentRole, string operation, AccessRights neededRights, out bool withAllow, out string? getPolicy,
855-
string objPath, string? aasResourceType, IClass? aasResource, string? policy = null)
860+
string objPath, string? aasResourceType, IClass? aasResource, string? policy = null,
861+
List<Claim>? tokenClaims = null)
856862
{
857863
withAllow = false;
858864
getPolicy = "";
@@ -872,7 +878,7 @@ private static bool CheckAccessLevelWithError(out string error, string currentRo
872878
if (aasResource == null)
873879
{
874880
//API security check
875-
return CheckAccessLevelApi(currentRole, operation, neededRights, out error, out getPolicy);
881+
return CheckAccessLevelApi(currentRole, operation, neededRights, out error, out getPolicy, tokenClaims);
876882
}
877883

878884
if (string.IsNullOrEmpty(objPath))
@@ -889,12 +895,13 @@ private static bool CheckAccessLevelWithError(out string error, string currentRo
889895
return false;
890896
}
891897

892-
private static bool CheckAccessLevelApi(string currentRole, string operation, AccessRights neededRights, out string error, out string? getPolicy)
898+
private static bool CheckAccessLevelApi(string currentRole, string operation, AccessRights neededRights, out string error,
899+
out string? getPolicy, List<Claim>? tokenClaims = null)
893900
{
894901
error = string.Empty;
895902
getPolicy = string.Empty;
896903

897-
var rules = GetAccessRulesStatic(currentRole, neededRights.ToString(), operation);
904+
var rules = GetAccessRulesStatic(currentRole, neededRights.ToString(), operation, tokenClaims);
898905

899906
if (rules != null && rules.Count != 0)
900907
{

src/AasxServerBlazor/AasxServerBlazor.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@
9191
</ItemGroup>
9292

9393
<ItemGroup>
94+
<None Update="accessrules - Kopieren.txt">
95+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
96+
</None>
9497
<None Update="accessrules.txt">
9598
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
9699
</None>

src/AasxServerBlazor/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"AasxServerBlazor": {
1212
"commandName": "Project",
13-
"commandLineArgs": "--with-db --start-index 1000 --secret-string-api 1234 --data-path \"C:\\Development\\newdb1\" --edit --external-blazor http://localhost:5001",
13+
"commandLineArgs": "--with-db --start-index 1000 --secret-string-api 1234 --data-path \"C:\\Development\\p5\" --edit --external-blazor http://localhost:5001",
1414
"launchBrowser": true,
1515
"environmentVariables": {
1616
"ASPNETCORE_ENVIRONMENT": "Development",

src/AasxServerBlazor/accessrules.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
"ACL": {
119119
"ATTRIBUTES": [
120120
{
121-
"CLAIM": "isAuthenticated"
121+
"CLAIM": "token:sub"
122122
}
123123
],
124124
"RIGHTS": [
@@ -150,6 +150,18 @@
150150
"$or": [
151151
{
152152
"$and": [
153+
{
154+
"$ends-with": [
155+
{
156+
"$attribute": {
157+
"CLAIM": "token:sub"
158+
}
159+
},
160+
{
161+
"$strVal": "xx.com"
162+
}
163+
]
164+
},
153165
{
154166
"$eq": [
155167
{
@@ -172,7 +184,7 @@
172184
}
173185
},
174186
{
175-
"$strVal": "phoenixcontact.com"
187+
"$strVal": "xx.com"
176188
}
177189
]
178190
},

src/AasxServerBlazor/trustlist.txt

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# This is the f-x trustlist
2+
3+
# url: https://www.admin-shell-io.com/50001/.well-known/openid-configuration
4+
serverName: identityserver.test.rsa
5+
6+
-----BEGIN CERTIFICATE-----
7+
MIIEkTCCAvmgAwIBAgIRAM4etV7VpsRyr47UXp5q52wwDQYJKoZIhvcNAQELBQAw
8+
gY0xHjAcBgNVBAoTFW1rY2VydCBkZXZlbG9wbWVudCBDQTExMC8GA1UECwwoRE9N
9+
SU5JQ0tCQUlBRTgwXGRvbWluaWNrQERPTUlOSUNLQkFJQUU4MDE4MDYGA1UEAwwv
10+
bWtjZXJ0IERPTUlOSUNLQkFJQUU4MFxkb21pbmlja0BET01JTklDS0JBSUFFODAw
11+
HhcNMTkwNjAxMDAwMDAwWhcNMjkxMTAyMDgwODU1WjB+MScwJQYDVQQKEx5ta2Nl
12+
cnQgZGV2ZWxvcG1lbnQgY2VydGlmaWNhdGUxMTAvBgNVBAsMKERPTUlOSUNLQkFJ
13+
QUU4MFxkb21pbmlja0BET01JTklDS0JBSUFFODAxIDAeBgNVBAMTF2lkZW50aXR5
14+
c2VydmVyLnRlc3QucnNhMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
15+
4BHPb4kNFadWsFfvOhAubS4GUsMogvBBpugquY0vlRlX9qYvA/Lmkmo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myqU3ZJ
32+
-----END CERTIFICATE-----
33+
34+
# url: https://auth.aas-voyager.com/.well-known/openid-configuration
35+
serverName: aas-voyager.com.rsa
36+
# domain: phoenixcontact.com
37+
38+
-----BEGIN CERTIFICATE-----
39+
MIID0TCCArkCFH+qHAtTwAgZlBxdwJqIrXH4hDQWMA0GCSqGSIb3DQEBCwUAMIGk
40+
MQswCQYDVQQGEwJERTEQMA4GA1UECAwHR2VybWFueTERMA8GA1UEBwwIQmxvbWJl
41+
cmcxEzARBgNVBAoMCkFhc1ZveWFnZXIxEzARBgNVBAsMCkFhc1ZveWFnZXIxGTAX
42+
BgNVBAMMEEFuZHJlYXMgT3J6ZWxza2kxKzApBgkqhkiG9w0BCQEWHGFvcnplbHNr
43+
aUBwaG9lbml4Y29udGFjdC5jb20wHhcNMjUwNzE4MTIyMzMwWhcNMzAwNzE3MTIy
44+
MzMwWjCBpDELMAkGA1UEBhMCREUxEDAOBgNVBAgMB0dlcm1hbnkxETAPBgNVBAcM
45+
CEJsb21iZXJnMRMwEQYDVQQKDApBYXNWb3lhZ2VyMRMwEQYDVQQLDApBYXNWb3lh
46+
Z2VyMRkwFwYDVQQDDBBBbmRyZWFzIE9yemVsc2tpMSswKQYJKoZIhvcNAQkBFhxh
47+
b3J6ZWxza2lAcGhvZW5peGNvbnRhY3QuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOC
48+
AQ8AMIIBCgKCAQEAxM47E7054b//40zCUNqUqpN2vKVePlk/4dzHV1iw98wetar4
49+
ou8gXJ5JkzlUcgSeqfr5Mm9QWVn2t8ilVL3DtZWkzUBVlS5H/yVjEHaEc6gmpxgJ
50+
XaT8vECUcNg8MSNab0FnOxhRTo/gMswD84gleItG6+hq/5rCjmDrulDlYj1EaVXe
51+
IOgTEAPMm0HKQBMQPCkV6x3hXQ6/H6FtjZMrOiEbGRKL3Pc87umxvKVbVoyJIdEN
52+
hh5LB5zz7x971noLDN8yFdQriDijxSPPAYO/oerAWm8QVuv2XmtpNrB5sHC2FHth
53+
I4Fnd/bx3JtcV0CpgKu++LW4381M12h2ChPFcQIDAQABMA0GCSqGSIb3DQEBCwUA
54+
A4IBAQBG4bVkRmCB7dhFXdWowex+avI6X/aO8w+8GULZVMG6XZpeC6ba6UQQZRl2
55+
V/w+eSCeu5jyYxX62lC/yslAc+PuVX2njcpm0yxk5L3eBddHH+QaadVkQiB0lQwY
56+
KORWgHJojsWia3rVJK+JF8mKsoJI5wqgbdB6CR4iHV+DsaDzvtSBwFdLfV5Itg7j
57+
08EdzU+aegQtP6PSv9KL8OyOOYV/IMkf09ERwEip8eDUssWR6H97kfycMHNeC8eT
58+
vIF6NaI/gf7pCsBo67ax0Ygrkt6gpSwGuBVH3nUpKRruJhwmQSPBSIS4ukTYBTjk
59+
AvIfdl+kJvjhcMhNyO71RgMBOppw
60+
-----END CERTIFICATE-----
61+
62+
63+
# url: https://credential.aas-voyager.com/token
64+
serverName: client-credential.rsa
65+
66+
-----BEGIN CERTIFICATE-----
67+
MIIDwzCCAqsCFC6KyzqWooqrGsmqebIqy9gSXrWJMA0GCSqGSIb3DQEBCwUAMIGd
68+
MQswCQYDVQQGEwJERTEQMA4GA1UECAwHR2VybWFueTERMA8GA1UEBwwIQmxvbWJl
69+
cmcxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEZMBcGA1UEAwwQ
70+
QW5kcmVhcyBPcnplbHNraTErMCkGCSqGSIb3DQEJARYcYW9yemVsc2tpQHBob2Vu
71+
aXhjb250YWN0LmNvbTAeFw0yNTA3MjgwNTQzMDBaFw0zMDA3MjcwNTQzMDBaMIGd
72+
MQswCQYDVQQGEwJERTEQMA4GA1UECAwHR2VybWFueTERMA8GA1UEBwwIQmxvbWJl
73+
cmcxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEZMBcGA1UEAwwQ
74+
QW5kcmVhcyBPcnplbHNraTErMCkGCSqGSIb3DQEJARYcYW9yemVsc2tpQHBob2Vu
75+
aXhjb250YWN0LmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALZ5
76+
7tatDmFvkWsoD3QYvUqqG9C9p8BIB5Y61n7Au9HFELgAYVxjWzJkPEgb1JdMW7+H
77+
Q5hG1SYYArdjJoGD1xeGAaLHnobZiZ6K8pUnvuS0mDeoaap1cc/S6Zzf3jbCZ1q9
78+
pRHRufUrpKEV4kgy1VIUu0U+MfFz6lHAmaUia7Q4/wN6ScsVltqxJkrR3D57ZTNc
79+
AbVoqFC2nLHgNLSQkSVHDIg55tOBjuDNrf5qNT2MLysUsf0+AZ8LDlmsmrmjj0ua
80+
7bmiAE5ZN8i3uSCA1CchV38p3dL9ytan5ryYh5Jrm/Lrvbi/FX2oHLVRcE48Jt8W
81+
XHgK6iW2lMD10SHBQjsCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAHpJxQdinqKMN
82+
1fR3gXxk9CbBaCBA+P5ii6/jvt6hTg6wSODB/ljAcY9zbF8nCJJVLiKiZWt2xBXR
83+
ZRUZmVnEWiuqiK2qmAPAdxzfqEioWts1czJVoDYK7UrGKTd1I611VZ9n6RjsH8fH
84+
bwMOFKmGjFTQV9NQiSKoaiPcNo7BE3iNt1/t7L9DCmypHqjcgYriJBeqa7GGXKE/
85+
qsGA0wuDXMP5MmqjVis7BvShZuB9ctHDz7xJeRbF5dlBpIj5wXLPIe+jlUnvXCVC
86+
ovsIBCzKo0Dt4orM+gVNsOuf32cif9sjkZ3KiSJPJK3i8PtgH/JcGBS/cWU7fBQx
87+
FIUuZ0fDbA==
88+
-----END CERTIFICATE-----
89+
90+
# url: localhost:5022/token on aas-voyager.com
91+
serverName: credential2.rsa
92+
93+
-----BEGIN CERTIFICATE-----
94+
MIIDmzCCAoMCFDOvlB89ZepXaqf42JHAjBJcaOnGMA0GCSqGSIb3DQEBCwUAMIGJ
95+
MQswCQYDVQQGEwJERTEQMA4GA1UECAwHR2VybWFueTERMA8GA1UEBwwIQmxvbWJl
96+
cmcx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2ogB2GTbYkuBSebhZ
112+
BmNbiHJ541E5aeIXKj1Ksdv6fUgYvzXgASKfjpq3l+bD7XSBbIAp9mMYl/pi0C8D
113+
ejiwt3d6N936huydhEwz
114+
-----END CERTIFICATE-----
115+
116+
# Token exchange
117+
serverName: STS
118+
jwks: https://iam-security-training.com/sts
119+
kid: demo-key

src/AasxServerDB/EntityFrameworkPersistenceService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,9 +2144,9 @@ private bool InitSecurity(ISecurityConfig? securityConfig, out Dictionary<string
21442144
securityCondition = _contractSecurityRules.GetCondition(accessRole, neededRights.ToString(), tokenClaims: tokenClaims);
21452145
accessRules = _contractSecurityRules.GetAccessRules(accessRole, neededRights.ToString(), tokenClaims: tokenClaims);
21462146

2147-
if (accessRole != null && httpRoute != null)
2147+
if (accessRules.Count != 0 && httpRoute != null)
21482148
{
2149-
authResult = _contractSecurityRules.AuthorizeRequest(accessRole, httpRoute, neededRights, out _, out _, out _);
2149+
authResult = _contractSecurityRules.AuthorizeRequest(accessRole, httpRoute, neededRights, out _, out _, out _, tokenClaims: tokenClaims);
21502150
}
21512151

21522152
return authResult;

src/Contracts/ContractSecurityRule.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ bool AuthorizeRequest(string accessRole,
3131
out string? getPolicy,
3232
string objPath = null,
3333
string? aasResourceType = null,
34-
IClass? aasResource = null, string? policy = null);
34+
IClass? aasResource = null, string? policy = null,
35+
List<Claim>? tokenClaims = null);
3536

3637
public void ClearSecurityRules();
3738
public void AddSecurityRule(string name, string acccess, string right, string objectType, string semanticId, string route);

src/Contracts/QueryParserJSON.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,10 @@ void ParseAccessRule(AccessPermissionRule rule, Dictionary<string, string> acces
882882
if (a.ItemType == "CLAIM")
883883
{
884884
claim = a.Value;
885-
claimList += claim + " ";
885+
if (!claimList.Contains(claim + " "))
886+
{
887+
claimList += claim + " ";
888+
}
886889
}
887890
}
888891
accessRuleExpression["claim"] = claimList;

0 commit comments

Comments
 (0)