2626import org .dspace .content .DSpaceObject ;
2727import org .dspace .content .Item ;
2828import org .dspace .content .service .BitstreamService ;
29- import org .dspace .core .Constants ;
3029import org .dspace .core .Context ;
3130import org .dspace .handle .service .HandleService ;
3231import org .springframework .beans .factory .annotation .Autowired ;
3332import org .springframework .http .HttpHeaders ;
3433import org .springframework .security .access .AccessDeniedException ;
34+ import org .springframework .security .access .prepost .PreAuthorize ;
3535import org .springframework .web .bind .annotation .GetMapping ;
3636import org .springframework .web .bind .annotation .PathVariable ;
3737import org .springframework .web .bind .annotation .RequestMapping ;
@@ -77,6 +77,7 @@ public class MetadataBitstreamController {
7777 * @throws UnprocessableEntityException if the handle does not resolve to a valid Item
7878 * or if the bitstream with the specified name is not found
7979 */
80+ @ PreAuthorize ("hasPermission(#handleId, 'ITEM', 'READ')" )
8081 @ GetMapping ("/handle/{prefix}/{suffix}/{name:.+}" )
8182 public void downloadBitstreamByName (
8283 @ PathVariable String prefix ,
@@ -101,11 +102,6 @@ public void downloadBitstreamByName(
101102
102103 Item item = (Item ) dso ;
103104
104- // Check READ permission on the actual Item object
105- if (!authorizeService .authorizeActionBoolean (context , item , Constants .READ )) {
106- throw new AuthorizeException ("User does not have permission to read Item: " + item .getHandle ());
107- }
108-
109105 Bitstream targetBitstream = findBitstreamByName (item , name );
110106
111107 if (Objects .isNull (targetBitstream )) {
@@ -118,8 +114,8 @@ public void downloadBitstreamByName(
118114 .map (fmt -> fmt .getMIMEType ())
119115 .orElse ("application/octet-stream" );
120116
121- // Set content type without charset to match test expectations
122- response .setHeader ( HttpHeaders . CONTENT_TYPE , mime );
117+ // Set content type (tests use startsWith to tolerate charset if appended)
118+ response .setContentType ( mime );
123119
124120 org .springframework .http .ContentDisposition cd =
125121 org .springframework .http .ContentDisposition .attachment ()
0 commit comments