Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SentryConfig.java
Go to the documentation of this file.
1 // Copyright 2014 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 package com.cloudera.impala.authorization;
16 
17 import java.io.File;
18 import java.net.MalformedURLException;
19 
20 import org.apache.hadoop.conf.Configuration;
21 
23 import com.google.common.base.Strings;
24 
28 public class SentryConfig {
29  // Absolute path to the sentry-site.xml configuration file.
30  private final String configFile_;
31 
32  // The Sentry configuration. Valid only after calling loadConfig().
33  private final Configuration config_;
34 
35  public SentryConfig(String configFilePath) {
36  configFile_ = configFilePath;
37  config_ = FileSystemUtil.getConfiguration();
38  }
39 
43  public void loadConfig() {
44  if (Strings.isNullOrEmpty(configFile_)) {
45  throw new IllegalArgumentException("A valid path to a sentry-site.xml config " +
46  "file must be set using --sentry_config to enable authorization.");
47  }
48 
49  File configFile = new File(configFile_);
50  if (!configFile.exists()) {
51  throw new RuntimeException("Sentry configuration file does not exist: " +
52  configFile_);
53  }
54 
55  if (!configFile.canRead()) {
56  throw new RuntimeException("Cannot read Sentry configuration file: " +
57  configFile_);
58  }
59 
60  // Load the config.
61  try {
62  config_.addResource(configFile.toURI().toURL());
63  } catch (MalformedURLException e) {
64  throw new RuntimeException("Invalid Sentry config file path: " + configFile_, e);
65  }
66  }
67 
68  public Configuration getConfig() { return config_; }
69  public String getConfigFile() { return configFile_; }
70 }