71
71
import org .apache .polaris .core .entity .PrincipalRoleEntity ;
72
72
import org .apache .polaris .core .persistence .MetaStoreManagerFactory ;
73
73
import org .apache .polaris .core .persistence .PolarisMetaStoreManager ;
74
+ import org .apache .polaris .core .persistence .dao .entity .BaseResult ;
75
+ import org .apache .polaris .core .persistence .dao .entity .PrivilegeResult ;
74
76
import org .apache .polaris .core .persistence .resolver .ResolutionManifestFactory ;
75
77
import org .apache .polaris .core .secrets .UserSecretsManager ;
76
78
import org .apache .polaris .core .secrets .UserSecretsManagerFactory ;
@@ -134,6 +136,13 @@ private PolarisAdminService newAdminService(
134
136
reservedProperties );
135
137
}
136
138
139
+ private static Response toResponse (BaseResult result , Response .Status successStatus ) {
140
+ if (!result .isSuccess ()) {
141
+ return Response .status (Response .Status .INTERNAL_SERVER_ERROR ).build ();
142
+ }
143
+ return Response .status (successStatus ).build ();
144
+ }
145
+
137
146
/** From PolarisCatalogsApiService */
138
147
@ Override
139
148
public Response createCatalog (
@@ -457,8 +466,9 @@ public Response assignPrincipalRole(
457
466
request .getPrincipalRole ().getName (),
458
467
principalName );
459
468
PolarisAdminService adminService = newAdminService (realmContext , securityContext );
460
- adminService .assignPrincipalRole (principalName , request .getPrincipalRole ().getName ());
461
- return Response .status (Response .Status .CREATED ).build ();
469
+ PrivilegeResult result =
470
+ adminService .assignPrincipalRole (principalName , request .getPrincipalRole ().getName ());
471
+ return toResponse (result , Response .Status .CREATED );
462
472
}
463
473
464
474
/** From PolarisPrincipalsApiService */
@@ -470,8 +480,8 @@ public Response revokePrincipalRole(
470
480
SecurityContext securityContext ) {
471
481
LOGGER .info ("Revoking principalRole {} from principal {}" , principalRoleName , principalName );
472
482
PolarisAdminService adminService = newAdminService (realmContext , securityContext );
473
- adminService .revokePrincipalRole (principalName , principalRoleName );
474
- return Response . status ( Response .Status .NO_CONTENT ). build ( );
483
+ PrivilegeResult result = adminService .revokePrincipalRole (principalName , principalRoleName );
484
+ return toResponse ( result , Response .Status .NO_CONTENT );
475
485
}
476
486
477
487
/** From PolarisPrincipalsApiService */
@@ -503,9 +513,10 @@ public Response assignCatalogRoleToPrincipalRole(
503
513
catalogName ,
504
514
principalRoleName );
505
515
PolarisAdminService adminService = newAdminService (realmContext , securityContext );
506
- adminService .assignCatalogRoleToPrincipalRole (
507
- principalRoleName , catalogName , request .getCatalogRole ().getName ());
508
- return Response .status (Response .Status .CREATED ).build ();
516
+ PrivilegeResult result =
517
+ adminService .assignCatalogRoleToPrincipalRole (
518
+ principalRoleName , catalogName , request .getCatalogRole ().getName ());
519
+ return toResponse (result , Response .Status .CREATED );
509
520
}
510
521
511
522
/** From PolarisPrincipalRolesApiService */
@@ -522,9 +533,10 @@ public Response revokeCatalogRoleFromPrincipalRole(
522
533
catalogName ,
523
534
principalRoleName );
524
535
PolarisAdminService adminService = newAdminService (realmContext , securityContext );
525
- adminService .revokeCatalogRoleFromPrincipalRole (
526
- principalRoleName , catalogName , catalogRoleName );
527
- return Response .status (Response .Status .NO_CONTENT ).build ();
536
+ PrivilegeResult result =
537
+ adminService .revokeCatalogRoleFromPrincipalRole (
538
+ principalRoleName , catalogName , catalogRoleName );
539
+ return toResponse (result , Response .Status .NO_CONTENT );
528
540
}
529
541
530
542
/** From PolarisPrincipalRolesApiService */
@@ -574,6 +586,7 @@ public Response addGrantToCatalogRole(
574
586
catalogRoleName ,
575
587
catalogName );
576
588
PolarisAdminService adminService = newAdminService (realmContext , securityContext );
589
+ PrivilegeResult result ;
577
590
switch (grantRequest .getGrant ()) {
578
591
// The per-securable-type Privilege enums must be exact String match for a subset of all
579
592
// PolarisPrivilege values.
@@ -583,11 +596,12 @@ public Response addGrantToCatalogRole(
583
596
PolarisPrivilege .valueOf (viewGrant .getPrivilege ().toString ());
584
597
String viewName = viewGrant .getViewName ();
585
598
String [] namespaceParts = viewGrant .getNamespace ().toArray (new String [0 ]);
586
- adminService .grantPrivilegeOnViewToRole (
587
- catalogName ,
588
- catalogRoleName ,
589
- TableIdentifier .of (Namespace .of (namespaceParts ), viewName ),
590
- privilege );
599
+ result =
600
+ adminService .grantPrivilegeOnViewToRole (
601
+ catalogName ,
602
+ catalogRoleName ,
603
+ TableIdentifier .of (Namespace .of (namespaceParts ), viewName ),
604
+ privilege );
591
605
break ;
592
606
}
593
607
case TableGrant tableGrant :
@@ -596,27 +610,30 @@ public Response addGrantToCatalogRole(
596
610
PolarisPrivilege .valueOf (tableGrant .getPrivilege ().toString ());
597
611
String tableName = tableGrant .getTableName ();
598
612
String [] namespaceParts = tableGrant .getNamespace ().toArray (new String [0 ]);
599
- adminService .grantPrivilegeOnTableToRole (
600
- catalogName ,
601
- catalogRoleName ,
602
- TableIdentifier .of (Namespace .of (namespaceParts ), tableName ),
603
- privilege );
613
+ result =
614
+ adminService .grantPrivilegeOnTableToRole (
615
+ catalogName ,
616
+ catalogRoleName ,
617
+ TableIdentifier .of (Namespace .of (namespaceParts ), tableName ),
618
+ privilege );
604
619
break ;
605
620
}
606
621
case NamespaceGrant namespaceGrant :
607
622
{
608
623
PolarisPrivilege privilege =
609
624
PolarisPrivilege .valueOf (namespaceGrant .getPrivilege ().toString ());
610
625
String [] namespaceParts = namespaceGrant .getNamespace ().toArray (new String [0 ]);
611
- adminService .grantPrivilegeOnNamespaceToRole (
612
- catalogName , catalogRoleName , Namespace .of (namespaceParts ), privilege );
626
+ result =
627
+ adminService .grantPrivilegeOnNamespaceToRole (
628
+ catalogName , catalogRoleName , Namespace .of (namespaceParts ), privilege );
613
629
break ;
614
630
}
615
631
case CatalogGrant catalogGrant :
616
632
{
617
633
PolarisPrivilege privilege =
618
634
PolarisPrivilege .valueOf (catalogGrant .getPrivilege ().toString ());
619
- adminService .grantPrivilegeOnCatalogToRole (catalogName , catalogRoleName , privilege );
635
+ result =
636
+ adminService .grantPrivilegeOnCatalogToRole (catalogName , catalogRoleName , privilege );
620
637
break ;
621
638
}
622
639
case PolicyGrant policyGrant :
@@ -625,11 +642,12 @@ public Response addGrantToCatalogRole(
625
642
PolarisPrivilege .valueOf (policyGrant .getPrivilege ().toString ());
626
643
String policyName = policyGrant .getPolicyName ();
627
644
String [] namespaceParts = policyGrant .getNamespace ().toArray (new String [0 ]);
628
- adminService .grantPrivilegeOnPolicyToRole (
629
- catalogName ,
630
- catalogRoleName ,
631
- new PolicyIdentifier (Namespace .of (namespaceParts ), policyName ),
632
- privilege );
645
+ result =
646
+ adminService .grantPrivilegeOnPolicyToRole (
647
+ catalogName ,
648
+ catalogRoleName ,
649
+ new PolicyIdentifier (Namespace .of (namespaceParts ), policyName ),
650
+ privilege );
633
651
break ;
634
652
}
635
653
default :
@@ -640,7 +658,7 @@ public Response addGrantToCatalogRole(
640
658
.log ("Don't know how to handle privilege grant: {}" , grantRequest );
641
659
return Response .status (Response .Status .BAD_REQUEST ).build ();
642
660
}
643
- return Response . status ( Response .Status .CREATED ). build ( );
661
+ return toResponse ( result , Response .Status .CREATED );
644
662
}
645
663
646
664
/** From PolarisCatalogsApiService */
@@ -663,6 +681,7 @@ public Response revokeGrantFromCatalogRole(
663
681
}
664
682
665
683
PolarisAdminService adminService = newAdminService (realmContext , securityContext );
684
+ PrivilegeResult result ;
666
685
switch (grantRequest .getGrant ()) {
667
686
// The per-securable-type Privilege enums must be exact String match for a subset of all
668
687
// PolarisPrivilege values.
@@ -672,11 +691,12 @@ public Response revokeGrantFromCatalogRole(
672
691
PolarisPrivilege .valueOf (viewGrant .getPrivilege ().toString ());
673
692
String viewName = viewGrant .getViewName ();
674
693
String [] namespaceParts = viewGrant .getNamespace ().toArray (new String [0 ]);
675
- adminService .revokePrivilegeOnViewFromRole (
676
- catalogName ,
677
- catalogRoleName ,
678
- TableIdentifier .of (Namespace .of (namespaceParts ), viewName ),
679
- privilege );
694
+ result =
695
+ adminService .revokePrivilegeOnViewFromRole (
696
+ catalogName ,
697
+ catalogRoleName ,
698
+ TableIdentifier .of (Namespace .of (namespaceParts ), viewName ),
699
+ privilege );
680
700
break ;
681
701
}
682
702
case TableGrant tableGrant :
@@ -685,27 +705,31 @@ public Response revokeGrantFromCatalogRole(
685
705
PolarisPrivilege .valueOf (tableGrant .getPrivilege ().toString ());
686
706
String tableName = tableGrant .getTableName ();
687
707
String [] namespaceParts = tableGrant .getNamespace ().toArray (new String [0 ]);
688
- adminService .revokePrivilegeOnTableFromRole (
689
- catalogName ,
690
- catalogRoleName ,
691
- TableIdentifier .of (Namespace .of (namespaceParts ), tableName ),
692
- privilege );
708
+ result =
709
+ adminService .revokePrivilegeOnTableFromRole (
710
+ catalogName ,
711
+ catalogRoleName ,
712
+ TableIdentifier .of (Namespace .of (namespaceParts ), tableName ),
713
+ privilege );
693
714
break ;
694
715
}
695
716
case NamespaceGrant namespaceGrant :
696
717
{
697
718
PolarisPrivilege privilege =
698
719
PolarisPrivilege .valueOf (namespaceGrant .getPrivilege ().toString ());
699
720
String [] namespaceParts = namespaceGrant .getNamespace ().toArray (new String [0 ]);
700
- adminService .revokePrivilegeOnNamespaceFromRole (
701
- catalogName , catalogRoleName , Namespace .of (namespaceParts ), privilege );
721
+ result =
722
+ adminService .revokePrivilegeOnNamespaceFromRole (
723
+ catalogName , catalogRoleName , Namespace .of (namespaceParts ), privilege );
702
724
break ;
703
725
}
704
726
case CatalogGrant catalogGrant :
705
727
{
706
728
PolarisPrivilege privilege =
707
729
PolarisPrivilege .valueOf (catalogGrant .getPrivilege ().toString ());
708
- adminService .revokePrivilegeOnCatalogFromRole (catalogName , catalogRoleName , privilege );
730
+ result =
731
+ adminService .revokePrivilegeOnCatalogFromRole (
732
+ catalogName , catalogRoleName , privilege );
709
733
break ;
710
734
}
711
735
case PolicyGrant policyGrant :
@@ -714,11 +738,12 @@ public Response revokeGrantFromCatalogRole(
714
738
PolarisPrivilege .valueOf (policyGrant .getPrivilege ().toString ());
715
739
String policyName = policyGrant .getPolicyName ();
716
740
String [] namespaceParts = policyGrant .getNamespace ().toArray (new String [0 ]);
717
- adminService .revokePrivilegeOnPolicyFromRole (
718
- catalogName ,
719
- catalogRoleName ,
720
- new PolicyIdentifier (Namespace .of (namespaceParts ), policyName ),
721
- privilege );
741
+ result =
742
+ adminService .revokePrivilegeOnPolicyFromRole (
743
+ catalogName ,
744
+ catalogRoleName ,
745
+ new PolicyIdentifier (Namespace .of (namespaceParts ), policyName ),
746
+ privilege );
722
747
break ;
723
748
}
724
749
default :
@@ -729,7 +754,7 @@ public Response revokeGrantFromCatalogRole(
729
754
.log ("Don't know how to handle privilege revocation: {}" , grantRequest );
730
755
return Response .status (Response .Status .BAD_REQUEST ).build ();
731
756
}
732
- return Response . status ( Response .Status .CREATED ). build ( );
757
+ return toResponse ( result , Response .Status .CREATED );
733
758
}
734
759
735
760
/** From PolarisCatalogsApiService */
0 commit comments