Search in sources :

Example 1 with MultiUserAuthorizations

use of org.apache.hadoop.hbase.shaded.protobuf.generated.VisibilityLabelsProtos.MultiUserAuthorizations in project hbase by apache.

the class VisibilityUtils method readUserAuthsFromZKData.

/**
 * Reads back User auth data written to zookeeper.
 * @param data
 * @return User auth details
 * @throws DeserializationException
 */
public static MultiUserAuthorizations readUserAuthsFromZKData(byte[] data) throws DeserializationException {
    if (ProtobufUtil.isPBMagicPrefix(data)) {
        int pblen = ProtobufUtil.lengthOfPBMagic();
        try {
            MultiUserAuthorizations.Builder builder = MultiUserAuthorizations.newBuilder();
            ProtobufUtil.mergeFrom(builder, data, pblen, data.length - pblen);
            return builder.build();
        } catch (IOException e) {
            throw new DeserializationException(e);
        }
    }
    return null;
}
Also used : IOException(java.io.IOException) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException) MultiUserAuthorizations(org.apache.hadoop.hbase.shaded.protobuf.generated.VisibilityLabelsProtos.MultiUserAuthorizations)

Example 2 with MultiUserAuthorizations

use of org.apache.hadoop.hbase.shaded.protobuf.generated.VisibilityLabelsProtos.MultiUserAuthorizations in project hbase by apache.

the class VisibilityLabelsCache method refreshUserAuthsCache.

public void refreshUserAuthsCache(byte[] data) throws IOException {
    MultiUserAuthorizations multiUserAuths = null;
    try {
        multiUserAuths = VisibilityUtils.readUserAuthsFromZKData(data);
    } catch (DeserializationException dse) {
        throw new IOException(dse);
    }
    this.lock.writeLock().lock();
    try {
        this.userAuths.clear();
        this.groupAuths.clear();
        for (UserAuthorizations userAuths : multiUserAuths.getUserAuthsList()) {
            String user = Bytes.toString(userAuths.getUser().toByteArray());
            if (AuthUtil.isGroupPrincipal(user)) {
                this.groupAuths.put(AuthUtil.getGroupName(user), new HashSet<>(userAuths.getAuthList()));
            } else {
                this.userAuths.put(user, new HashSet<>(userAuths.getAuthList()));
            }
        }
    } finally {
        this.lock.writeLock().unlock();
    }
}
Also used : IOException(java.io.IOException) UserAuthorizations(org.apache.hadoop.hbase.shaded.protobuf.generated.VisibilityLabelsProtos.UserAuthorizations) MultiUserAuthorizations(org.apache.hadoop.hbase.shaded.protobuf.generated.VisibilityLabelsProtos.MultiUserAuthorizations) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException) MultiUserAuthorizations(org.apache.hadoop.hbase.shaded.protobuf.generated.VisibilityLabelsProtos.MultiUserAuthorizations)

Aggregations

IOException (java.io.IOException)2 DeserializationException (org.apache.hadoop.hbase.exceptions.DeserializationException)2 MultiUserAuthorizations (org.apache.hadoop.hbase.shaded.protobuf.generated.VisibilityLabelsProtos.MultiUserAuthorizations)2 UserAuthorizations (org.apache.hadoop.hbase.shaded.protobuf.generated.VisibilityLabelsProtos.UserAuthorizations)1