org.apache.kafka.common.errors.AuthorizationException Java Examples

The following examples show how to use org.apache.kafka.common.errors.AuthorizationException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KafkaExceptionMapper.java    From rest-utils with Apache License 2.0 6 votes vote down vote up
private Response handleException(final Throwable exception) {
  if (exception instanceof AuthenticationException) {
    return getResponse(exception, Status.UNAUTHORIZED,
        KAFKA_AUTHENTICATION_ERROR_CODE);
  } else if (exception instanceof AuthorizationException) {
    return getResponse(exception, Status.FORBIDDEN,
        KAFKA_AUTHORIZATION_ERROR_CODE);
  } else if (HANDLED.containsKey(exception.getClass())) {
    return getResponse(exception);
  } else if (exception instanceof RetriableException) {
    log.debug("Kafka retriable exception", exception);
    return getResponse(exception, Status.INTERNAL_SERVER_ERROR,
        KAFKA_RETRIABLE_ERROR_ERROR_CODE);
  } else if (exception instanceof KafkaException) {
    log.error("Kafka exception", exception);
    return getResponse(exception, Status.INTERNAL_SERVER_ERROR,
        KAFKA_ERROR_ERROR_CODE);
  } else if (exception instanceof InvalidFormatException) {
    return getResponse(exception, Status.BAD_REQUEST,
        KAFKA_BAD_REQUEST_ERROR_CODE);
  } else {
    log.error("Unhandled exception", exception);
    return super.toResponse(exception);
  }
}
 
Example #2
Source File: KafkaExceptionMapperTest.java    From rest-utils with Apache License 2.0 5 votes vote down vote up
@Test
public void testAuthorizationExceptions() {
  verifyMapperResponse(new AuthorizationException("some message"), Status.FORBIDDEN,
      KAFKA_AUTHORIZATION_ERROR_CODE);
  verifyMapperResponse(new ClusterAuthorizationException("some message"), Status.FORBIDDEN,
      KAFKA_AUTHORIZATION_ERROR_CODE);
  verifyMapperResponse(new DelegationTokenAuthorizationException("some message"), Status.FORBIDDEN,
      KAFKA_AUTHORIZATION_ERROR_CODE);
  verifyMapperResponse(new GroupAuthorizationException("some message"), Status.FORBIDDEN,
      KAFKA_AUTHORIZATION_ERROR_CODE);
  verifyMapperResponse(new TopicAuthorizationException("some message"), Status.FORBIDDEN,
      KAFKA_AUTHORIZATION_ERROR_CODE);
  verifyMapperResponse(new TransactionalIdAuthorizationException("some message"), Status.FORBIDDEN,
      KAFKA_AUTHORIZATION_ERROR_CODE);
}
 
Example #3
Source File: AsyncProducer.java    From apicurio-registry with Apache License 2.0 4 votes vote down vote up
private boolean isFatalException(Exception e) {
    return e instanceof UnsupportedVersionException ||
           e instanceof AuthorizationException ||
           e instanceof ProducerFencedException ||
           e instanceof OutOfOrderSequenceException;
}