001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.apache.hadoop.hbase.security.access;
020
021import java.util.Objects;
022import org.apache.hadoop.hbase.TableName;
023import org.apache.yetus.audience.InterfaceAudience;
024
025/**
026 * Used by
027 * {@link org.apache.hadoop.hbase.client.Admin#getUserPermissions(GetUserPermissionsRequest)}.
028 * Represents the params of user permissions needed to get from HBase.
029 */
030@InterfaceAudience.Public
031public final class GetUserPermissionsRequest {
032  private String userName;
033  private String namespace;
034  private TableName tableName;
035  private byte[] family;
036  private byte[] qualifier;
037
038  private GetUserPermissionsRequest(String userName, String namespace, TableName tableName,
039      byte[] family, byte[] qualifier) {
040    this.userName = userName;
041    this.namespace = namespace;
042    this.tableName = tableName;
043    this.family = family;
044    this.qualifier = qualifier;
045  }
046
047  /**
048   * Build a get global permission request
049   * @return a get global permission request builder
050   */
051  public static Builder newBuilder() {
052    return new Builder();
053  }
054
055  /**
056   * Build a get namespace permission request
057   * @param namespace the specific namespace
058   * @return a get namespace permission request builder
059   */
060  public static Builder newBuilder(String namespace) {
061    return new Builder(namespace);
062  }
063
064  /**
065   * Build a get table permission request
066   * @param tableName the specific table name
067   * @return a get table permission request builder
068   */
069  public static Builder newBuilder(TableName tableName) {
070    return new Builder(tableName);
071  }
072
073  public String getUserName() {
074    return userName;
075  }
076
077  public String getNamespace() {
078    return namespace;
079  }
080
081  public TableName getTableName() {
082    return tableName;
083  }
084
085  public byte[] getFamily() {
086    return family;
087  }
088
089  public byte[] getQualifier() {
090    return qualifier;
091  }
092
093  public static final class Builder {
094    private String userName;
095    private String namespace;
096    private TableName tableName;
097    private byte[] family;
098    private byte[] qualifier;
099
100    private Builder() {
101    }
102
103    private Builder(String namespace) {
104      this.namespace = namespace;
105    }
106
107    private Builder(TableName tableName) {
108      this.tableName = tableName;
109    }
110
111    /**
112     * user name could be null if need all global/namespace/table permissions
113     */
114    public Builder withUserName(String userName) {
115      this.userName = userName;
116      return this;
117    }
118
119    public Builder withFamily(byte[] family) {
120      Objects.requireNonNull(tableName, "The tableName can't be NULL");
121      this.family = family;
122      return this;
123    }
124
125    public Builder withQualifier(byte[] qualifier) {
126      Objects.requireNonNull(tableName, "The tableName can't be NULL");
127      // Objects.requireNonNull(family, "The family can't be NULL");
128      this.qualifier = qualifier;
129      return this;
130    }
131
132    public GetUserPermissionsRequest build() {
133      return new GetUserPermissionsRequest(userName, namespace, tableName, family, qualifier);
134    }
135  }
136}