/* The contents of this file are subject to the license and copyright terms
* detailed in the license directory at the root of the source tree (also
* available online at http://fedora-commons.org/license/).
*/
package org.fcrepo.server.security.xacml.pep.rest.objectshandlers;
import java.io.IOException;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.fcrepo.common.Constants;
import org.fcrepo.server.security.RequestCtx;
import org.fcrepo.server.security.xacml.pep.PEPException;
import org.fcrepo.server.security.xacml.pep.ResourceAttributes;
import org.fcrepo.server.security.xacml.pep.rest.filters.AbstractFilter;
import org.fcrepo.server.security.xacml.util.LogUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.jboss.security.xacml.sunxacml.attr.AttributeValue;
/**
* Handles REST API method getDatastreamHistory
*
* @author Stephen Bayliss
* @version $$Id$$
*/
public class GetDatastreamHistory
extends AbstractFilter {
public GetDatastreamHistory()
throws PEPException {
super();
}
private static final Logger logger =
LoggerFactory.getLogger(GetDatastreamHistory.class);
@Override
public RequestCtx handleRequest(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
if (logger.isDebugEnabled()) {
logger.debug("{}/handleRequest!", this.getClass().getName());
}
String[] parts = getPathParts(request);
// -/objects/{pid}/datastreams/{dsID}/history
if (parts.length < 5) {
logger.error("Not enough path components on the URI: {}", request.getRequestURI());
throw new ServletException("Not enough path components on the URI: " + request.getRequestURI());
}
RequestCtx req = null;
Map<URI, AttributeValue> actions = new HashMap<URI, AttributeValue>();
Map<URI, AttributeValue> resAttr;
try {
resAttr = ResourceAttributes.getResources(parts);
actions.put(Constants.ACTION.ID.getURI(),
Constants.ACTION.GET_DATASTREAM_HISTORY
.getStringAttribute());
actions.put(Constants.ACTION.API.getURI(),
Constants.ACTION.APIM.getStringAttribute());
req =
getContextHandler().buildRequest(getSubjects(request),
actions,
resAttr,
getEnvironment(request));
LogUtil.statLog(request.getRemoteUser(),
Constants.ACTION.GET_DATASTREAM_HISTORY.uri,
parts[1],
parts[3]);
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new ServletException(e.getMessage(), e);
}
return req;
}
}