-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic authentication to Pinot connector
- Loading branch information
Showing
28 changed files
with
888 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
plugin/trino-pinot/src/main/java/io/trino/plugin/pinot/auth/PinotAuthenticationModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* Licensed 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.trino.plugin.pinot.auth; | ||
|
||
import com.google.inject.Binder; | ||
import com.google.inject.Module; | ||
import com.google.inject.Provides; | ||
import io.airlift.configuration.AbstractConfigurationAwareModule; | ||
import io.trino.plugin.pinot.auth.none.PinotEmptyAuthenticationProvider; | ||
import io.trino.plugin.pinot.auth.password.PinotPasswordAuthenticationProvider; | ||
import io.trino.plugin.pinot.auth.password.inline.PinotPasswordBrokerAuthenticationConfig; | ||
import io.trino.plugin.pinot.auth.password.inline.PinotPasswordControllerAuthenticationConfig; | ||
|
||
import javax.inject.Singleton; | ||
|
||
import static io.airlift.configuration.ConditionalModule.conditionalModule; | ||
import static io.airlift.configuration.ConfigBinder.configBinder; | ||
import static io.trino.plugin.pinot.auth.PinotAuthenticationType.NONE; | ||
import static io.trino.plugin.pinot.auth.PinotAuthenticationType.PASSWORD; | ||
|
||
public class PinotAuthenticationModule | ||
extends AbstractConfigurationAwareModule | ||
{ | ||
@Override | ||
protected void setup(Binder binder) | ||
{ | ||
bindAuthenticationProviderModule( | ||
NONE, | ||
new PinotNoneControllerAuthenticationProviderModule(), | ||
new PinotNoneBrokerAuthenticationProviderModule()); | ||
bindAuthenticationProviderModule( | ||
PASSWORD, | ||
new PinotPasswordControllerAuthenticationProviderModule(), | ||
new PinotPasswordBrokerAuthenticationProviderModule()); | ||
} | ||
|
||
private void bindAuthenticationProviderModule(PinotAuthenticationType authType, Module controllerModule, Module brokerModule) | ||
{ | ||
install(conditionalModule( | ||
PinotAuthenticationTypeConfig.class, | ||
config -> authType == config.getControllerAuthenticationType(), | ||
controllerModule)); | ||
install(conditionalModule( | ||
PinotAuthenticationTypeConfig.class, | ||
config -> authType == config.getBrokerAuthenticationType(), | ||
brokerModule)); | ||
} | ||
|
||
private static class PinotNoneControllerAuthenticationProviderModule | ||
implements Module | ||
{ | ||
@Override | ||
public void configure(Binder binder) | ||
{ | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
public PinotControllerAuthenticationProvider getAuthenticationProvider() | ||
{ | ||
return PinotControllerAuthenticationProvider.create(PinotEmptyAuthenticationProvider.instance()); | ||
} | ||
} | ||
|
||
private static class PinotNoneBrokerAuthenticationProviderModule | ||
implements Module | ||
{ | ||
@Override | ||
public void configure(Binder binder) | ||
{ | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
public PinotBrokerAuthenticationProvider getAuthenticationProvider() | ||
{ | ||
return PinotBrokerAuthenticationProvider.create(PinotEmptyAuthenticationProvider.instance()); | ||
} | ||
} | ||
|
||
private static class PinotPasswordControllerAuthenticationProviderModule | ||
implements Module | ||
{ | ||
@Override | ||
public void configure(Binder binder) | ||
{ | ||
configBinder(binder).bindConfig(PinotPasswordControllerAuthenticationConfig.class); | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
public PinotControllerAuthenticationProvider getAuthenticationProvider( | ||
PinotPasswordControllerAuthenticationConfig config) | ||
{ | ||
return PinotControllerAuthenticationProvider.create(new PinotPasswordAuthenticationProvider(config.getUser(), config.getPassword())); | ||
} | ||
} | ||
|
||
private static class PinotPasswordBrokerAuthenticationProviderModule | ||
implements Module | ||
{ | ||
@Override | ||
public void configure(Binder binder) | ||
{ | ||
configBinder(binder).bindConfig(PinotPasswordBrokerAuthenticationConfig.class); | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
public PinotBrokerAuthenticationProvider getAuthenticationProvider( | ||
PinotPasswordBrokerAuthenticationConfig config) | ||
{ | ||
return PinotBrokerAuthenticationProvider.create(new PinotPasswordAuthenticationProvider(config.getUser(), config.getPassword())); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
plugin/trino-pinot/src/main/java/io/trino/plugin/pinot/auth/PinotAuthenticationProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Licensed 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.trino.plugin.pinot.auth; | ||
|
||
import java.util.Optional; | ||
|
||
public interface PinotAuthenticationProvider | ||
{ | ||
Optional<String> getAuthenticationToken(); | ||
} |
19 changes: 19 additions & 0 deletions
19
plugin/trino-pinot/src/main/java/io/trino/plugin/pinot/auth/PinotAuthenticationType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Licensed 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.trino.plugin.pinot.auth; | ||
|
||
public enum PinotAuthenticationType { | ||
NONE, | ||
PASSWORD, | ||
} |
50 changes: 50 additions & 0 deletions
50
...n/trino-pinot/src/main/java/io/trino/plugin/pinot/auth/PinotAuthenticationTypeConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Licensed 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.trino.plugin.pinot.auth; | ||
|
||
import io.airlift.configuration.Config; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
public class PinotAuthenticationTypeConfig | ||
{ | ||
private PinotAuthenticationType controllerAuthenticationType = PinotAuthenticationType.NONE; | ||
private PinotAuthenticationType brokerAuthenticationType = PinotAuthenticationType.NONE; | ||
|
||
@NotNull | ||
public PinotAuthenticationType getControllerAuthenticationType() | ||
{ | ||
return controllerAuthenticationType; | ||
} | ||
|
||
@Config("pinot.controller.authentication.type") | ||
public PinotAuthenticationTypeConfig setControllerAuthenticationType(PinotAuthenticationType controllerAuthenticationType) | ||
{ | ||
this.controllerAuthenticationType = controllerAuthenticationType; | ||
return this; | ||
} | ||
|
||
@NotNull | ||
public PinotAuthenticationType getBrokerAuthenticationType() | ||
{ | ||
return brokerAuthenticationType; | ||
} | ||
|
||
@Config("pinot.broker.authentication.type") | ||
public PinotAuthenticationTypeConfig setBrokerAuthenticationType(PinotAuthenticationType brokerAuthenticationType) | ||
{ | ||
this.brokerAuthenticationType = brokerAuthenticationType; | ||
return this; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...ino-pinot/src/main/java/io/trino/plugin/pinot/auth/PinotBrokerAuthenticationProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Licensed 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.trino.plugin.pinot.auth; | ||
|
||
import java.util.Optional; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
public class PinotBrokerAuthenticationProvider | ||
implements PinotAuthenticationProvider | ||
{ | ||
public static PinotBrokerAuthenticationProvider create(PinotAuthenticationProvider delegate) | ||
{ | ||
return new PinotBrokerAuthenticationProvider(delegate); | ||
} | ||
|
||
private final PinotAuthenticationProvider delegate; | ||
|
||
private PinotBrokerAuthenticationProvider(PinotAuthenticationProvider delegate) | ||
{ | ||
this.delegate = requireNonNull(delegate, "Delegate broker authentication provider is required"); | ||
} | ||
|
||
@Override | ||
public Optional<String> getAuthenticationToken() | ||
{ | ||
return delegate.getAuthenticationToken(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...pinot/src/main/java/io/trino/plugin/pinot/auth/PinotControllerAuthenticationProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Licensed 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.trino.plugin.pinot.auth; | ||
|
||
import java.util.Optional; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
public class PinotControllerAuthenticationProvider | ||
implements PinotAuthenticationProvider | ||
{ | ||
public static PinotControllerAuthenticationProvider create(PinotAuthenticationProvider delegate) | ||
{ | ||
return new PinotControllerAuthenticationProvider(delegate); | ||
} | ||
|
||
private final PinotAuthenticationProvider delegate; | ||
|
||
private PinotControllerAuthenticationProvider(PinotAuthenticationProvider delegate) | ||
{ | ||
this.delegate = requireNonNull(delegate, "Delegate controller authentication provider is required"); | ||
} | ||
|
||
@Override | ||
public Optional<String> getAuthenticationToken() | ||
{ | ||
return delegate.getAuthenticationToken(); | ||
} | ||
} |
Oops, something went wrong.