Skip to content

Commit

Permalink
Merged in task/dspace-cris-2023_02_x/LM-46 (pull request DSpace#2398)
Browse files Browse the repository at this point in the history
[LM-46] first set of changes for login miur properties
  • Loading branch information
steph-ieffam committed Aug 16, 2024
2 parents 108cff6 + 3ded519 commit ef6d2c4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
*/
package org.dspace.app.rest.repository;

import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;

import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException;
import org.dspace.app.rest.model.PropertyRest;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.core.Context;
import org.dspace.services.ConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -27,13 +29,19 @@
@Component(PropertyRest.CATEGORY + "." + PropertyRest.NAME)
public class ConfigurationRestRepository extends DSpaceRestRepository<PropertyRest, String> {

@Autowired
private AuthorizeService authorizeService;

private ConfigurationService configurationService;
private List<String> exposedProperties;
private List<String> adminRestrictedProperties;

@Autowired
public ConfigurationRestRepository(ConfigurationService configurationService) {
this.configurationService = configurationService;
this.exposedProperties = Arrays.asList(configurationService.getArrayProperty("rest.properties.exposed"));
this.adminRestrictedProperties =
Arrays.asList(configurationService.getArrayProperty("admin.rest.properties.exposed"));
}

/**
Expand All @@ -54,16 +62,27 @@ public ConfigurationRestRepository(ConfigurationService configurationService) {
@Override
@PreAuthorize("permitAll()")
public PropertyRest findOne(Context context, String property) {
if (!exposedProperties.contains(property) || !configurationService.hasProperty(property)) {
if ((!exposedProperties.contains(property) && !isCurrentUserAdmin(context))
|| !configurationService.hasProperty(property)
|| (isCurrentUserAdmin(context) && !adminRestrictedProperties.contains(property))) {
throw new ResourceNotFoundException("No such configuration property: " + property);
}

String[] propertyValues = configurationService.getArrayProperty(property);
PropertyRest propertyRest = new PropertyRest();
propertyRest.setName(property);
propertyRest.setValues(Arrays.asList(propertyValues));
return propertyRest;
}

private boolean isCurrentUserAdmin(Context context) {
try {
return authorizeService.isAdmin(context);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}

@Override
public Page<PropertyRest> findAll(Context context, Pageable pageable) {
throw new RepositoryMethodNotImplementedException("No implementation found; Method not allowed", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ public void getNonExposedValue() throws Exception {
.andExpect(status().isNotFound());
}

@Test
public void getAdminRestrictedValue() throws Exception {
getClient().perform(get("/api/config/properties/loginmiur.dlexporter.url"))
.andExpect(status().isNotFound());
}

@Test
public void getAdminRestrictedValueRetrieved() throws Exception {
String tokenAdmin = getAuthToken(admin.getEmail(), password);
getClient(tokenAdmin).perform(get("/api/config/properties/loginmiur.dlexporter.url"))
.andExpect(status().is2xxSuccessful());
}

@Test
public void getAll() throws Exception {
getClient().perform(get("/api/config/properties/"))
Expand Down
4 changes: 4 additions & 0 deletions dspace/config/dspace.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,10 @@ webui.browse.link.1 = author:dc.contributor.*
### ANCE REQUEST JOURNALS ENDPOINT
#ance.webservice.addjournal.endpoint = https://webservice.cineca.it/pubblicazioni

### DLExporter URL
loginmiur.dlexporter.accesstoken =
loginmiur.dlexporter.url = /dlexporter?accessToken=${loginmiur.dlexporter.accesstoken}


### i18n - Locales / Language ####
# Default Locale
Expand Down
3 changes: 3 additions & 0 deletions dspace/config/modules/rest.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ rest.properties.exposed = identifiers.item-status.register-doi
rest.properties.exposed = authentication-password.domain.valid
rest.properties.exposed = request.item.type
rest.properties.exposed = handle.canonical.prefix
admin.rest.properties.exposed = loginmiur.dlexporter.url
admin.rest.properties.exposed = loginmiur.dlexporter.accesstoken

#------------------------------------------------------------------#
#------------DEDUPLICATION / DATAQUALITY CONFIGURATIONS------------#
#------------------------------------------------------------------#
Expand Down

0 comments on commit ef6d2c4

Please sign in to comment.