private static String serverErrorToString(TSentryResponseStatus thriftStatus) { String msg = thriftStatus.getMessage(); String stack = thriftStatus.getStack(); if (stack == null) { return msg; } return msg + ". Server Stacktrace: " + stack; } }
private static String serverErrorToString(TSentryResponseStatus thriftStatus) { String msg = thriftStatus.getMessage(); String stack = thriftStatus.getStack(); if (stack == null) { return msg; } return msg + ". Server Stacktrace: " + stack; } }
public Object getFieldValue(_Fields field) { switch (field) { case VALUE: return Integer.valueOf(getValue()); case MESSAGE: return getMessage(); case STACK: return getStack(); } throw new IllegalStateException(); }
public Object getFieldValue(_Fields field) { switch (field) { case VALUE: return getValue(); case MESSAGE: return getMessage(); case STACK: return getStack(); } throw new IllegalStateException(); }
public static void throwIfNotOk(TSentryResponseStatus thriftStatus) throws SentryUserException { Status status = Status.fromCode(thriftStatus.getValue()); switch(status) { case OK: break; case ALREADY_EXISTS: throw new SentryAlreadyExistsException(serverErrorToString(thriftStatus), thriftStatus.getMessage()); case NO_SUCH_OBJECT: throw new SentryNoSuchObjectException(serverErrorToString(thriftStatus), thriftStatus.getMessage()); case RUNTIME_ERROR: throw new RuntimeException(serverErrorToString(thriftStatus)); case INVALID_INPUT: throw new SentryInvalidInputException(serverErrorToString(thriftStatus), thriftStatus.getMessage()); case ACCESS_DENIED: throw new SentryAccessDeniedException(serverErrorToString(thriftStatus), thriftStatus.getMessage()); case THRIFT_VERSION_MISMATCH: throw new SentryThriftAPIMismatchException(serverErrorToString(thriftStatus), thriftStatus.getMessage()); case UNKNOWN: throw new AssertionError(serverErrorToString(thriftStatus)); default: throw new AssertionError("Unknown status code: " + status + ". Msg: " + serverErrorToString(thriftStatus)); } }
public static void throwIfNotOk(TSentryResponseStatus thriftStatus) throws SentryUserException { Status status = Status.fromCode(thriftStatus.getValue()); switch(status) { case OK: break; case ALREADY_EXISTS: throw new SentryAlreadyExistsException(serverErrorToString(thriftStatus), thriftStatus.getMessage()); case NO_SUCH_OBJECT: throw new SentryNoSuchObjectException(serverErrorToString(thriftStatus), thriftStatus.getMessage()); case RUNTIME_ERROR: throw new RuntimeException(serverErrorToString(thriftStatus)); case INVALID_INPUT: throw new SentryInvalidInputException(serverErrorToString(thriftStatus), thriftStatus.getMessage()); case ACCESS_DENIED: throw new SentryAccessDeniedException(serverErrorToString(thriftStatus), thriftStatus.getMessage()); case THRIFT_VERSION_MISMATCH: throw new SentryThriftAPIMismatchException(serverErrorToString(thriftStatus), thriftStatus.getMessage()); case UNKNOWN: throw new AssertionError(serverErrorToString(thriftStatus)); default: throw new AssertionError("Unknown status code: " + status + ". Msg: " + serverErrorToString(thriftStatus)); } }
protected static void assertStatus(Status status, TSentryResponseStatus resp) { if (resp.getValue() != status.getCode()) { String message = "Expected: " + status + ", Response: " + Status.fromCode(resp.getValue()) + ", Code: " + resp.getValue() + ", Message: " + resp.getMessage(); String stackTrace = Strings.nullToEmpty(resp.getStack()).trim(); if (!stackTrace.isEmpty()) { message += ", StackTrace: " + stackTrace; } Assert.fail(message); } }
protected static void assertStatus(Status status, TSentryResponseStatus resp) { if (resp.getValue() != status.getCode()) { String message = "Expected: " + status + ", Response: " + Status.fromCode(resp.getValue()) + ", Code: " + resp.getValue() + ", Message: " + resp.getMessage(); String stackTrace = Strings.nullToEmpty(resp.getStack()).trim(); if (!stackTrace.isEmpty()) { message += ", StackTrace: " + stackTrace; } Assert.fail(message); } }
Status.ACCESS_DENIED.getCode(), response.getStatus().getValue()); assertTrue("ALTER privileges should not be permitted", response.getStatus().getMessage().contains("ALTER")); Assert.assertFalse("SELECT privileges should be permitted", response.getStatus().getMessage().contains("SELECT"));