public Object getFieldValue(_Fields field) { switch (field) { case STATUS: return getStatus(); case ROLES: return getRoles(); } throw new IllegalStateException(); }
/** * Gets sentry role objects for a given userName using the Sentry service * * @param requestorUserName : user on whose behalf the request is issued * @param userName : userName to look up (can't be empty) * @return Set of thrift sentry role objects * @throws SentryUserException */ @Override public Set<TSentryRole> listRolesByUserName(String requestorUserName, String userName) throws SentryUserException { TListSentryRolesForUserRequest request = new TListSentryRolesForUserRequest(); request.setProtocol_version(ThriftConstants.TSENTRY_SERVICE_VERSION_CURRENT); request.setRequestorUserName(requestorUserName); request.setUserName(userName); TListSentryRolesResponse response; try { response = client.list_sentry_roles_by_user(request); Status.throwIfNotOk(response.getStatus()); return response.getRoles(); } catch (TException e) { throw new SentryUserException(THRIFT_EXCEPTION_MESSAGE, e); } }
/** * Gets sentry role objects for a given groupName using the Sentry service * * @param requestorUserName : user on whose behalf the request is issued * @param groupName : groupName to look up ( if null returns all roles for all groups) * @return Set of thrift sentry role objects * @throws SentryUserException */ @Override public Set<TSentryRole> listRolesByGroupName( String requestorUserName, String groupName) throws SentryUserException { TListSentryRolesRequest request = new TListSentryRolesRequest(); request.setProtocol_version(ThriftConstants.TSENTRY_SERVICE_VERSION_CURRENT); request.setRequestorUserName(requestorUserName); request.setGroupName(groupName); TListSentryRolesResponse response; try { response = client.list_sentry_roles_by_group(request); Status status = Status.fromCode(response.getStatus().getValue()); if (status == Status.NO_SUCH_OBJECT) { return Collections.emptySet(); } Status.throwIfNotOk(response.getStatus()); return response.getRoles(); } catch (TException e) { throw new SentryUserException(THRIFT_EXCEPTION_MESSAGE, e); } }