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 */
018package org.apache.hadoop.hdfs.protocol;
019
020import org.apache.commons.lang.builder.EqualsBuilder;
021import org.apache.commons.lang.builder.HashCodeBuilder;
022import org.apache.hadoop.classification.InterfaceAudience;
023import org.apache.hadoop.classification.InterfaceStability;
024import org.apache.hadoop.crypto.CipherSuite;
025import org.apache.hadoop.crypto.CryptoProtocolVersion;
026
027/**
028 * A simple class for representing an encryption zone. Presently an encryption
029 * zone only has a path (the root of the encryption zone), a key name, and a
030 * unique id. The id is used to implement batched listing of encryption zones.
031 */
032@InterfaceAudience.Public
033@InterfaceStability.Evolving
034public class EncryptionZone {
035
036  private final long id;
037  private final String path;
038  private final CipherSuite suite;
039  private final CryptoProtocolVersion version;
040  private final String keyName;
041
042  public EncryptionZone(long id, String path, CipherSuite suite,
043      CryptoProtocolVersion version, String keyName) {
044    this.id = id;
045    this.path = path;
046    this.suite = suite;
047    this.version = version;
048    this.keyName = keyName;
049  }
050
051  public long getId() {
052    return id;
053  }
054
055  public String getPath() {
056    return path;
057  }
058
059  public CipherSuite getSuite() {
060    return suite;
061  }
062
063  public CryptoProtocolVersion getVersion() { return version; }
064
065  public String getKeyName() {
066    return keyName;
067  }
068
069  @Override
070  public int hashCode() {
071    return new HashCodeBuilder(13, 31)
072        .append(id)
073        .append(path)
074        .append(suite)
075        .append(version)
076        .append(keyName).
077      toHashCode();
078  }
079
080  @Override
081  public boolean equals(Object obj) {
082    if (obj == null) {
083      return false;
084    }
085    if (obj == this) {
086      return true;
087    }
088    if (obj.getClass() != getClass()) {
089      return false;
090    }
091
092    EncryptionZone rhs = (EncryptionZone) obj;
093    return new EqualsBuilder().
094      append(id, rhs.id).
095      append(path, rhs.path).
096      append(suite, rhs.suite).
097      append(version, rhs.version).
098      append(keyName, rhs.keyName).
099      isEquals();
100  }
101
102  @Override
103  public String toString() {
104    return "EncryptionZone [id=" + id +
105        ", path=" + path +
106        ", suite=" + suite +
107        ", version=" + version +
108        ", keyName=" + keyName + "]";
109  }
110}