All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.crnk.spring.internal.AccessDeniedExceptionMapper Maven / Gradle / Ivy

package io.crnk.spring.internal;

import io.crnk.core.engine.error.ErrorResponse;
import io.crnk.core.engine.error.ExceptionMapper;
import io.crnk.core.engine.error.ExceptionMapperHelper;
import io.crnk.core.engine.http.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.AccessDeniedException;

/**
 * Mapper class for Spring AccessDeniedExceptions.
 */
public class AccessDeniedExceptionMapper implements ExceptionMapper {

	private static final Logger LOGGER = LoggerFactory.getLogger(AccessDeniedException.class);

	private static final String META_TYPE_VALUE = "AccessDeniedException";

	private static final int ACCESS_DENIED = HttpStatus.FORBIDDEN_403;

	@Override
	public ErrorResponse toErrorResponse(AccessDeniedException exception) {
		LOGGER.warn("access was denied", exception);
		return ExceptionMapperHelper.toErrorResponse(exception, ACCESS_DENIED, META_TYPE_VALUE);
	}

	@Override
	public AccessDeniedException fromErrorResponse(ErrorResponse errorResponse) {
		return new AccessDeniedException(ExceptionMapperHelper.createErrorMessage(errorResponse));
	}

	@Override
	public boolean accepts(ErrorResponse errorResponse) {
		return ExceptionMapperHelper.accepts(errorResponse, ACCESS_DENIED, META_TYPE_VALUE);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy