Skip to content

Commit 5989414

Browse files
committed
feat(admin): route policies for whole admin gui
* Route authorization is now implemented in the whole admin gui. * In side-menu and all overviews is now using canNavigate() function instead of isAuthorized() + 'policy', so all policies are now located in route-policy.service.ts. * Fixed side-menu for resource under facility (resource and facility were displayed under VO in side-menu).
1 parent a05c29e commit 5989414

File tree

18 files changed

+644
-349
lines changed

18 files changed

+644
-349
lines changed

apps/admin-gui/src/app/admin/admin-routing.module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ import { UserAccountsComponent } from '../users/pages/user-detail-page/user-acco
3232
import { AdminAuditLogComponent } from './pages/admin-page/admin-audit-log/admin-audit-log.component';
3333
import { AdminConsentHubsComponent } from './pages/admin-page/admin-consent-hubs/admin-consent-hubs.component';
3434
import { AdminSearcherComponent } from './pages/admin-page/admin-searcher/admin-searcher.component';
35+
import { RouteAuthGuardService } from '../shared/route-auth-guard.service';
3536

3637
const routes: Routes = [
3738
{
3839
path: '',
3940
component: AdminPageComponent,
41+
canActivateChild: [RouteAuthGuardService],
4042
children: [
4143
{
4244
path: '',
@@ -114,6 +116,7 @@ const routes: Routes = [
114116
{
115117
path: 'users/:userId',
116118
component: AdminUserDetailPageComponent,
119+
canActivateChild: [RouteAuthGuardService],
117120
children: [
118121
{
119122
path: '',
@@ -191,6 +194,7 @@ const routes: Routes = [
191194
{
192195
path: 'services/:serviceId',
193196
component: ServiceDetailPageComponent,
197+
canActivateChild: [RouteAuthGuardService],
194198
children: [
195199
{
196200
path: '',

apps/admin-gui/src/app/facilities/facilities-routing.module.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,25 @@ import { FacilityTaskResultsComponent } from './pages/facility-detail-page/facil
3131
import { ResourceTagsComponent } from './pages/resource-detail-page/resource-tags/resource-tags.component';
3232
import { FacilityConfigurationPageComponent } from './pages/facility-configuration-page/facility-configuration-page.component';
3333
import { ConfigureFacilityGuardService } from './services/configure-facility-guard.service';
34+
import { RouteAuthGuardService } from '../shared/route-auth-guard.service';
3435

3536
const routes: Routes = [
3637
{
3738
path: '',
3839
component: FacilitySelectPageComponent,
40+
canActivateChild: [RouteAuthGuardService],
41+
children: [
42+
{
43+
path: '',
44+
component: FacilitySelectPageComponent,
45+
data: { animation: 'FacilitySelectPage' },
46+
},
47+
],
3948
},
4049
{
4150
path: ':facilityId',
4251
component: FacilityDetailPageComponent,
52+
canActivateChild: [RouteAuthGuardService],
4353
children: [
4454
{
4555
path: '',
@@ -138,6 +148,7 @@ const routes: Routes = [
138148
{
139149
path: ':facilityId/resources/:resourceId',
140150
component: ResourceDetailPageComponent,
151+
canActivateChild: [RouteAuthGuardService],
141152
children: [
142153
{
143154
path: '',

apps/admin-gui/src/app/facilities/pages/facility-detail-page/facility-overview/facility-overview.component.ts

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { Component, HostBinding, OnInit } from '@angular/core';
22
import { MenuItem } from '@perun-web-apps/perun/models';
33
import { FacilitiesManagerService, Facility } from '@perun-web-apps/perun/openapi';
4-
import { EntityStorageService, GuiAuthResolver } from '@perun-web-apps/perun/services';
4+
import {
5+
EntityStorageService,
6+
GuiAuthResolver,
7+
RoutePolicyService,
8+
} from '@perun-web-apps/perun/services';
59

610
@Component({
711
selector: 'app-facility-overview',
@@ -18,7 +22,8 @@ export class FacilityOverviewComponent implements OnInit {
1822
constructor(
1923
private facilityManager: FacilitiesManagerService,
2024
private authResolver: GuiAuthResolver,
21-
private entityStorageService: EntityStorageService
25+
private entityStorageService: EntityStorageService,
26+
private routePolicyService: RoutePolicyService
2227
) {}
2328

2429
ngOnInit(): void {
@@ -32,9 +37,7 @@ export class FacilityOverviewComponent implements OnInit {
3237
this.navItems = [];
3338

3439
// Resources
35-
if (
36-
this.authResolver.isAuthorized('getAssignedRichResources_Facility_policy', [this.facility])
37-
) {
40+
if (this.routePolicyService.canNavigate('facilities-resources', this.facility)) {
3841
this.navItems.push({
3942
cssIcon: 'perun-manage-facility',
4043
url: `/facilities/${this.facility.id}/resources`,
@@ -43,9 +46,7 @@ export class FacilityOverviewComponent implements OnInit {
4346
});
4447
}
4548
// Allowed users
46-
if (
47-
this.authResolver.isAuthorized('getAssignedUsers_Facility_Service_policy', [this.facility])
48-
) {
49+
if (this.routePolicyService.canNavigate('facilities-allowed-users', this.facility)) {
4950
this.navItems.push({
5051
cssIcon: 'perun-user',
5152
url: `/facilities/${this.facility.id}/allowed-users`,
@@ -54,9 +55,7 @@ export class FacilityOverviewComponent implements OnInit {
5455
});
5556
}
5657
// Allowed groups
57-
if (
58-
this.authResolver.isAuthorized('getAllowedGroups_Facility_Vo_Service_policy', [this.facility])
59-
) {
58+
if (this.routePolicyService.canNavigate('facilities-allowed-groups', this.facility)) {
6059
this.navItems.push({
6160
cssIcon: 'perun-group',
6261
url: `/facilities/${this.facility.id}/allowed-groups`,
@@ -65,9 +64,7 @@ export class FacilityOverviewComponent implements OnInit {
6564
});
6665
}
6766
// Service state
68-
if (
69-
this.authResolver.isAuthorized('getFacilityServicesState_Facility_policy', [this.facility])
70-
) {
67+
if (this.routePolicyService.canNavigate('facilities-services-status', this.facility)) {
7168
this.navItems.push({
7269
cssIcon: 'perun-service-status',
7370
url: `/facilities/${this.facility.id}/services-status`,
@@ -76,7 +73,7 @@ export class FacilityOverviewComponent implements OnInit {
7673
});
7774
}
7875
// Service destination
79-
if (this.authResolver.isAuthorized('getAllRichDestinations_Facility_policy', [this.facility])) {
76+
if (this.routePolicyService.canNavigate('facilities-services-destinations', this.facility)) {
8077
this.navItems.push({
8178
cssIcon: 'perun-service_destination',
8279
url: `/facilities/${this.facility.id}/services-destinations`,
@@ -85,8 +82,7 @@ export class FacilityOverviewComponent implements OnInit {
8582
});
8683
}
8784
// Hosts
88-
// TODO fix when policies are updated
89-
if (this.authResolver.isFacilityAdmin()) {
85+
if (this.routePolicyService.canNavigate('facilities-hosts', this.facility)) {
9086
this.navItems.push({
9187
cssIcon: 'perun-hosts',
9288
url: `/facilities/${this.facility.id}/hosts`,
@@ -95,20 +91,17 @@ export class FacilityOverviewComponent implements OnInit {
9591
});
9692
}
9793
// Attributes
98-
this.navItems.push({
99-
cssIcon: 'perun-attributes',
100-
url: `/facilities/${this.facility.id}/attributes`,
101-
label: 'MENU_ITEMS.FACILITY.ATTRIBUTES',
102-
style: 'facility-btn',
103-
});
94+
if (this.routePolicyService.canNavigate('facilities-attributes', this.facility)) {
95+
this.navItems.push({
96+
cssIcon: 'perun-attributes',
97+
url: `/facilities/${this.facility.id}/attributes`,
98+
label: 'MENU_ITEMS.FACILITY.ATTRIBUTES',
99+
style: 'facility-btn',
100+
});
101+
}
104102

105103
// Settings
106-
if (
107-
this.authResolver.isAuthorized('getBansForFacility_int_policy', [this.facility]) ||
108-
this.authResolver.isManagerPagePrivileged(this.facility) ||
109-
this.authResolver.isAuthorized('getOwners_Facility_policy', [this.facility]) ||
110-
this.authResolver.isAuthorized('getAssignedSecurityTeams_Facility_policy', [this.facility])
111-
) {
104+
if (this.routePolicyService.canNavigate('facilities-settings', this.facility)) {
112105
this.navItems.push({
113106
cssIcon: 'perun-settings2',
114107
url: `/facilities/${this.facility.id}/settings`,

apps/admin-gui/src/app/facilities/pages/facility-detail-page/facility-settings/facility-settings-overview/facility-settings-overview.component.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { Component, HostBinding, OnInit } from '@angular/core';
22
import { MenuItem } from '@perun-web-apps/perun/models';
33
import { FacilitiesManagerService, Facility } from '@perun-web-apps/perun/openapi';
4-
import { EntityStorageService, GuiAuthResolver } from '@perun-web-apps/perun/services';
4+
import {
5+
EntityStorageService,
6+
GuiAuthResolver,
7+
RoutePolicyService,
8+
} from '@perun-web-apps/perun/services';
59

610
@Component({
711
selector: 'app-facility-settings-overview',
@@ -18,7 +22,8 @@ export class FacilitySettingsOverviewComponent implements OnInit {
1822
constructor(
1923
private facilityManager: FacilitiesManagerService,
2024
private authResolver: GuiAuthResolver,
21-
private entityStorageService: EntityStorageService
25+
private entityStorageService: EntityStorageService,
26+
private routePolicyService: RoutePolicyService
2227
) {}
2328

2429
ngOnInit(): void {
@@ -32,7 +37,7 @@ export class FacilitySettingsOverviewComponent implements OnInit {
3237
this.items = [];
3338

3439
// Owners
35-
if (this.authResolver.isAuthorized('getOwners_Facility_policy', [this.facility])) {
40+
if (this.routePolicyService.canNavigate('facilities-settings-owners', this.facility)) {
3641
this.items.push({
3742
cssIcon: 'perun-owner-grey',
3843
url: `/facilities/${this.facility.id}/settings/owners`,
@@ -41,7 +46,7 @@ export class FacilitySettingsOverviewComponent implements OnInit {
4146
});
4247
}
4348
// Managers
44-
if (this.authResolver.isManagerPagePrivileged(this.facility)) {
49+
if (this.routePolicyService.canNavigate('facilities-settings-managers', this.facility)) {
4550
this.items.push({
4651
cssIcon: 'perun-manager',
4752
url: `/facilities/${this.facility.id}/settings/managers`,
@@ -50,9 +55,7 @@ export class FacilitySettingsOverviewComponent implements OnInit {
5055
});
5156
}
5257
// Security teams
53-
if (
54-
this.authResolver.isAuthorized('getAssignedSecurityTeams_Facility_policy', [this.facility])
55-
) {
58+
if (this.routePolicyService.canNavigate('facilities-settings-security-teams', this.facility)) {
5659
this.items.push({
5760
cssIcon: 'perun-security-teams',
5861
url: `/facilities/${this.facility.id}/settings/security-teams`,
@@ -61,7 +64,7 @@ export class FacilitySettingsOverviewComponent implements OnInit {
6164
});
6265
}
6366
// Blacklist
64-
if (this.authResolver.isAuthorized('getBansForFacility_int_policy', [this.facility])) {
67+
if (this.routePolicyService.canNavigate('facilities-settings-blacklist', this.facility)) {
6568
this.items.push({
6669
cssIcon: 'perun-black-list',
6770
url: `/facilities/${this.facility.id}/settings/blacklist`,

apps/admin-gui/src/app/facilities/pages/resource-detail-page/resource-detail-page.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,11 @@ export class ResourceDetailPageComponent extends destroyDetailMixin() implements
113113
const resourceItem = this.sideMenuItemService.parseResource(this.resource, this.underVoUrl);
114114
if (this.underVoUrl) {
115115
parentItem = this.sideMenuItemService.parseVo(this.vo);
116+
this.sideMenuService.setAccessMenuItems([parentItem, resourceItem]);
116117
} else {
117118
parentItem = this.sideMenuItemService.parseFacility(this.facility);
119+
this.sideMenuService.setFacilityMenuItems([parentItem, resourceItem]);
118120
}
119-
this.sideMenuService.setAccessMenuItems([parentItem, resourceItem]);
120121
}
121122

122123
editResource(): void {

apps/admin-gui/src/app/facilities/pages/resource-detail-page/resource-overview/resource-overview.component.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import { Component, HostBinding, OnInit } from '@angular/core';
22
import { ActivatedRoute } from '@angular/router';
33
import { MenuItem } from '@perun-web-apps/perun/models';
44
import { Resource, ResourcesManagerService } from '@perun-web-apps/perun/openapi';
5-
import { EntityStorageService, GuiAuthResolver } from '@perun-web-apps/perun/services';
5+
import {
6+
EntityStorageService,
7+
GuiAuthResolver,
8+
RoutePolicyService,
9+
} from '@perun-web-apps/perun/services';
610

711
@Component({
812
selector: 'app-resource-overview',
@@ -20,7 +24,8 @@ export class ResourceOverviewComponent implements OnInit {
2024
private resourcesManager: ResourcesManagerService,
2125
private route: ActivatedRoute,
2226
public guiAuthResolver: GuiAuthResolver,
23-
private entityStorageService: EntityStorageService
27+
private entityStorageService: EntityStorageService,
28+
private routePolicyService: RoutePolicyService
2429
) {}
2530

2631
ngOnInit(): void {
@@ -40,35 +45,31 @@ export class ResourceOverviewComponent implements OnInit {
4045
: `/facilities/${this.resource.facilityId}`;
4146
this.navItems = [];
4247

43-
if (this.guiAuthResolver.isAuthorized('getAssignedGroups_Resource_policy', [this.resource])) {
48+
if (this.routePolicyService.canNavigate('resources-groups', this.resource)) {
4449
this.navItems.push({
4550
cssIcon: 'perun-group',
4651
url: `${urlStart}/resources/${this.resource.id}/groups`,
4752
label: 'MENU_ITEMS.RESOURCE.ASSIGNED_GROUPS',
4853
style: 'resource-btn',
4954
});
5055
}
51-
if (this.guiAuthResolver.isAuthorized('getAssignedServices_Resource_policy', [this.resource])) {
56+
if (this.routePolicyService.canNavigate('resources-services', this.resource)) {
5257
this.navItems.push({
5358
cssIcon: 'perun-service',
5459
url: `/${urlStart}/resources/${this.resource.id}/services`,
5560
label: 'MENU_ITEMS.RESOURCE.ASSIGNED_SERVICES',
5661
style: 'resource-btn',
5762
});
5863
}
59-
if (this.guiAuthResolver.isAuthorized('getAssignedMembers_Resource_policy', [this.resource])) {
64+
if (this.routePolicyService.canNavigate('resources-members', this.resource)) {
6065
this.navItems.push({
6166
cssIcon: 'perun-user',
6267
url: `${urlStart}/resources/${this.resource.id}/members`,
6368
label: 'MENU_ITEMS.RESOURCE.ASSIGNED_MEMBERS',
6469
style: 'resource-btn',
6570
});
6671
}
67-
if (
68-
this.guiAuthResolver.isAuthorized('getAllResourcesTagsForResource_Resource_policy', [
69-
this.resource,
70-
])
71-
) {
72+
if (this.routePolicyService.canNavigate('resources-tags', this.resource)) {
7273
this.navItems.push({
7374
cssIcon: 'perun-resource-tags',
7475
url: `${urlStart}/resources/${this.resource.id}/tags`,
@@ -77,15 +78,16 @@ export class ResourceOverviewComponent implements OnInit {
7778
});
7879
}
7980

80-
this.navItems.push({
81-
cssIcon: 'perun-attributes',
82-
url: `${urlStart}/resources/${this.resource.id}/attributes`,
83-
label: 'MENU_ITEMS.RESOURCE.ATTRIBUTES',
84-
style: 'resource-btn',
85-
});
81+
if (this.routePolicyService.canNavigate('resources-attributes', this.resource)) {
82+
this.navItems.push({
83+
cssIcon: 'perun-attributes',
84+
url: `${urlStart}/resources/${this.resource.id}/attributes`,
85+
label: 'MENU_ITEMS.RESOURCE.ATTRIBUTES',
86+
style: 'resource-btn',
87+
});
88+
}
8689

87-
const managersAuth = this.guiAuthResolver.isManagerPagePrivileged(this.resource);
88-
if (managersAuth) {
90+
if (this.routePolicyService.canNavigate('resources-settings', this.resource)) {
8991
this.navItems.push({
9092
cssIcon: 'perun-settings2',
9193
url: `${urlStart}/resources/${this.resource.id}/settings`,

apps/admin-gui/src/app/facilities/pages/resource-detail-page/resource-settings/resource-settings-overview/resource-settings-overview.component.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import { Component, HostBinding, OnInit } from '@angular/core';
22
import { ActivatedRoute } from '@angular/router';
33
import { MenuItem } from '@perun-web-apps/perun/models';
44
import { Resource, ResourcesManagerService } from '@perun-web-apps/perun/openapi';
5-
import { EntityStorageService, GuiAuthResolver } from '@perun-web-apps/perun/services';
5+
import {
6+
EntityStorageService,
7+
GuiAuthResolver,
8+
RoutePolicyService,
9+
} from '@perun-web-apps/perun/services';
610

711
@Component({
812
selector: 'app-resource-settings-overview',
@@ -19,7 +23,8 @@ export class ResourceSettingsOverviewComponent implements OnInit {
1923
private route: ActivatedRoute,
2024
private resourceManager: ResourcesManagerService,
2125
private authResolver: GuiAuthResolver,
22-
private entityStorageService: EntityStorageService
26+
private entityStorageService: EntityStorageService,
27+
private routePolicyService: RoutePolicyService
2328
) {}
2429

2530
ngOnInit(): void {
@@ -36,8 +41,7 @@ export class ResourceSettingsOverviewComponent implements OnInit {
3641
private initItems(inVo: boolean): void {
3742
this.items = [];
3843

39-
const managersAuth = this.authResolver.isManagerPagePrivileged(this.resource);
40-
if (managersAuth) {
44+
if (this.routePolicyService.canNavigate('resources-settings-managers', this.resource)) {
4145
this.items.push({
4246
cssIcon: 'perun-manager',
4347
url: `${

0 commit comments

Comments
 (0)