Skip to content

Commit

Permalink
Fix authz issue on epersons endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
abollini committed Jun 1, 2018
1 parent 07b4926 commit 1d7efbd
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import java.util.UUID;

import org.dspace.app.rest.converter.EPersonConverter;
import org.dspace.app.rest.exception.RESTAuthorizationException;
import org.dspace.app.rest.model.EPersonRest;
import org.dspace.app.rest.model.hateoas.EPersonResource;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
import org.dspace.eperson.factory.EPersonServiceFactory;
Expand All @@ -33,6 +35,9 @@
@Component(EPersonRest.CATEGORY + "." + EPersonRest.NAME)
public class EPersonRestRepository extends DSpaceRestRepository<EPersonRest, UUID> {
EPersonService es = EPersonServiceFactory.getInstance().getEPersonService();

@Autowired
AuthorizeService authorizeService;

@Autowired
EPersonConverter converter;
Expand All @@ -56,6 +61,10 @@ public Page<EPersonRest> findAll(Context context, Pageable pageable) {
List<EPerson> epersons = null;
int total = 0;
try {
if (!authorizeService.isAdmin(context)) {
throw new RESTAuthorizationException(
"The EPerson collection endpoint is reserved to system administrators");
}
total = es.countTotal(context);
epersons = es.findAll(context, EPerson.ID, pageable.getPageSize(), pageable.getOffset());
} catch (SQLException e) {
Expand Down

0 comments on commit 1d7efbd

Please sign in to comment.