2626import jakarta .ws .rs .core .Response ;
2727import jakarta .ws .rs .core .SecurityContext ;
2828import org .apache .polaris .core .context .RealmContext ;
29+ import org .apache .polaris .service .catalog .CatalogPrefixParser ;
2930import org .apache .polaris .service .catalog .api .PolarisCatalogPolicyApiService ;
3031import org .apache .polaris .service .catalog .common .CatalogAdapter ;
3132import org .apache .polaris .service .events .CatalogPolicyServiceEvents ;
@@ -44,6 +45,7 @@ public class CatalogPolicyEventServiceDelegator
4445
4546 @ Inject @ Delegate PolicyCatalogAdapter delegate ;
4647 @ Inject PolarisEventListener polarisEventListener ;
48+ @ Inject CatalogPrefixParser prefixParser ;
4749
4850 @ Override
4951 public Response createPolicy (
@@ -52,15 +54,16 @@ public Response createPolicy(
5254 CreatePolicyRequest createPolicyRequest ,
5355 RealmContext realmContext ,
5456 SecurityContext securityContext ) {
57+ String catalogName = getCatalogFromPrefix (prefix , realmContext );
5558 polarisEventListener .onBeforeCreatePolicy (
5659 new CatalogPolicyServiceEvents .BeforeCreatePolicyEvent (
57- prefix , namespace , createPolicyRequest ));
60+ catalogName , namespace , createPolicyRequest ));
5861 Response resp =
5962 delegate .createPolicy (
6063 prefix , namespace , createPolicyRequest , realmContext , securityContext );
6164 polarisEventListener .onAfterCreatePolicy (
6265 new CatalogPolicyServiceEvents .AfterCreatePolicyEvent (
63- prefix , namespace , resp . readEntity (LoadPolicyResponse . class )));
66+ catalogName , namespace , (LoadPolicyResponse ) resp . getEntity ( )));
6467 return resp ;
6568 }
6669
@@ -73,13 +76,14 @@ public Response listPolicies(
7376 String policyType ,
7477 RealmContext realmContext ,
7578 SecurityContext securityContext ) {
79+ String catalogName = getCatalogFromPrefix (prefix , realmContext );
7680 polarisEventListener .onBeforeListPolicies (
77- new CatalogPolicyServiceEvents .BeforeListPoliciesEvent (prefix , namespace , policyType ));
81+ new CatalogPolicyServiceEvents .BeforeListPoliciesEvent (catalogName , namespace , policyType ));
7882 Response resp =
7983 delegate .listPolicies (
8084 prefix , namespace , pageToken , pageSize , policyType , realmContext , securityContext );
8185 polarisEventListener .onAfterListPolicies (
82- new CatalogPolicyServiceEvents .AfterListPoliciesEvent (prefix , namespace , policyType ));
86+ new CatalogPolicyServiceEvents .AfterListPoliciesEvent (catalogName , namespace , policyType ));
8387 return resp ;
8488 }
8589
@@ -90,13 +94,14 @@ public Response loadPolicy(
9094 String policyName ,
9195 RealmContext realmContext ,
9296 SecurityContext securityContext ) {
97+ String catalogName = getCatalogFromPrefix (prefix , realmContext );
9398 polarisEventListener .onBeforeLoadPolicy (
94- new CatalogPolicyServiceEvents .BeforeLoadPolicyEvent (prefix , namespace , policyName ));
99+ new CatalogPolicyServiceEvents .BeforeLoadPolicyEvent (catalogName , namespace , policyName ));
95100 Response resp =
96101 delegate .loadPolicy (prefix , namespace , policyName , realmContext , securityContext );
97102 polarisEventListener .onAfterLoadPolicy (
98103 new CatalogPolicyServiceEvents .AfterLoadPolicyEvent (
99- prefix , namespace , resp . readEntity (LoadPolicyResponse . class )));
104+ catalogName , namespace , (LoadPolicyResponse ) resp . getEntity ( )));
100105 return resp ;
101106 }
102107
@@ -108,15 +113,16 @@ public Response updatePolicy(
108113 UpdatePolicyRequest updatePolicyRequest ,
109114 RealmContext realmContext ,
110115 SecurityContext securityContext ) {
116+ String catalogName = getCatalogFromPrefix (prefix , realmContext );
111117 polarisEventListener .onBeforeUpdatePolicy (
112118 new CatalogPolicyServiceEvents .BeforeUpdatePolicyEvent (
113- prefix , namespace , policyName , updatePolicyRequest ));
119+ catalogName , namespace , policyName , updatePolicyRequest ));
114120 Response resp =
115121 delegate .updatePolicy (
116122 prefix , namespace , policyName , updatePolicyRequest , realmContext , securityContext );
117123 polarisEventListener .onAfterUpdatePolicy (
118124 new CatalogPolicyServiceEvents .AfterUpdatePolicyEvent (
119- prefix , namespace , resp . readEntity (LoadPolicyResponse . class )));
125+ catalogName , namespace , (LoadPolicyResponse ) resp . getEntity ( )));
120126 return resp ;
121127 }
122128
@@ -128,15 +134,16 @@ public Response dropPolicy(
128134 Boolean detachAll ,
129135 RealmContext realmContext ,
130136 SecurityContext securityContext ) {
137+ String catalogName = getCatalogFromPrefix (prefix , realmContext );
131138 polarisEventListener .onBeforeDropPolicy (
132139 new CatalogPolicyServiceEvents .BeforeDropPolicyEvent (
133- prefix , namespace , policyName , detachAll ));
140+ catalogName , namespace , policyName , detachAll ));
134141 Response resp =
135142 delegate .dropPolicy (
136143 prefix , namespace , policyName , detachAll , realmContext , securityContext );
137144 polarisEventListener .onAfterDropPolicy (
138145 new CatalogPolicyServiceEvents .AfterDropPolicyEvent (
139- prefix , namespace , policyName , detachAll ));
146+ catalogName , namespace , policyName , detachAll ));
140147 return resp ;
141148 }
142149
@@ -148,15 +155,16 @@ public Response attachPolicy(
148155 AttachPolicyRequest attachPolicyRequest ,
149156 RealmContext realmContext ,
150157 SecurityContext securityContext ) {
158+ String catalogName = getCatalogFromPrefix (prefix , realmContext );
151159 polarisEventListener .onBeforeAttachPolicy (
152160 new CatalogPolicyServiceEvents .BeforeAttachPolicyEvent (
153- prefix , namespace , policyName , attachPolicyRequest ));
161+ catalogName , namespace , policyName , attachPolicyRequest ));
154162 Response resp =
155163 delegate .attachPolicy (
156164 prefix , namespace , policyName , attachPolicyRequest , realmContext , securityContext );
157165 polarisEventListener .onAfterAttachPolicy (
158166 new CatalogPolicyServiceEvents .AfterAttachPolicyEvent (
159- prefix , namespace , policyName , attachPolicyRequest ));
167+ catalogName , namespace , policyName , attachPolicyRequest ));
160168 return resp ;
161169 }
162170
@@ -168,15 +176,16 @@ public Response detachPolicy(
168176 DetachPolicyRequest detachPolicyRequest ,
169177 RealmContext realmContext ,
170178 SecurityContext securityContext ) {
179+ String catalogName = getCatalogFromPrefix (prefix , realmContext );
171180 polarisEventListener .onBeforeDetachPolicy (
172181 new CatalogPolicyServiceEvents .BeforeDetachPolicyEvent (
173- prefix , namespace , policyName , detachPolicyRequest ));
182+ catalogName , namespace , policyName , detachPolicyRequest ));
174183 Response resp =
175184 delegate .detachPolicy (
176185 prefix , namespace , policyName , detachPolicyRequest , realmContext , securityContext );
177186 polarisEventListener .onAfterDetachPolicy (
178187 new CatalogPolicyServiceEvents .AfterDetachPolicyEvent (
179- prefix , namespace , policyName , detachPolicyRequest ));
188+ catalogName , namespace , policyName , detachPolicyRequest ));
180189 return resp ;
181190 }
182191
@@ -190,9 +199,10 @@ public Response getApplicablePolicies(
190199 String policyType ,
191200 RealmContext realmContext ,
192201 SecurityContext securityContext ) {
202+ String catalogName = getCatalogFromPrefix (prefix , realmContext );
193203 polarisEventListener .onBeforeGetApplicablePolicies (
194204 new CatalogPolicyServiceEvents .BeforeGetApplicablePoliciesEvent (
195- prefix , namespace , targetName , policyType ));
205+ catalogName , namespace , targetName , policyType ));
196206 Response resp =
197207 delegate .getApplicablePolicies (
198208 prefix ,
@@ -205,11 +215,15 @@ public Response getApplicablePolicies(
205215 securityContext );
206216 polarisEventListener .onAfterGetApplicablePolicies (
207217 new CatalogPolicyServiceEvents .AfterGetApplicablePoliciesEvent (
208- prefix ,
218+ catalogName ,
209219 namespace ,
210220 targetName ,
211221 policyType ,
212- resp . readEntity (GetApplicablePoliciesResponse . class )));
222+ (GetApplicablePoliciesResponse ) resp . getEntity ( )));
213223 return resp ;
214224 }
225+
226+ private String getCatalogFromPrefix (String prefix , RealmContext realmContext ) {
227+ return prefixParser .prefixToCatalogName (realmContext , prefix );
228+ }
215229}
0 commit comments