15 package com.cloudera.impala.authorization;
17 import java.util.EnumSet;
18 import java.util.List;
21 import org.apache.commons.lang.reflect.ConstructorUtils;
22 import org.apache.sentry.core.common.ActiveRoleSet;
23 import org.apache.sentry.core.common.Subject;
24 import org.apache.sentry.core.model.db.DBModelAction;
25 import org.apache.sentry.core.model.db.DBModelAuthorizable;
26 import org.apache.sentry.policy.db.SimpleDBPolicyEngine;
27 import org.apache.sentry.provider.cache.SimpleCacheProviderBackend;
28 import org.apache.sentry.provider.common.ProviderBackend;
29 import org.apache.sentry.provider.common.ProviderBackendContext;
30 import org.apache.sentry.provider.common.ResourceAuthorizationProvider;
31 import org.apache.sentry.provider.file.SimpleFileProviderBackend;
35 import com.google.common.base.Preconditions;
36 import com.google.common.collect.Lists;
42 private final ResourceAuthorizationProvider
provider_;
50 Preconditions.checkNotNull(config);
68 ProviderBackend providerBe;
71 providerBe =
new SimpleFileProviderBackend(config.
getSentryConfig().getConfig(),
77 providerBe =
new SimpleCacheProviderBackend(config.
getSentryConfig().getConfig(),
79 Preconditions.checkNotNull(policy);
80 ProviderBackendContext context =
new ProviderBackendContext();
81 context.setBindingHandle(policy);
82 providerBe.initialize(context);
85 SimpleDBPolicyEngine engine =
90 String policyFile = config.getPolicyFile() == null ?
"" : config.
getPolicyFile();
91 return (ResourceAuthorizationProvider) ConstructorUtils.invokeConstructor(
92 Class.forName(config.getPolicyProviderClassName()),
93 new Object[] {policyFile, engine});
94 }
catch (Exception e) {
96 throw new IllegalStateException(
97 "Error creating ResourceAuthorizationProvider: ", e);
112 return provider_.getGroupMapping().getGroups(user.
getShortName());
121 Preconditions.checkNotNull(privilegeRequest);
123 if (!
hasAccess(user, privilegeRequest)) {
126 "User '%s' does not have privileges to CREATE/DROP functions.",
130 Privilege privilege = privilegeRequest.getPrivilege();
132 .contains(privilege)) {
134 "User '%s' does not have privileges to access: %s",
135 user.getName(), privilegeRequest.getName()));
138 "User '%s' does not have privileges to execute '%s' on: %s",
139 user.getName(), privilege, privilegeRequest.getName()));
149 Preconditions.checkNotNull(user);
150 Preconditions.checkNotNull(request);
158 EnumSet<DBModelAction> actions = request.getPrivilege().getHiveActions();
160 List<DBModelAuthorizable> authorizeables = Lists.newArrayList(
161 server_.getHiveAuthorizeableHierarchy());
164 authorizeables.addAll(request.getAuthorizeable().getHiveAuthorizeableHierarchy());
170 for (DBModelAction action: actions) {
177 }
else if (request.
getPrivilege() == Privilege.CREATE && authorizeables.size() > 1) {
180 authorizeables.remove(authorizeables.size() - 1);
182 return provider_.hasAccess(
new Subject(user.
getShortName()), authorizeables, actions,
boolean hasAccess(User user, PrivilegeRequest request)
AuthorizationConfig getConfig()
SentryConfig getSentryConfig()
final AuthorizeableServer server_
final ResourceAuthorizationProvider provider_
Set< String > getUserGroups(User user)
void checkAccess(User user, PrivilegeRequest privilegeRequest)
static ResourceAuthorizationProvider createProvider(AuthorizationConfig config, AuthorizationPolicy policy)
final AuthorizationConfig config_
Authorizeable getAuthorizeable()
AuthorizationChecker(AuthorizationConfig config, AuthorizationPolicy policy)
boolean isFileBasedPolicy()