Skip to content

Commit

Permalink
Merge pull request DSpace#9080 from TexasDigitalLibrary/DS-4414
Browse files Browse the repository at this point in the history
DS-4414: adds authorization check for license bitstream in OAI import
  • Loading branch information
tdonohue authored Nov 2, 2023
2 parents bb72aeb + 4917bad commit af2ede3
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 af2ede3

Please sign in to comment.