Skip to content

Commit

Permalink
added authorization check for license bitstream in OAI import
Browse files Browse the repository at this point in the history
  • Loading branch information
nwoodward committed Sep 18, 2023
1 parent 1d4c441 commit 4917bad
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions dspace-oai/src/main/java/org/dspace/xoai/util/ItemUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.dspace.app.util.factory.UtilServiceFactory;
import org.dspace.app.util.service.MetadataExposureService;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.factory.AuthorizeServiceFactory;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.content.Bitstream;
import org.dspace.content.Bundle;
import org.dspace.content.Item;
Expand Down Expand Up @@ -59,6 +61,10 @@ public class ItemUtils {

private static final ConfigurationService configurationService
= DSpaceServicesFactory.getInstance().getConfigurationService();

private static final AuthorizeService authorizeService
= AuthorizeServiceFactory.getInstance().getAuthorizeService();

/**
* Default constructor
*/
Expand Down Expand Up @@ -163,13 +169,17 @@ private static Element createLicenseElement(Context context, Item item)
List<Bitstream> licBits = licBundle.getBitstreams();
if (!licBits.isEmpty()) {
Bitstream licBit = licBits.get(0);
InputStream in;

in = bitstreamService.retrieve(context, licBit);
ByteArrayOutputStream out = new ByteArrayOutputStream();
Utils.bufferedCopy(in, out);
license.getField().add(createValue("bin", Base64Utils.encode(out.toString())));

if (authorizeService.authorizeActionBoolean(context, licBit, Constants.READ)) {
InputStream in;

in = bitstreamService.retrieve(context, licBit);
ByteArrayOutputStream out = new ByteArrayOutputStream();
Utils.bufferedCopy(in, out);
license.getField().add(createValue("bin", Base64Utils.encode(out.toString())));
} else {
log.info("Missing READ rights for license bitstream. Did not include license bitstream for item: "
+ item.getID() + ".");
}
}
}
return license;
Expand Down

0 comments on commit 4917bad

Please sign in to comment.