public HiveRoleGrant(RolePrincipalGrant thriftRoleGrant) { this.roleName = thriftRoleGrant.getRoleName(); this.principalName = thriftRoleGrant.getPrincipalName(); this.principalType = thriftRoleGrant.getPrincipalType().name(); this.grantOption = thriftRoleGrant.isGrantOption(); this.grantTime = thriftRoleGrant.getGrantTime(); this.grantor = thriftRoleGrant.getGrantorName(); this.grantorType = thriftRoleGrant.getGrantorPrincipalType() == null ? null : thriftRoleGrant.getGrantorPrincipalType().name(); }
@Override public void read(org.apache.thrift.protocol.TProtocol prot, GetRoleGrantsForPrincipalResponse struct) throws org.apache.thrift.TException { TTupleProtocol iprot = (TTupleProtocol) prot; { org.apache.thrift.protocol.TList _list91 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32()); struct.principalGrants = new ArrayList<RolePrincipalGrant>(_list91.size); RolePrincipalGrant _elem92; for (int _i93 = 0; _i93 < _list91.size; ++_i93) { _elem92 = new RolePrincipalGrant(); _elem92.read(iprot); struct.principalGrants.add(_elem92); } } struct.setPrincipalGrantsIsSet(true); } }
@Override public boolean equals(Object that) { if (that == null) return false; if (that instanceof RolePrincipalGrant) return this.equals((RolePrincipalGrant)that); return false; }
/** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ public boolean isSet(_Fields field) { if (field == null) { throw new IllegalArgumentException(); } switch (field) { case ROLE_NAME: return isSetRoleName(); case PRINCIPAL_NAME: return isSetPrincipalName(); case PRINCIPAL_TYPE: return isSetPrincipalType(); case GRANT_OPTION: return isSetGrantOption(); case GRANT_TIME: return isSetGrantTime(); case GRANTOR_NAME: return isSetGrantorName(); case GRANTOR_PRINCIPAL_TYPE: return isSetGrantorPrincipalType(); } throw new IllegalStateException(); }
static String writeRoleGrantsInfo(List<RolePrincipalGrant> roleGrants, boolean testMode) { if (roleGrants == null || roleGrants.isEmpty()) { return ""; } StringBuilder builder = new StringBuilder(); //sort the list to get sorted (deterministic) output (for ease of testing) Collections.sort(roleGrants); for (RolePrincipalGrant roleGrant : roleGrants) { appendNonNull(builder, roleGrant.getRoleName(), true); appendNonNull(builder, roleGrant.isGrantOption()); appendNonNull(builder, testMode ? -1 : roleGrant.getGrantTime() * 1000L); appendNonNull(builder, roleGrant.getGrantorName()); } return builder.toString(); }
public static RoleGrant fromRolePrincipalGrant(RolePrincipalGrant grant) { return new RoleGrant( new PrestoPrincipal(fromMetastoreApiPrincipalType(grant.getPrincipalType()), grant.getPrincipalName()), grant.getRoleName(), grant.isGrantOption()); }
@Override public void grantRole(String role, String granteeName, PrincipalType granteeType, String grantorName, PrincipalType grantorType, boolean grantOption) throws TException { List<RolePrincipalGrant> grants = listRoleGrants(granteeName, granteeType); for (RolePrincipalGrant grant : grants) { if (grant.getRoleName().equals(role)) { if (grant.isGrantOption() == grantOption) { return; } if (!grant.isGrantOption() && grantOption) { revokeRole(role, granteeName, granteeType, false); break; } } } createGrant(role, granteeName, granteeType, grantorName, grantorType, grantOption); }
public RolePrincipalGrant deepCopy() { return new RolePrincipalGrant(this); }
/** * Add role names of parentRoles and its parents to processedRolesMap * * @param processedRolesMap * @param roleGrants * @throws TException * @throws HiveAuthzPluginException * @throws MetaException */ private void getAllRoleAncestors(Map<String, HiveRoleGrant> processedRolesMap, List<RolePrincipalGrant> roleGrants) throws MetaException, HiveAuthzPluginException, TException { for (RolePrincipalGrant parentRoleGrant : roleGrants) { String parentRoleName = parentRoleGrant.getRoleName(); if (processedRolesMap.get(parentRoleName) == null) { // unprocessed role: get its parents, add it to processed, and call this // function recursively List<RolePrincipalGrant> nextParentRoles = getRoleGrants(parentRoleName, PrincipalType.ROLE); processedRolesMap.put(parentRoleName, new HiveRoleGrant(parentRoleGrant)); getAllRoleAncestors(processedRolesMap, nextParentRoles); } } }
lastComparison = Boolean.valueOf(isSetRoleName()).compareTo(other.isSetRoleName()); if (lastComparison != 0) { return lastComparison; if (isSetRoleName()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.roleName, other.roleName); if (lastComparison != 0) { lastComparison = Boolean.valueOf(isSetPrincipalName()).compareTo(other.isSetPrincipalName()); if (lastComparison != 0) { return lastComparison; if (isSetPrincipalName()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.principalName, other.principalName); if (lastComparison != 0) { lastComparison = Boolean.valueOf(isSetPrincipalType()).compareTo(other.isSetPrincipalType()); if (lastComparison != 0) { return lastComparison; if (isSetPrincipalType()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.principalType, other.principalType); if (lastComparison != 0) { lastComparison = Boolean.valueOf(isSetGrantOption()).compareTo(other.isSetGrantOption()); if (lastComparison != 0) { return lastComparison; if (isSetGrantOption()) {
static String writeRoleGrantsInfo(List<RolePrincipalGrant> roleGrants, boolean testMode) { if (roleGrants == null || roleGrants.isEmpty()) { return ""; } StringBuilder builder = new StringBuilder(); //sort the list to get sorted (deterministic) output (for ease of testing) Collections.sort(roleGrants); for (RolePrincipalGrant roleGrant : roleGrants) { appendNonNull(builder, roleGrant.getRoleName(), true); appendNonNull(builder, roleGrant.isGrantOption()); appendNonNull(builder, testMode ? -1 : roleGrant.getGrantTime() * 1000L); appendNonNull(builder, roleGrant.getGrantorName()); } return builder.toString(); }
@Override public void revokeRole(String role, String granteeName, PrincipalType granteeType, boolean grantOption) throws TException { List<RolePrincipalGrant> grants = listRoleGrants(granteeName, granteeType); RolePrincipalGrant currentGrant = null; for (RolePrincipalGrant grant : grants) { if (grant.getRoleName().equals(role)) { currentGrant = grant; break; } } if (currentGrant == null) { return; } if (!currentGrant.isGrantOption() && grantOption) { return; } removeGrant(role, granteeName, granteeType, grantOption); }
/** * Performs a deep copy on <i>other</i>. */ public GetPrincipalsInRoleResponse(GetPrincipalsInRoleResponse other) { if (other.isSetPrincipalGrants()) { List<RolePrincipalGrant> __this__principalGrants = new ArrayList<RolePrincipalGrant>(other.principalGrants.size()); for (RolePrincipalGrant other_element : other.principalGrants) { __this__principalGrants.add(new RolePrincipalGrant(other_element)); } this.principalGrants = __this__principalGrants; } }
/** * Add role names of parentRoles and its parents to processedRolesMap * * @param processedRolesMap * @param roleGrants * @throws TException * @throws HiveAuthzPluginException * @throws MetaException */ private void getAllRoleAncestors(Map<String, HiveRoleGrant> processedRolesMap, List<RolePrincipalGrant> roleGrants) throws MetaException, HiveAuthzPluginException, TException { for (RolePrincipalGrant parentRoleGrant : roleGrants) { String parentRoleName = parentRoleGrant.getRoleName(); if (processedRolesMap.get(parentRoleName) == null) { // unprocessed role: get its parents, add it to processed, and call this // function recursively List<RolePrincipalGrant> nextParentRoles = getRoleGrants(parentRoleName, PrincipalType.ROLE); processedRolesMap.put(parentRoleName, new HiveRoleGrant(parentRoleGrant)); getAllRoleAncestors(processedRolesMap, nextParentRoles); } } }
public Object getFieldValue(_Fields field) { switch (field) { case ROLE_NAME: return getRoleName(); case PRINCIPAL_NAME: return getPrincipalName(); case PRINCIPAL_TYPE: return getPrincipalType(); case GRANT_OPTION: return isGrantOption(); case GRANT_TIME: return getGrantTime(); case GRANTOR_NAME: return getGrantorName(); case GRANTOR_PRINCIPAL_TYPE: return getGrantorPrincipalType(); } throw new IllegalStateException(); }
TTupleProtocol oprot = (TTupleProtocol) prot; BitSet optionals = new BitSet(); if (struct.isSetRoleName()) { optionals.set(0); if (struct.isSetPrincipalName()) { optionals.set(1); if (struct.isSetPrincipalType()) { optionals.set(2); if (struct.isSetGrantOption()) { optionals.set(3); if (struct.isSetGrantTime()) { optionals.set(4); if (struct.isSetGrantorName()) { optionals.set(5); if (struct.isSetGrantorPrincipalType()) { optionals.set(6); if (struct.isSetRoleName()) { oprot.writeString(struct.roleName); if (struct.isSetPrincipalName()) { oprot.writeString(struct.principalName);
static String writeRoleGrantsInfo(List<RolePrincipalGrant> roleGrants, boolean testMode) { if (roleGrants == null || roleGrants.isEmpty()) { return ""; } StringBuilder builder = new StringBuilder(); //sort the list to get sorted (deterministic) output (for ease of testing) Collections.sort(roleGrants); for (RolePrincipalGrant roleGrant : roleGrants) { appendNonNull(builder, roleGrant.getRoleName(), true); appendNonNull(builder, roleGrant.isGrantOption()); appendNonNull(builder, testMode ? -1 : roleGrant.getGrantTime() * 1000L); appendNonNull(builder, roleGrant.getGrantorName()); } return builder.toString(); }
@Override public void read(org.apache.thrift.protocol.TProtocol prot, GetPrincipalsInRoleResponse struct) throws org.apache.thrift.TException { TTupleProtocol iprot = (TTupleProtocol) prot; { org.apache.thrift.protocol.TList _list99 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32()); struct.principalGrants = new ArrayList<RolePrincipalGrant>(_list99.size); RolePrincipalGrant _elem100; for (int _i101 = 0; _i101 < _list99.size; ++_i101) { _elem100 = new RolePrincipalGrant(); _elem100.read(iprot); struct.principalGrants.add(_elem100); } } struct.setPrincipalGrantsIsSet(true); } }
/** * Performs a deep copy on <i>other</i>. */ public GetRoleGrantsForPrincipalResponse(GetRoleGrantsForPrincipalResponse other) { if (other.isSetPrincipalGrants()) { List<RolePrincipalGrant> __this__principalGrants = new ArrayList<RolePrincipalGrant>(other.principalGrants.size()); for (RolePrincipalGrant other_element : other.principalGrants) { __this__principalGrants.add(new RolePrincipalGrant(other_element)); } this.principalGrants = __this__principalGrants; } }
/** * Add role names of parentRoles and its parents to processedRolesMap * * @param processedRolesMap * @param roleGrants * @throws TException * @throws HiveAuthzPluginException * @throws MetaException */ private void getAllRoleAncestors(Map<String, HiveRoleGrant> processedRolesMap, List<RolePrincipalGrant> roleGrants) throws MetaException, HiveAuthzPluginException, TException { for (RolePrincipalGrant parentRoleGrant : roleGrants) { String parentRoleName = parentRoleGrant.getRoleName(); if (processedRolesMap.get(parentRoleName) == null) { // unprocessed role: get its parents, add it to processed, and call this // function recursively List<RolePrincipalGrant> nextParentRoles = getRoleGrants(parentRoleName, PrincipalType.ROLE); processedRolesMap.put(parentRoleName, new HiveRoleGrant(parentRoleGrant)); getAllRoleAncestors(processedRolesMap, nextParentRoles); } } }