uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/controllers/ConnectController.java

117 lines
5.1 KiB
Java
Raw Normal View History

package eu.dnetlib.uoaadmintools.controllers;
import eu.dnetlib.uoaadmintools.entities.Layout;
import eu.dnetlib.uoaadmintools.services.LayoutService;
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PortalResponse;
[Trunk | Admin Tools]: 1. pom.xml: Added dependency for spring security. 2. UoaAdminToolsApplication.java: Import AuthorizationConfiguration.class | Remove SecurityConfig.class from @EnableConfigurationProperties. 3. UoaAdminToolsConfiguration.java: Comment "addInterceptors()" method calling AuthorizationHandler with SecurityConfig. 4. SecurityConfig.java & AuthorizationHandler.java & AuthorizationUtils.java & CommunityInfo.java & UserInfo.java: Commented all contents of these files (files will be deleted in coming commit). 5. PortalSubscribersController.java: Comment imports from commeted files. 6. Notifications.java: Added field "aaiId" get getters and setters. 7. NotificationsController.java: a. Method "getNotifications()" is replaced by "getNotificationsForUser()" (/community/{pid}/notifications) - returns notification settings only for user who made the request (uoa-authorization-li$ b. Path changed for method "getNotifications()": /community/{pid}/notifications/all c. Remove "@RequestBody String email" parameter from method "deleteNotification()" - get email from user who made the request (uoa-authorization-library). d. In method "saveNotification()" get aaiId and email from user who made the request (uoa-authorization-library). e. Added checks and throw Exceptions in all methods. f. Added @PreAuthorize Portal Admins: "getNotifications()" (/community/{pid}/notifications/all) Portal Admins - Curators - Managers: "getNotificationsForUser()" (/community/{pid}/notifications), "deleteNotification()" (/community/{pid}/notifications), "saveNotification()" (/communit$ 8. ExploreController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateExplore()" (/explore/update), "insertExplore()" (/explore/save), "deleteExplore()" (/explore/delete). 9. ConnectController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateConnect()" (/connect/update), "insertConnect()" (/connect/save), "deleteConnect()" (/connect/delete). c. Commented methods "getLayoutForConnect()" and "updateLayoutForConnect()" (/connect/{pid}/layout). 10. CommunityController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateCommunity()" (/community/update), "insertCommunity()" (/community/save), "deleteCommunity()" (/community/delete). Portal Admin - Curators - Managers: "updateLayoutForCommunity()" (/community/{pid}/layout). 11. CuratorController.java: a. In "insertCurator() (/curator) set _id field with aaiId from user who made the request (uoa-authorization-library). b. Added @PreAuthorize Authenticated users: "getCuratorById()" (/curator/{id}), "insertCurator()" (/curator). Portal Admins: "deleteCurators()" (/curator).
2021-02-25 12:57:22 +01:00
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException;
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
[Trunk | Admin Tools]: 1. pom.xml: Added dependency for spring security. 2. UoaAdminToolsApplication.java: Import AuthorizationConfiguration.class | Remove SecurityConfig.class from @EnableConfigurationProperties. 3. UoaAdminToolsConfiguration.java: Comment "addInterceptors()" method calling AuthorizationHandler with SecurityConfig. 4. SecurityConfig.java & AuthorizationHandler.java & AuthorizationUtils.java & CommunityInfo.java & UserInfo.java: Commented all contents of these files (files will be deleted in coming commit). 5. PortalSubscribersController.java: Comment imports from commeted files. 6. Notifications.java: Added field "aaiId" get getters and setters. 7. NotificationsController.java: a. Method "getNotifications()" is replaced by "getNotificationsForUser()" (/community/{pid}/notifications) - returns notification settings only for user who made the request (uoa-authorization-li$ b. Path changed for method "getNotifications()": /community/{pid}/notifications/all c. Remove "@RequestBody String email" parameter from method "deleteNotification()" - get email from user who made the request (uoa-authorization-library). d. In method "saveNotification()" get aaiId and email from user who made the request (uoa-authorization-library). e. Added checks and throw Exceptions in all methods. f. Added @PreAuthorize Portal Admins: "getNotifications()" (/community/{pid}/notifications/all) Portal Admins - Curators - Managers: "getNotificationsForUser()" (/community/{pid}/notifications), "deleteNotification()" (/community/{pid}/notifications), "saveNotification()" (/communit$ 8. ExploreController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateExplore()" (/explore/update), "insertExplore()" (/explore/save), "deleteExplore()" (/explore/delete). 9. ConnectController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateConnect()" (/connect/update), "insertConnect()" (/connect/save), "deleteConnect()" (/connect/delete). c. Commented methods "getLayoutForConnect()" and "updateLayoutForConnect()" (/connect/{pid}/layout). 10. CommunityController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateCommunity()" (/community/update), "insertCommunity()" (/community/save), "deleteCommunity()" (/community/delete). Portal Admin - Curators - Managers: "updateLayoutForCommunity()" (/community/{pid}/layout). 11. CuratorController.java: a. In "insertCurator() (/curator) set _id field with aaiId from user who made the request (uoa-authorization-library). b. Added @PreAuthorize Authenticated users: "getCuratorById()" (/curator/{id}), "insertCurator()" (/curator). Portal Admins: "deleteCurators()" (/curator).
2021-02-25 12:57:22 +01:00
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/connect")
@CrossOrigin(origins = "*")
public class ConnectController {
private final Logger log = LogManager.getLogger(this.getClass());
@Autowired
private LayoutService layoutService;
@Autowired
private PortalService portalService;
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
@RequestMapping(value = "/update", method = RequestMethod.POST)
[Trunk | Admin Tools]: 1. pom.xml: Added dependency for spring security. 2. UoaAdminToolsApplication.java: Import AuthorizationConfiguration.class | Remove SecurityConfig.class from @EnableConfigurationProperties. 3. UoaAdminToolsConfiguration.java: Comment "addInterceptors()" method calling AuthorizationHandler with SecurityConfig. 4. SecurityConfig.java & AuthorizationHandler.java & AuthorizationUtils.java & CommunityInfo.java & UserInfo.java: Commented all contents of these files (files will be deleted in coming commit). 5. PortalSubscribersController.java: Comment imports from commeted files. 6. Notifications.java: Added field "aaiId" get getters and setters. 7. NotificationsController.java: a. Method "getNotifications()" is replaced by "getNotificationsForUser()" (/community/{pid}/notifications) - returns notification settings only for user who made the request (uoa-authorization-li$ b. Path changed for method "getNotifications()": /community/{pid}/notifications/all c. Remove "@RequestBody String email" parameter from method "deleteNotification()" - get email from user who made the request (uoa-authorization-library). d. In method "saveNotification()" get aaiId and email from user who made the request (uoa-authorization-library). e. Added checks and throw Exceptions in all methods. f. Added @PreAuthorize Portal Admins: "getNotifications()" (/community/{pid}/notifications/all) Portal Admins - Curators - Managers: "getNotificationsForUser()" (/community/{pid}/notifications), "deleteNotification()" (/community/{pid}/notifications), "saveNotification()" (/communit$ 8. ExploreController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateExplore()" (/explore/update), "insertExplore()" (/explore/save), "deleteExplore()" (/explore/delete). 9. ConnectController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateConnect()" (/connect/update), "insertConnect()" (/connect/save), "deleteConnect()" (/connect/delete). c. Commented methods "getLayoutForConnect()" and "updateLayoutForConnect()" (/connect/{pid}/layout). 10. CommunityController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateCommunity()" (/community/update), "insertCommunity()" (/community/save), "deleteCommunity()" (/community/delete). Portal Admin - Curators - Managers: "updateLayoutForCommunity()" (/community/{pid}/layout). 11. CuratorController.java: a. In "insertCurator() (/curator) set _id field with aaiId from user who made the request (uoa-authorization-library). b. Added @PreAuthorize Authenticated users: "getCuratorById()" (/curator/{id}), "insertCurator()" (/curator). Portal Admins: "deleteCurators()" (/curator).
2021-02-25 12:57:22 +01:00
public PortalResponse updateConnect(@RequestBody Portal portal) {
if (!portal.getType().equals("connect")) {
[Trunk | Admin Tools]: 1. pom.xml: Added dependency for spring security. 2. UoaAdminToolsApplication.java: Import AuthorizationConfiguration.class | Remove SecurityConfig.class from @EnableConfigurationProperties. 3. UoaAdminToolsConfiguration.java: Comment "addInterceptors()" method calling AuthorizationHandler with SecurityConfig. 4. SecurityConfig.java & AuthorizationHandler.java & AuthorizationUtils.java & CommunityInfo.java & UserInfo.java: Commented all contents of these files (files will be deleted in coming commit). 5. PortalSubscribersController.java: Comment imports from commeted files. 6. Notifications.java: Added field "aaiId" get getters and setters. 7. NotificationsController.java: a. Method "getNotifications()" is replaced by "getNotificationsForUser()" (/community/{pid}/notifications) - returns notification settings only for user who made the request (uoa-authorization-li$ b. Path changed for method "getNotifications()": /community/{pid}/notifications/all c. Remove "@RequestBody String email" parameter from method "deleteNotification()" - get email from user who made the request (uoa-authorization-library). d. In method "saveNotification()" get aaiId and email from user who made the request (uoa-authorization-library). e. Added checks and throw Exceptions in all methods. f. Added @PreAuthorize Portal Admins: "getNotifications()" (/community/{pid}/notifications/all) Portal Admins - Curators - Managers: "getNotificationsForUser()" (/community/{pid}/notifications), "deleteNotification()" (/community/{pid}/notifications), "saveNotification()" (/communit$ 8. ExploreController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateExplore()" (/explore/update), "insertExplore()" (/explore/save), "deleteExplore()" (/explore/delete). 9. ConnectController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateConnect()" (/connect/update), "insertConnect()" (/connect/save), "deleteConnect()" (/connect/delete). c. Commented methods "getLayoutForConnect()" and "updateLayoutForConnect()" (/connect/{pid}/layout). 10. CommunityController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateCommunity()" (/community/update), "insertCommunity()" (/community/save), "deleteCommunity()" (/community/delete). Portal Admin - Curators - Managers: "updateLayoutForCommunity()" (/community/{pid}/layout). 11. CuratorController.java: a. In "insertCurator() (/curator) set _id field with aaiId from user who made the request (uoa-authorization-library). b. Added @PreAuthorize Authenticated users: "getCuratorById()" (/curator/{id}), "insertCurator()" (/curator). Portal Admins: "deleteCurators()" (/curator).
2021-02-25 12:57:22 +01:00
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("Update Connect: Portal with id: " + portal.getId() + " has type: " + portal.getType() + " instead of connect");
[Trunk | Admin Tools]: 1. pom.xml: Added dependency for spring security. 2. UoaAdminToolsApplication.java: Import AuthorizationConfiguration.class | Remove SecurityConfig.class from @EnableConfigurationProperties. 3. UoaAdminToolsConfiguration.java: Comment "addInterceptors()" method calling AuthorizationHandler with SecurityConfig. 4. SecurityConfig.java & AuthorizationHandler.java & AuthorizationUtils.java & CommunityInfo.java & UserInfo.java: Commented all contents of these files (files will be deleted in coming commit). 5. PortalSubscribersController.java: Comment imports from commeted files. 6. Notifications.java: Added field "aaiId" get getters and setters. 7. NotificationsController.java: a. Method "getNotifications()" is replaced by "getNotificationsForUser()" (/community/{pid}/notifications) - returns notification settings only for user who made the request (uoa-authorization-li$ b. Path changed for method "getNotifications()": /community/{pid}/notifications/all c. Remove "@RequestBody String email" parameter from method "deleteNotification()" - get email from user who made the request (uoa-authorization-library). d. In method "saveNotification()" get aaiId and email from user who made the request (uoa-authorization-library). e. Added checks and throw Exceptions in all methods. f. Added @PreAuthorize Portal Admins: "getNotifications()" (/community/{pid}/notifications/all) Portal Admins - Curators - Managers: "getNotificationsForUser()" (/community/{pid}/notifications), "deleteNotification()" (/community/{pid}/notifications), "saveNotification()" (/communit$ 8. ExploreController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateExplore()" (/explore/update), "insertExplore()" (/explore/save), "deleteExplore()" (/explore/delete). 9. ConnectController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateConnect()" (/connect/update), "insertConnect()" (/connect/save), "deleteConnect()" (/connect/delete). c. Commented methods "getLayoutForConnect()" and "updateLayoutForConnect()" (/connect/{pid}/layout). 10. CommunityController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateCommunity()" (/community/update), "insertCommunity()" (/community/save), "deleteCommunity()" (/community/delete). Portal Admin - Curators - Managers: "updateLayoutForCommunity()" (/community/{pid}/layout). 11. CuratorController.java: a. In "insertCurator() (/curator) set _id field with aaiId from user who made the request (uoa-authorization-library). b. Added @PreAuthorize Authenticated users: "getCuratorById()" (/curator/{id}), "insertCurator()" (/curator). Portal Admins: "deleteCurators()" (/curator).
2021-02-25 12:57:22 +01:00
}
PortalResponse portalResponse = portalService.updatePortal(portal);
String old_pid = portalResponse.getPid();
String new_pid = portal.getPid();
if (!old_pid.equals(new_pid)) {
layoutService.updatePid(old_pid, new_pid);
}
return portalResponse;
}
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
@RequestMapping(value = "/save", method = RequestMethod.POST)
[Trunk | Admin Tools]: 1. pom.xml: Added dependency for spring security. 2. UoaAdminToolsApplication.java: Import AuthorizationConfiguration.class | Remove SecurityConfig.class from @EnableConfigurationProperties. 3. UoaAdminToolsConfiguration.java: Comment "addInterceptors()" method calling AuthorizationHandler with SecurityConfig. 4. SecurityConfig.java & AuthorizationHandler.java & AuthorizationUtils.java & CommunityInfo.java & UserInfo.java: Commented all contents of these files (files will be deleted in coming commit). 5. PortalSubscribersController.java: Comment imports from commeted files. 6. Notifications.java: Added field "aaiId" get getters and setters. 7. NotificationsController.java: a. Method "getNotifications()" is replaced by "getNotificationsForUser()" (/community/{pid}/notifications) - returns notification settings only for user who made the request (uoa-authorization-li$ b. Path changed for method "getNotifications()": /community/{pid}/notifications/all c. Remove "@RequestBody String email" parameter from method "deleteNotification()" - get email from user who made the request (uoa-authorization-library). d. In method "saveNotification()" get aaiId and email from user who made the request (uoa-authorization-library). e. Added checks and throw Exceptions in all methods. f. Added @PreAuthorize Portal Admins: "getNotifications()" (/community/{pid}/notifications/all) Portal Admins - Curators - Managers: "getNotificationsForUser()" (/community/{pid}/notifications), "deleteNotification()" (/community/{pid}/notifications), "saveNotification()" (/communit$ 8. ExploreController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateExplore()" (/explore/update), "insertExplore()" (/explore/save), "deleteExplore()" (/explore/delete). 9. ConnectController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateConnect()" (/connect/update), "insertConnect()" (/connect/save), "deleteConnect()" (/connect/delete). c. Commented methods "getLayoutForConnect()" and "updateLayoutForConnect()" (/connect/{pid}/layout). 10. CommunityController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateCommunity()" (/community/update), "insertCommunity()" (/community/save), "deleteCommunity()" (/community/delete). Portal Admin - Curators - Managers: "updateLayoutForCommunity()" (/community/{pid}/layout). 11. CuratorController.java: a. In "insertCurator() (/curator) set _id field with aaiId from user who made the request (uoa-authorization-library). b. Added @PreAuthorize Authenticated users: "getCuratorById()" (/curator/{id}), "insertCurator()" (/curator). Portal Admins: "deleteCurators()" (/curator).
2021-02-25 12:57:22 +01:00
public PortalResponse insertConnect(@RequestBody Portal portal) {
if (!portal.getType().equals("connect")) {
[Trunk | Admin Tools]: 1. pom.xml: Added dependency for spring security. 2. UoaAdminToolsApplication.java: Import AuthorizationConfiguration.class | Remove SecurityConfig.class from @EnableConfigurationProperties. 3. UoaAdminToolsConfiguration.java: Comment "addInterceptors()" method calling AuthorizationHandler with SecurityConfig. 4. SecurityConfig.java & AuthorizationHandler.java & AuthorizationUtils.java & CommunityInfo.java & UserInfo.java: Commented all contents of these files (files will be deleted in coming commit). 5. PortalSubscribersController.java: Comment imports from commeted files. 6. Notifications.java: Added field "aaiId" get getters and setters. 7. NotificationsController.java: a. Method "getNotifications()" is replaced by "getNotificationsForUser()" (/community/{pid}/notifications) - returns notification settings only for user who made the request (uoa-authorization-li$ b. Path changed for method "getNotifications()": /community/{pid}/notifications/all c. Remove "@RequestBody String email" parameter from method "deleteNotification()" - get email from user who made the request (uoa-authorization-library). d. In method "saveNotification()" get aaiId and email from user who made the request (uoa-authorization-library). e. Added checks and throw Exceptions in all methods. f. Added @PreAuthorize Portal Admins: "getNotifications()" (/community/{pid}/notifications/all) Portal Admins - Curators - Managers: "getNotificationsForUser()" (/community/{pid}/notifications), "deleteNotification()" (/community/{pid}/notifications), "saveNotification()" (/communit$ 8. ExploreController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateExplore()" (/explore/update), "insertExplore()" (/explore/save), "deleteExplore()" (/explore/delete). 9. ConnectController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateConnect()" (/connect/update), "insertConnect()" (/connect/save), "deleteConnect()" (/connect/delete). c. Commented methods "getLayoutForConnect()" and "updateLayoutForConnect()" (/connect/{pid}/layout). 10. CommunityController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateCommunity()" (/community/update), "insertCommunity()" (/community/save), "deleteCommunity()" (/community/delete). Portal Admin - Curators - Managers: "updateLayoutForCommunity()" (/community/{pid}/layout). 11. CuratorController.java: a. In "insertCurator() (/curator) set _id field with aaiId from user who made the request (uoa-authorization-library). b. Added @PreAuthorize Authenticated users: "getCuratorById()" (/curator/{id}), "insertCurator()" (/curator). Portal Admins: "deleteCurators()" (/curator).
2021-02-25 12:57:22 +01:00
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("Save Connect: Portal with id: " + portal.getId() + " has type: " + portal.getType() + " instead of connect");
[Trunk | Admin Tools]: 1. pom.xml: Added dependency for spring security. 2. UoaAdminToolsApplication.java: Import AuthorizationConfiguration.class | Remove SecurityConfig.class from @EnableConfigurationProperties. 3. UoaAdminToolsConfiguration.java: Comment "addInterceptors()" method calling AuthorizationHandler with SecurityConfig. 4. SecurityConfig.java & AuthorizationHandler.java & AuthorizationUtils.java & CommunityInfo.java & UserInfo.java: Commented all contents of these files (files will be deleted in coming commit). 5. PortalSubscribersController.java: Comment imports from commeted files. 6. Notifications.java: Added field "aaiId" get getters and setters. 7. NotificationsController.java: a. Method "getNotifications()" is replaced by "getNotificationsForUser()" (/community/{pid}/notifications) - returns notification settings only for user who made the request (uoa-authorization-li$ b. Path changed for method "getNotifications()": /community/{pid}/notifications/all c. Remove "@RequestBody String email" parameter from method "deleteNotification()" - get email from user who made the request (uoa-authorization-library). d. In method "saveNotification()" get aaiId and email from user who made the request (uoa-authorization-library). e. Added checks and throw Exceptions in all methods. f. Added @PreAuthorize Portal Admins: "getNotifications()" (/community/{pid}/notifications/all) Portal Admins - Curators - Managers: "getNotificationsForUser()" (/community/{pid}/notifications), "deleteNotification()" (/community/{pid}/notifications), "saveNotification()" (/communit$ 8. ExploreController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateExplore()" (/explore/update), "insertExplore()" (/explore/save), "deleteExplore()" (/explore/delete). 9. ConnectController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateConnect()" (/connect/update), "insertConnect()" (/connect/save), "deleteConnect()" (/connect/delete). c. Commented methods "getLayoutForConnect()" and "updateLayoutForConnect()" (/connect/{pid}/layout). 10. CommunityController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateCommunity()" (/community/update), "insertCommunity()" (/community/save), "deleteCommunity()" (/community/delete). Portal Admin - Curators - Managers: "updateLayoutForCommunity()" (/community/{pid}/layout). 11. CuratorController.java: a. In "insertCurator() (/curator) set _id field with aaiId from user who made the request (uoa-authorization-library). b. Added @PreAuthorize Authenticated users: "getCuratorById()" (/curator/{id}), "insertCurator()" (/curator). Portal Admins: "deleteCurators()" (/curator).
2021-02-25 12:57:22 +01:00
}
PortalResponse portalResponse = portalService.insertPortal(portal);
return portalResponse;
}
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
@RequestMapping(value = "/delete", method = RequestMethod.POST)
[Trunk | Admin Tools]: 1. pom.xml: Added dependency for spring security. 2. UoaAdminToolsApplication.java: Import AuthorizationConfiguration.class | Remove SecurityConfig.class from @EnableConfigurationProperties. 3. UoaAdminToolsConfiguration.java: Comment "addInterceptors()" method calling AuthorizationHandler with SecurityConfig. 4. SecurityConfig.java & AuthorizationHandler.java & AuthorizationUtils.java & CommunityInfo.java & UserInfo.java: Commented all contents of these files (files will be deleted in coming commit). 5. PortalSubscribersController.java: Comment imports from commeted files. 6. Notifications.java: Added field "aaiId" get getters and setters. 7. NotificationsController.java: a. Method "getNotifications()" is replaced by "getNotificationsForUser()" (/community/{pid}/notifications) - returns notification settings only for user who made the request (uoa-authorization-li$ b. Path changed for method "getNotifications()": /community/{pid}/notifications/all c. Remove "@RequestBody String email" parameter from method "deleteNotification()" - get email from user who made the request (uoa-authorization-library). d. In method "saveNotification()" get aaiId and email from user who made the request (uoa-authorization-library). e. Added checks and throw Exceptions in all methods. f. Added @PreAuthorize Portal Admins: "getNotifications()" (/community/{pid}/notifications/all) Portal Admins - Curators - Managers: "getNotificationsForUser()" (/community/{pid}/notifications), "deleteNotification()" (/community/{pid}/notifications), "saveNotification()" (/communit$ 8. ExploreController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateExplore()" (/explore/update), "insertExplore()" (/explore/save), "deleteExplore()" (/explore/delete). 9. ConnectController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateConnect()" (/connect/update), "insertConnect()" (/connect/save), "deleteConnect()" (/connect/delete). c. Commented methods "getLayoutForConnect()" and "updateLayoutForConnect()" (/connect/{pid}/layout). 10. CommunityController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateCommunity()" (/community/update), "insertCommunity()" (/community/save), "deleteCommunity()" (/community/delete). Portal Admin - Curators - Managers: "updateLayoutForCommunity()" (/community/{pid}/layout). 11. CuratorController.java: a. In "insertCurator() (/curator) set _id field with aaiId from user who made the request (uoa-authorization-library). b. Added @PreAuthorize Authenticated users: "getCuratorById()" (/curator/{id}), "insertCurator()" (/curator). Portal Admins: "deleteCurators()" (/curator).
2021-02-25 12:57:22 +01:00
public Boolean deleteConnect(@RequestBody List<String> portals) {
for (String id : portals) {
[Trunk | Admin Tools]: 1. pom.xml: Added dependency for spring security. 2. UoaAdminToolsApplication.java: Import AuthorizationConfiguration.class | Remove SecurityConfig.class from @EnableConfigurationProperties. 3. UoaAdminToolsConfiguration.java: Comment "addInterceptors()" method calling AuthorizationHandler with SecurityConfig. 4. SecurityConfig.java & AuthorizationHandler.java & AuthorizationUtils.java & CommunityInfo.java & UserInfo.java: Commented all contents of these files (files will be deleted in coming commit). 5. PortalSubscribersController.java: Comment imports from commeted files. 6. Notifications.java: Added field "aaiId" get getters and setters. 7. NotificationsController.java: a. Method "getNotifications()" is replaced by "getNotificationsForUser()" (/community/{pid}/notifications) - returns notification settings only for user who made the request (uoa-authorization-li$ b. Path changed for method "getNotifications()": /community/{pid}/notifications/all c. Remove "@RequestBody String email" parameter from method "deleteNotification()" - get email from user who made the request (uoa-authorization-library). d. In method "saveNotification()" get aaiId and email from user who made the request (uoa-authorization-library). e. Added checks and throw Exceptions in all methods. f. Added @PreAuthorize Portal Admins: "getNotifications()" (/community/{pid}/notifications/all) Portal Admins - Curators - Managers: "getNotificationsForUser()" (/community/{pid}/notifications), "deleteNotification()" (/community/{pid}/notifications), "saveNotification()" (/communit$ 8. ExploreController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateExplore()" (/explore/update), "insertExplore()" (/explore/save), "deleteExplore()" (/explore/delete). 9. ConnectController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateConnect()" (/connect/update), "insertConnect()" (/connect/save), "deleteConnect()" (/connect/delete). c. Commented methods "getLayoutForConnect()" and "updateLayoutForConnect()" (/connect/{pid}/layout). 10. CommunityController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateCommunity()" (/community/update), "insertCommunity()" (/community/save), "deleteCommunity()" (/community/delete). Portal Admin - Curators - Managers: "updateLayoutForCommunity()" (/community/{pid}/layout). 11. CuratorController.java: a. In "insertCurator() (/curator) set _id field with aaiId from user who made the request (uoa-authorization-library). b. Added @PreAuthorize Authenticated users: "getCuratorById()" (/curator/{id}), "insertCurator()" (/curator). Portal Admins: "deleteCurators()" (/curator).
2021-02-25 12:57:22 +01:00
Portal portal = portalService.getPortalById(id);
if (portal == null) {
[Trunk | Admin Tools]: 1. pom.xml: Added dependency for spring security. 2. UoaAdminToolsApplication.java: Import AuthorizationConfiguration.class | Remove SecurityConfig.class from @EnableConfigurationProperties. 3. UoaAdminToolsConfiguration.java: Comment "addInterceptors()" method calling AuthorizationHandler with SecurityConfig. 4. SecurityConfig.java & AuthorizationHandler.java & AuthorizationUtils.java & CommunityInfo.java & UserInfo.java: Commented all contents of these files (files will be deleted in coming commit). 5. PortalSubscribersController.java: Comment imports from commeted files. 6. Notifications.java: Added field "aaiId" get getters and setters. 7. NotificationsController.java: a. Method "getNotifications()" is replaced by "getNotificationsForUser()" (/community/{pid}/notifications) - returns notification settings only for user who made the request (uoa-authorization-li$ b. Path changed for method "getNotifications()": /community/{pid}/notifications/all c. Remove "@RequestBody String email" parameter from method "deleteNotification()" - get email from user who made the request (uoa-authorization-library). d. In method "saveNotification()" get aaiId and email from user who made the request (uoa-authorization-library). e. Added checks and throw Exceptions in all methods. f. Added @PreAuthorize Portal Admins: "getNotifications()" (/community/{pid}/notifications/all) Portal Admins - Curators - Managers: "getNotificationsForUser()" (/community/{pid}/notifications), "deleteNotification()" (/community/{pid}/notifications), "saveNotification()" (/communit$ 8. ExploreController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateExplore()" (/explore/update), "insertExplore()" (/explore/save), "deleteExplore()" (/explore/delete). 9. ConnectController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateConnect()" (/connect/update), "insertConnect()" (/connect/save), "deleteConnect()" (/connect/delete). c. Commented methods "getLayoutForConnect()" and "updateLayoutForConnect()" (/connect/{pid}/layout). 10. CommunityController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateCommunity()" (/community/update), "insertCommunity()" (/community/save), "deleteCommunity()" (/community/delete). Portal Admin - Curators - Managers: "updateLayoutForCommunity()" (/community/{pid}/layout). 11. CuratorController.java: a. In "insertCurator() (/curator) set _id field with aaiId from user who made the request (uoa-authorization-library). b. Added @PreAuthorize Authenticated users: "getCuratorById()" (/curator/{id}), "insertCurator()" (/curator). Portal Admins: "deleteCurators()" (/curator).
2021-02-25 12:57:22 +01:00
// EXCEPTION - Entity Not Found
throw new ContentNotFoundException("Delete connect: Portal with id: " + id + " not found");
}
if (!portal.getType().equals("connect")) {
[Trunk | Admin Tools]: 1. pom.xml: Added dependency for spring security. 2. UoaAdminToolsApplication.java: Import AuthorizationConfiguration.class | Remove SecurityConfig.class from @EnableConfigurationProperties. 3. UoaAdminToolsConfiguration.java: Comment "addInterceptors()" method calling AuthorizationHandler with SecurityConfig. 4. SecurityConfig.java & AuthorizationHandler.java & AuthorizationUtils.java & CommunityInfo.java & UserInfo.java: Commented all contents of these files (files will be deleted in coming commit). 5. PortalSubscribersController.java: Comment imports from commeted files. 6. Notifications.java: Added field "aaiId" get getters and setters. 7. NotificationsController.java: a. Method "getNotifications()" is replaced by "getNotificationsForUser()" (/community/{pid}/notifications) - returns notification settings only for user who made the request (uoa-authorization-li$ b. Path changed for method "getNotifications()": /community/{pid}/notifications/all c. Remove "@RequestBody String email" parameter from method "deleteNotification()" - get email from user who made the request (uoa-authorization-library). d. In method "saveNotification()" get aaiId and email from user who made the request (uoa-authorization-library). e. Added checks and throw Exceptions in all methods. f. Added @PreAuthorize Portal Admins: "getNotifications()" (/community/{pid}/notifications/all) Portal Admins - Curators - Managers: "getNotificationsForUser()" (/community/{pid}/notifications), "deleteNotification()" (/community/{pid}/notifications), "saveNotification()" (/communit$ 8. ExploreController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateExplore()" (/explore/update), "insertExplore()" (/explore/save), "deleteExplore()" (/explore/delete). 9. ConnectController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateConnect()" (/connect/update), "insertConnect()" (/connect/save), "deleteConnect()" (/connect/delete). c. Commented methods "getLayoutForConnect()" and "updateLayoutForConnect()" (/connect/{pid}/layout). 10. CommunityController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateCommunity()" (/community/update), "insertCommunity()" (/community/save), "deleteCommunity()" (/community/delete). Portal Admin - Curators - Managers: "updateLayoutForCommunity()" (/community/{pid}/layout). 11. CuratorController.java: a. In "insertCurator() (/curator) set _id field with aaiId from user who made the request (uoa-authorization-library). b. Added @PreAuthorize Authenticated users: "getCuratorById()" (/curator/{id}), "insertCurator()" (/curator). Portal Admins: "deleteCurators()" (/curator).
2021-02-25 12:57:22 +01:00
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("Delete Connect: Portal with id: " + id + " has type: " + portal.getType() + " instead of connect");
[Trunk | Admin Tools]: 1. pom.xml: Added dependency for spring security. 2. UoaAdminToolsApplication.java: Import AuthorizationConfiguration.class | Remove SecurityConfig.class from @EnableConfigurationProperties. 3. UoaAdminToolsConfiguration.java: Comment "addInterceptors()" method calling AuthorizationHandler with SecurityConfig. 4. SecurityConfig.java & AuthorizationHandler.java & AuthorizationUtils.java & CommunityInfo.java & UserInfo.java: Commented all contents of these files (files will be deleted in coming commit). 5. PortalSubscribersController.java: Comment imports from commeted files. 6. Notifications.java: Added field "aaiId" get getters and setters. 7. NotificationsController.java: a. Method "getNotifications()" is replaced by "getNotificationsForUser()" (/community/{pid}/notifications) - returns notification settings only for user who made the request (uoa-authorization-li$ b. Path changed for method "getNotifications()": /community/{pid}/notifications/all c. Remove "@RequestBody String email" parameter from method "deleteNotification()" - get email from user who made the request (uoa-authorization-library). d. In method "saveNotification()" get aaiId and email from user who made the request (uoa-authorization-library). e. Added checks and throw Exceptions in all methods. f. Added @PreAuthorize Portal Admins: "getNotifications()" (/community/{pid}/notifications/all) Portal Admins - Curators - Managers: "getNotificationsForUser()" (/community/{pid}/notifications), "deleteNotification()" (/community/{pid}/notifications), "saveNotification()" (/communit$ 8. ExploreController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateExplore()" (/explore/update), "insertExplore()" (/explore/save), "deleteExplore()" (/explore/delete). 9. ConnectController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateConnect()" (/connect/update), "insertConnect()" (/connect/save), "deleteConnect()" (/connect/delete). c. Commented methods "getLayoutForConnect()" and "updateLayoutForConnect()" (/connect/{pid}/layout). 10. CommunityController.java: a. Added checks and throw Exceptions in all methods. b. Added @PreAuthorize Portal Admins: "updateCommunity()" (/community/update), "insertCommunity()" (/community/save), "deleteCommunity()" (/community/delete). Portal Admin - Curators - Managers: "updateLayoutForCommunity()" (/community/{pid}/layout). 11. CuratorController.java: a. In "insertCurator() (/curator) set _id field with aaiId from user who made the request (uoa-authorization-library). b. Added @PreAuthorize Authenticated users: "getCuratorById()" (/curator/{id}), "insertCurator()" (/curator). Portal Admins: "deleteCurators()" (/curator).
2021-02-25 12:57:22 +01:00
}
String pid = portalService.deletePortal(id);
layoutService.deleteByPid(pid);
}
return true;
}
// no authorization here, because it is called by server
@RequestMapping(value = "/{pid}/layout", method = RequestMethod.GET)
public Layout getLayoutForConnect(@PathVariable(value = "pid") String pid) {
if(!pid.equals("connect") && !pid.equals("default")) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("ConnectController - Get layout: Not accepted pid: "+pid);
}
return layoutService.findByPid(pid);
}
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
@RequestMapping(value = "/{pid}/layout", method = RequestMethod.POST)
public Layout updateLayoutForConnect(@PathVariable(value = "pid") String pid, @RequestBody Layout layout) {
if(!pid.equals("connect") && !pid.equals("default")) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("ConnectController - Update layout: Not accepted pid: "+pid);
}
if(!pid.equals(layout.getPortalPid())) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("ConnectController - Update layout: Portal has pid: "+pid+" while layout has portalPid: "+layout.getPortalPid());
}
return layoutService.save(layout);
}
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
@RequestMapping(value = "/{pid}/layout", method = RequestMethod.DELETE)
public boolean deleteLayoutForConnect(@PathVariable(value = "pid") String pid) {
if(!pid.equals("connect") && !pid.equals("default")) {
// EXCEPTION - MismatchingContent
throw new MismatchingContentException("ConnectController - Delete layout: Not accepted pid: "+pid);
}
return layoutService.deleteByPid(pid);
}
}