001/*
002 * The contents of this file are subject to the license and copyright
003 * detailed in the LICENSE and NOTICE files at the root of the source
004 * tree.
005 */
006package org.fcrepo.http.commons.exceptionhandlers;
007
008import static javax.ws.rs.core.Response.status;
009import static javax.ws.rs.core.Response.Status.FORBIDDEN;
010
011import javax.ws.rs.core.Response;
012import javax.ws.rs.ext.ExceptionMapper;
013import javax.ws.rs.ext.Provider;
014
015import org.fcrepo.kernel.api.exception.AccessDeniedException;
016import org.slf4j.Logger;
017import org.slf4j.LoggerFactory;
018
019/**
020 * @author fasseg
021 */
022@Provider
023public class AccessDeniedExceptionMapper implements
024        ExceptionMapper<AccessDeniedException>, ExceptionDebugLogging {
025
026    private static final Logger LOGGER = LoggerFactory
027            .getLogger(AccessDeniedExceptionMapper.class);
028
029    /*
030     * (non-Javadoc)
031     * @see javax.ws.rs.ext.ExceptionMapper#toResponse(java.lang.Throwable)
032     */
033    @Override
034    public Response toResponse(final AccessDeniedException e) {
035        debugException(this, e, LOGGER);
036        return status(FORBIDDEN).build();
037    }
038}