diff --git a/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25.xml b/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25.xml
index 0fad7f5..548fa8f 100644
--- a/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25.xml
+++ b/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25.xml
@@ -11,9 +11,9 @@
4||10|c|G
4||10|C|G
4||10|T|G
- 6992
+ 7186
16.2
- 1714636069
+ 1715783487
true ACDT
true ACSST
false ACST
@@ -808,7 +808,7 @@ false Zulu
13474||10|C|G
13474||-9223372036854775808|U|G
13474||10|U|G
- 6992
+ 7186
37312
postgres
@@ -838,50 +838,50 @@ false Zulu
1
1
-
+
+ 4544
+
+
+ 6304
+
+
6171
-
- 6181
+
+ 4571
-
- 6182
-
-
+
3373
3374
3375
3377
-
+
+ 6181
+
+
3374
-
+
3375
-
- 3377
-
-
+
4569
-
- 4570
-
-
- 4571
-
-
+
4200
-
- 4544
+
+ 3377
-
+
4550
-
- 6304
+
+ 6182
+
+
+ 4570
1
@@ -4249,8 +4249,8 @@ false Zulu
standard public schema
1
- 6992
- 2024-05-05.03:46:49
+ 7186
+ 2024-05-17.11:41:59
2200
523
pg_database_owner
@@ -4393,7 +4393,7 @@ false Zulu
37314
- 6227
+ 7177
2
littlesheep
@@ -4423,7 +4423,7 @@ false Zulu
37510
- 6251
+ 7011
2
littlesheep
@@ -4881,7 +4881,13 @@ false Zulu
6224
20
-
+
+ jsonb|0s
+ 12
+ 7177
+ 3802
+
+
id
1
37320
@@ -4890,7 +4896,7 @@ false Zulu
1
403
-
+
name
37322
6225
@@ -4900,20 +4906,20 @@ false Zulu
100
pg_catalog
-
+
deleted_at
37323
6226
403
-
+
1
37321
1
6224
37320
-
+
bigint|0s
nextval('passport_action_events_id_seq'::regclass)
1
@@ -4922,68 +4928,68 @@ false Zulu
37474
20
-
+
timestamp with time zone|0s
2
6247
1184
-
+
timestamp with time zone|0s
3
6247
1184
-
+
timestamp with time zone|0s
4
6247
1184
-
+
text|0s
5
6247
25
-
+
text|0s
6
6247
25
-
+
text|0s
7
6247
25
-
+
text|0s
8
6247
25
-
+
text|0s
9
6247
25
-
+
bigint|0s
10
6247
20
-
+
account_id
37483
6247
1
37314
-
+
id
1
37481
@@ -4992,20 +4998,20 @@ false Zulu
1
403
-
+
deleted_at
37488
6248
403
-
+
1
37482
1
6247
37481
-
+
bigint|0s
nextval('passport_auth_factors_id_seq'::regclass)
1
@@ -5014,56 +5020,56 @@ false Zulu
37324
20
-
+
timestamp with time zone|0s
2
6227
1184
-
+
timestamp with time zone|0s
3
6227
1184
-
+
timestamp with time zone|0s
4
6227
1184
-
+
smallint|0s
5
6227
21
-
+
text|0s
6
6227
25
-
+
jsonb|0s
7
6227
3802
-
+
bigint|0s
8
6227
20
-
+
account_id
37333
6227
1
37314
-
+
id
1
37331
@@ -5072,20 +5078,20 @@ false Zulu
1
403
-
+
deleted_at
37338
6228
403
-
+
1
37332
1
6227
37331
-
+
bigint|0s
nextval('passport_auth_tickets_id_seq'::regclass)
1
@@ -5094,136 +5100,136 @@ false Zulu
37526
20
-
+
timestamp with time zone|0s
2
6259
1184
-
+
timestamp with time zone|0s
3
6259
1184
-
+
timestamp with time zone|0s
4
6259
1184
-
+
text|0s
5
6259
25
-
+
text|0s
6
6259
25
-
+
text|0s
7
6259
25
-
+
boolean|0s
8
6259
16
-
+
boolean|0s
9
6259
16
-
+
jsonb|0s
10
6259
3802
-
+
jsonb|0s
11
6259
3802
-
+
text|0s
12
6259
25
-
+
text|0s
13
6259
25
-
+
text|0s
14
6259
25
-
+
timestamp with time zone|0s
15
6259
1184
-
+
timestamp with time zone|0s
16
6259
1184
-
+
timestamp with time zone|0s
17
6259
1184
-
+
bigint|0s
18
6259
20
-
+
bigint|0s
19
6259
20
-
+
client_id
37540
6259
1
37404
-
+
account_id
37535
6259
1
37314
-
+
account_id
37546
6301
1
37314
-
+
id
1
37533
@@ -5232,20 +5238,20 @@ false Zulu
1
403
-
+
deleted_at
37545
6260
403
-
+
1
37534
1
6259
37533
-
+
bigint|0s
nextval('passport_magic_tokens_id_seq'::regclass)
1
@@ -5254,56 +5260,56 @@ false Zulu
37459
20
-
+
timestamp with time zone|0s
2
6245
1184
-
+
timestamp with time zone|0s
3
6245
1184
-
+
timestamp with time zone|0s
4
6245
1184
-
+
text|0s
5
6245
25
-
+
smallint|0s
6
6245
21
-
+
bigint|0s
7
6245
20
-
+
timestamp with time zone|0s
8
6245
1184
-
+
assign_to
37468
6245
1
37314
-
+
id
1
37466
@@ -5312,20 +5318,20 @@ false Zulu
1
403
-
+
deleted_at
37473
6246
403
-
+
1
37467
1
6245
37466
-
+
bigint|0s
nextval('passport_notification_subscribers_id_seq'::regclass)
1
@@ -5334,56 +5340,62 @@ false Zulu
37509
20
-
+
timestamp with time zone|0s
2
6251
1184
-
+
timestamp with time zone|0s
3
6251
1184
-
+
timestamp with time zone|0s
4
6251
1184
-
+
text|0s
5
6251
25
-
+
text|0s
6
6251
25
-
+
text|0s
7
6251
25
-
+
bigint|0s
8
6251
20
-
+
+ text|0s
+ 9
+ 7011
+ 25
+
+
account_id
37518
6251
1
37314
-
+
id
1
37516
@@ -5392,7 +5404,7 @@ false Zulu
1
403
-
+
device_id
37523
6252
@@ -5402,20 +5414,20 @@ false Zulu
100
pg_catalog
-
+
deleted_at
37524
6253
403
-
+
1
37517
1
6251
37516
-
+
bigint|0s
nextval('passport_notifications_id_seq'::regclass)
1
@@ -5424,81 +5436,81 @@ false Zulu
37489
20
-
+
timestamp with time zone|0s
2
6249
1184
-
+
timestamp with time zone|0s
3
6249
1184
-
+
timestamp with time zone|0s
4
6249
1184
-
+
text|0s
5
6249
25
-
+
text|0s
6
6249
25
-
+
jsonb|0s
7
6249
3802
-
+
boolean|0s
8
6249
16
-
+
timestamp with time zone|0s
9
6249
1184
-
+
bigint|0s
10
6249
20
-
+
bigint|0s
11
6249
20
-
+
sender_id
37498
6249
1
37404
-
+
recipient_id
37503
6249
1
37314
-
+
id
1
37496
@@ -5507,20 +5519,20 @@ false Zulu
1
403
-
+
deleted_at
37508
6250
403
-
+
1
37497
1
6249
37496
-
+
bigint|0s
nextval('passport_realm_members_id_seq'::regclass)
1
@@ -5529,57 +5541,64 @@ false Zulu
37562
20
-
+
timestamp with time zone|0s
2
6430
1184
-
+
timestamp with time zone|0s
3
6430
1184
-
+
timestamp with time zone|0s
4
6430
1184
-
+
bigint|0s
5
6430
20
-
+
bigint|0s
6
6430
20
-
+
bigint|0s
7
6430
20
-
+
realm_id
37574
6430
1
37552
-
+
+ account_id
+ 38570
+ 7010
+ 1
+ 37314
+
+
account_id
37569
6430
1
37314
-
+
id
1
37567
@@ -5588,20 +5607,20 @@ false Zulu
1
403
-
+
deleted_at
37579
6431
403
-
+
1
37568
1
6430
37567
-
+
bigint|0s
nextval('passport_realms_id_seq'::regclass)
1
@@ -5610,61 +5629,61 @@ false Zulu
37551
20
-
+
timestamp with time zone|0s
2
6427
1184
-
+
timestamp with time zone|0s
3
6427
1184
-
+
timestamp with time zone|0s
4
6427
1184
-
+
text|0s
5
6427
25
-
+
text|0s
6
6427
25
-
+
text|0s
7
6427
25
-
+
boolean|0s
8
6427
16
-
+
boolean|0s
9
6427
16
-
+
bigint|0s
10
6427
20
-
+
id
1
37558
@@ -5673,7 +5692,7 @@ false Zulu
1
403
-
+
alias
37561
6429
@@ -5683,20 +5702,20 @@ false Zulu
100
pg_catalog
-
+
deleted_at
37560
6428
403
-
+
1
37559
1
6427
37558
-
+
bigint|0s
nextval('passport_third_clients_id_seq'::regclass)
1
@@ -5705,80 +5724,80 @@ false Zulu
37403
20
-
+
timestamp with time zone|0s
2
6238
1184
-
+
timestamp with time zone|0s
3
6238
1184
-
+
timestamp with time zone|0s
4
6238
1184
-
+
text|0s
5
6238
25
-
+
text|0s
6
6238
25
-
+
text|0s
7
6238
25
-
+
text|0s
8
6238
25
-
+
jsonb|0s
9
6238
3802
-
+
jsonb|0s
10
6238
3802
-
+
boolean|0s
11
6238
16
-
+
bigint|0s
12
6238
20
-
+
account_id
37412
6238
1
37314
-
+
id
1
37410
@@ -5787,7 +5806,7 @@ false Zulu
1
403
-
+
alias
37417
6239
@@ -5797,13 +5816,13 @@ false Zulu
100
pg_catalog
-
+
deleted_at
37418
6240
403
-
+
1
37411
1
diff --git a/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25/storage_v2/_src_/database/hy_passport.gNOKQQ/schema/public.abK9xQ.meta b/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25/storage_v2/_src_/database/hy_passport.gNOKQQ/schema/public.abK9xQ.meta
index 8a7058b..0bfb1f5 100644
--- a/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25/storage_v2/_src_/database/hy_passport.gNOKQQ/schema/public.abK9xQ.meta
+++ b/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25/storage_v2/_src_/database/hy_passport.gNOKQQ/schema/public.abK9xQ.meta
@@ -1,2 +1,2 @@
#n:public
-! [6992, 0, null, null, -2147483648, -2147483648]
+! [7186, 0, null, null, -2147483648, -2147483648]
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index a517cd5..160800f 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,19 +4,12 @@
-
+
+
+
-
-
-
-
-
-
-
-
-
-
+
@@ -54,7 +47,7 @@
-
@@ -174,9 +166,21 @@
-
+
+
true
+
+
+
+
+ file://$PROJECT_DIR$/pkg/services/perms.go
+ 49
+
+
+
+
+
\ No newline at end of file
diff --git a/pkg/services/auth.go b/pkg/services/auth.go
index 353449f..f260d09 100644
--- a/pkg/services/auth.go
+++ b/pkg/services/auth.go
@@ -30,18 +30,7 @@ func Authenticate(access, refresh string, depth int) (user models.Account, perms
newRefresh = refresh
var ctx models.AuthContext
-
- ctx, lookupErr := GetAuthContext(claims.ID)
- if lookupErr == nil {
- log.Debug().Str("jti", claims.ID).Msg("Hit auth context cache once!")
- perms = FilterPermNodes(ctx.Account.PermNodes, ctx.Ticket.Claims)
- user = ctx.Account
- return
- }
-
- ctx, err = GrantAuthContext(claims.ID)
- if err == nil {
-
+ if ctx, err = GetAuthContext(claims.ID); err == nil {
perms = FilterPermNodes(ctx.Account.PermNodes, ctx.Ticket.Claims)
user = ctx.Account
return
@@ -61,14 +50,14 @@ func GetAuthContext(jti string) (models.AuthContext, error) {
authContextCache[jti] = ctx
log.Debug().Str("jti", jti).Msg("Used an auth context cache")
} else {
- ctx, err = GrantAuthContext(jti)
+ ctx, err = CacheAuthContext(jti)
log.Debug().Str("jti", jti).Msg("Created a new auth context cache")
}
return ctx, err
}
-func GrantAuthContext(jti string) (models.AuthContext, error) {
+func CacheAuthContext(jti string) (models.AuthContext, error) {
var ctx models.AuthContext
// Query data from primary database
diff --git a/pkg/services/perms.go b/pkg/services/perms.go
index 438a6e1..0ea3316 100644
--- a/pkg/services/perms.go
+++ b/pkg/services/perms.go
@@ -1,6 +1,7 @@
package services
import (
+ "fmt"
"reflect"
"regexp"
"strings"
@@ -45,8 +46,8 @@ func FilterPermNodes(tree map[string]any, claims []string) map[string]any {
filteredTree := make(map[string]any)
match := func(claim, permission string) bool {
- regex := strings.Replace(permission, "*", ".*", -1)
- match, _ := regexp.MatchString("^"+regex+"$", claim)
+ regex := strings.ReplaceAll(claim, "*", ".*")
+ match, _ := regexp.MatchString(fmt.Sprintf("^%s$", regex), permission)
return match
}