-
Notifications
You must be signed in to change notification settings - Fork 237
[CALCITE-6135] BEARER authentication support #299
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF 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 org.apache.calcite.avatica; | ||
|
|
||
| public interface ConnectionPropertyValue { | ||
| /** | ||
| * Returns the string value of this property, or null if not specified and | ||
| * no default. | ||
| */ | ||
| String getString(); | ||
|
|
||
| /** | ||
| * Returns the string value of this property, or null if not specified and | ||
| * no default. | ||
| */ | ||
| String getString(String defaultValue); | ||
|
|
||
| /** | ||
| * Returns the int value of this property. Throws if not set and no | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does "default" mean here?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It has been copied from PropEnv, the same applies to all similar functions.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, it's not "long"
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. property is a ConnectionProperty which has a defaultValue functions. |
||
| * default. | ||
| */ | ||
| int getInt(); | ||
|
|
||
| /** | ||
| * Returns the int value of this property. Throws if not set and no | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No default means defaultValue is null?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably You are right it can only happen if the defaultValue is set to null |
||
| * default. | ||
| */ | ||
| int getInt(Number defaultValue); | ||
|
|
||
| /** | ||
| * Returns the long value of this property. Throws if not set and no | ||
| * default. | ||
| */ | ||
| long getLong(); | ||
|
|
||
| /** | ||
| * Returns the long value of this property. Throws if not set and no | ||
| * default. | ||
| */ | ||
| long getLong(Number defaultValue); | ||
|
|
||
| /** | ||
| * Returns the double value of this property. Throws if not set and no | ||
| * default. | ||
| */ | ||
| double getDouble(); | ||
|
|
||
| /** | ||
| * Returns the double value of this property. Throws if not set and no | ||
| * default. | ||
| */ | ||
| double getDouble(Number defaultValue); | ||
|
|
||
| /** | ||
| * Returns the boolean value of this property. Throws if not set and no | ||
| * default. | ||
| */ | ||
| boolean getBoolean(); | ||
|
|
||
| /** | ||
| * Returns the boolean value of this property. Throws if not set and no | ||
| * default. | ||
| */ | ||
| boolean getBoolean(boolean defaultValue); | ||
|
|
||
| /** | ||
| * Returns the enum value of this property. Throws if not set and no | ||
| * default. | ||
| */ | ||
| <E extends Enum<E>> E getEnum(Class<E> enumClass); | ||
|
|
||
| /** | ||
| * Returns the enum value of this property. Throws if not set and no | ||
| * default. | ||
| */ | ||
| <E extends Enum<E>> E getEnum(Class<E> enumClass, E defaultValue); | ||
|
|
||
| /** | ||
| * Returns an instance of a plugin. | ||
| * | ||
| * <p>Throws if not set and no default. | ||
| * Also throws if the class does not implement the required interface, | ||
| * or if it does not have a public default constructor or an public static | ||
| * field called {@code #INSTANCE}. | ||
| */ | ||
| <T> T getPlugin(Class<T> pluginClass, T defaultInstance); | ||
|
|
||
| /** | ||
| * Returns an instance of a plugin, using a given class name if none is | ||
| * set. | ||
| * | ||
| * <p>Throws if not set and no default. | ||
| * Also throws if the class does not implement the required interface, | ||
| * or if it does not have a public default constructor or an public static | ||
| * field called {@code #INSTANCE}. | ||
| */ | ||
| <T> T getPlugin(Class<T> pluginClass, String defaultClassName, | ||
| T defaultInstance); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ public enum AuthenticationType { | |
| BASIC, | ||
| DIGEST, | ||
| SPNEGO, | ||
| BEARER, | ||
| CUSTOM; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -131,6 +131,24 @@ public static AvaticaHttpClientFactoryImpl getInstance() { | |
| LOG.debug("{} is not capable of kerberos authentication.", authType); | ||
| } | ||
|
|
||
| if (client instanceof BearerAuthenticateable) { | ||
| if (AuthenticationType.BEARER == authType) { | ||
| try { | ||
| BearerTokenProvider tokenProvider = | ||
| BearerTokenProviderFactory.getBearerTokenProvider(config); | ||
| String username = config.avaticaUser(); | ||
| if (null == username) { | ||
| username = System.getProperty("user.name"); | ||
| } | ||
| ((BearerAuthenticateable) client).setTokenProvider(username, tokenProvider); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can userName by null here?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The userName can not be null when calling setTokenProvider
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But can't System.getProperty return null? |
||
| } catch (java.io.IOException e) { | ||
| LOG.debug("Failed to initialize bearer authentication"); | ||
| } | ||
| } | ||
| } else { | ||
| LOG.debug("{} is not capable of bearer authentication.", authType); | ||
| } | ||
|
|
||
| if (null != kerberosUtil) { | ||
| client = new DoAsAvaticaHttpClient(client, kerberosUtil); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF 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 org.apache.calcite.avatica.remote; | ||
|
|
||
| /** | ||
| * Interface that allows configuration of a username and BearerTokenProvider HTTP authentication. | ||
| */ | ||
| public interface BearerAuthenticateable { | ||
|
|
||
| /** | ||
| * Sets the username, tokenProvider to be used for authentication. | ||
| * | ||
| * @param username Username | ||
| * @param tokenProvider Bearer Token Provider | ||
| */ | ||
| void setTokenProvider(String username, BearerTokenProvider tokenProvider); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF 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 org.apache.calcite.avatica.remote; | ||
|
|
||
| import org.apache.calcite.avatica.ConnectionConfig; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Interface that provides bearer token for authentication. | ||
| */ | ||
| public interface BearerTokenProvider { | ||
|
|
||
| /** | ||
| * Initialize JSON Web Token from the config to be used for authentication. | ||
| * | ||
| * @param config ConnectionConfig | ||
| */ | ||
| void init(ConnectionConfig config) throws IOException; | ||
|
|
||
| /** | ||
| * Returns JSON Web Token used for authentication or null. | ||
| * | ||
| * @param username Username | ||
| */ | ||
| String obtain(String username); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please document this method?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I'll do that It returns the Token used for Authentication. |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the only one that never throws, why this asymmetry?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think either getString methods Throw.
It has been copied from PropEnv which is the implementation of this ConnectionPropertyValue interface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you didn't write that documentation, but is there a way to check whether this is correct?
If not, maybe you can fix it there too.