Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SELC-4326] Feat: added check permission in operation with relationshipId #353

Merged
merged 3 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 36 additions & 36 deletions app/src/main/resources/swagger/api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"description" : "UserGroups operations"
} ],
"paths" : {
"/delegations" : {
"/v1/delegations" : {
"post" : {
"tags" : [ "delegations" ],
"summary" : "createDelegation",
Expand Down Expand Up @@ -116,7 +116,7 @@
} ]
}
},
"/institutions" : {
"/v1/institutions" : {
"get" : {
"tags" : [ "institutions" ],
"summary" : "getInstitutions",
Expand Down Expand Up @@ -223,7 +223,7 @@
} ]
}
},
"/institutions/products" : {
"/v1/institutions/products" : {
"get" : {
"tags" : [ "institutions" ],
"summary" : "getProductsTree",
Expand Down Expand Up @@ -289,7 +289,7 @@
} ]
}
},
"/institutions/{institutionId}" : {
"/v1/institutions/{institutionId}" : {
"get" : {
"tags" : [ "institutions" ],
"summary" : "getInstitution",
Expand Down Expand Up @@ -432,7 +432,7 @@
} ]
}
},
"/institutions/{institutionId}/geographicTaxonomy" : {
"/v1/institutions/{institutionId}/geographicTaxonomy" : {
"get" : {
"tags" : [ "institutions" ],
"summary" : "getInstitutionGeographicTaxonomy",
Expand Down Expand Up @@ -571,7 +571,7 @@
} ]
}
},
"/institutions/{institutionId}/institutions" : {
"/v1/institutions/{institutionId}/institutions" : {
"get" : {
"tags" : [ "institutions" ],
"summary" : "Retrieve list of delegation using to",
Expand Down Expand Up @@ -656,7 +656,7 @@
} ]
}
},
"/institutions/{institutionId}/logo" : {
"/v1/institutions/{institutionId}/logo" : {
"put" : {
"tags" : [ "institutions" ],
"summary" : "saveInstitutionLogo",
Expand Down Expand Up @@ -741,7 +741,7 @@
} ]
}
},
"/institutions/{institutionId}/partners" : {
"/v1/institutions/{institutionId}/partners" : {
"get" : {
"tags" : [ "institutions" ],
"summary" : "Retrieve institution's delegations",
Expand Down Expand Up @@ -826,7 +826,7 @@
} ]
}
},
"/institutions/{institutionId}/products" : {
"/v1/institutions/{institutionId}/products" : {
"get" : {
"tags" : [ "institutions" ],
"summary" : "getInstitutionProducts",
Expand Down Expand Up @@ -903,7 +903,7 @@
} ]
}
},
"/institutions/{institutionId}/products/{productId}/users" : {
"/v1/institutions/{institutionId}/products/{productId}/users" : {
"get" : {
"tags" : [ "institutions" ],
"summary" : "getInstitutionProductUsers",
Expand Down Expand Up @@ -1087,7 +1087,7 @@
} ]
}
},
"/institutions/{institutionId}/products/{productId}/users/{userId}" : {
"/v1/institutions/{institutionId}/products/{productId}/users/{userId}" : {
"put" : {
"tags" : [ "institutions" ],
"summary" : "addUserProductRoles",
Expand Down Expand Up @@ -1170,7 +1170,7 @@
} ]
}
},
"/institutions/{institutionId}/users" : {
"/v1/institutions/{institutionId}/users" : {
"get" : {
"tags" : [ "institutions" ],
"summary" : "getInstitutionUsers",
Expand Down Expand Up @@ -1276,7 +1276,7 @@
} ]
}
},
"/institutions/{institutionId}/users/{userId}" : {
"/v1/institutions/{institutionId}/users/{userId}" : {
"get" : {
"tags" : [ "institutions" ],
"summary" : "getInstitutionUser",
Expand Down Expand Up @@ -1358,7 +1358,7 @@
} ]
}
},
"/onboarding-requests/approve/{tokenId}" : {
"/v1/onboarding-requests/approve/{tokenId}" : {
"post" : {
"tags" : [ "onboarding" ],
"summary" : "approveOnboardingRequest",
Expand Down Expand Up @@ -1415,7 +1415,7 @@
} ]
}
},
"/onboarding-requests/reject/{tokenId}" : {
"/v1/onboarding-requests/reject/{tokenId}" : {
"delete" : {
"tags" : [ "onboarding" ],
"summary" : "rejectOnboardingRequest",
Expand Down Expand Up @@ -1472,7 +1472,7 @@
} ]
}
},
"/onboarding-requests/{tokenId}" : {
"/v1/onboarding-requests/{tokenId}" : {
"get" : {
"tags" : [ "onboarding" ],
"summary" : "retrieveOnboardingRequest",
Expand Down Expand Up @@ -1546,7 +1546,7 @@
} ]
}
},
"/pnPGInstitutions/{institutionId}/products" : {
"/v1/pnPGInstitutions/{institutionId}/products" : {
"get" : {
"tags" : [ "pnPGInstitutions" ],
"summary" : "getPnPGInstitutionProducts",
Expand Down Expand Up @@ -1622,7 +1622,7 @@
} ]
}
},
"/products/{productId}/back-office" : {
"/v1/products/{productId}/back-office" : {
"get" : {
"tags" : [ "products" ],
"summary" : "retrieveProductBackoffice",
Expand Down Expand Up @@ -1714,7 +1714,7 @@
} ]
}
},
"/products/{productId}/brokers/{institutionType}" : {
"/v1/products/{productId}/brokers/{institutionType}" : {
"get" : {
"tags" : [ "products" ],
"summary" : "getProductBrokers",
Expand Down Expand Up @@ -1800,7 +1800,7 @@
} ]
}
},
"/products/{productId}/roles" : {
"/v1/products/{productId}/roles" : {
"get" : {
"tags" : [ "products" ],
"summary" : "getProductRoles",
Expand Down Expand Up @@ -1876,7 +1876,7 @@
} ]
}
},
"/relationships/{relationshipId}" : {
"/v1/relationships/{relationshipId}" : {
"delete" : {
"tags" : [ "relationships" ],
"summary" : "deleteRelationshipById",
Expand Down Expand Up @@ -1932,7 +1932,7 @@
} ]
}
},
"/relationships/{relationshipId}/activate" : {
"/v1/relationships/{relationshipId}/activate" : {
"post" : {
"tags" : [ "relationships" ],
"summary" : "activateRelationship",
Expand Down Expand Up @@ -1988,7 +1988,7 @@
} ]
}
},
"/relationships/{relationshipId}/suspend" : {
"/v1/relationships/{relationshipId}/suspend" : {
"post" : {
"tags" : [ "relationships" ],
"summary" : "suspendRelationship",
Expand Down Expand Up @@ -2044,7 +2044,7 @@
} ]
}
},
"/support" : {
"/v1/support" : {
"post" : {
"tags" : [ "external-v2", "support" ],
"summary" : "sendSupportRequest",
Expand Down Expand Up @@ -2147,7 +2147,7 @@
} ]
}
},
"/token/exchange" : {
"/v1/token/exchange" : {
"get" : {
"tags" : [ "token" ],
"summary" : "exchange",
Expand Down Expand Up @@ -2238,7 +2238,7 @@
} ]
}
},
"/token/exchange/fatturazione" : {
"/v1/token/exchange/fatturazione" : {
"get" : {
"tags" : [ "token" ],
"summary" : "billingToken",
Expand Down Expand Up @@ -2321,7 +2321,7 @@
} ]
}
},
"/users" : {
"/v1/users" : {
"post" : {
"tags" : [ "user" ],
"summary" : "saveUser",
Expand Down Expand Up @@ -2393,7 +2393,7 @@
} ]
}
},
"/users/search" : {
"/v1/users/search" : {
"post" : {
"tags" : [ "user" ],
"summary" : "search",
Expand Down Expand Up @@ -2475,7 +2475,7 @@
} ]
}
},
"/users/{id}" : {
"/v1/users/{id}" : {
"get" : {
"tags" : [ "user" ],
"summary" : "getUserByInternalId",
Expand Down Expand Up @@ -2686,7 +2686,7 @@
} ]
}
},
"/user-groups" : {
"/v1/user-groups" : {
"get" : {
"tags" : [ "user-groups" ],
"summary" : "getUserGroups",
Expand Down Expand Up @@ -2813,7 +2813,7 @@
} ]
}
},
"/user-groups/" : {
"/v1/user-groups/" : {
"post" : {
"tags" : [ "user-groups" ],
"summary" : "createUserGroup",
Expand Down Expand Up @@ -2878,7 +2878,7 @@
} ]
}
},
"/user-groups/{id}" : {
"/v1/user-groups/{id}" : {
"get" : {
"tags" : [ "user-groups" ],
"summary" : "getUserGroupById",
Expand Down Expand Up @@ -3080,7 +3080,7 @@
} ]
}
},
"/user-groups/{id}/activate" : {
"/v1/user-groups/{id}/activate" : {
"post" : {
"tags" : [ "user-groups" ],
"summary" : "activateUserGroup",
Expand Down Expand Up @@ -3136,7 +3136,7 @@
} ]
}
},
"/user-groups/{id}/members/{userId}" : {
"/v1/user-groups/{id}/members/{userId}" : {
"post" : {
"tags" : [ "user-groups" ],
"summary" : "addMemberToUserGroup",
Expand Down Expand Up @@ -3202,7 +3202,7 @@
} ]
}
},
"/user-groups/{id}/suspend" : {
"/v1/user-groups/{id}/suspend" : {
"post" : {
"tags" : [ "user-groups" ],
"summary" : "suspendUserGroup",
Expand Down Expand Up @@ -3258,7 +3258,7 @@
} ]
}
},
"/user-groups/{userGroupId}/members/{userId}" : {
"/v1/user-groups/{userGroupId}/members/{userId}" : {
"delete" : {
"tags" : [ "user-groups" ],
"summary" : "deleteMemberFromUserGroup",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package it.pagopa.selfcare.dashboard.web.config;

import it.pagopa.selfcare.dashboard.connector.api.MsCoreConnector;
import it.pagopa.selfcare.dashboard.web.security.SelfCarePermissionEvaluator;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler;
Expand All @@ -11,10 +12,16 @@
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class MethodSecurityConfig extends GlobalMethodSecurityConfiguration {

private final MsCoreConnector msCoreConnector;

public MethodSecurityConfig(MsCoreConnector msCoreConnector) {
this.msCoreConnector = msCoreConnector;
}

@Override
protected MethodSecurityExpressionHandler createExpressionHandler() {
DefaultMethodSecurityExpressionHandler expressionHandler = new DefaultMethodSecurityExpressionHandler();
expressionHandler.setPermissionEvaluator(new SelfCarePermissionEvaluator());
expressionHandler.setPermissionEvaluator(new SelfCarePermissionEvaluator(msCoreConnector));
return expressionHandler;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Slf4j
Expand All @@ -28,6 +29,7 @@ public RelationshipController(RelationshipService relationshipService) {
@PostMapping(value = "/{relationshipId}/suspend")
@ResponseStatus(HttpStatus.NO_CONTENT)
@ApiOperation(value = "", notes = "${swagger.dashboard.institutions.api.suspendUser}")
@PreAuthorize("hasPermission(#relationshipId, 'relationshipId', 'ADMIN')")
public void suspendRelationship(@ApiParam("${swagger.dashboard.user.model.relationshipId}")
@PathVariable("relationshipId")
String relationshipId) {
Expand All @@ -43,6 +45,7 @@ public void suspendRelationship(@ApiParam("${swagger.dashboard.user.model.relati
@PostMapping(value = "/{relationshipId}/activate")
@ResponseStatus(HttpStatus.NO_CONTENT)
@ApiOperation(value = "", notes = "${swagger.dashboard.institutions.api.activateUser}")
@PreAuthorize("hasPermission(#relationshipId, 'relationshipId', 'ADMIN')")
public void activateRelationship(@ApiParam("${swagger.dashboard.user.model.relationshipId}")
@PathVariable("relationshipId")
String relationshipId) {
Expand All @@ -57,6 +60,7 @@ public void activateRelationship(@ApiParam("${swagger.dashboard.user.model.relat
@DeleteMapping(value = "/{relationshipId}")
@ResponseStatus(HttpStatus.NO_CONTENT)
@ApiOperation(value = "", notes = "${swagger.dashboard.institutions.api.deleteUser}")
@PreAuthorize("hasPermission(#relationshipId, 'relationshipId', 'ADMIN')")
public void deleteRelationshipById(@ApiParam("${swagger.dashboard.user.model.relationshipId}")
@PathVariable("relationshipId")
String relationshipId) {
Expand Down
Loading
Loading