1. removed registeredBy from add/update interface controllers

2. changed authorization expression for interface validation
This commit is contained in:
Konstantinos Spyrou 2022-11-10 17:34:23 +00:00
parent cff16a2d7c
commit e99f334708
4 changed files with 19 additions and 18 deletions

View File

@ -205,10 +205,9 @@ public class RepositoryController {
@PreAuthorize("hasAuthority('SUPER_ADMINISTRATOR') or hasAuthority('CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or @authorizationService.isMemberOf(#id)") @PreAuthorize("hasAuthority('SUPER_ADMINISTRATOR') or hasAuthority('CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or @authorizationService.isMemberOf(#id)")
public RepositoryInterface addRepositoryInterface(@RequestParam("datatype") String datatype, public RepositoryInterface addRepositoryInterface(@RequestParam("datatype") String datatype,
@RequestParam("repoId") String id, @RequestParam("repoId") String id,
@RequestParam("registeredBy") String registeredBy,
@RequestParam(value = "comment", required = false) String comment, @RequestParam(value = "comment", required = false) String comment,
@RequestBody RepositoryInterface repositoryInterface) throws Exception { @RequestBody RepositoryInterface repositoryInterface) throws Exception {
return repositoryService.addRepositoryInterface(datatype, id, registeredBy, comment, repositoryInterface); return repositoryService.addRepositoryInterface(datatype, id, comment, repositoryInterface);
} }
@RequestMapping(value = "/updateRepositoryInterface", method = RequestMethod.POST, @RequestMapping(value = "/updateRepositoryInterface", method = RequestMethod.POST,
@ -216,10 +215,9 @@ public class RepositoryController {
@ResponseBody @ResponseBody
@PreAuthorize("hasAuthority('SUPER_ADMINISTRATOR') or hasAuthority('CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or @authorizationService.isMemberOf(#id)") @PreAuthorize("hasAuthority('SUPER_ADMINISTRATOR') or hasAuthority('CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or @authorizationService.isMemberOf(#id)")
public RepositoryInterface updateRepositoryInterface(@RequestParam("repoId") String id, public RepositoryInterface updateRepositoryInterface(@RequestParam("repoId") String id,
@RequestParam("registeredBy") String registeredBy,
@RequestParam(value = "comment", required = false) String comment, @RequestParam(value = "comment", required = false) String comment,
@RequestBody RepositoryInterface repositoryInterface) throws Exception { @RequestBody RepositoryInterface repositoryInterface) throws Exception {
return repositoryService.updateRepositoryInterface(id, registeredBy, comment, repositoryInterface); return repositoryService.updateRepositoryInterface(id, comment, repositoryInterface);
} }
@RequestMapping(value = "/getUrlsOfUserRepos/{page}/{size}/", method = RequestMethod.GET, @RequestMapping(value = "/getUrlsOfUserRepos/{page}/{size}/", method = RequestMethod.GET,

View File

@ -68,7 +68,6 @@ public interface RepositoryService {
RepositoryInterface addRepositoryInterface(String datatype, RepositoryInterface addRepositoryInterface(String datatype,
String repoId, String repoId,
String registeredBy,
String comment, RepositoryInterface repositoryInterface) throws Exception; String comment, RepositoryInterface repositoryInterface) throws Exception;
List<String> getDnetCountries(); List<String> getDnetCountries();
@ -93,6 +92,6 @@ public interface RepositoryService {
Map<String, String> getListLatestUpdate(String mode) throws JSONException; Map<String, String> getListLatestUpdate(String mode) throws JSONException;
RepositoryInterface updateRepositoryInterface(String repoId, String registeredBy, String comment, RepositoryInterface repositoryInterface) throws Exception; RepositoryInterface updateRepositoryInterface(String repoId, String comment, RepositoryInterface repositoryInterface) throws Exception;
} }

View File

@ -11,6 +11,7 @@ import eu.dnetlib.domain.enabling.Vocabulary;
import eu.dnetlib.domain.functionality.validator.JobForValidation; import eu.dnetlib.domain.functionality.validator.JobForValidation;
import eu.dnetlib.repo.manager.domain.*; import eu.dnetlib.repo.manager.domain.*;
import eu.dnetlib.repo.manager.domain.dto.Role; import eu.dnetlib.repo.manager.domain.dto.Role;
import eu.dnetlib.repo.manager.domain.dto.User;
import eu.dnetlib.repo.manager.exception.BrokerException; import eu.dnetlib.repo.manager.exception.BrokerException;
import eu.dnetlib.repo.manager.exception.RepositoryServiceException; import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException; import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
@ -653,8 +654,8 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override @Override
public RepositoryInterface addRepositoryInterface(String datatype, public RepositoryInterface addRepositoryInterface(String datatype,
String repoId, String repoId,
String registeredBy,
String comment, RepositoryInterface repositoryInterface) throws Exception { String comment, RepositoryInterface repositoryInterface) throws Exception {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Repository e = this.getRepositoryById(repoId); Repository e = this.getRepositoryById(repoId);
repositoryInterface = createRepositoryInterface(e, repositoryInterface, datatype); repositoryInterface = createRepositoryInterface(e, repositoryInterface, datatype);
// String json_interface = converter.toJson(e, repositoryInterface); // String json_interface = converter.toJson(e, repositoryInterface);
@ -669,22 +670,22 @@ public class RepositoryServiceImpl implements RepositoryService {
restTemplate.postForObject(uriComponents.toUri(), httpEntity, String.class); restTemplate.postForObject(uriComponents.toUri(), httpEntity, String.class);
try { try {
emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication()); emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication()); emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
} catch (Exception ex) { } catch (Exception ex) {
LOGGER.error("Error sending emails: " + ex); LOGGER.error("Error sending emails: " + ex);
} }
submitInterfaceValidation(e, registeredBy, repositoryInterface, false); submitInterfaceValidation(e, getAuthenticatedUser().getEmail(), repositoryInterface, false);
return repositoryInterface; return repositoryInterface;
} }
@Override @Override
public RepositoryInterface updateRepositoryInterface(String repoId, public RepositoryInterface updateRepositoryInterface(String repoId,
String registeredBy, String comment,
String comment, RepositoryInterface repositoryInterface) throws Exception { RepositoryInterface repositoryInterface) throws Exception {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
this.updateBaseUrl(repoId, repositoryInterface.getId(), repositoryInterface.getBaseurl()); this.updateBaseUrl(repoId, repositoryInterface.getId(), repositoryInterface.getBaseurl());
this.updateCompliance(repoId, repositoryInterface.getId(), repositoryInterface.getCompatibility()); this.updateCompliance(repoId, repositoryInterface.getId(), repositoryInterface.getCompatibility());
this.updateValidationSet(repoId, repositoryInterface.getId(), repositoryInterface.getAccessSet()); this.updateValidationSet(repoId, repositoryInterface.getId(), repositoryInterface.getAccessSet());
@ -692,8 +693,8 @@ public class RepositoryServiceImpl implements RepositoryService {
Repository repository = this.getRepositoryById(repoId); Repository repository = this.getRepositoryById(repoId);
try { try {
try { try {
emailUtils.sendAdminUpdateInterfaceEmail(repository, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication()); emailUtils.sendAdminUpdateInterfaceEmail(repository, comment, repositoryInterface, authentication);
emailUtils.sendUserUpdateInterfaceEmail(repository, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication()); emailUtils.sendUserUpdateInterfaceEmail(repository, comment, repositoryInterface, authentication);
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Error sending emails: " + e); LOGGER.error("Error sending emails: " + e);
} }
@ -701,11 +702,15 @@ public class RepositoryServiceImpl implements RepositoryService {
LOGGER.warn("Could not send emails", e); LOGGER.warn("Could not send emails", e);
} }
submitInterfaceValidation(getRepositoryById(repoId), registeredBy, repositoryInterface, true); submitInterfaceValidation(getRepositoryById(repoId), getAuthenticatedUser().getEmail(), repositoryInterface, true);
return repositoryInterface; return repositoryInterface;
} }
private User getAuthenticatedUser() {
return User.from(((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo());
}
private void submitInterfaceValidation(Repository repo, String userEmail, RepositoryInterface iFace, boolean updateExisting) throws ValidatorServiceException { private void submitInterfaceValidation(Repository repo, String userEmail, RepositoryInterface iFace, boolean updateExisting) throws ValidatorServiceException {
JobForValidation job = new JobForValidation(); JobForValidation job = new JobForValidation();

View File

@ -127,7 +127,7 @@ public class ValidatorServiceImpl implements ValidatorService {
} }
@Override @Override
@PreAuthorize("hasAuthority('REGISTERED_USER') and #jobForValidation.userEmail == authentication.userInfo.email") @PreAuthorize("hasAuthority('REGISTERED_USER') and @authorizationService.isMemberOf(#jobForValidation.datasourceId)")
public JobForValidation submitJobForValidation(JobForValidation jobForValidation) throws ValidatorServiceException { public JobForValidation submitJobForValidation(JobForValidation jobForValidation) throws ValidatorServiceException {
LOGGER.debug("Submit job for validation with id : " + jobForValidation.getDatasourceId()); LOGGER.debug("Submit job for validation with id : " + jobForValidation.getDatasourceId());
try { try {
@ -158,7 +158,6 @@ public class ValidatorServiceImpl implements ValidatorService {
} }
@Override @Override
@PreAuthorize("hasAuthority('REGISTERED_USER') and #email == authentication.userInfo.email")
public ResponseEntity<Object> reSubmitJobForValidation(String email, public ResponseEntity<Object> reSubmitJobForValidation(String email,
String jobId) throws JSONException, ValidatorServiceException { String jobId) throws JSONException, ValidatorServiceException {
LOGGER.debug("Resubmit validation job with id : " + jobId); LOGGER.debug("Resubmit validation job with id : " + jobId);