PageRenderTime 58ms CodeModel.GetById 53ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/release-0.1-rc2/hive/external/hwi/src/java/org/apache/hadoop/hive/hwi/HWIAuth.java

#
Java | 105 lines | 57 code | 12 blank | 36 comment | 15 complexity | 1580df32ee62a87be393a67b7c501f52 MD5 | raw file
  1/**
  2 * Licensed to the Apache Software Foundation (ASF) under one
  3 * or more contributor license agreements.  See the NOTICE file
  4 * distributed with this work for additional information
  5 * regarding copyright ownership.  The ASF licenses this file
  6 * to you under the Apache License, Version 2.0 (the
  7 * "License"); you may not use this file except in compliance
  8 * with the License.  You may obtain a copy of the License at
  9 *
 10 *     http://www.apache.org/licenses/LICENSE-2.0
 11 *
 12 * Unless required by applicable law or agreed to in writing, software
 13 * distributed under the License is distributed on an "AS IS" BASIS,
 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15 * See the License for the specific language governing permissions and
 16 * limitations under the License.
 17 */
 18
 19package org.apache.hadoop.hive.hwi;
 20
 21/**
 22 * Represents an authenticated user. This class is stored in the users session.
 23 * It is also used as a key for the HiveSessionManager
 24 */
 25public class HWIAuth implements Comparable {
 26  private String user;
 27  private String[] groups;
 28
 29  public HWIAuth() {
 30
 31  }
 32
 33  public String getUser() {
 34    return user;
 35  }
 36
 37  public void setUser(String user) {
 38    this.user = user;
 39  }
 40
 41  public String[] getGroups() {
 42    return groups;
 43  }
 44
 45  public void setGroups(String[] groups) {
 46    this.groups = groups;
 47  }
 48
 49  /**
 50   * HWIAuth is used in SortedSets(s) the compartTo method is required.
 51   * 
 52   * @return chained call to String.compareTo based on user property
 53   */
 54  public int compareTo(Object obj) {
 55    if (obj == null) {
 56      return -1;
 57    }
 58    if (!(obj instanceof HWIAuth)) {
 59      return -1;
 60    }
 61    HWIAuth o = (HWIAuth) obj;
 62    return o.getUser().compareTo(user);
 63  }
 64
 65  /**
 66   * HWIAuth is used in Map(s) the hashCode method is required.
 67   * 
 68   * @see java.lang.Object#hashCode()
 69   */
 70  @Override
 71  public int hashCode() {
 72    final int prime = 31;
 73    int result = 1;
 74    result = prime * result + ((user == null) ? 0 : user.hashCode());
 75    return result;
 76  }
 77
 78  /**
 79   * HWIAuth is used in Map(s) the equals method is required.
 80   * 
 81   * @see java.lang.Object#equals(java.lang.Object)
 82   */
 83  @Override
 84  public boolean equals(Object obj) {
 85    if (this == obj) {
 86      return true;
 87    }
 88    if (obj == null) {
 89      return false;
 90    }
 91    if (!(obj instanceof HWIAuth)) {
 92      return false;
 93    }
 94    HWIAuth other = (HWIAuth) obj;
 95    if (user == null) {
 96      if (other.user != null) {
 97        return false;
 98      }
 99    } else if (!user.equals(other.user)) {
100      return false;
101    }
102    return true;
103  }
104
105}