created repository metrics calls and excluded them from authentication

This commit is contained in:
Konstantinos Spyrou 2023-10-11 14:45:53 +03:00
parent 5138605163
commit 4b5132358a
3 changed files with 32 additions and 11 deletions

View File

@ -63,6 +63,7 @@ public class AaiSecurityConfiguration extends WebSecurityConfigurerAdapter {
.csrf().disable() .csrf().disable()
.authorizeRequests() .authorizeRequests()
.regexMatchers("/actuator/.*").permitAll() .regexMatchers("/actuator/.*").permitAll()
.regexMatchers("/repository/.*/metrics/?.*").permitAll()
.regexMatchers("/metrics").permitAll() .regexMatchers("/metrics").permitAll()
.antMatchers("/api-docs/**","/swagger-ui/**").permitAll() .antMatchers("/api-docs/**","/swagger-ui/**").permitAll()
.anyRequest().authenticated() .anyRequest().authenticated()

View File

@ -39,16 +39,6 @@ public class PiWikController {
@Autowired @Autowired
private PiWikServiceImpl piWikService; private PiWikServiceImpl piWikService;
@RequestMapping(value = "/validated", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Boolean isPiwikValidated(@RequestParam("repositoryId") String repositoryId) {
PiwikInfo info = piWikService.getPiwikSiteForRepo(repositoryId);
if (info != null) {
return info.isValidated();
}
return false;
}
@RequestMapping(value = "/getPiwikSiteForRepo/{repositoryId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/getPiwikSiteForRepo/{repositoryId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
@PreAuthorize("hasAnyAuthority('SUPER_ADMINISTRATOR', 'CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or @authorizationService.isMemberOf(#repositoryId) or (@repositoryService.getRepositoryById(#repositoryId).registeredby==null and hasAuthority('REGISTERED_USER'))") @PreAuthorize("hasAnyAuthority('SUPER_ADMINISTRATOR', 'CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or @authorizationService.isMemberOf(#repositoryId) or (@repositoryService.getRepositoryById(#repositoryId).registeredby==null and hasAuthority('REGISTERED_USER'))")

View File

@ -1,5 +1,6 @@
package eu.dnetlib.repo.manager.controllers; package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.domain.data.PiwikInfo;
import eu.dnetlib.enabling.datasources.common.AggregationInfo; import eu.dnetlib.enabling.datasources.common.AggregationInfo;
import eu.dnetlib.repo.manager.domain.*; import eu.dnetlib.repo.manager.domain.*;
import eu.dnetlib.repo.manager.domain.dto.RepositoryTerms; import eu.dnetlib.repo.manager.domain.dto.RepositoryTerms;
@ -7,6 +8,8 @@ import eu.dnetlib.repo.manager.domain.dto.User;
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;
import eu.dnetlib.repo.manager.service.AggregationService; import eu.dnetlib.repo.manager.service.AggregationService;
import eu.dnetlib.repo.manager.service.PiWikService;
import eu.dnetlib.repo.manager.service.PiWikServiceImpl;
import eu.dnetlib.repo.manager.service.RepositoryService; import eu.dnetlib.repo.manager.service.RepositoryService;
import eu.dnetlib.repo.manager.service.security.AuthorizationService; import eu.dnetlib.repo.manager.service.security.AuthorizationService;
import eu.dnetlib.repo.manager.utils.JsonUtils; import eu.dnetlib.repo.manager.utils.JsonUtils;
@ -43,12 +46,17 @@ public class RepositoryController {
private final AuthorizationService authorizationService; private final AuthorizationService authorizationService;
private final PiWikService piWikService;
@Autowired @Autowired
RepositoryController(RepositoryService repositoryService, RepositoryController(RepositoryService repositoryService,
AggregationService aggregationService, AuthorizationService authorizationService) { AggregationService aggregationService,
AuthorizationService authorizationService,
PiWikService piWikService) {
this.repositoryService = repositoryService; this.repositoryService = repositoryService;
this.aggregationService = aggregationService; this.aggregationService = aggregationService;
this.authorizationService = authorizationService; this.authorizationService = authorizationService;
this.piWikService = piWikService;
} }
@RequestMapping(value = "/countries", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/countries", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ -295,4 +303,26 @@ public class RepositoryController {
authorizationService.removeAdmin(id, email); authorizationService.removeAdmin(id, email);
return new ResponseEntity<>(HttpStatus.NO_CONTENT); return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} }
///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Returns whether the Piwik Site of a repository is enabled and validated.
*/
@RequestMapping(value = "{repositoryId}/metrics/valid", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public boolean getMetricsEnabledAndValidated(@PathVariable("repositoryId") String repositoryId) {
PiwikInfo info = piWikService.getPiwikSiteForRepo(repositoryId);
return info != null && info.isValidated();
}
/**
* Returns repository Metrics.
*/
@RequestMapping(value = "{repositoryId}/metrics", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public MetricsInfo getMetricsInfo(@PathVariable("repositoryId") String id) throws RepositoryServiceException {
return repositoryService.getMetricsInfoForRepository(id);
}
} }