001/* 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019 020package org.apache.hadoop.hbase.security.visibility; 021 022import java.io.IOException; 023import java.util.Optional; 024import org.apache.hadoop.conf.Configuration; 025import org.apache.hadoop.hbase.CoprocessorEnvironment; 026import org.apache.hadoop.hbase.coprocessor.ObserverContext; 027import org.apache.hadoop.hbase.coprocessor.RegionServerCoprocessor; 028import org.apache.hadoop.hbase.coprocessor.RegionServerCoprocessorEnvironment; 029import org.apache.hadoop.hbase.coprocessor.RegionServerObserver; 030import org.apache.hadoop.hbase.replication.ReplicationEndpoint; 031import org.apache.yetus.audience.InterfaceAudience; 032 033/** 034 * A RegionServerObserver impl that provides the custom 035 * VisibilityReplicationEndpoint. This class should be configured as the 036 * 'hbase.coprocessor.regionserver.classes' for the visibility tags to be 037 * replicated as string. The value for the configuration should be 038 * 'org.apache.hadoop.hbase.security.visibility.VisibilityController$VisibilityReplication'. 039 */ 040@InterfaceAudience.Private 041public class VisibilityReplication implements RegionServerCoprocessor, RegionServerObserver { 042 private Configuration conf; 043 private VisibilityLabelService visibilityLabelService; 044 045 @Override 046 public void start(CoprocessorEnvironment env) throws IOException { 047 this.conf = env.getConfiguration(); 048 visibilityLabelService = VisibilityLabelServiceManager.getInstance() 049 .getVisibilityLabelService(this.conf); 050 } 051 052 @Override 053 public void stop(CoprocessorEnvironment env) throws IOException { 054 } 055 056 @Override public Optional<RegionServerObserver> getRegionServerObserver() { 057 return Optional.of(this); 058 } 059 060 @Override 061 public ReplicationEndpoint postCreateReplicationEndPoint( 062 ObserverContext<RegionServerCoprocessorEnvironment> ctx, ReplicationEndpoint endpoint) { 063 return new VisibilityReplicationEndpoint(endpoint, visibilityLabelService); 064 } 065}