11
11
import com .datahub .authorization .ConjunctivePrivilegeGroup ;
12
12
import com .datahub .authorization .DisjunctivePrivilegeGroup ;
13
13
import com .datahub .authorization .EntitySpec ;
14
- import com .datahub .plugins .auth .authorization .Authorizer ;
15
14
import com .google .common .collect .ImmutableList ;
16
15
import com .linkedin .common .urn .Urn ;
17
16
import com .linkedin .datahub .graphql .QueryContext ;
21
20
import java .lang .reflect .InvocationTargetException ;
22
21
import java .lang .reflect .Method ;
23
22
import java .util .List ;
24
- import java .util .Set ;
25
23
import javax .annotation .Nonnull ;
26
24
import lombok .extern .slf4j .Slf4j ;
27
25
import org .apache .commons .lang3 .reflect .ConstructorUtils ;
@@ -40,29 +38,25 @@ public class AuthorizationUtils {
40
38
41
39
public static boolean canManageUsersAndGroups (@ Nonnull QueryContext context ) {
42
40
return AuthUtil .isAuthorizedEntityType (
43
- context .getActorUrn (),
44
- context .getAuthorizer (),
41
+ context .getOperationContext (),
45
42
MANAGE ,
46
43
List .of (CORP_USER_ENTITY_NAME , CORP_GROUP_ENTITY_NAME ));
47
44
}
48
45
49
46
public static boolean canManagePolicies (@ Nonnull QueryContext context ) {
50
47
return AuthUtil .isAuthorizedEntityType (
51
- context .getActorUrn (), context . getAuthorizer (), MANAGE , List .of (POLICY_ENTITY_NAME ));
48
+ context .getOperationContext (), MANAGE , List .of (POLICY_ENTITY_NAME ));
52
49
}
53
50
54
51
public static boolean canGeneratePersonalAccessToken (@ Nonnull QueryContext context ) {
55
52
return AuthUtil .isAuthorized (
56
- context .getAuthorizer (),
57
- context .getActorUrn (),
58
- PoliciesConfig .GENERATE_PERSONAL_ACCESS_TOKENS_PRIVILEGE )
59
- || AuthUtil .isAuthorized (
60
- context .getAuthorizer (), context .getActorUrn (), MANAGE_ACCESS_TOKENS );
53
+ context .getOperationContext (), PoliciesConfig .GENERATE_PERSONAL_ACCESS_TOKENS_PRIVILEGE )
54
+ || AuthUtil .isAuthorized (context .getOperationContext (), MANAGE_ACCESS_TOKENS );
61
55
}
62
56
63
57
public static boolean canManageTokens (@ Nonnull QueryContext context ) {
64
58
return AuthUtil .isAuthorizedEntityType (
65
- context .getActorUrn (), context . getAuthorizer (), MANAGE , List .of (ACCESS_TOKEN_ENTITY_NAME ));
59
+ context .getOperationContext (), MANAGE , List .of (ACCESS_TOKEN_ENTITY_NAME ));
66
60
}
67
61
68
62
/**
@@ -78,13 +72,12 @@ public static boolean canCreateDomains(@Nonnull QueryContext context) {
78
72
new ConjunctivePrivilegeGroup (
79
73
ImmutableList .of (PoliciesConfig .MANAGE_DOMAINS_PRIVILEGE .getType ()))));
80
74
81
- return AuthUtil .isAuthorized (
82
- context .getAuthorizer (), context .getActorUrn (), orPrivilegeGroups , null );
75
+ return AuthUtil .isAuthorized (context .getOperationContext (), orPrivilegeGroups , null );
83
76
}
84
77
85
78
public static boolean canManageDomains (@ Nonnull QueryContext context ) {
86
79
return AuthUtil .isAuthorized (
87
- context .getAuthorizer (), context . getActorUrn (), PoliciesConfig .MANAGE_DOMAINS_PRIVILEGE );
80
+ context .getOperationContext (), PoliciesConfig .MANAGE_DOMAINS_PRIVILEGE );
88
81
}
89
82
90
83
/**
@@ -100,25 +93,22 @@ public static boolean canCreateTags(@Nonnull QueryContext context) {
100
93
new ConjunctivePrivilegeGroup (
101
94
ImmutableList .of (PoliciesConfig .MANAGE_TAGS_PRIVILEGE .getType ()))));
102
95
103
- return AuthUtil .isAuthorized (
104
- context .getAuthorizer (), context .getActorUrn (), orPrivilegeGroups , null );
96
+ return AuthUtil .isAuthorized (context .getOperationContext (), orPrivilegeGroups , null );
105
97
}
106
98
107
99
public static boolean canManageTags (@ Nonnull QueryContext context ) {
108
100
return AuthUtil .isAuthorized (
109
- context .getAuthorizer (), context . getActorUrn (), PoliciesConfig .MANAGE_TAGS_PRIVILEGE );
101
+ context .getOperationContext (), PoliciesConfig .MANAGE_TAGS_PRIVILEGE );
110
102
}
111
103
112
104
public static boolean canDeleteEntity (@ Nonnull Urn entityUrn , @ Nonnull QueryContext context ) {
113
105
return AuthUtil .isAuthorizedEntityUrns (
114
- context .getAuthorizer (), context . getActorUrn (), DELETE , List .of (entityUrn ));
106
+ context .getOperationContext (), DELETE , List .of (entityUrn ));
115
107
}
116
108
117
109
public static boolean canManageUserCredentials (@ Nonnull QueryContext context ) {
118
110
return AuthUtil .isAuthorized (
119
- context .getAuthorizer (),
120
- context .getActorUrn (),
121
- PoliciesConfig .MANAGE_USER_CREDENTIALS_PRIVILEGE );
111
+ context .getOperationContext (), PoliciesConfig .MANAGE_USER_CREDENTIALS_PRIVILEGE );
122
112
}
123
113
124
114
public static boolean canEditGroupMembers (
@@ -130,12 +120,7 @@ public static boolean canEditGroupMembers(
130
120
new ConjunctivePrivilegeGroup (
131
121
ImmutableList .of (PoliciesConfig .EDIT_GROUP_MEMBERS_PRIVILEGE .getType ()))));
132
122
133
- return isAuthorized (
134
- context .getAuthorizer (),
135
- context .getActorUrn (),
136
- CORP_GROUP_ENTITY_NAME ,
137
- groupUrnStr ,
138
- orPrivilegeGroups );
123
+ return isAuthorized (context , CORP_GROUP_ENTITY_NAME , groupUrnStr , orPrivilegeGroups );
139
124
}
140
125
141
126
public static boolean canCreateGlobalAnnouncements (@ Nonnull QueryContext context ) {
@@ -149,27 +134,21 @@ public static boolean canCreateGlobalAnnouncements(@Nonnull QueryContext context
149
134
ImmutableList .of (
150
135
PoliciesConfig .MANAGE_GLOBAL_ANNOUNCEMENTS_PRIVILEGE .getType ()))));
151
136
152
- return AuthUtil .isAuthorized (
153
- context .getAuthorizer (), context .getActorUrn (), orPrivilegeGroups , null );
137
+ return AuthUtil .isAuthorized (context .getOperationContext (), orPrivilegeGroups , null );
154
138
}
155
139
156
140
public static boolean canManageGlobalAnnouncements (@ Nonnull QueryContext context ) {
157
141
return AuthUtil .isAuthorized (
158
- context .getAuthorizer (),
159
- context .getActorUrn (),
160
- PoliciesConfig .MANAGE_GLOBAL_ANNOUNCEMENTS_PRIVILEGE );
142
+ context .getOperationContext (), PoliciesConfig .MANAGE_GLOBAL_ANNOUNCEMENTS_PRIVILEGE );
161
143
}
162
144
163
145
public static boolean canManageGlobalViews (@ Nonnull QueryContext context ) {
164
- return AuthUtil .isAuthorized (
165
- context .getAuthorizer (), context .getActorUrn (), PoliciesConfig .MANAGE_GLOBAL_VIEWS );
146
+ return AuthUtil .isAuthorized (context .getOperationContext (), PoliciesConfig .MANAGE_GLOBAL_VIEWS );
166
147
}
167
148
168
149
public static boolean canManageOwnershipTypes (@ Nonnull QueryContext context ) {
169
150
return AuthUtil .isAuthorized (
170
- context .getAuthorizer (),
171
- context .getActorUrn (),
172
- PoliciesConfig .MANAGE_GLOBAL_OWNERSHIP_TYPES );
151
+ context .getOperationContext (), PoliciesConfig .MANAGE_GLOBAL_OWNERSHIP_TYPES );
173
152
}
174
153
175
154
public static boolean canEditProperties (@ Nonnull Urn targetUrn , @ Nonnull QueryContext context ) {
@@ -183,11 +162,7 @@ public static boolean canEditProperties(@Nonnull Urn targetUrn, @Nonnull QueryCo
183
162
ImmutableList .of (PoliciesConfig .EDIT_ENTITY_PROPERTIES_PRIVILEGE .getType ()))));
184
163
185
164
return AuthorizationUtils .isAuthorized (
186
- context .getAuthorizer (),
187
- context .getActorUrn (),
188
- targetUrn .getEntityType (),
189
- targetUrn .toString (),
190
- orPrivilegeGroups );
165
+ context , targetUrn .getEntityType (), targetUrn .toString (), orPrivilegeGroups );
191
166
}
192
167
193
168
public static boolean canEditEntityQueries (
@@ -202,11 +177,7 @@ public static boolean canEditEntityQueries(
202
177
.allMatch (
203
178
entityUrn ->
204
179
isAuthorized (
205
- context .getAuthorizer (),
206
- context .getActorUrn (),
207
- entityUrn .getEntityType (),
208
- entityUrn .toString (),
209
- orPrivilegeGroups ));
180
+ context , entityUrn .getEntityType (), entityUrn .toString (), orPrivilegeGroups ));
210
181
}
211
182
212
183
public static boolean canCreateQuery (
@@ -251,28 +222,7 @@ public static boolean canView(@Nonnull OperationContext opContext, @Nonnull Urn
251
222
&& !opContext .isSystemAuth ()
252
223
&& VIEW_RESTRICTED_ENTITY_TYPES .contains (urn .getEntityType ())) {
253
224
254
- return opContext
255
- .getViewAuthorizationContext ()
256
- .map (
257
- viewAuthContext -> {
258
-
259
- // check cache
260
- if (viewAuthContext .canView (Set .of (urn ))) {
261
- return true ;
262
- }
263
-
264
- if (!canViewEntity (
265
- opContext .getSessionAuthentication ().getActor ().toUrnStr (),
266
- opContext .getAuthorizerContext ().getAuthorizer (),
267
- urn )) {
268
- return false ;
269
- }
270
-
271
- // cache viewable urn
272
- viewAuthContext .addViewableUrns (Set .of (urn ));
273
- return true ;
274
- })
275
- .orElse (false );
225
+ return canViewEntity (opContext , urn );
276
226
}
277
227
return true ;
278
228
}
@@ -386,38 +336,32 @@ public static <T> T restrictEntity(@Nonnull Object entity, Class<T> clazz) {
386
336
387
337
public static boolean canManageStructuredProperties (@ Nonnull QueryContext context ) {
388
338
return AuthUtil .isAuthorized (
389
- context .getAuthorizer (),
390
- context .getActorUrn (),
391
- PoliciesConfig .MANAGE_STRUCTURED_PROPERTIES_PRIVILEGE );
339
+ context .getOperationContext (), PoliciesConfig .MANAGE_STRUCTURED_PROPERTIES_PRIVILEGE );
392
340
}
393
341
394
342
public static boolean canManageForms (@ Nonnull QueryContext context ) {
395
343
return AuthUtil .isAuthorized (
396
- context .getAuthorizer (),
397
- context .getActorUrn (),
398
- PoliciesConfig .MANAGE_DOCUMENTATION_FORMS_PRIVILEGE );
344
+ context .getOperationContext (), PoliciesConfig .MANAGE_DOCUMENTATION_FORMS_PRIVILEGE );
399
345
}
400
346
401
347
public static boolean canManageFeatures (@ Nonnull QueryContext context ) {
402
348
return AuthUtil .isAuthorized (
403
- context .getAuthorizer (), context . getActorUrn (), PoliciesConfig .MANAGE_FEATURES_PRIVILEGE );
349
+ context .getOperationContext (), PoliciesConfig .MANAGE_FEATURES_PRIVILEGE );
404
350
}
405
351
406
352
public static boolean isAuthorized (
407
- @ Nonnull Authorizer authorizer ,
408
- @ Nonnull String actor ,
353
+ @ Nonnull QueryContext context ,
409
354
@ Nonnull String resourceType ,
410
355
@ Nonnull String resource ,
411
356
@ Nonnull DisjunctivePrivilegeGroup privilegeGroup ) {
412
357
final EntitySpec resourceSpec = new EntitySpec (resourceType , resource );
413
- return AuthUtil .isAuthorized (authorizer , actor , privilegeGroup , resourceSpec );
358
+ return AuthUtil .isAuthorized (context . getOperationContext () , privilegeGroup , resourceSpec );
414
359
}
415
360
416
361
public static boolean isViewDatasetUsageAuthorized (
417
362
final QueryContext context , final Urn resourceUrn ) {
418
363
return AuthUtil .isAuthorized (
419
- context .getAuthorizer (),
420
- context .getActorUrn (),
364
+ context .getOperationContext (),
421
365
PoliciesConfig .VIEW_DATASET_USAGE_PRIVILEGE ,
422
366
new EntitySpec (resourceUrn .getEntityType (), resourceUrn .toString ()));
423
367
}
0 commit comments