-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HDFS-16591. Setup JaasConfiguration in ZKCuratorManager when SASL is … #4447
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
...-auth/src/main/java/org/apache/hadoop/security/authentication/util/JaasConfiguration.java
This file contains hidden or 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,77 @@ | ||
| /** | ||
| * 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. See accompanying LICENSE file. | ||
| */ | ||
| package org.apache.hadoop.security.authentication.util; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import javax.security.auth.login.AppConfigurationEntry; | ||
| import javax.security.auth.login.Configuration; | ||
|
|
||
|
|
||
| /** | ||
| * Creates a programmatic version of a jaas.conf file. This can be used | ||
| * instead of writing a jaas.conf file and setting the system property, | ||
| * "java.security.auth.login.config", to point to that file. It is meant to be | ||
| * used for connecting to ZooKeeper. | ||
| */ | ||
| public class JaasConfiguration extends Configuration { | ||
|
|
||
| private final javax.security.auth.login.Configuration baseConfig = | ||
| javax.security.auth.login.Configuration.getConfiguration(); | ||
| private final AppConfigurationEntry[] entry; | ||
| private final String entryName; | ||
|
|
||
| /** | ||
| * Add an entry to the jaas configuration with the passed in name, | ||
| * principal, and keytab. The other necessary options will be set for you. | ||
| * | ||
| * @param entryName The name of the entry (e.g. "Client") | ||
| * @param principal The principal of the user | ||
| * @param keytab The location of the keytab | ||
| */ | ||
| public JaasConfiguration(String entryName, String principal, String keytab) { | ||
| this.entryName = entryName; | ||
| Map<String, String> options = new HashMap<>(); | ||
| options.put("keyTab", keytab); | ||
| options.put("principal", principal); | ||
| options.put("useKeyTab", "true"); | ||
| options.put("storeKey", "true"); | ||
| options.put("useTicketCache", "false"); | ||
| options.put("refreshKrb5Config", "true"); | ||
| String jaasEnvVar = System.getenv("HADOOP_JAAS_DEBUG"); | ||
| if ("true".equalsIgnoreCase(jaasEnvVar)) { | ||
| options.put("debug", "true"); | ||
| } | ||
| entry = new AppConfigurationEntry[]{ | ||
| new AppConfigurationEntry(getKrb5LoginModuleName(), | ||
| AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, | ||
| options)}; | ||
| } | ||
|
|
||
| @Override | ||
| public AppConfigurationEntry[] getAppConfigurationEntry(String name) { | ||
| return (entryName.equals(name)) ? entry : ((baseConfig != null) | ||
| ? baseConfig.getAppConfigurationEntry(name) : null); | ||
| } | ||
|
|
||
| private String getKrb5LoginModuleName() { | ||
| String krb5LoginModuleName; | ||
| if (System.getProperty("java.vendor").contains("IBM")) { | ||
| krb5LoginModuleName = "com.ibm.security.auth.module.Krb5LoginModule"; | ||
| } else { | ||
| krb5LoginModuleName = "com.sun.security.auth.module.Krb5LoginModule"; | ||
| } | ||
| return krb5LoginModuleName; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
There are unused imports between line 28 and 34.
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.
Thanks. I've removed these and other unused imports in RegistrySecurity