Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to grant permissions when the authorization is disabled #7074

Merged
merged 2 commits into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,20 @@ public class AuthorizationService {

public AuthorizationService(ServiceConfiguration conf, ConfigurationCacheService configCache)
throws PulsarServerException {

this.conf = conf;
if (this.conf.isAuthorizationEnabled()) {
try {
final String providerClassname = conf.getAuthorizationProvider();
if (StringUtils.isNotBlank(providerClassname)) {
provider = (AuthorizationProvider) Class.forName(providerClassname).newInstance();
provider.initialize(conf, configCache);
log.info("{} has been loaded.", providerClassname);
} else {
throw new PulsarServerException("No authorization providers are present.");
}
} catch (PulsarServerException e) {
throw e;
} catch (Throwable e) {
throw new PulsarServerException("Failed to load an authorization provider.", e);
try {
final String providerClassname = conf.getAuthorizationProvider();
if (StringUtils.isNotBlank(providerClassname)) {
provider = (AuthorizationProvider) Class.forName(providerClassname).newInstance();
provider.initialize(conf, configCache);
log.info("{} has been loaded.", providerClassname);
} else {
throw new PulsarServerException("No authorization providers are present.");
}
} else {
log.info("Authorization is disabled");
} catch (PulsarServerException e) {
throw e;
} catch (Throwable e) {
throw new PulsarServerException("Failed to load an authorization provider.", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,11 @@ protected void internalGrantPermissionOnNamespace(String role, Set<AuthAction> a
} catch (ExecutionException e) {
if (e.getCause() instanceof IllegalArgumentException) {
log.warn("[{}] Failed to set permissions for namespace {}: does not exist", clientAppId(),
namespaceName);
namespaceName, e);
throw new RestException(Status.NOT_FOUND, "Namespace does not exist");
} else if (e.getCause() instanceof IllegalStateException) {
log.warn("[{}] Failed to set permissions for namespace {}: concurrent modification",
clientAppId(), namespaceName);
log.warn("[{}] Failed to set permissions for namespace {}: {}",
clientAppId(), namespaceName, e.getCause().getMessage(), e);
throw new RestException(Status.CONFLICT, "Concurrent modification");
} else {
log.error("[{}] Failed to get permissions for namespace {}", clientAppId(), namespaceName, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,7 @@ public BrokerService(PulsarService pulsar) throws Exception {
this.workerGroup = EventLoopUtil.newEventLoopGroup(numThreads, workersThreadFactory);
this.statsUpdater = Executors
.newSingleThreadScheduledExecutor(new DefaultThreadFactory("pulsar-stats-updater"));
if (pulsar.getConfiguration().isAuthorizationEnabled()) {
this.authorizationService = new AuthorizationService(pulsar.getConfiguration(),
pulsar.getConfigurationCache());
}
this.authorizationService = new AuthorizationService(pulsar.getConfiguration(), pulsar.getConfigurationCache());

if (pulsar.getConfigurationCache() != null) {
pulsar.getConfigurationCache().policiesCache().registerListener(this);
Expand Down Expand Up @@ -1464,7 +1461,7 @@ public boolean isAuthenticationEnabled() {
}

public boolean isAuthorizationEnabled() {
return authorizationService != null;
return pulsar.getConfiguration().isAuthorizationEnabled();
}

public int getKeepAliveIntervalSeconds() {
Expand Down