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.hbase.security.visibility;
019
020import java.io.IOException;
021import java.util.Optional;
022import org.apache.hadoop.conf.Configuration;
023import org.apache.hadoop.hbase.CoprocessorEnvironment;
024import org.apache.hadoop.hbase.coprocessor.ObserverContext;
025import org.apache.hadoop.hbase.coprocessor.RegionServerCoprocessor;
026import org.apache.hadoop.hbase.coprocessor.RegionServerCoprocessorEnvironment;
027import org.apache.hadoop.hbase.coprocessor.RegionServerObserver;
028import org.apache.hadoop.hbase.replication.ReplicationEndpoint;
029import org.apache.yetus.audience.InterfaceAudience;
030
031/**
032 * A RegionServerObserver impl that provides the custom VisibilityReplicationEndpoint. This class
033 * should be configured as the 'hbase.coprocessor.regionserver.classes' for the visibility tags to
034 * be replicated as string. The value for the configuration should be
035 * 'org.apache.hadoop.hbase.security.visibility.VisibilityController$VisibilityReplication'.
036 */
037@InterfaceAudience.Private
038public class VisibilityReplication implements RegionServerCoprocessor, RegionServerObserver {
039  private Configuration conf;
040  private VisibilityLabelService visibilityLabelService;
041
042  @Override
043  public void start(CoprocessorEnvironment env) throws IOException {
044    this.conf = env.getConfiguration();
045    visibilityLabelService =
046      VisibilityLabelServiceManager.getInstance().getVisibilityLabelService(this.conf);
047  }
048
049  @Override
050  public void stop(CoprocessorEnvironment env) throws IOException {
051  }
052
053  @Override
054  public Optional<RegionServerObserver> getRegionServerObserver() {
055    return Optional.of(this);
056  }
057
058  @Override
059  public ReplicationEndpoint postCreateReplicationEndPoint(
060    ObserverContext<RegionServerCoprocessorEnvironment> ctx, ReplicationEndpoint endpoint) {
061    return new VisibilityReplicationEndpoint(endpoint, visibilityLabelService);
062  }
063}