New mapping for RepositorySnippet + Using SecurityContext to get the email of user

This commit is contained in:
Ioannis Diplas 2019-12-18 10:04:22 +00:00
parent 33e3975de3
commit bf0bdf50c1
6 changed files with 50 additions and 2 deletions

View File

@ -7,10 +7,12 @@ import eu.dnetlib.repo.manager.service.BrokerServiceImpl;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import org.json.JSONException; import org.json.JSONException;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.io.IOException; import java.io.IOException;
@ -35,6 +37,7 @@ public class BrokerController{
@ApiParam(value = "Include shared datasources", required = true , defaultValue = "false") String includeShared, @ApiParam(value = "Include shared datasources", required = true , defaultValue = "false") String includeShared,
@RequestParam("includeByOthers") @RequestParam("includeByOthers")
@ApiParam(value = "Include datasources of other", required = true,defaultValue = "false") String includeByOthers) throws JSONException { @ApiParam(value = "Include datasources of other", required = true,defaultValue = "false") String includeByOthers) throws JSONException {
user = ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail();
return brokerService.getDatasourcesOfUser(user, includeShared, includeByOthers); return brokerService.getDatasourcesOfUser(user, includeShared, includeByOthers);
} }
@ -75,6 +78,7 @@ public class BrokerController{
@ResponseBody @ResponseBody
@PreAuthorize("hasRole('ROLE_USER')") @PreAuthorize("hasRole('ROLE_USER')")
public Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser(@PathVariable("userEmail") String userEmail) throws BrokerException{ public Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser(@PathVariable("userEmail") String userEmail) throws BrokerException{
userEmail = ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail();
return brokerService.getSimpleSubscriptionsOfUser(userEmail); return brokerService.getSimpleSubscriptionsOfUser(userEmail);
} }

View File

@ -7,9 +7,11 @@ import eu.dnetlib.repo.manager.service.PiWikService;
import eu.dnetlib.repo.manager.service.RepositoryService; import eu.dnetlib.repo.manager.service.RepositoryService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import org.json.JSONException; import org.json.JSONException;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
@ -38,6 +40,7 @@ public class DashboardController {
public List<RepositorySummaryInfo> getRepositoriesSummaryInfo(@PathVariable("userEmail") String userEmail, public List<RepositorySummaryInfo> getRepositoriesSummaryInfo(@PathVariable("userEmail") String userEmail,
@PathVariable("page") String page, @PathVariable("page") String page,
@PathVariable("size") String size) throws JSONException { @PathVariable("size") String size) throws JSONException {
userEmail = ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail();
return dashboardService.getRepositoriesSummaryInfo(userEmail, page, size); return dashboardService.getRepositoriesSummaryInfo(userEmail, page, size);
} }
@ -84,6 +87,7 @@ public class DashboardController {
public BrokerSummary getBrokerSummary( public BrokerSummary getBrokerSummary(
@PathVariable("email") String email, @PathVariable("email") String email,
@PathVariable("ds_name") String datasourceName) throws BrokerException { @PathVariable("ds_name") String datasourceName) throws BrokerException {
email = ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail();
return new BrokerSummary(brokerService.getSimpleSubscriptionsOfUser(email), brokerService.getTopicsForDatasource(datasourceName)); return new BrokerSummary(brokerService.getSimpleSubscriptionsOfUser(email), brokerService.getTopicsForDatasource(datasourceName));
} }

View File

@ -8,9 +8,11 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.json.JSONException; import org.json.JSONException;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@RestController @RestController
@ -37,7 +39,7 @@ public class MonitorController {
@RequestParam(value = "dateTo", required = false) @ApiParam(value = "Null value") String dateTo, @RequestParam(value = "dateTo", required = false) @ApiParam(value = "Null value") String dateTo,
@RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs", required = false) String validationStatus, @RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs", required = false) String validationStatus,
@RequestParam("includeJobsTotal") @ApiParam(value = "Always true", required = true) String includeJobsTotal) throws JSONException, ValidatorServiceException { @RequestParam("includeJobsTotal") @ApiParam(value = "Always true", required = true) String includeJobsTotal) throws JSONException, ValidatorServiceException {
user = ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail();
return monitorService.getJobsOfUser(user, jobType, offset, limit, dateFrom, dateTo, validationStatus, includeJobsTotal); return monitorService.getJobsOfUser(user, jobType, offset, limit, dateFrom, dateTo, validationStatus, includeJobsTotal);
} }
@ -47,6 +49,7 @@ public class MonitorController {
public int getJobsOfUserPerValidationStatus(@RequestBody String user, public int getJobsOfUserPerValidationStatus(@RequestBody String user,
@RequestBody String jobType, @RequestBody String jobType,
@RequestBody String validationStatus) throws JSONException { @RequestBody String validationStatus) throws JSONException {
user = ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail();
return monitorService.getJobsOfUserPerValidationStatus(user, jobType, validationStatus); return monitorService.getJobsOfUserPerValidationStatus(user, jobType, validationStatus);
} }

View File

@ -8,11 +8,13 @@ import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.service.RepositoryServiceImpl; import eu.dnetlib.repo.manager.service.RepositoryServiceImpl;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import org.json.JSONException; import org.json.JSONException;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PostAuthorize; import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.io.IOException; import java.io.IOException;
@ -49,6 +51,7 @@ public class RepositoryController {
public List<RepositorySnippet> getRepositoriesOfUser(@PathVariable("userEmail") String userEmail, public List<RepositorySnippet> getRepositoriesOfUser(@PathVariable("userEmail") String userEmail,
@PathVariable("page") String page, @PathVariable("page") String page,
@PathVariable("size") String size) throws JSONException, IOException { @PathVariable("size") String size) throws JSONException, IOException {
userEmail = ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail();
return repositoryService.getRepositoriesSnippetOfUser(userEmail, page, size); return repositoryService.getRepositoriesSnippetOfUser(userEmail, page, size);
} }
@ -172,6 +175,7 @@ public class RepositoryController {
public List<String> getUrlsOfUserRepos(@PathVariable("user_email") String userEmail, public List<String> getUrlsOfUserRepos(@PathVariable("user_email") String userEmail,
@PathVariable("page") String page, @PathVariable("page") String page,
@PathVariable("size") String size) throws JSONException { @PathVariable("size") String size) throws JSONException {
userEmail = ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail();
return repositoryService.getUrlsOfUserRepos(userEmail, page, size); return repositoryService.getUrlsOfUserRepos(userEmail, page, size);
} }

View File

@ -12,10 +12,12 @@ import eu.dnetlib.repo.manager.service.ValidatorServiceImpl;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import org.json.JSONException; import org.json.JSONException;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
@ -45,9 +47,10 @@ public class ValidatorController {
consumes = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE) produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
@PreAuthorize("hasRole('ROLE_USER') and #email == authentication.userInfo.email") @PreAuthorize("hasRole('ROLE_USER')")
public ResponseEntity<Object> reSubmitJobForValidation(@PathVariable("email") String email, public ResponseEntity<Object> reSubmitJobForValidation(@PathVariable("email") String email,
@PathVariable("jobId") String jobId) throws JSONException, ValidatorServiceException { @PathVariable("jobId") String jobId) throws JSONException, ValidatorServiceException {
email = ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail();
return validatorService.reSubmitJobForValidation(email, jobId); return validatorService.reSubmitJobForValidation(email, jobId);
} }
@ -87,6 +90,7 @@ public class ValidatorController {
@RequestParam(value = "dateTo", required = false) @ApiParam(value = "Null value") String dateTo, @RequestParam(value = "dateTo", required = false) @ApiParam(value = "Null value") String dateTo,
@RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs", required = true) String validationStatus @RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs", required = true) String validationStatus
) throws ValidatorServiceException { ) throws ValidatorServiceException {
user = ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail();
return validatorService.getStoredJobsNew(user, jobType, offset, limit, dateFrom, dateTo, validationStatus); return validatorService.getStoredJobsNew(user, jobType, offset, limit, dateFrom, dateTo, validationStatus);
} }

View File

@ -3,6 +3,8 @@ package eu.dnetlib.repo.manager.domain;
import eu.dnetlib.domain.data.PiwikInfo; import eu.dnetlib.domain.data.PiwikInfo;
import java.util.Date;
public class RepositorySnippet { public class RepositorySnippet {
private String id; private String id;
@ -15,6 +17,9 @@ public class RepositorySnippet {
private String registrationdate; private String registrationdate;
private String logoUrl; private String logoUrl;
private String description; private String description;
private String fullTextDownload;
private String consentTermsOfUse;
private Date consentTermsOfUseDate;
private PiwikInfo piwikInfo; private PiwikInfo piwikInfo;
@ -108,4 +113,28 @@ public class RepositorySnippet {
public void setDescription(String description) { public void setDescription(String description) {
this.description = description; this.description = description;
} }
public String getFullTextDownload() {
return fullTextDownload;
}
public void setFullTextDownload(String fullTextDownload) {
this.fullTextDownload = fullTextDownload;
}
public String getConsentTermsOfUse() {
return consentTermsOfUse;
}
public void setConsentTermsOfUse(String consentTermsOfUse) {
this.consentTermsOfUse = consentTermsOfUse;
}
public Date getConsentTermsOfUseDate() {
return consentTermsOfUseDate;
}
public void setConsentTermsOfUseDate(Date consentTermsOfUseDate) {
this.consentTermsOfUseDate = consentTermsOfUseDate;
}
} }