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

Druid authentication/authorization on router's side #73

Open
wants to merge 7 commits into
base: 0.12.1-mmx
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -0,0 +1,120 @@
/*
* Licensed to Metamarkets Group Inc. (Metamarkets) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Metamarkets licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package io.druid.security.basic;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

public class BasicAuthClassCompositionConfig

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class has a lot of fields, but seems that only one of them is used, why is that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, all of them are in use (see BasicSecurityDruidModule)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a class-level comment describing something or pointing somewhere.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

{
@JsonProperty
private final String authenticatorMetadataStorageUpdater;

@JsonProperty
private final String authenticatorCacheManager;

@JsonProperty
private final String authenticatorResourceHandler;

@JsonProperty
private final String authenticatorCacheNotifier;

@JsonProperty
private final String authorizerMetadataStorageUpdater;

@JsonProperty
private final String authorizerCacheManager;

@JsonProperty
private final String authorizerResourceHandler;

@JsonProperty
private final String authorizerCacheNotifier;

@JsonCreator
public BasicAuthClassCompositionConfig(
@JsonProperty("authenticatorMetadataStorageUpdater") String authenticatorMetadataStorageUpdater,
@JsonProperty("authenticatorCacheManager") String authenticatorCacheManager,
@JsonProperty("authenticatorResourceHandler") String authenticatorResourceHandler,
@JsonProperty("authenticatorCacheNotifier") String authenticatorCacheNotifier,
@JsonProperty("authorizerMetadataStorageUpdater") String authorizerMetadataStorageUpdater,
@JsonProperty("authorizerCacheManager") String authorizerCacheManager,
@JsonProperty("authorizerResourceHandler") String authorizerResourceHandler,
@JsonProperty("authorizerCacheNotifier") String authorizerCacheNotifier
)
{
this.authenticatorMetadataStorageUpdater = authenticatorMetadataStorageUpdater;
this.authenticatorCacheManager = authenticatorCacheManager;
this.authenticatorResourceHandler = authenticatorResourceHandler;
this.authenticatorCacheNotifier = authenticatorCacheNotifier;
this.authorizerMetadataStorageUpdater = authorizerMetadataStorageUpdater;
this.authorizerCacheManager = authorizerCacheManager;
this.authorizerResourceHandler = authorizerResourceHandler;
this.authorizerCacheNotifier = authorizerCacheNotifier;
}

@JsonProperty
public String getAuthenticatorMetadataStorageUpdater()
{
return authenticatorMetadataStorageUpdater;
}

@JsonProperty
public String getAuthenticatorCacheManager()
{
return authenticatorCacheManager;
}

@JsonProperty
public String getAuthenticatorResourceHandler()
{
return authenticatorResourceHandler;
}

@JsonProperty
public String getAuthenticatorCacheNotifier()
{
return authenticatorCacheNotifier;
}

@JsonProperty
public String getAuthorizerMetadataStorageUpdater()
{
return authorizerMetadataStorageUpdater;
}

@JsonProperty
public String getAuthorizerCacheManager()
{
return authorizerCacheManager;
}

@JsonProperty
public String getAuthorizerResourceHandler()
{
return authorizerResourceHandler;
}

@JsonProperty
public String getAuthorizerCacheNotifier()
{
return authorizerCacheNotifier;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import io.druid.guice.LazySingleton;
import io.druid.guice.LifecycleModule;
import io.druid.initialization.DruidModule;
import io.druid.metadata.MetadataStorage;
import io.druid.metadata.MetadataStorageProvider;
import io.druid.security.basic.authentication.BasicHTTPAuthenticator;
import io.druid.security.basic.authentication.BasicHTTPEscalator;
import io.druid.security.basic.authentication.db.cache.BasicAuthenticatorCacheManager;
Expand Down Expand Up @@ -62,10 +64,12 @@

public class BasicSecurityDruidModule implements DruidModule
{

@Override
public void configure(Binder binder)
{
JsonConfigProvider.bind(binder, "druid.auth.basic.common", BasicAuthCommonCacheConfig.class);
JsonConfigProvider.bind(binder, "druid.auth.basic.composition", BasicAuthClassCompositionConfig.class);

LifecycleModule.register(binder, BasicAuthenticatorMetadataStorageUpdater.class);
LifecycleModule.register(binder, BasicAuthorizerMetadataStorageUpdater.class);
Expand All @@ -74,81 +78,149 @@ public void configure(Binder binder)

Jerseys.addResource(binder, BasicAuthenticatorResource.class);
Jerseys.addResource(binder, BasicAuthorizerResource.class);

binder.bind(MetadataStorage.class).toProvider(MetadataStorageProvider.class);
LifecycleModule.register(binder, MetadataStorage.class);
}

@Provides @LazySingleton
public static BasicAuthenticatorMetadataStorageUpdater createAuthenticatorStorageUpdater(final Injector injector)
@Provides
@LazySingleton
public static BasicAuthenticatorMetadataStorageUpdater createAuthenticatorStorageUpdater(
final Injector injector,
BasicAuthClassCompositionConfig config
) throws ClassNotFoundException
{
if (config.getAuthenticatorMetadataStorageUpdater() != null) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block of code can be extracted as a method.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some explanation. What is going on here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored and added description

return (BasicAuthenticatorMetadataStorageUpdater)
injector.getInstance(Class.forName(config.getAuthenticatorMetadataStorageUpdater()));
}
if (isCoordinator(injector)) {
return injector.getInstance(CoordinatorBasicAuthenticatorMetadataStorageUpdater.class);
} else {
return null;
}
}

@Provides @LazySingleton
public static BasicAuthenticatorCacheManager createAuthenticatorCacheManager(final Injector injector)
@Provides
@LazySingleton
public static BasicAuthenticatorCacheManager createAuthenticatorCacheManager(
final Injector injector,
BasicAuthClassCompositionConfig config
) throws ClassNotFoundException
{
if (config.getAuthenticatorCacheManager() != null) {
return (BasicAuthenticatorCacheManager)
injector.getInstance(Class.forName(config.getAuthenticatorCacheManager()));
}
if (isCoordinator(injector)) {
return injector.getInstance(MetadataStoragePollingBasicAuthenticatorCacheManager.class);
} else {
return injector.getInstance(CoordinatorPollingBasicAuthenticatorCacheManager.class);
}
}

@Provides @LazySingleton
public static BasicAuthenticatorResourceHandler createAuthenticatorResourceHandler(final Injector injector)
@Provides
@LazySingleton
public static BasicAuthenticatorResourceHandler createAuthenticatorResourceHandler(
final Injector injector,
BasicAuthClassCompositionConfig config
) throws ClassNotFoundException
{
if (config.getAuthenticatorResourceHandler() != null) {
return (BasicAuthenticatorResourceHandler)
injector.getInstance(Class.forName(config.getAuthenticatorResourceHandler()));
}
if (isCoordinator(injector)) {
return injector.getInstance(CoordinatorBasicAuthenticatorResourceHandler.class);
} else {
return injector.getInstance(DefaultBasicAuthenticatorResourceHandler.class);
}
}

@Provides @LazySingleton
public static BasicAuthenticatorCacheNotifier createAuthenticatorCacheNotifier(final Injector injector)
@Provides
@LazySingleton
public static BasicAuthenticatorCacheNotifier createAuthenticatorCacheNotifier(
final Injector injector,
BasicAuthClassCompositionConfig config
) throws ClassNotFoundException
{
if (config.getAuthenticatorCacheNotifier() != null) {
return (BasicAuthenticatorCacheNotifier)
injector.getInstance(Class.forName(config.getAuthenticatorCacheNotifier()));
}
if (isCoordinator(injector)) {
return injector.getInstance(CoordinatorBasicAuthenticatorCacheNotifier.class);
} else {
return null;
}
}

@Provides @LazySingleton
public static BasicAuthorizerMetadataStorageUpdater createAuthorizerStorageUpdater(final Injector injector)
@Provides
@LazySingleton
public static BasicAuthorizerMetadataStorageUpdater createAuthorizerStorageUpdater(
final Injector injector,
BasicAuthClassCompositionConfig config
)
throws ClassNotFoundException
{
if (config.getAuthorizerMetadataStorageUpdater() != null) {
return (BasicAuthorizerMetadataStorageUpdater)
injector.getInstance(Class.forName(config.getAuthorizerMetadataStorageUpdater()));
}
if (isCoordinator(injector)) {
return injector.getInstance(CoordinatorBasicAuthorizerMetadataStorageUpdater.class);
} else {
return null;
}
}

@Provides @LazySingleton
public static BasicAuthorizerCacheManager createAuthorizerCacheManager(final Injector injector)
@Provides
@LazySingleton
public static BasicAuthorizerCacheManager createAuthorizerCacheManager(
final Injector injector,
BasicAuthClassCompositionConfig config
) throws ClassNotFoundException
{
if (config.getAuthorizerCacheManager() != null) {
return (BasicAuthorizerCacheManager)
injector.getInstance(Class.forName(config.getAuthorizerCacheManager()));
}
if (isCoordinator(injector)) {
return injector.getInstance(MetadataStoragePollingBasicAuthorizerCacheManager.class);
} else {
return injector.getInstance(CoordinatorPollingBasicAuthorizerCacheManager.class);
}
}

@Provides @LazySingleton
public static BasicAuthorizerResourceHandler createAuthorizerResourceHandler(final Injector injector)
@Provides
@LazySingleton
public static BasicAuthorizerResourceHandler createAuthorizerResourceHandler(
final Injector injector,
BasicAuthClassCompositionConfig config
) throws ClassNotFoundException
{
if (config.getAuthorizerResourceHandler() != null) {
return (BasicAuthorizerResourceHandler)
injector.getInstance(Class.forName(config.getAuthorizerResourceHandler()));
}
if (isCoordinator(injector)) {
return injector.getInstance(CoordinatorBasicAuthorizerResourceHandler.class);
} else {
return injector.getInstance(DefaultBasicAuthorizerResourceHandler.class);
}
}

@Provides @LazySingleton
public static BasicAuthorizerCacheNotifier createAuthorizerCacheNotifier(final Injector injector)
@Provides
@LazySingleton
public static BasicAuthorizerCacheNotifier createAuthorizerCacheNotifier(
final Injector injector,
BasicAuthClassCompositionConfig config
) throws ClassNotFoundException
{
if (config.getAuthorizerCacheNotifier() != null) {
return (BasicAuthorizerCacheNotifier)
injector.getInstance(Class.forName(config.getAuthorizerCacheNotifier()));
}
if (isCoordinator(injector)) {
return injector.getInstance(CoordinatorBasicAuthorizerCacheNotifier.class);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to Metamarkets Group Inc. (Metamarkets) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Metamarkets licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package io.druid.security.basic.authentication.db.cache;

public class NoopBasicAuthenticatorCacheNotifier implements BasicAuthenticatorCacheNotifier

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this class is needed? It's not used in this PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is needed on a config level
https://github.com/metamx/druid-config/pull/99

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to specify whether "noop" means "no auth" or "always rejecting auth".

{
@Override
public void addUpdate(String updatedAuthenticatorPrefix, byte[] updatedUserMap)
{
// Do nothing as this is a noop implementation
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to Metamarkets Group Inc. (Metamarkets) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Metamarkets licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package io.druid.security.basic.authorization.db.cache;

public class NoopBasicAuthorizerCacheNotifier implements BasicAuthorizerCacheNotifier

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also removed the same classes from test scope so this class is used in tests now

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

{
@Override
public void addUpdate(String authorizerPrefix, byte[] userAndRoleMap)
{
// Do nothing as this is a noop implementation
}
}