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(); }
private Status fromTSentryStatus(TSentryResponseStatus status) { return Status.fromCode(status.getValue()); }
private Status fromTSentryStatus(TSentryResponseStatus status) { return Status.fromCode(status.getValue()); }
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); } }
@Override public TCreateSentryRoleResponse create_sentry_role( final TCreateSentryRoleRequest request) throws TException { Response<Void> respose = requestHandle(new RequestHandler<Void>() { @Override public Response<Void> handle() throws Exception { validateClientVersion(request.getProtocol_version()); authorize(request.getRequestorUserName(), getRequestorGroups(conf, request.getRequestorUserName())); CommitContext context = store.createRole(request.getComponent(), request.getRoleName(), request.getRequestorUserName()); return new Response<Void>(Status.OK(), context); } }); TCreateSentryRoleResponse tResponse = new TCreateSentryRoleResponse(respose.status); if (Status.OK.getCode() == respose.status.getValue()) { handerInvoker.create_sentry_role(respose.context, request, tResponse); } try { AUDIT_LOGGER.info(JsonLogEntityFactory.getInstance() .createJsonLogEntity(request, tResponse, conf).toJsonFormatLog()); } catch (Exception e) { // if any exception, log the exception. String msg = "Error creating audit log for create role: " + e.getMessage(); LOGGER.error(msg, e); } return tResponse; }
@Override public TDropSentryRoleResponse drop_sentry_role(final TDropSentryRoleRequest request) throws TException { Response<Void> respose = requestHandle(new RequestHandler<Void>() { @Override public Response<Void> handle() throws Exception { validateClientVersion(request.getProtocol_version()); authorize(request.getRequestorUserName(), getRequestorGroups(conf, request.getRequestorUserName())); CommitContext context = store.dropRole(request.getComponent(), request.getRoleName(), request.getRequestorUserName()); return new Response<Void>(Status.OK(), context); } }); TDropSentryRoleResponse tResponse = new TDropSentryRoleResponse(respose.status); if (Status.OK.getCode() == respose.status.getValue()) { handerInvoker.drop_sentry_role(respose.context, request, tResponse); } try { AUDIT_LOGGER.info(JsonLogEntityFactory.getInstance() .createJsonLogEntity(request, tResponse, conf).toJsonFormatLog()); } catch (Exception e) { // if any exception, log the exception. String msg = "Error creating audit log for drop role: " + e.getMessage(); LOGGER.error(msg, e); } return tResponse; }
@Override public TDropPrivilegesResponse drop_sentry_privilege( final TDropPrivilegesRequest request) throws TException { Response<Void> respose = requestHandle(new RequestHandler<Void>() { @Override public Response<Void> handle() throws Exception { validateClientVersion(request.getProtocol_version()); authorize(request.getRequestorUserName(), getRequestorGroups(conf, request.getRequestorUserName())); store.dropPrivilege(request.getComponent(), toPrivilegeObject(request.getPrivilege()), request.getRequestorUserName()); return new Response<Void>(Status.OK()); } }); TDropPrivilegesResponse tResponse = new TDropPrivilegesResponse(respose.status); if (Status.OK.getCode() == respose.status.getValue()) { handerInvoker.drop_sentry_privilege(request, tResponse); } return tResponse; }
@Override public TDropPrivilegesResponse drop_sentry_privilege( final TDropPrivilegesRequest request) throws TException { Response<Void> respose = requestHandle(new RequestHandler<Void>() { @Override public Response<Void> handle() throws Exception { validateClientVersion(request.getProtocol_version()); authorize(request.getRequestorUserName(), getRequestorGroups(conf, request.getRequestorUserName())); CommitContext context = store.dropPrivilege(request.getComponent(), toPrivilegeObject(request.getPrivilege()), request.getRequestorUserName()); return new Response<Void>(Status.OK(), context); } }); TDropPrivilegesResponse tResponse = new TDropPrivilegesResponse(respose.status); if (Status.OK.getCode() == respose.status.getValue()) { handerInvoker.drop_sentry_privilege(respose.context, request, tResponse); } return tResponse; }
@Override public TRenamePrivilegesResponse rename_sentry_privilege( final TRenamePrivilegesRequest request) throws TException { Response<Void> respose = requestHandle(new RequestHandler<Void>() { @Override public Response<Void> handle() throws Exception { validateClientVersion(request.getProtocol_version()); authorize(request.getRequestorUserName(), getRequestorGroups(conf, request.getRequestorUserName())); store.renamePrivilege(request.getComponent(), request.getServiceName(), toAuthorizables(request.getOldAuthorizables()), toAuthorizables(request.getNewAuthorizables()), request.getRequestorUserName()); return new Response<Void>(Status.OK()); } }); TRenamePrivilegesResponse tResponse = new TRenamePrivilegesResponse(respose.status); if (Status.OK.getCode() == respose.status.getValue()) { handerInvoker.rename_sentry_privilege(request, tResponse); } return tResponse; }
@Override public TRenamePrivilegesResponse rename_sentry_privilege( final TRenamePrivilegesRequest request) throws TException { Response<Void> respose = requestHandle(new RequestHandler<Void>() { @Override public Response<Void> handle() throws Exception { validateClientVersion(request.getProtocol_version()); authorize(request.getRequestorUserName(), getRequestorGroups(conf, request.getRequestorUserName())); CommitContext context = store.renamePrivilege(request.getComponent(), request.getServiceName(), toAuthorizables(request.getOldAuthorizables()), toAuthorizables(request.getNewAuthorizables()), request.getRequestorUserName()); return new Response<Void>(Status.OK(),context); } }); TRenamePrivilegesResponse tResponse = new TRenamePrivilegesResponse(respose.status); if (Status.OK.getCode() == respose.status.getValue()) { handerInvoker.rename_sentry_privilege(respose.context, request, tResponse); } return tResponse; }
private void dropRole(String requestorUserName, String roleName, boolean ifExists) throws SentryUserException { TDropSentryRoleRequest request = new TDropSentryRoleRequest(); request.setProtocol_version(ThriftConstants.TSENTRY_SERVICE_VERSION_CURRENT); request.setRequestorUserName(requestorUserName); request.setRoleName(roleName); try { TDropSentryRoleResponse response = client.drop_sentry_role(request); Status status = Status.fromCode(response.getStatus().getValue()); if (ifExists && status == Status.NO_SUCH_OBJECT) { return; } Status.throwIfNotOk(response.getStatus()); } catch (TException e) { throw new SentryUserException(THRIFT_EXCEPTION_MESSAGE, e); } }
private synchronized void dropRole(String requestorUserName, String roleName, boolean ifExists) throws SentryUserException { TDropSentryRoleRequest request = new TDropSentryRoleRequest(); request.setProtocol_version(ThriftConstants.TSENTRY_SERVICE_VERSION_CURRENT); request.setRequestorUserName(requestorUserName); request.setRoleName(roleName); try { TDropSentryRoleResponse response = client.drop_sentry_role(request); Status status = Status.fromCode(response.getStatus().getValue()); if (ifExists && status == Status.NO_SUCH_OBJECT) { return; } Status.throwIfNotOk(response.getStatus()); } catch (TException e) { throw new SentryUserException(THRIFT_EXCEPTION_MESSAGE, e); } }
void verify(Status status) throws Exception { TAlterSentryRoleRevokePrivilegeRequest revokeRequest = new TAlterSentryRoleRevokePrivilegeRequest(); revokeRequest.setProtocol_version(ThriftConstants.TSENTRY_SERVICE_VERSION_CURRENT); revokeRequest.setRequestorUserName(REQUESTOR_USER); revokeRequest.setRoleName(roleName); revokeRequest.setPrivilege(privilege); TAlterSentryRoleRevokePrivilegeResponse response = processor.alter_sentry_role_revoke_privilege(revokeRequest); if (response.getStatus().getValue() == Status.OK.getCode()) { Mockito.verify(sentryStore).alterSentryRoleRevokePrivileges(revokeRequest.getRoleName(), revokeRequest.getPrivileges()); } else { Mockito.verify(sentryStore, Mockito.times(0)) .alterSentryRoleRevokePrivileges(Mockito.anyString(), Mockito.anySet()); } assertEquals("Revoke " + privilege.getAction() + " response is not valid", status.getCode(), response.getStatus().getValue()); Mockito.reset(sentryStore); } }
void verify(Status status) throws Exception { TAlterSentryRoleGrantPrivilegeRequest grantRequest = new TAlterSentryRoleGrantPrivilegeRequest(); grantRequest.setProtocol_version(ThriftConstants.TSENTRY_SERVICE_VERSION_CURRENT); grantRequest.setRequestorUserName(REQUESTOR_USER); grantRequest.setRoleName(roleName); grantRequest.setPrivilege(privilege); TAlterSentryRoleGrantPrivilegeResponse response = processor.alter_sentry_role_grant_privilege(grantRequest); if (response.getStatus().getValue() == Status.OK.getCode()) { Mockito.verify(sentryStore).alterSentryRoleGrantPrivileges(grantRequest.getRoleName(), grantRequest.getPrivileges()); } else { Mockito.verify(sentryStore, Mockito.times(0)) .alterSentryRoleGrantPrivileges(Mockito.anyString(), Mockito.anySet()); } assertEquals("Grant " + privilege.getAction() + " response is not valid", status.getCode(), response.getStatus().getValue()); Mockito.reset(sentryStore); } }
@Override public void createRoleIfNotExist(String requestorUserName, String roleName, String component) throws SentryUserException { TCreateSentryRoleRequest request = new TCreateSentryRoleRequest(); request.setProtocol_version(sentry_common_serviceConstants.TSENTRY_SERVICE_V2); request.setRequestorUserName(requestorUserName); request.setRoleName(roleName); request.setComponent(component); try { TCreateSentryRoleResponse response = client.create_sentry_role(request); Status status = Status.fromCode(response.getStatus().getValue()); if (status == Status.ALREADY_EXISTS) { return; } Status.throwIfNotOk(response.getStatus()); } catch (TException e) { throw new SentryUserException(THRIFT_EXCEPTION_MESSAGE, e); } }
public void createRoleIfNotExist(String requestorUserName, String roleName, String component) throws SentryUserException { TCreateSentryRoleRequest request = new TCreateSentryRoleRequest(); request.setProtocol_version(sentry_common_serviceConstants.TSENTRY_SERVICE_V2); request.setRequestorUserName(requestorUserName); request.setRoleName(roleName); request.setComponent(component); try { TCreateSentryRoleResponse response = client.create_sentry_role(request); Status status = Status.fromCode(response.getStatus().getValue()); if (status == Status.ALREADY_EXISTS) { return; } Status.throwIfNotOk(response.getStatus()); } catch (TException e) { throw new SentryUserException(THRIFT_EXCEPTION_MESSAGE, e); } }
private void dropRole(String requestorUserName, String roleName, String component, boolean ifExists) throws SentryUserException { TDropSentryRoleRequest request = new TDropSentryRoleRequest(); request.setProtocol_version(sentry_common_serviceConstants.TSENTRY_SERVICE_V2); request.setRequestorUserName(requestorUserName); request.setRoleName(roleName); request.setComponent(component); try { TDropSentryRoleResponse response = client.drop_sentry_role(request); Status status = Status.fromCode(response.getStatus().getValue()); if (ifExists && status == Status.NO_SUCH_OBJECT) { return; } Status.throwIfNotOk(response.getStatus()); } catch (TException e) { throw new SentryUserException(THRIFT_EXCEPTION_MESSAGE, e); } }
private void dropRole(String requestorUserName, String roleName, String component , boolean ifExists) throws SentryUserException { TDropSentryRoleRequest request = new TDropSentryRoleRequest(); request.setProtocol_version(sentry_common_serviceConstants.TSENTRY_SERVICE_V2); request.setRequestorUserName(requestorUserName); request.setRoleName(roleName); request.setComponent(component); try { TDropSentryRoleResponse response = client.drop_sentry_role(request); Status status = Status.fromCode(response.getStatus().getValue()); if (ifExists && status == Status.NO_SUCH_OBJECT) { return; } Status.throwIfNotOk(response.getStatus()); } catch (TException e) { throw new SentryUserException(THRIFT_EXCEPTION_MESSAGE, e); } }