Skip to content

Commit

Permalink
Add auth-check to look-up by Handle
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdietz committed Oct 18, 2013
1 parent 8900a83 commit 9949350
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions dspace-rest/src/main/java/org/dspace/rest/HandleResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package org.dspace.rest;

import org.apache.log4j.Logger;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.handle.HandleManager;
Expand Down Expand Up @@ -50,15 +51,19 @@ public org.dspace.rest.common.DSpaceObject getObject(@PathParam("prefix") String
}
log.info("DSO Lookup by handle: [" + prefix + "] / [" + suffix + "] got result of: " + dso.getTypeText() + "_" + dso.getID());

switch(dso.getType()) {
case Constants.COMMUNITY:
return new Community((org.dspace.content.Community) dso, expand, context);
case Constants.COLLECTION:
return new Collection((org.dspace.content.Collection) dso, expand, context, null, null);
case Constants.ITEM:
return new Item((org.dspace.content.Item) dso, expand, context);
default:
return new DSpaceObject(dso);
if(AuthorizeManager.authorizeActionBoolean(context, dso, org.dspace.core.Constants.READ)) {
switch(dso.getType()) {
case Constants.COMMUNITY:
return new Community((org.dspace.content.Community) dso, expand, context);
case Constants.COLLECTION:
return new Collection((org.dspace.content.Collection) dso, expand, context, null, null);
case Constants.ITEM:
return new Item((org.dspace.content.Item) dso, expand, context);
default:
return new DSpaceObject(dso);
}
} else {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
} catch (SQLException e) {
log.error(e.getMessage());
Expand Down

0 comments on commit 9949350

Please sign in to comment.