From 76a5d7fa4904119c7e69329e490ad8a09f61061a Mon Sep 17 00:00:00 2001
From: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com>
Date: Thu, 1 Jun 2023 10:03:13 -0400
Subject: [PATCH] Updates the style of all java files under the */dlic/util/
dir. (#2823)
* rebase
Signed-off-by: Stephen Crawford
* Update java style under **/auth
Signed-off-by: Stephen Crawford
* Update Util dir
Signed-off-by: Stephen Crawford
* readd formatting
Signed-off-by: Stephen Crawford
---------
Signed-off-by: Stephen Crawford
---
build.gradle | 54 +-
.../SecurityBackwardsCompatibilityIT.java | 8 +-
gradle/formatting.gradle | 129 ++-
.../jwt/AbstractHTTPJwtAuthenticator.java | 24 +-
.../auth/http/jwt/HTTPJwtAuthenticator.java | 113 ++-
.../AuthenticatorUnavailableException.java | 33 +-
.../keybyoidc/BadCredentialsException.java | 33 +-
...TTPJwtKeyByOpenIdConnectAuthenticator.java | 92 +-
.../auth/http/jwt/keybyoidc/JwtVerifier.java | 177 ++--
.../auth/http/jwt/keybyoidc/KeyProvider.java | 5 +-
.../http/jwt/keybyoidc/KeySetProvider.java | 2 +-
.../http/jwt/keybyoidc/KeySetRetriever.java | 343 +++----
.../jwt/keybyoidc/SelfRefreshingKeySet.java | 587 ++++++------
.../json/OpenIdProviderConfiguration.java | 16 +-
.../kerberos/HTTPSpnegoAuthenticator.java | 106 +-
.../auth/http/kerberos/util/JaasKrbUtil.java | 344 +++----
.../auth/http/kerberos/util/KrbConstants.java | 45 +-
.../http/saml/AuthTokenProcessorHandler.java | 96 +-
.../auth/http/saml/HTTPSamlAuthenticator.java | 70 +-
.../auth/http/saml/Saml2SettingsProvider.java | 81 +-
.../http/saml/SamlHTTPMetadataResolver.java | 3 +-
.../com/amazon/dlic/auth/ldap/LdapUser.java | 22 +-
.../backend/LDAPAuthenticationBackend.java | 115 ++-
.../backend/LDAPAuthorizationBackend.java | 364 ++++---
.../dlic/auth/ldap/util/ConfigConstants.java | 9 +-
.../dlic/auth/ldap/util/LdapHelper.java | 28 +-
.../com/amazon/dlic/auth/ldap/util/Utils.java | 12 +-
.../ldap2/LDAPAuthenticationBackend2.java | 37 +-
.../auth/ldap2/LDAPAuthorizationBackend2.java | 132 ++-
.../ldap2/LDAPConnectionFactoryFactory.java | 74 +-
.../dlic/auth/ldap2/LDAPUserSearcher.java | 63 +-
.../util/SettingsBasedSSLConfigurator.java | 233 +++--
.../util/SettingsBasedSSLConfiguratorV4.java | 233 +++--
.../security/DefaultObjectMapper.java | 6 +-
.../ConfigUpdateNodeResponse.java | 10 +-
.../TransportConfigUpdateAction.java | 8 +-
.../action/whoami/TransportWhoAmIAction.java | 6 +-
.../action/whoami/WhoAmIRequestBuilder.java | 2 +-
.../action/whoami/WhoAmIResponse.java | 8 +-
.../security/auditlog/AuditLog.java | 2 +-
.../security/auditlog/config/AuditConfig.java | 2 +-
.../security/auth/AuthFailureListener.java | 6 +-
.../security/auth/AuthenticationBackend.java | 14 +-
.../security/auth/AuthorizationBackend.java | 4 +-
.../security/auth/BackendRegistry.java | 12 +-
.../security/auth/HTTPAuthenticator.java | 16 +-
.../auth/blocking/ClientBlockRegistry.java | 6 +-
.../HeapBasedClientBlockRegistry.java | 6 +-
.../auth/limiting/AbstractRateLimiter.java | 6 +-
.../limiting/AddressBasedRateLimiter.java | 6 +-
.../limiting/UserNameBasedRateLimiter.java | 6 +-
.../security/configuration/AdminDNs.java | 30 +-
.../configuration/ClusterInfoHolder.java | 6 +-
.../security/configuration/CompatConfig.java | 6 +-
.../configuration/ConfigCallback.java | 2 +-
...onfigUpdateAlreadyInProgressException.java | 6 +-
.../configuration/DlsFlsRequestValve.java | 4 +-
.../configuration/DlsFlsValveImpl.java | 6 +-
.../configuration/DlsQueryParser.java | 8 +-
.../configuration/EmptyFilterLeafReader.java | 2 +-
.../configuration/InvalidConfigException.java | 2 +-
.../StaticResourceException.java | 6 +-
.../security/filter/SecurityFilter.java | 22 +-
.../security/filter/SecurityRestFilter.java | 12 +-
.../security/http/HTTPBasicAuthenticator.java | 8 +-
.../http/HTTPClientCertAuthenticator.java | 18 +-
.../security/http/HTTPProxyAuthenticator.java | 6 +-
.../security/http/RemoteIpDetector.java | 20 +-
.../http/SecurityHttpServerTransport.java | 2 +-
.../SecurityNonSslHttpServerTransport.java | 2 +-
.../opensearch/security/http/XFFResolver.java | 14 +-
.../proxy/HTTPExtendedProxyAuthenticator.java | 4 +-
.../security/httpclient/HttpClient.java | 2 +-
.../privileges/DocumentAllowList.java | 2 +-
.../privileges/PrivilegesEvaluator.java | 10 +-
.../PrivilegesEvaluatorResponse.java | 12 +-
.../privileges/PrivilegesInterceptor.java | 4 +-
.../SecurityIndexAccessEvaluator.java | 6 +-
.../privileges/SnapshotRestoreEvaluator.java | 18 +-
.../privileges/TermsAggregationEvaluator.java | 14 +-
.../resolver/IndexResolverReplacer.java | 12 +-
.../security/rest/DashboardsInfoAction.java | 8 +-
.../security/rest/SecurityHealthAction.java | 14 +-
.../security/rest/SecurityInfoAction.java | 14 +-
.../security/rest/TenantInfoAction.java | 24 +-
.../security/securityconf/ConfigModelV6.java | 72 +-
.../security/securityconf/ConfigModelV7.java | 80 +-
.../securityconf/DynamicConfigFactory.java | 44 +-
.../securityconf/DynamicConfigModel.java | 18 +-
.../securityconf/DynamicConfigModelV6.java | 58 +-
.../securityconf/DynamicConfigModelV7.java | 54 +-
.../securityconf/EvaluatedDlsFlsConfig.java | 4 +-
.../security/securityconf/Hideable.java | 2 +-
.../security/securityconf/Initializable.java | 2 +-
.../securityconf/InternalUsersModel.java | 2 +-
.../security/securityconf/Migration.java | 48 +-
.../securityconf/StaticDefinable.java | 2 +-
.../security/securityconf/impl/Meta.java | 16 +-
.../impl/SecurityDynamicConfiguration.java | 60 +-
.../securityconf/impl/v6/ActionGroupsV6.java | 8 +-
.../securityconf/impl/v6/ConfigV6.java | 64 +-
.../securityconf/impl/v6/InternalUserV6.java | 14 +-
.../securityconf/impl/v6/RoleMappingsV6.java | 2 +-
.../security/securityconf/impl/v6/RoleV6.java | 10 +-
.../securityconf/impl/v7/ActionGroupsV7.java | 18 +-
.../securityconf/impl/v7/ConfigV7.java | 112 +--
.../securityconf/impl/v7/InternalUserV7.java | 16 +-
.../securityconf/impl/v7/RoleMappingsV7.java | 2 +-
.../security/securityconf/impl/v7/RoleV7.java | 54 +-
.../securityconf/impl/v7/TenantV7.java | 10 +-
.../ssl/ExternalSecurityKeyStore.java | 30 +-
.../ssl/OpenSearchSecuritySSLPlugin.java | 76 +-
.../security/ssl/SecurityKeyStore.java | 8 +-
.../security/ssl/SslExceptionHandler.java | 12 +-
.../SecuritySSLNettyHttpServerTransport.java | 12 +-
.../ssl/http/netty/ValidatingDispatcher.java | 14 +-
.../ssl/rest/SecuritySSLInfoAction.java | 14 +-
.../transport/DefaultPrincipalExtractor.java | 16 +-
.../ssl/transport/PrincipalExtractor.java | 14 +-
.../transport/SecuritySSLNettyTransport.java | 22 +-
.../transport/SecuritySSLRequestHandler.java | 34 +-
.../SecuritySSLTransportInterceptor.java | 12 +-
.../ssl/util/CertificateValidator.java | 68 +-
.../security/ssl/util/ExceptionUtils.java | 20 +-
.../ssl/util/SSLCertificateHelper.java | 34 +-
.../security/ssl/util/SSLConfigConstants.java | 52 +-
.../security/ssl/util/SSLRequestHelper.java | 50 +-
.../opensearch/security/ssl/util/Utils.java | 12 +-
.../security/support/ConfigConstants.java | 24 +-
.../security/support/HTTPHelper.java | 14 +-
.../security/support/HeaderHelper.java | 6 +-
.../opensearch/security/support/MapUtils.java | 6 +-
.../security/support/ModuleInfo.java | 18 +-
.../security/support/PemKeyReader.java | 86 +-
.../support/ReflectiveAttributeAccessors.java | 4 +-
.../security/support/SecurityJsonNode.java | 30 +-
.../security/support/SecurityUtils.java | 20 +-
.../support/SnapshotRestoreHelper.java | 18 +-
.../security/support/SourceFieldsContext.java | 2 +-
.../security/support/WildcardMatcher.java | 2 +-
.../org/opensearch/security/tools/Hasher.java | 4 +-
.../opensearch/security/tools/Migrater.java | 32 +-
.../security/tools/SecurityAdmin.java | 202 ++--
.../DefaultInterClusterRequestEvaluator.java | 10 +-
.../InterClusterRequestEvaluator.java | 8 +-
.../transport/SecurityInterceptor.java | 8 +-
.../transport/SecurityRequestHandler.java | 2 +-
.../security/user/CustomAttributesAware.java | 2 +-
.../org/opensearch/security/user/User.java | 34 +-
.../ratetracking/HeapBasedRateTracker.java | 8 +-
.../util/ratetracking/RateTracker.java | 6 +-
.../ratetracking/SingleTryRateTracker.java | 6 +-
.../http/jwt/HTTPJwtAuthenticatorTest.java | 149 +--
.../auth/http/jwt/keybyoidc/CxfTestTools.java | 6 +-
...wtKeyByOpenIdConnectAuthenticatorTest.java | 699 +++++++-------
.../jwt/keybyoidc/KeySetRetrieverTest.java | 32 +-
.../http/jwt/keybyoidc/MockIpdServer.java | 250 ++---
.../keybyoidc/SelfRefreshingKeySetTest.java | 135 ++-
...wtKeyByOpenIdConnectAuthenticatorTest.java | 361 ++++---
.../dlic/auth/http/jwt/keybyoidc/TestJwk.java | 152 +--
.../auth/http/jwt/keybyoidc/TestJwts.java | 157 +--
.../http/saml/HTTPSamlAuthenticatorTest.java | 471 +++++----
.../auth/http/saml/MockSamlIdpServer.java | 188 ++--
.../dlic/auth/ldap/LdapBackendIntegTest.java | 15 +-
.../dlic/auth/ldap/LdapBackendTest.java | 904 +++++++++---------
.../auth/ldap/LdapBackendTestClientCert.java | 303 +++---
.../ldap/LdapBackendTestNewStyleConfig.java | 714 ++++++++------
.../com/amazon/dlic/auth/ldap/UtilsTest.java | 37 +-
.../auth/ldap/srv/EmbeddedLDAPServer.java | 1 -
.../amazon/dlic/auth/ldap/srv/LdapServer.java | 37 +-
.../auth/ldap2/LdapBackendIntegTest2.java | 15 +-
.../ldap2/LdapBackendTestClientCert2.java | 303 +++---
.../ldap2/LdapBackendTestNewStyleConfig2.java | 873 ++++++++++-------
.../ldap2/LdapBackendTestOldStyleConfig2.java | 878 +++++++++--------
.../org/opensearch/node/PluginAwareNode.java | 4 +-
.../opensearch/security/AggregationTests.java | 24 +-
...waysFalseInterClusterRequestEvaluator.java | 4 +-
.../org/opensearch/security/ConfigTests.java | 40 +-
.../org/opensearch/security/HealthTests.java | 12 +-
.../security/HttpIntegrationTests.java | 220 ++---
.../security/IndexIntegrationTests.java | 236 ++---
.../InitializationIntegrationTests.java | 38 +-
.../opensearch/security/IntegrationTests.java | 140 +--
.../opensearch/security/ResolveAPITests.java | 2 +-
.../security/RolesInjectorIntegTest.java | 2 +-
.../security/RolesValidationIntegTest.java | 2 +-
.../security/SecurityAdminTests.java | 152 +--
.../security/SlowIntegrationTests.java | 40 +-
.../security/SystemIntegratorsTests.java | 80 +-
.../org/opensearch/security/TaskTests.java | 10 +-
.../org/opensearch/security/UtilTests.java | 20 +-
.../compliance/ComplianceAuditlogTest.java | 2 +-
.../integration/BasicAuditlogTest.java | 4 +-
.../HeapBasedClientBlockRegistryTest.java | 22 +-
.../limiting/AddressBasedRateLimiterTest.java | 6 +-
.../limiting/HeapBasedRateTrackerTest.java | 64 +-
.../UserNameBasedRateLimiterTest.java | 6 +-
.../ccstest/CrossClusterSearchTests.java | 8 +-
.../security/ccstest/RemoteReindexTests.java | 36 +-
.../dlic/dlsfls/AbstractDlsFlsTest.java | 12 +-
.../dlic/dlsfls/CCReplicationTest.java | 2 +-
.../security/dlic/dlsfls/DlsDateMathTest.java | 10 +-
.../dlic/dlsfls/DlsTermLookupQueryTest.java | 4 +-
.../dlic/dlsfls/FlsIndexingTests.java | 4 +-
.../dlic/rest/api/AccountApiTest.java | 4 +-
.../dlic/rest/api/ActionGroupsApiTest.java | 2 +-
.../dlic/rest/api/AuditApiActionTest.java | 2 +-
.../rest/api/DashboardsInfoActionTest.java | 2 +-
.../dlic/rest/api/FlushCacheApiTest.java | 2 +-
.../rest/api/GetConfigurationApiTest.java | 2 +-
.../dlic/rest/api/IndexMissingTest.java | 2 +-
.../dlic/rest/api/NodesDnApiTest.java | 2 +-
.../dlic/rest/api/RoleBasedAccessTest.java | 2 +-
.../dlic/rest/api/RolesMappingApiTest.java | 2 +-
.../dlic/rest/api/SecurityApiAccessTest.java | 2 +-
.../dlic/rest/api/SecurityConfigApiTest.java | 4 +-
.../rest/api/SecurityHealthActionTest.java | 2 +-
.../dlic/rest/api/SecurityInfoActionTest.java | 2 +-
.../dlic/rest/api/TenantInfoActionTest.java | 4 +-
.../dlic/rest/api/WhitelistApiTest.java | 2 +-
.../security/filter/SecurityFilterTest.java | 2 +-
.../HTTPExtendedProxyAuthenticatorTest.java | 24 +-
.../test/TenancyMultitenancyEnabledTests.java | 4 +-
.../SecurityIndexAccessEvaluatorTest.java | 6 +-
.../impl/v7/IndexPatternTests.java | 10 +-
.../setting/DeprecatedSettingsTest.java | 2 +-
.../ssl/CertificateValidatorTest.java | 50 +-
.../opensearch/security/ssl/OpenSSLTest.java | 24 +-
.../security/ssl/TestPrincipalExtractor.java | 14 +-
.../test/AbstractSecurityUnitTest.java | 4 +-
.../helper/cluster/ClusterConfiguration.java | 28 +-
.../test/helper/cluster/ClusterHelper.java | 4 +-
.../security/test/helper/file/FileHelper.java | 12 +-
.../security/test/helper/rest/RestHelper.java | 36 +-
.../helper/rules/SecurityTestWatcher.java | 2 +-
.../test/plugin/UserInjectorPlugin.java | 16 +-
236 files changed, 7670 insertions(+), 6451 deletions(-)
diff --git a/build.gradle b/build.gradle
index bd2eba30ba..94f62ab567 100644
--- a/build.gradle
+++ b/build.gradle
@@ -10,6 +10,7 @@
*/
+import com.diffplug.gradle.spotless.JavaExtension
import org.opensearch.gradle.test.RestIntegTestTask
buildscript {
@@ -51,7 +52,7 @@ plugins {
id 'idea'
id 'jacoco'
id 'maven-publish'
- id 'com.diffplug.spotless' version '6.18.0'
+ id 'com.diffplug.spotless' version '6.19.0'
id 'checkstyle'
id 'com.netflix.nebula.ospackage' version "11.1.0"
id "org.gradle.test-retry" version "1.5.2"
@@ -69,7 +70,56 @@ apply plugin: 'opensearch.opensearchplugin'
apply plugin: 'opensearch.pluginzip'
apply plugin: 'opensearch.rest-test'
apply plugin: 'opensearch.testclusters'
-apply from: 'gradle/formatting.gradle'
+//apply from: 'gradle/formatting.gradle'
+
+spotless {
+ java {
+ // Normally this isn't necessary, but we have Java sources in
+ // non-standard places
+ target '**/com/amazon/dlic/**/*.java'
+
+ removeUnusedImports()
+ eclipse().configFile rootProject.file('formatter/formatterConfig.xml')
+ trimTrailingWhitespace()
+ endWithNewline();
+
+ // note: you can use an empty string for all the imports you didn't specify explicitly, and '\\#` prefix for static imports
+ importOrder('java', 'javax', '', 'com.amazon', 'org.opensearch', '\\#')
+
+ custom 'Refuse wildcard imports', {
+ // Wildcard imports can't be resolved; fail the build
+ if (it =~ /\s+import .*\*;/) {
+ throw new AssertionError("Do not use wildcard imports. 'spotlessApply' cannot resolve this issue.")
+ }
+ }
+
+ // See DEVELOPER_GUIDE.md for details of when to enable this.
+ if (System.getProperty('spotless.paddedcell') != null) {
+ paddedCell()
+ }
+ }
+ format 'misc', {
+ target '*.md', '*.gradle', '**/*.json', '**/*.yaml', '**/*.yml', '**/*.svg'
+
+ trimTrailingWhitespace()
+ endWithNewline()
+ }
+ format('javaFoo', JavaExtension) {
+
+ importOrder('java', 'javax', '', 'com.amazon', 'org.opensearch', '\\#')
+ target '**/*.java'
+ targetExclude '**/com/amazon/dlic/**/*.java'
+ targetExclude('src/integrationTest/**')
+
+ trimTrailingWhitespace()
+ endWithNewline();
+ }
+ format("integrationTest", JavaExtension) {
+ target('src/integrationTest/java/**/*.java')
+ importOrder('java', 'javax', '', 'com.amazon', 'org.opensearch', '\\#')
+ indentWithTabs(4)
+ }
+}
licenseFile = rootProject.file('LICENSE.txt')
noticeFile = rootProject.file('NOTICE.txt')
diff --git a/bwc-test/src/test/java/SecurityBackwardsCompatibilityIT.java b/bwc-test/src/test/java/SecurityBackwardsCompatibilityIT.java
index 1afc1b88d5..d3c3658245 100644
--- a/bwc-test/src/test/java/SecurityBackwardsCompatibilityIT.java
+++ b/bwc-test/src/test/java/SecurityBackwardsCompatibilityIT.java
@@ -12,17 +12,17 @@
import java.util.Set;
import java.util.stream.Collectors;
-import org.junit.Assume;
+import com.google.common.collect.ImmutableMap;
import org.junit.Assert;
+import org.junit.Assume;
import org.junit.Before;
+
+import org.opensearch.Version;
import org.opensearch.client.Response;
import org.opensearch.common.settings.Settings;
import org.opensearch.rest.RestStatus;
import org.opensearch.test.rest.OpenSearchRestTestCase;
-import org.opensearch.Version;
-import com.google.common.collect.ImmutableMap;
-
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItem;
diff --git a/gradle/formatting.gradle b/gradle/formatting.gradle
index 1851438039..40ae51afb1 100644
--- a/gradle/formatting.gradle
+++ b/gradle/formatting.gradle
@@ -1,36 +1,95 @@
-allprojects {
- project.apply plugin: "com.diffplug.spotless"
- spotless {
- java {
- // Normally this isn't necessary, but we have Java sources in
- // non-standard places
- target '*/com/amazon/dlic/auth/**/*.java'
-
- removeUnusedImports()
- eclipse().configFile rootProject.file('formatter/formatterConfig.xml')
- trimTrailingWhitespace()
- endWithNewline();
-
- // note: you can use an empty string for all the imports you didn't specify explicitly, and '\\#` prefix for static imports
- importOrder('java', 'javax', '', 'com.amazon', 'org.opensearch', '\\#')
-
- custom 'Refuse wildcard imports', {
- // Wildcard imports can't be resolved; fail the build
- if (it =~ /\s+import .*\*;/) {
- throw new AssertionError("Do not use wildcard imports. 'spotlessApply' cannot resolve this issue.")
- }
- }
-
- // See DEVELOPER_GUIDE.md for details of when to enable this.
- if (System.getProperty('spotless.paddedcell') != null) {
- paddedCell()
- }
- }
- format 'misc', {
- target '*.md', '*.gradle', '**/*.json', '**/*.yaml', '**/*.yml', '**/*.svg'
-
- trimTrailingWhitespace()
- endWithNewline()
- }
- }
+/*
+* SPDX-License-Identifier: Apache-2.0
+*
+* The OpenSearch Contributors require contributions made to
+* this file be licensed under the Apache-2.0 license or a
+* compatible open source license.
+*
+* Modifications Copyright OpenSearch Contributors. See
+* GitHub history for details.
+*/
+
+/*
+ * Licensed to Elasticsearch under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch 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.
+ */
+
+import org.opensearch.gradle.BuildPlugin
+
+/*
+ * This script plugin configures formatting for Java source using Spotless
+ * for Gradle. Since the act of formatting existing source can interfere
+ * with developers' workflows, we don't automatically format all code
+ * (yet). Instead, we maintain a list of projects that are excluded from
+ * formatting, until we reach a point where we can comfortably format them
+ * in one go without too much disruption.
+ *
+ * Any new sub-projects must not be added to the exclusions list!
+ *
+ * To perform a reformat, run:
+ *
+ * ./gradlew spotlessApply
+ *
+ * To check the current format, run:
+ *
+ * ./gradlew spotlessJavaCheck
+ *
+ * This is also carried out by the `precommit` task.
+ *
+ * For more about Spotless, see:
+ *
+ * https://github.com/diffplug/spotless/tree/master/plugin-gradle
+ */
+
+org.opensearch.gradle.BuildPlugin {
+ plugins.withType(BuildPlugin).whenPluginAdded {
+ project.apply plugin: "com.diffplug.spotless"
+
+ spotless {
+ java {
+ // Normally this isn't necessary, but we have Java sources in
+ // non-standard places
+ target '**/*.java'
+
+ removeUnusedImports()
+ eclipse().configFile rootProject.file('buildSrc/formatterConfig.xml')
+ trimTrailingWhitespace()
+ endWithNewline()
+
+ custom 'Refuse wildcard imports', {
+ // Wildcard imports can't be resolved; fail the build
+ if (it =~ /\s+import .*\*;/) {
+ throw new AssertionError("Do not use wildcard imports. 'spotlessApply' cannot resolve this issue.")
+ }
+ }
+
+ // See DEVELOPER_GUIDE.md for details of when to enable this.
+ if (System.getProperty('spotless.paddedcell') != null) {
+ paddedCell()
+ }
+ }
+ format 'misc', {
+ target '*.md', '*.gradle', '**/*.yaml', '**/*.yml', '**/*.svg'
+
+ trimTrailingWhitespace()
+ endWithNewline()
+ }
+ }
+
+ precommit.dependsOn 'spotlessJavaCheck'
+ }
}
diff --git a/src/main/java/com/amazon/dlic/auth/http/jwt/AbstractHTTPJwtAuthenticator.java b/src/main/java/com/amazon/dlic/auth/http/jwt/AbstractHTTPJwtAuthenticator.java
index bef819effd..ffe9db81f2 100644
--- a/src/main/java/com/amazon/dlic/auth/http/jwt/AbstractHTTPJwtAuthenticator.java
+++ b/src/main/java/com/amazon/dlic/auth/http/jwt/AbstractHTTPJwtAuthenticator.java
@@ -59,7 +59,7 @@ public abstract class AbstractHTTPJwtAuthenticator implements HTTPAuthenticator
private final String requiredIssuer;
public static final int DEFAULT_CLOCK_SKEW_TOLERANCE_SECONDS = 30;
- private final int clockSkewToleranceSeconds ;
+ private final int clockSkewToleranceSeconds;
public AbstractHTTPJwtAuthenticator(Settings settings, Path configPath) {
jwtUrlParameter = settings.get("jwt_url_parameter");
@@ -83,8 +83,7 @@ public AbstractHTTPJwtAuthenticator(Settings settings, Path configPath) {
@Override
@SuppressWarnings("removal")
- public AuthCredentials extractCredentials(RestRequest request, ThreadContext context)
- throws OpenSearchSecurityException {
+ public AuthCredentials extractCredentials(RestRequest request, ThreadContext context) throws OpenSearchSecurityException {
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
@@ -186,8 +185,11 @@ public String extractSubject(JwtClaims claims) {
// warning
if (!(subjectObject instanceof String)) {
log.warn(
- "Expected type String for roles in the JWT for subject_key {}, but value was '{}' ({}). Will convert this value to String.",
- subjectKey, subjectObject, subjectObject.getClass());
+ "Expected type String for roles in the JWT for subject_key {}, but value was '{}' ({}). Will convert this value to String.",
+ subjectKey,
+ subjectObject,
+ subjectObject.getClass()
+ );
subject = String.valueOf(subjectObject);
} else {
subject = (String) subjectObject;
@@ -207,8 +209,9 @@ public String[] extractRoles(JwtClaims claims) {
if (rolesObject == null) {
log.warn(
- "Failed to get roles from JWT claims with roles_key '{}'. Check if this key is correct and available in the JWT payload.",
- rolesKey);
+ "Failed to get roles from JWT claims with roles_key '{}'. Check if this key is correct and available in the JWT payload.",
+ rolesKey
+ );
return new String[0];
}
@@ -218,8 +221,11 @@ public String[] extractRoles(JwtClaims claims) {
// String but issue a warning
if (!(rolesObject instanceof String) && !(rolesObject instanceof Collection>)) {
log.warn(
- "Expected type String or Collection for roles in the JWT for roles_key {}, but value was '{}' ({}). Will convert this value to String.",
- rolesKey, rolesObject, rolesObject.getClass());
+ "Expected type String or Collection for roles in the JWT for roles_key {}, but value was '{}' ({}). Will convert this value to String.",
+ rolesKey,
+ rolesObject,
+ rolesObject.getClass()
+ );
} else if (rolesObject instanceof Collection>) {
roles = ((Collection) rolesObject).toArray(new String[0]);
}
diff --git a/src/main/java/com/amazon/dlic/auth/http/jwt/HTTPJwtAuthenticator.java b/src/main/java/com/amazon/dlic/auth/http/jwt/HTTPJwtAuthenticator.java
index 16cc71ffbd..3468bb89af 100644
--- a/src/main/java/com/amazon/dlic/auth/http/jwt/HTTPJwtAuthenticator.java
+++ b/src/main/java/com/amazon/dlic/auth/http/jwt/HTTPJwtAuthenticator.java
@@ -68,7 +68,7 @@ public HTTPJwtAuthenticator(final Settings settings, final Path configPath) {
try {
String signingKey = settings.get("signing_key");
- if(signingKey == null || signingKey.length() == 0) {
+ if (signingKey == null || signingKey.length() == 0) {
log.error("signingKey must not be null or empty. JWT authentication will not work");
} else {
@@ -90,7 +90,7 @@ public HTTPJwtAuthenticator(final Settings settings, final Path configPath) {
log.debug("No public ECDSA key, try other algos ({})", e.toString());
}
- if(key != null) {
+ if (key != null) {
_jwtParser = Jwts.parser().setSigningKey(key);
} else {
_jwtParser = Jwts.parser().setSigningKey(decoded);
@@ -121,7 +121,6 @@ public HTTPJwtAuthenticator(final Settings settings, final Path configPath) {
jwtParser = _jwtParser;
}
-
@Override
@SuppressWarnings("removal")
public AuthCredentials extractCredentials(RestRequest request, ThreadContext context) throws OpenSearchSecurityException {
@@ -152,25 +151,29 @@ private AuthCredentials extractCredentials0(final RestRequest request) {
jwtToken = null;
}
- if((jwtToken == null || jwtToken.isEmpty()) && jwtUrlParameter != null) {
+ if ((jwtToken == null || jwtToken.isEmpty()) && jwtUrlParameter != null) {
jwtToken = request.param(jwtUrlParameter);
} else {
- //just consume to avoid "contains unrecognized parameter"
+ // just consume to avoid "contains unrecognized parameter"
request.param(jwtUrlParameter);
}
if (jwtToken == null || jwtToken.length() == 0) {
- if(log.isDebugEnabled()) {
- log.debug("No JWT token found in '{}' {} header", jwtUrlParameter==null?jwtHeaderName:jwtUrlParameter, jwtUrlParameter==null?"header":"url parameter");
+ if (log.isDebugEnabled()) {
+ log.debug(
+ "No JWT token found in '{}' {} header",
+ jwtUrlParameter == null ? jwtHeaderName : jwtUrlParameter,
+ jwtUrlParameter == null ? "header" : "url parameter"
+ );
}
return null;
}
final int index;
- if((index = jwtToken.toLowerCase().indexOf(BEARER)) > -1) { //detect Bearer
- jwtToken = jwtToken.substring(index+BEARER.length());
+ if ((index = jwtToken.toLowerCase().indexOf(BEARER)) > -1) { // detect Bearer
+ jwtToken = jwtToken.substring(index + BEARER.length());
} else {
- if(log.isDebugEnabled()) {
+ if (log.isDebugEnabled()) {
log.debug("No Bearer scheme found in header");
}
}
@@ -181,16 +184,16 @@ private AuthCredentials extractCredentials0(final RestRequest request) {
final String subject = extractSubject(claims, request);
if (subject == null) {
- log.error("No subject found in JWT token");
- return null;
+ log.error("No subject found in JWT token");
+ return null;
}
final String[] roles = extractRoles(claims, request);
final AuthCredentials ac = new AuthCredentials(subject, roles).markComplete();
- for(Entry claim: claims.entrySet()) {
- ac.addAttribute("attr.jwt."+claim.getKey(), String.valueOf(claim.getValue()));
+ for (Entry claim : claims.entrySet()) {
+ ac.addAttribute("attr.jwt." + claim.getKey(), String.valueOf(claim.getValue()));
}
return ac;
@@ -199,7 +202,7 @@ private AuthCredentials extractCredentials0(final RestRequest request) {
log.error("Cannot authenticate user with JWT because of ", e);
return null;
} catch (Exception e) {
- if(log.isDebugEnabled()) {
+ if (log.isDebugEnabled()) {
log.debug("Invalid or expired JWT token.", e);
}
return null;
@@ -208,7 +211,7 @@ private AuthCredentials extractCredentials0(final RestRequest request) {
@Override
public boolean reRequestAuthentication(final RestChannel channel, AuthCredentials creds) {
- final BytesRestResponse wwwAuthenticateResponse = new BytesRestResponse(RestStatus.UNAUTHORIZED,"");
+ final BytesRestResponse wwwAuthenticateResponse = new BytesRestResponse(RestStatus.UNAUTHORIZED, "");
wwwAuthenticateResponse.addHeader("WWW-Authenticate", "Bearer realm=\"OpenSearch Security\"");
channel.sendResponse(wwwAuthenticateResponse);
return true;
@@ -221,16 +224,21 @@ public String getType() {
protected String extractSubject(final Claims claims, final RestRequest request) {
String subject = claims.getSubject();
- if(subjectKey != null) {
- // try to get roles from claims, first as Object to avoid having to catch the ExpectedTypeException
+ if (subjectKey != null) {
+ // try to get roles from claims, first as Object to avoid having to catch the ExpectedTypeException
Object subjectObject = claims.get(subjectKey, Object.class);
- if(subjectObject == null) {
+ if (subjectObject == null) {
log.warn("Failed to get subject from JWT claims, check if subject_key '{}' is correct.", subjectKey);
return null;
}
- // We expect a String. If we find something else, convert to String but issue a warning
- if(!(subjectObject instanceof String)) {
- log.warn("Expected type String for roles in the JWT for subject_key {}, but value was '{}' ({}). Will convert this value to String.", subjectKey, subjectObject, subjectObject.getClass());
+ // We expect a String. If we find something else, convert to String but issue a warning
+ if (!(subjectObject instanceof String)) {
+ log.warn(
+ "Expected type String for roles in the JWT for subject_key {}, but value was '{}' ({}). Will convert this value to String.",
+ subjectKey,
+ subjectObject,
+ subjectObject.getClass()
+ );
}
subject = String.valueOf(subjectObject);
}
@@ -239,34 +247,43 @@ protected String extractSubject(final Claims claims, final RestRequest request)
@SuppressWarnings("unchecked")
protected String[] extractRoles(final Claims claims, final RestRequest request) {
- // no roles key specified
- if(rolesKey == null) {
- return new String[0];
- }
- // try to get roles from claims, first as Object to avoid having to catch the ExpectedTypeException
- final Object rolesObject = claims.get(rolesKey, Object.class);
- if(rolesObject == null) {
- log.warn("Failed to get roles from JWT claims with roles_key '{}'. Check if this key is correct and available in the JWT payload.", rolesKey);
- return new String[0];
- }
-
- String[] roles = String.valueOf(rolesObject).split(",");
-
- // We expect a String or Collection. If we find something else, convert to String but issue a warning
- if (!(rolesObject instanceof String) && !(rolesObject instanceof Collection>)) {
- log.warn("Expected type String or Collection for roles in the JWT for roles_key {}, but value was '{}' ({}). Will convert this value to String.", rolesKey, rolesObject, rolesObject.getClass());
- } else if (rolesObject instanceof Collection>) {
- roles = ((Collection) rolesObject).toArray(new String[0]);
- }
-
- for (int i = 0; i < roles.length; i++) {
- roles[i] = roles[i].trim();
- }
-
- return roles;
+ // no roles key specified
+ if (rolesKey == null) {
+ return new String[0];
+ }
+ // try to get roles from claims, first as Object to avoid having to catch the ExpectedTypeException
+ final Object rolesObject = claims.get(rolesKey, Object.class);
+ if (rolesObject == null) {
+ log.warn(
+ "Failed to get roles from JWT claims with roles_key '{}'. Check if this key is correct and available in the JWT payload.",
+ rolesKey
+ );
+ return new String[0];
+ }
+
+ String[] roles = String.valueOf(rolesObject).split(",");
+
+ // We expect a String or Collection. If we find something else, convert to String but issue a warning
+ if (!(rolesObject instanceof String) && !(rolesObject instanceof Collection>)) {
+ log.warn(
+ "Expected type String or Collection for roles in the JWT for roles_key {}, but value was '{}' ({}). Will convert this value to String.",
+ rolesKey,
+ rolesObject,
+ rolesObject.getClass()
+ );
+ } else if (rolesObject instanceof Collection>) {
+ roles = ((Collection) rolesObject).toArray(new String[0]);
+ }
+
+ for (int i = 0; i < roles.length; i++) {
+ roles[i] = roles[i].trim();
+ }
+
+ return roles;
}
- private static PublicKey getPublicKey(final byte[] keyBytes, final String algo) throws NoSuchAlgorithmException, InvalidKeySpecException {
+ private static PublicKey getPublicKey(final byte[] keyBytes, final String algo) throws NoSuchAlgorithmException,
+ InvalidKeySpecException {
X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
KeyFactory kf = KeyFactory.getInstance(algo);
return kf.generatePublic(spec);
diff --git a/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/AuthenticatorUnavailableException.java b/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/AuthenticatorUnavailableException.java
index d9aa1aebb6..b17663b429 100644
--- a/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/AuthenticatorUnavailableException.java
+++ b/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/AuthenticatorUnavailableException.java
@@ -12,27 +12,26 @@
package com.amazon.dlic.auth.http.jwt.keybyoidc;
public class AuthenticatorUnavailableException extends RuntimeException {
- private static final long serialVersionUID = -7007025852090301416L;
+ private static final long serialVersionUID = -7007025852090301416L;
- public AuthenticatorUnavailableException() {
- super();
- }
+ public AuthenticatorUnavailableException() {
+ super();
+ }
- public AuthenticatorUnavailableException(String message, Throwable cause, boolean enableSuppression,
- boolean writableStackTrace) {
- super(message, cause, enableSuppression, writableStackTrace);
- }
+ public AuthenticatorUnavailableException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
+ super(message, cause, enableSuppression, writableStackTrace);
+ }
- public AuthenticatorUnavailableException(String message, Throwable cause) {
- super(message, cause);
- }
+ public AuthenticatorUnavailableException(String message, Throwable cause) {
+ super(message, cause);
+ }
- public AuthenticatorUnavailableException(String message) {
- super(message);
- }
+ public AuthenticatorUnavailableException(String message) {
+ super(message);
+ }
- public AuthenticatorUnavailableException(Throwable cause) {
- super(cause);
- }
+ public AuthenticatorUnavailableException(Throwable cause) {
+ super(cause);
+ }
}
diff --git a/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/BadCredentialsException.java b/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/BadCredentialsException.java
index 12b9195c0e..0d705f98cf 100644
--- a/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/BadCredentialsException.java
+++ b/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/BadCredentialsException.java
@@ -13,26 +13,25 @@
public class BadCredentialsException extends Exception {
- private static final long serialVersionUID = 9092575587366580869L;
+ private static final long serialVersionUID = 9092575587366580869L;
- public BadCredentialsException() {
- super();
- }
+ public BadCredentialsException() {
+ super();
+ }
- public BadCredentialsException(String message, Throwable cause, boolean enableSuppression,
- boolean writableStackTrace) {
- super(message, cause, enableSuppression, writableStackTrace);
- }
+ public BadCredentialsException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
+ super(message, cause, enableSuppression, writableStackTrace);
+ }
- public BadCredentialsException(String message, Throwable cause) {
- super(message, cause);
- }
+ public BadCredentialsException(String message, Throwable cause) {
+ super(message, cause);
+ }
- public BadCredentialsException(String message) {
- super(message);
- }
+ public BadCredentialsException(String message) {
+ super(message);
+ }
- public BadCredentialsException(Throwable cause) {
- super(cause);
- }
+ public BadCredentialsException(Throwable cause) {
+ super(cause);
+ }
}
diff --git a/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/HTTPJwtKeyByOpenIdConnectAuthenticator.java b/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/HTTPJwtKeyByOpenIdConnectAuthenticator.java
index b6738b725b..808abfc5ea 100644
--- a/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/HTTPJwtKeyByOpenIdConnectAuthenticator.java
+++ b/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/HTTPJwtKeyByOpenIdConnectAuthenticator.java
@@ -20,48 +20,54 @@
public class HTTPJwtKeyByOpenIdConnectAuthenticator extends AbstractHTTPJwtAuthenticator {
- //private final static Logger log = LogManager.getLogger(HTTPJwtKeyByOpenIdConnectAuthenticator.class);
-
- public HTTPJwtKeyByOpenIdConnectAuthenticator(Settings settings, Path configPath) {
- super(settings, configPath);
- }
-
- protected KeyProvider initKeyProvider(Settings settings, Path configPath) throws Exception {
- int idpRequestTimeoutMs = settings.getAsInt("idp_request_timeout_ms", 5000);
- int idpQueuedThreadTimeoutMs = settings.getAsInt("idp_queued_thread_timeout_ms", 2500);
-
- int refreshRateLimitTimeWindowMs = settings.getAsInt("refresh_rate_limit_time_window_ms", 10000);
- int refreshRateLimitCount = settings.getAsInt("refresh_rate_limit_count", 10);
- String jwksUri = settings.get("jwks_uri");
-
- KeySetRetriever keySetRetriever;
- if(jwksUri != null && !jwksUri.isBlank()) {
- keySetRetriever =
- new KeySetRetriever(getSSLConfig(settings, configPath), settings.getAsBoolean("cache_jwks_endpoint", false), jwksUri);
- } else {
- keySetRetriever = new KeySetRetriever(settings.get("openid_connect_url"), getSSLConfig(settings, configPath), settings.getAsBoolean("cache_jwks_endpoint", false));
- }
-
- keySetRetriever.setRequestTimeoutMs(idpRequestTimeoutMs);
-
- SelfRefreshingKeySet selfRefreshingKeySet = new SelfRefreshingKeySet(keySetRetriever);
-
- selfRefreshingKeySet.setRequestTimeoutMs(idpRequestTimeoutMs);
- selfRefreshingKeySet.setQueuedThreadTimeoutMs(idpQueuedThreadTimeoutMs);
- selfRefreshingKeySet.setRefreshRateLimitTimeWindowMs(refreshRateLimitTimeWindowMs);
- selfRefreshingKeySet.setRefreshRateLimitCount(refreshRateLimitCount);
-
- return selfRefreshingKeySet;
- }
-
- private static SettingsBasedSSLConfigurator.SSLConfig getSSLConfig(Settings settings, Path configPath)
- throws Exception {
- return new SettingsBasedSSLConfigurator(settings, configPath, "openid_connect_idp").buildSSLConfig();
- }
-
- @Override
- public String getType() {
- return "jwt-key-by-oidc";
- }
+ // private final static Logger log = LogManager.getLogger(HTTPJwtKeyByOpenIdConnectAuthenticator.class);
+
+ public HTTPJwtKeyByOpenIdConnectAuthenticator(Settings settings, Path configPath) {
+ super(settings, configPath);
+ }
+
+ protected KeyProvider initKeyProvider(Settings settings, Path configPath) throws Exception {
+ int idpRequestTimeoutMs = settings.getAsInt("idp_request_timeout_ms", 5000);
+ int idpQueuedThreadTimeoutMs = settings.getAsInt("idp_queued_thread_timeout_ms", 2500);
+
+ int refreshRateLimitTimeWindowMs = settings.getAsInt("refresh_rate_limit_time_window_ms", 10000);
+ int refreshRateLimitCount = settings.getAsInt("refresh_rate_limit_count", 10);
+ String jwksUri = settings.get("jwks_uri");
+
+ KeySetRetriever keySetRetriever;
+ if (jwksUri != null && !jwksUri.isBlank()) {
+ keySetRetriever = new KeySetRetriever(
+ getSSLConfig(settings, configPath),
+ settings.getAsBoolean("cache_jwks_endpoint", false),
+ jwksUri
+ );
+ } else {
+ keySetRetriever = new KeySetRetriever(
+ settings.get("openid_connect_url"),
+ getSSLConfig(settings, configPath),
+ settings.getAsBoolean("cache_jwks_endpoint", false)
+ );
+ }
+
+ keySetRetriever.setRequestTimeoutMs(idpRequestTimeoutMs);
+
+ SelfRefreshingKeySet selfRefreshingKeySet = new SelfRefreshingKeySet(keySetRetriever);
+
+ selfRefreshingKeySet.setRequestTimeoutMs(idpRequestTimeoutMs);
+ selfRefreshingKeySet.setQueuedThreadTimeoutMs(idpQueuedThreadTimeoutMs);
+ selfRefreshingKeySet.setRefreshRateLimitTimeWindowMs(refreshRateLimitTimeWindowMs);
+ selfRefreshingKeySet.setRefreshRateLimitCount(refreshRateLimitCount);
+
+ return selfRefreshingKeySet;
+ }
+
+ private static SettingsBasedSSLConfigurator.SSLConfig getSSLConfig(Settings settings, Path configPath) throws Exception {
+ return new SettingsBasedSSLConfigurator(settings, configPath, "openid_connect_idp").buildSSLConfig();
+ }
+
+ @Override
+ public String getType() {
+ return "jwt-key-by-oidc";
+ }
}
diff --git a/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/JwtVerifier.java b/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/JwtVerifier.java
index a337224cdc..5893d623a7 100644
--- a/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/JwtVerifier.java
+++ b/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/JwtVerifier.java
@@ -29,107 +29,106 @@
public class JwtVerifier {
- private final static Logger log = LogManager.getLogger(JwtVerifier.class);
-
- private final KeyProvider keyProvider;
- private final int clockSkewToleranceSeconds;
- private final String requiredIssuer;
- private final String requiredAudience;
-
- public JwtVerifier(KeyProvider keyProvider, int clockSkewToleranceSeconds, String requiredIssuer, String requiredAudience) {
- this.keyProvider = keyProvider;
- this.clockSkewToleranceSeconds = clockSkewToleranceSeconds;
- this.requiredIssuer = requiredIssuer;
- this.requiredAudience = requiredAudience;
- }
-
- public JwtToken getVerifiedJwtToken(String encodedJwt) throws BadCredentialsException {
- try {
- JwsJwtCompactConsumer jwtConsumer = new JwsJwtCompactConsumer(encodedJwt);
- JwtToken jwt = jwtConsumer.getJwtToken();
-
- String escapedKid = jwt.getJwsHeaders().getKeyId();
- String kid = escapedKid;
- if (!Strings.isNullOrEmpty(kid)) {
- kid = StringEscapeUtils.unescapeJava(escapedKid);
- }
- JsonWebKey key = keyProvider.getKey(kid);
-
- // Algorithm is not mandatory for the key material, so we set it to the same as the JWT
- if (key.getAlgorithm() == null && key.getPublicKeyUse() == PublicKeyUse.SIGN && key.getKeyType() == KeyType.RSA)
- {
- key.setAlgorithm(jwt.getJwsHeaders().getAlgorithm());
- }
-
- JwsSignatureVerifier signatureVerifier = getInitializedSignatureVerifier(key, jwt);
-
-
- boolean signatureValid = jwtConsumer.verifySignatureWith(signatureVerifier);
-
- if (!signatureValid && Strings.isNullOrEmpty(kid)) {
- key = keyProvider.getKeyAfterRefresh(null);
- signatureVerifier = getInitializedSignatureVerifier(key, jwt);
- signatureValid = jwtConsumer.verifySignatureWith(signatureVerifier);
- }
-
- if (!signatureValid) {
- throw new BadCredentialsException("Invalid JWT signature");
- }
-
- validateClaims(jwt);
-
- return jwt;
- } catch (JwtException e) {
- throw new BadCredentialsException(e.getMessage(), e);
- }
- }
+ private final static Logger log = LogManager.getLogger(JwtVerifier.class);
+
+ private final KeyProvider keyProvider;
+ private final int clockSkewToleranceSeconds;
+ private final String requiredIssuer;
+ private final String requiredAudience;
+
+ public JwtVerifier(KeyProvider keyProvider, int clockSkewToleranceSeconds, String requiredIssuer, String requiredAudience) {
+ this.keyProvider = keyProvider;
+ this.clockSkewToleranceSeconds = clockSkewToleranceSeconds;
+ this.requiredIssuer = requiredIssuer;
+ this.requiredAudience = requiredAudience;
+ }
+
+ public JwtToken getVerifiedJwtToken(String encodedJwt) throws BadCredentialsException {
+ try {
+ JwsJwtCompactConsumer jwtConsumer = new JwsJwtCompactConsumer(encodedJwt);
+ JwtToken jwt = jwtConsumer.getJwtToken();
+
+ String escapedKid = jwt.getJwsHeaders().getKeyId();
+ String kid = escapedKid;
+ if (!Strings.isNullOrEmpty(kid)) {
+ kid = StringEscapeUtils.unescapeJava(escapedKid);
+ }
+ JsonWebKey key = keyProvider.getKey(kid);
+
+ // Algorithm is not mandatory for the key material, so we set it to the same as the JWT
+ if (key.getAlgorithm() == null && key.getPublicKeyUse() == PublicKeyUse.SIGN && key.getKeyType() == KeyType.RSA) {
+ key.setAlgorithm(jwt.getJwsHeaders().getAlgorithm());
+ }
+
+ JwsSignatureVerifier signatureVerifier = getInitializedSignatureVerifier(key, jwt);
+
+ boolean signatureValid = jwtConsumer.verifySignatureWith(signatureVerifier);
+
+ if (!signatureValid && Strings.isNullOrEmpty(kid)) {
+ key = keyProvider.getKeyAfterRefresh(null);
+ signatureVerifier = getInitializedSignatureVerifier(key, jwt);
+ signatureValid = jwtConsumer.verifySignatureWith(signatureVerifier);
+ }
+
+ if (!signatureValid) {
+ throw new BadCredentialsException("Invalid JWT signature");
+ }
+
+ validateClaims(jwt);
+
+ return jwt;
+ } catch (JwtException e) {
+ throw new BadCredentialsException(e.getMessage(), e);
+ }
+ }
private void validateSignatureAlgorithm(JsonWebKey key, JwtToken jwt) throws BadCredentialsException {
if (Strings.isNullOrEmpty(key.getAlgorithm())) {
return;
}
- SignatureAlgorithm keyAlgorithm =SignatureAlgorithm.getAlgorithm(key.getAlgorithm());
+ SignatureAlgorithm keyAlgorithm = SignatureAlgorithm.getAlgorithm(key.getAlgorithm());
SignatureAlgorithm tokenAlgorithm = SignatureAlgorithm.getAlgorithm(jwt.getJwsHeaders().getAlgorithm());
if (!keyAlgorithm.equals(tokenAlgorithm)) {
- throw new BadCredentialsException("Algorithm of JWT does not match algorithm of JWK (" + keyAlgorithm + " != " + tokenAlgorithm + ")");
+ throw new BadCredentialsException(
+ "Algorithm of JWT does not match algorithm of JWK (" + keyAlgorithm + " != " + tokenAlgorithm + ")"
+ );
}
}
+ private JwsSignatureVerifier getInitializedSignatureVerifier(JsonWebKey key, JwtToken jwt) throws BadCredentialsException,
+ JwtException {
- private JwsSignatureVerifier getInitializedSignatureVerifier(JsonWebKey key, JwtToken jwt)
- throws BadCredentialsException, JwtException {
-
- validateSignatureAlgorithm(key, jwt);
+ validateSignatureAlgorithm(key, jwt);
JwsSignatureVerifier result = JwsUtils.getSignatureVerifier(key, jwt.getJwsHeaders().getSignatureAlgorithm());
- if (result == null) {
- throw new BadCredentialsException("Cannot verify JWT");
- } else {
- return result;
- }
- }
-
- private void validateClaims(JwtToken jwt) throws JwtException {
- JwtClaims claims = jwt.getClaims();
-
- if (claims != null) {
- JwtUtils.validateJwtExpiry(claims, clockSkewToleranceSeconds, false);
- JwtUtils.validateJwtNotBefore(claims, clockSkewToleranceSeconds, false);
- validateRequiredAudienceAndIssuer(claims);
- }
- }
-
- private void validateRequiredAudienceAndIssuer(JwtClaims claims) {
- String audience = claims.getAudience();
- String issuer = claims.getIssuer();
-
- if (!Strings.isNullOrEmpty(requiredAudience) && !requiredAudience.equals(audience)) {
- throw new JwtException("Invalid audience");
- }
-
- if (!Strings.isNullOrEmpty(requiredIssuer) && !requiredIssuer.equals(issuer)) {
- throw new JwtException("Invalid issuer");
- }
- }
+ if (result == null) {
+ throw new BadCredentialsException("Cannot verify JWT");
+ } else {
+ return result;
+ }
+ }
+
+ private void validateClaims(JwtToken jwt) throws JwtException {
+ JwtClaims claims = jwt.getClaims();
+
+ if (claims != null) {
+ JwtUtils.validateJwtExpiry(claims, clockSkewToleranceSeconds, false);
+ JwtUtils.validateJwtNotBefore(claims, clockSkewToleranceSeconds, false);
+ validateRequiredAudienceAndIssuer(claims);
+ }
+ }
+
+ private void validateRequiredAudienceAndIssuer(JwtClaims claims) {
+ String audience = claims.getAudience();
+ String issuer = claims.getIssuer();
+
+ if (!Strings.isNullOrEmpty(requiredAudience) && !requiredAudience.equals(audience)) {
+ throw new JwtException("Invalid audience");
+ }
+
+ if (!Strings.isNullOrEmpty(requiredIssuer) && !requiredIssuer.equals(issuer)) {
+ throw new JwtException("Invalid issuer");
+ }
+ }
}
diff --git a/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/KeyProvider.java b/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/KeyProvider.java
index 5eff7cb213..a0e76c918f 100644
--- a/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/KeyProvider.java
+++ b/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/KeyProvider.java
@@ -14,6 +14,7 @@
import org.apache.cxf.rs.security.jose.jwk.JsonWebKey;
public interface KeyProvider {
- public JsonWebKey getKey(String kid) throws AuthenticatorUnavailableException, BadCredentialsException;
- public JsonWebKey getKeyAfterRefresh(String kid) throws AuthenticatorUnavailableException, BadCredentialsException;
+ public JsonWebKey getKey(String kid) throws AuthenticatorUnavailableException, BadCredentialsException;
+
+ public JsonWebKey getKeyAfterRefresh(String kid) throws AuthenticatorUnavailableException, BadCredentialsException;
}
diff --git a/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/KeySetProvider.java b/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/KeySetProvider.java
index edbe39f020..53ea0237db 100644
--- a/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/KeySetProvider.java
+++ b/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/KeySetProvider.java
@@ -15,5 +15,5 @@
@FunctionalInterface
public interface KeySetProvider {
- JsonWebKeys get() throws AuthenticatorUnavailableException;
+ JsonWebKeys get() throws AuthenticatorUnavailableException;
}
diff --git a/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/KeySetRetriever.java b/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/KeySetRetriever.java
index f56c0dd90c..9ef50a4404 100644
--- a/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/KeySetRetriever.java
+++ b/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/KeySetRetriever.java
@@ -39,205 +39,218 @@
import org.opensearch.security.DefaultObjectMapper;
-
public class KeySetRetriever implements KeySetProvider {
- private final static Logger log = LogManager.getLogger(KeySetRetriever.class);
- private static final long CACHE_STATUS_LOG_INTERVAL_MS = 60L * 60L * 1000L;
-
- private String openIdConnectEndpoint;
- private SSLConfig sslConfig;
- private int requestTimeoutMs = 10000;
- private CacheConfig cacheConfig;
- private HttpCacheStorage oidcHttpCacheStorage;
- private int oidcCacheHits = 0;
- private int oidcCacheMisses = 0;
- private int oidcCacheHitsValidated = 0;
- private int oidcCacheModuleResponses = 0;
- private long oidcRequests = 0;
- private long lastCacheStatusLog = 0;
- private String jwksUri;
-
- KeySetRetriever(String openIdConnectEndpoint, SSLConfig sslConfig, boolean useCacheForOidConnectEndpoint) {
- this.openIdConnectEndpoint = openIdConnectEndpoint;
- this.sslConfig = sslConfig;
-
- configureCache(useCacheForOidConnectEndpoint);
- }
-
- KeySetRetriever(SSLConfig sslConfig, boolean useCacheForOidConnectEndpoint, String jwksUri) {
- this.jwksUri = jwksUri;
- this.sslConfig = sslConfig;
-
- configureCache(useCacheForOidConnectEndpoint);
- }
-
- public JsonWebKeys get() throws AuthenticatorUnavailableException {
- String uri = getJwksUri();
-
- try (CloseableHttpClient httpClient = createHttpClient(null)) {
-
- HttpGet httpGet = new HttpGet(uri);
-
- RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(getRequestTimeoutMs(), TimeUnit.MILLISECONDS)
- .setConnectTimeout(getRequestTimeoutMs(), TimeUnit.MILLISECONDS).build();
-
- httpGet.setConfig(requestConfig);
-
- try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
- if (response.getCode() < 200 || response.getCode() >= 300) {
- throw new AuthenticatorUnavailableException("Error while getting " + uri + ": " + response.getReasonPhrase());
- }
-
- HttpEntity httpEntity = response.getEntity();
-
- if (httpEntity == null) {
- throw new AuthenticatorUnavailableException(
- "Error while getting " + uri + ": Empty response entity");
- }
+ private final static Logger log = LogManager.getLogger(KeySetRetriever.class);
+ private static final long CACHE_STATUS_LOG_INTERVAL_MS = 60L * 60L * 1000L;
- JsonWebKeys keySet = JwkUtils.readJwkSet(httpEntity.getContent());
+ private String openIdConnectEndpoint;
+ private SSLConfig sslConfig;
+ private int requestTimeoutMs = 10000;
+ private CacheConfig cacheConfig;
+ private HttpCacheStorage oidcHttpCacheStorage;
+ private int oidcCacheHits = 0;
+ private int oidcCacheMisses = 0;
+ private int oidcCacheHitsValidated = 0;
+ private int oidcCacheModuleResponses = 0;
+ private long oidcRequests = 0;
+ private long lastCacheStatusLog = 0;
+ private String jwksUri;
- return keySet;
- }
- } catch (IOException e) {
- throw new AuthenticatorUnavailableException("Error while getting " + uri + ": " + e, e);
- }
+ KeySetRetriever(String openIdConnectEndpoint, SSLConfig sslConfig, boolean useCacheForOidConnectEndpoint) {
+ this.openIdConnectEndpoint = openIdConnectEndpoint;
+ this.sslConfig = sslConfig;
- }
+ configureCache(useCacheForOidConnectEndpoint);
+ }
- String getJwksUri() throws AuthenticatorUnavailableException {
+ KeySetRetriever(SSLConfig sslConfig, boolean useCacheForOidConnectEndpoint, String jwksUri) {
+ this.jwksUri = jwksUri;
+ this.sslConfig = sslConfig;
- if (!Strings.isNullOrEmpty(jwksUri)) {
- return jwksUri;
- }
+ configureCache(useCacheForOidConnectEndpoint);
+ }
- if (Strings.isNullOrEmpty(openIdConnectEndpoint)) {
- throw new AuthenticatorUnavailableException("Either openid_connect_url or jwks_uri must be configured for OIDC Authentication backend");
- }
+ public JsonWebKeys get() throws AuthenticatorUnavailableException {
+ String uri = getJwksUri();
- try (CloseableHttpClient httpClient = createHttpClient(oidcHttpCacheStorage)) {
+ try (CloseableHttpClient httpClient = createHttpClient(null)) {
- HttpGet httpGet = new HttpGet(openIdConnectEndpoint);
+ HttpGet httpGet = new HttpGet(uri);
- RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(getRequestTimeoutMs(), TimeUnit.MILLISECONDS)
- .setConnectTimeout(getRequestTimeoutMs(), TimeUnit.MILLISECONDS).build();
+ RequestConfig requestConfig = RequestConfig.custom()
+ .setConnectionRequestTimeout(getRequestTimeoutMs(), TimeUnit.MILLISECONDS)
+ .setConnectTimeout(getRequestTimeoutMs(), TimeUnit.MILLISECONDS)
+ .build();
- httpGet.setConfig(requestConfig);
+ httpGet.setConfig(requestConfig);
- HttpCacheContext httpContext = null;
+ try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
+ if (response.getCode() < 200 || response.getCode() >= 300) {
+ throw new AuthenticatorUnavailableException("Error while getting " + uri + ": " + response.getReasonPhrase());
+ }
- if (oidcHttpCacheStorage != null) {
- httpContext = new HttpCacheContext();
- }
+ HttpEntity httpEntity = response.getEntity();
- try (CloseableHttpResponse response = httpClient.execute(httpGet, httpContext)) {
- if (httpContext != null) {
- logCacheResponseStatus(httpContext);
- }
+ if (httpEntity == null) {
+ throw new AuthenticatorUnavailableException("Error while getting " + uri + ": Empty response entity");
+ }
- if (response.getCode() < 200 || response.getCode() >= 300) {
- throw new AuthenticatorUnavailableException(
- "Error while getting " + openIdConnectEndpoint + ": " + response.getReasonPhrase());
- }
+ JsonWebKeys keySet = JwkUtils.readJwkSet(httpEntity.getContent());
- HttpEntity httpEntity = response.getEntity();
+ return keySet;
+ }
+ } catch (IOException e) {
+ throw new AuthenticatorUnavailableException("Error while getting " + uri + ": " + e, e);
+ }
- if (httpEntity == null) {
- throw new AuthenticatorUnavailableException(
- "Error while getting " + openIdConnectEndpoint + ": Empty response entity");
- }
+ }
+
+ String getJwksUri() throws AuthenticatorUnavailableException {
- OpenIdProviderConfiguration parsedEntity = DefaultObjectMapper.objectMapper.readValue(httpEntity.getContent(),
- OpenIdProviderConfiguration.class);
+ if (!Strings.isNullOrEmpty(jwksUri)) {
+ return jwksUri;
+ }
- return parsedEntity.getJwksUri();
+ if (Strings.isNullOrEmpty(openIdConnectEndpoint)) {
+ throw new AuthenticatorUnavailableException(
+ "Either openid_connect_url or jwks_uri must be configured for OIDC Authentication backend"
+ );
+ }
+
+ try (CloseableHttpClient httpClient = createHttpClient(oidcHttpCacheStorage)) {
- }
+ HttpGet httpGet = new HttpGet(openIdConnectEndpoint);
- } catch (IOException e) {
- throw new AuthenticatorUnavailableException("Error while getting " + openIdConnectEndpoint + ": " + e, e);
- }
+ RequestConfig requestConfig = RequestConfig.custom()
+ .setConnectionRequestTimeout(getRequestTimeoutMs(), TimeUnit.MILLISECONDS)
+ .setConnectTimeout(getRequestTimeoutMs(), TimeUnit.MILLISECONDS)
+ .build();
- }
+ httpGet.setConfig(requestConfig);
- public int getRequestTimeoutMs() {
- return requestTimeoutMs;
- }
+ HttpCacheContext httpContext = null;
- public void setRequestTimeoutMs(int httpTimeoutMs) {
- this.requestTimeoutMs = httpTimeoutMs;
- }
+ if (oidcHttpCacheStorage != null) {
+ httpContext = new HttpCacheContext();
+ }
- private void logCacheResponseStatus(HttpCacheContext httpContext) {
- this.oidcRequests++;
+ try (CloseableHttpResponse response = httpClient.execute(httpGet, httpContext)) {
+ if (httpContext != null) {
+ logCacheResponseStatus(httpContext);
+ }
- switch (httpContext.getCacheResponseStatus()) {
- case CACHE_HIT:
- this.oidcCacheHits++;
- break;
- case CACHE_MODULE_RESPONSE:
- this.oidcCacheModuleResponses++;
- break;
- case CACHE_MISS:
- this.oidcCacheMisses++;
- break;
- case VALIDATED:
- this.oidcCacheHitsValidated++;
- break;
- }
+ if (response.getCode() < 200 || response.getCode() >= 300) {
+ throw new AuthenticatorUnavailableException(
+ "Error while getting " + openIdConnectEndpoint + ": " + response.getReasonPhrase()
+ );
+ }
+
+ HttpEntity httpEntity = response.getEntity();
- long now = System.currentTimeMillis();
+ if (httpEntity == null) {
+ throw new AuthenticatorUnavailableException("Error while getting " + openIdConnectEndpoint + ": Empty response entity");
+ }
- if (this.oidcRequests >= 2 && now - lastCacheStatusLog > CACHE_STATUS_LOG_INTERVAL_MS) {
- log.info("Cache status for KeySetRetriever:\noidcCacheHits: {}\noidcCacheHitsValidated: {}"
- + "\noidcCacheModuleResponses: {}" + "\noidcCacheMisses: {}", oidcCacheHits, oidcCacheHitsValidated, oidcCacheModuleResponses, oidcCacheMisses);
- lastCacheStatusLog = now;
- }
+ OpenIdProviderConfiguration parsedEntity = DefaultObjectMapper.objectMapper.readValue(
+ httpEntity.getContent(),
+ OpenIdProviderConfiguration.class
+ );
- }
+ return parsedEntity.getJwksUri();
- private CloseableHttpClient createHttpClient(HttpCacheStorage httpCacheStorage) {
- HttpClientBuilder builder;
+ }
- if (httpCacheStorage != null) {
- builder = CachingHttpClients.custom().setCacheConfig(cacheConfig).setHttpCacheStorage(httpCacheStorage);
- } else {
- builder = HttpClients.custom();
- }
+ } catch (IOException e) {
+ throw new AuthenticatorUnavailableException("Error while getting " + openIdConnectEndpoint + ": " + e, e);
+ }
- builder.useSystemProperties();
+ }
- if (sslConfig != null) {
- final HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create()
- .setSSLSocketFactory(sslConfig.toSSLConnectionSocketFactory())
- .build();
+ public int getRequestTimeoutMs() {
+ return requestTimeoutMs;
+ }
- builder.setConnectionManager(cm);
- }
+ public void setRequestTimeoutMs(int httpTimeoutMs) {
+ this.requestTimeoutMs = httpTimeoutMs;
+ }
- return builder.build();
- }
+ private void logCacheResponseStatus(HttpCacheContext httpContext) {
+ this.oidcRequests++;
- private void configureCache(boolean useCacheForOidConnectEndpoint) {
- if (useCacheForOidConnectEndpoint) {
- cacheConfig = CacheConfig.custom().setMaxCacheEntries(10).setMaxObjectSize(1024L * 1024L).build();
- oidcHttpCacheStorage = new BasicHttpCacheStorage(cacheConfig);
- }
- }
-
- public int getOidcCacheHits() {
- return oidcCacheHits;
- }
-
- public int getOidcCacheMisses() {
- return oidcCacheMisses;
- }
-
- public int getOidcCacheHitsValidated() {
- return oidcCacheHitsValidated;
- }
-
- public int getOidcCacheModuleResponses() {
- return oidcCacheModuleResponses;
- }
+ switch (httpContext.getCacheResponseStatus()) {
+ case CACHE_HIT:
+ this.oidcCacheHits++;
+ break;
+ case CACHE_MODULE_RESPONSE:
+ this.oidcCacheModuleResponses++;
+ break;
+ case CACHE_MISS:
+ this.oidcCacheMisses++;
+ break;
+ case VALIDATED:
+ this.oidcCacheHitsValidated++;
+ break;
+ }
+
+ long now = System.currentTimeMillis();
+
+ if (this.oidcRequests >= 2 && now - lastCacheStatusLog > CACHE_STATUS_LOG_INTERVAL_MS) {
+ log.info(
+ "Cache status for KeySetRetriever:\noidcCacheHits: {}\noidcCacheHitsValidated: {}"
+ + "\noidcCacheModuleResponses: {}"
+ + "\noidcCacheMisses: {}",
+ oidcCacheHits,
+ oidcCacheHitsValidated,
+ oidcCacheModuleResponses,
+ oidcCacheMisses
+ );
+ lastCacheStatusLog = now;
+ }
+
+ }
+
+ private CloseableHttpClient createHttpClient(HttpCacheStorage httpCacheStorage) {
+ HttpClientBuilder builder;
+
+ if (httpCacheStorage != null) {
+ builder = CachingHttpClients.custom().setCacheConfig(cacheConfig).setHttpCacheStorage(httpCacheStorage);
+ } else {
+ builder = HttpClients.custom();
+ }
+
+ builder.useSystemProperties();
+
+ if (sslConfig != null) {
+ final HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create()
+ .setSSLSocketFactory(sslConfig.toSSLConnectionSocketFactory())
+ .build();
+
+ builder.setConnectionManager(cm);
+ }
+
+ return builder.build();
+ }
+
+ private void configureCache(boolean useCacheForOidConnectEndpoint) {
+ if (useCacheForOidConnectEndpoint) {
+ cacheConfig = CacheConfig.custom().setMaxCacheEntries(10).setMaxObjectSize(1024L * 1024L).build();
+ oidcHttpCacheStorage = new BasicHttpCacheStorage(cacheConfig);
+ }
+ }
+
+ public int getOidcCacheHits() {
+ return oidcCacheHits;
+ }
+
+ public int getOidcCacheMisses() {
+ return oidcCacheMisses;
+ }
+
+ public int getOidcCacheHitsValidated() {
+ return oidcCacheHitsValidated;
+ }
+
+ public int getOidcCacheModuleResponses() {
+ return oidcCacheModuleResponses;
+ }
}
diff --git a/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/SelfRefreshingKeySet.java b/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/SelfRefreshingKeySet.java
index 7e3cec8246..fe410b171c 100644
--- a/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/SelfRefreshingKeySet.java
+++ b/src/main/java/com/amazon/dlic/auth/http/jwt/keybyoidc/SelfRefreshingKeySet.java
@@ -25,295 +25,300 @@
import org.apache.logging.log4j.Logger;
public class SelfRefreshingKeySet implements KeyProvider {
- private static final Logger log = LogManager.getLogger(SelfRefreshingKeySet.class);
-
- private final KeySetProvider keySetProvider;
- private final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 10, 1000, TimeUnit.MILLISECONDS,
- new LinkedBlockingQueue());
- private volatile JsonWebKeys jsonWebKeys = new JsonWebKeys();
- private boolean refreshInProgress = false;
- private long refreshCount = 0;
- private long queuedGetCount = 0;
- private long recentRefreshCount = 0;
- private long refreshTime = 0;
- private Throwable lastRefreshFailure = null;
- private int requestTimeoutMs = 5000;
- private int queuedThreadTimeoutMs = 2500;
- private int refreshRateLimitTimeWindowMs = 10000;
- private int refreshRateLimitCount = 10;
-
- public SelfRefreshingKeySet(KeySetProvider refreshFunction) {
- this.keySetProvider = refreshFunction;
- }
-
- public JsonWebKey getKey(String kid) throws AuthenticatorUnavailableException, BadCredentialsException {
- if (Strings.isNullOrEmpty(kid)) {
- return getKeyWithoutKeyId();
- } else {
- return getKeyWithKeyId(kid);
- }
- }
-
- public synchronized JsonWebKey getKeyAfterRefresh(String kid)
- throws AuthenticatorUnavailableException, BadCredentialsException {
- JsonWebKey result = getKeyAfterRefreshInternal(kid);
-
- if (result != null) {
- return result;
- } else if (jsonWebKeys.getKeys().size() == 0) {
- throw new AuthenticatorUnavailableException("No JWK are available from IdP");
- } else {
- throw new BadCredentialsException("JWT did not contain KID which is required if IdP provides multiple JWK");
- }
- }
-
- private synchronized JsonWebKey getKeyAfterRefreshInternal(String kid) throws AuthenticatorUnavailableException {
- if (refreshInProgress) {
- return waitForRefreshToFinish(kid);
- } else {
- return performRefresh(kid);
- }
- }
-
- private JsonWebKey getKeyWithoutKeyId() throws AuthenticatorUnavailableException, BadCredentialsException {
- List keys = jsonWebKeys.getKeys();
-
- if (keys == null || keys.size() == 0) {
- JsonWebKey result = getKeyWithRefresh(null);
-
- if (result != null) {
- return result;
- } else {
- throw new AuthenticatorUnavailableException("No JWK are available from IdP");
- }
- } else if (keys.size() == 1) {
- return keys.get(0);
- } else {
- JsonWebKey result = getKeyWithRefresh(null);
-
- if (result != null) {
- return result;
- } else {
- throw new BadCredentialsException(
- "JWT did not contain KID which is required if IdP provides multiple JWK");
- }
- }
- }
-
- private JsonWebKey getKeyWithKeyId(String kid) throws AuthenticatorUnavailableException, BadCredentialsException {
- JsonWebKey result = jsonWebKeys.getKey(kid);
-
- if (result != null) {
- return result;
- }
-
- result = getKeyWithRefresh(kid);
-
- if (result == null) {
- throw new BadCredentialsException("Unknown kid " + kid);
- }
-
- return result;
- }
-
- private synchronized JsonWebKey getKeyWithRefresh(String kid) throws AuthenticatorUnavailableException {
-
- // Always re-check within synchronized to handle any races
-
- JsonWebKey result = getKeySimple(kid);
-
- if (result != null) {
- return result;
- }
-
- return getKeyAfterRefreshInternal(kid);
- }
-
- private JsonWebKey getKeySimple(String kid) {
- if (Strings.isNullOrEmpty(kid)) {
- List keys = jsonWebKeys.getKeys();
-
- if (keys != null && keys.size() == 1) {
- return keys.get(0);
- } else {
- return null;
- }
-
- } else {
- return jsonWebKeys.getKey(kid);
- }
- }
-
- private synchronized JsonWebKey waitForRefreshToFinish(String kid) {
- queuedGetCount++;
- long currentRefreshCount = refreshCount;
-
- try {
- wait(queuedThreadTimeoutMs);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- log.debug(e.toString());
- }
-
- // Just be optimistic and re-check the key
-
- JsonWebKey result = getKeySimple(kid);
-
- if (result != null) {
- return result;
- }
-
- if (refreshInProgress && currentRefreshCount == refreshCount) {
- // The wait() call returned due to the timeout.
- throw new AuthenticatorUnavailableException("Authentication backend timed out");
- } else if (lastRefreshFailure != null) {
- throw new AuthenticatorUnavailableException("Authentication backend failed", lastRefreshFailure);
- } else {
- // Refresh was successful, but we did not get a matching key
- return null;
- }
- }
-
- private synchronized JsonWebKey performRefresh(String kid) {
- if (log.isDebugEnabled()) {
- log.debug("performRefresh({})", kid);
- }
-
- final boolean recentRefresh;
-
- if (System.currentTimeMillis() - refreshTime < refreshRateLimitTimeWindowMs) {
- recentRefreshCount++;
- recentRefresh = true;
-
- if (recentRefreshCount > refreshRateLimitCount) {
- throw new AuthenticatorUnavailableException("Too many unknown kids recently: " + recentRefreshCount);
- }
- } else {
- recentRefresh = false;
- }
-
- refreshInProgress = true;
- refreshCount++;
-
- log.info("Performing refresh {}", refreshCount);
-
- long currentRefreshCount = refreshCount;
-
- try {
-
- Future> future = threadPoolExecutor.submit(new Runnable() {
-
- @Override
- public void run() {
- try {
- JsonWebKeys newKeys = keySetProvider.get();
-
- if (newKeys == null) {
- throw new RuntimeException("Refresh function " + keySetProvider + " yielded null");
- }
-
- log.info("KeySetProvider finished");
-
- synchronized (SelfRefreshingKeySet.this) {
- jsonWebKeys = newKeys;
- refreshInProgress = false;
- lastRefreshFailure = null;
- SelfRefreshingKeySet.this.notifyAll();
- }
- } catch (Throwable e) {
- synchronized (SelfRefreshingKeySet.this) {
- lastRefreshFailure = e;
- refreshInProgress = false;
- SelfRefreshingKeySet.this.notifyAll();
- }
- log.warn("KeySetProvider threw error", e);
- } finally {
- if (!recentRefresh) {
- recentRefreshCount = 0;
- refreshTime = System.currentTimeMillis();
- }
- }
-
- }
- });
-
- try {
- wait(requestTimeoutMs);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- log.debug(e.toString());
- }
-
- JsonWebKey result = getKeySimple(kid);
-
- if (result != null) {
- return result;
- }
-
- if (refreshInProgress && currentRefreshCount == refreshCount) {
- if (!future.isDone()) {
- future.cancel(true);
- }
-
- lastRefreshFailure = new AuthenticatorUnavailableException("Authentication backend timed out");
-
- throw new AuthenticatorUnavailableException("Authentication backend timed out");
- }
-
- if (lastRefreshFailure != null) {
- throw new AuthenticatorUnavailableException("Authentication backend failed", lastRefreshFailure);
- }
-
- return null;
-
- } catch (RejectedExecutionException e) {
- throw new AuthenticatorUnavailableException("Did not try to call authentication backend because of "
- + threadPoolExecutor.getActiveCount() + " pending threads", e);
- } finally {
- if (refreshInProgress && currentRefreshCount == refreshCount) {
- refreshInProgress = false;
- notifyAll();
- }
- }
- }
-
- public int getRequestTimeoutMs() {
- return requestTimeoutMs;
- }
-
- public void setRequestTimeoutMs(int requestTimeoutMs) {
- this.requestTimeoutMs = requestTimeoutMs;
- }
-
- public int getQueuedThreadTimeoutMs() {
- return queuedThreadTimeoutMs;
- }
-
- public void setQueuedThreadTimeoutMs(int queuedThreadTimeoutMs) {
- this.queuedThreadTimeoutMs = queuedThreadTimeoutMs;
- }
-
- public long getRefreshCount() {
- return refreshCount;
- }
-
- public long getQueuedGetCount() {
- return queuedGetCount;
- }
-
- public int getRefreshRateLimitTimeWindowMs() {
- return refreshRateLimitTimeWindowMs;
- }
-
- public void setRefreshRateLimitTimeWindowMs(int refreshRateLimitTimeWindowMs) {
- this.refreshRateLimitTimeWindowMs = refreshRateLimitTimeWindowMs;
- }
-
- public int getRefreshRateLimitCount() {
- return refreshRateLimitCount;
- }
-
- public void setRefreshRateLimitCount(int refreshRateLimitCount) {
- this.refreshRateLimitCount = refreshRateLimitCount;
- }
+ private static final Logger log = LogManager.getLogger(SelfRefreshingKeySet.class);
+
+ private final KeySetProvider keySetProvider;
+ private final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
+ 1,
+ 10,
+ 1000,
+ TimeUnit.MILLISECONDS,
+ new LinkedBlockingQueue()
+ );
+ private volatile JsonWebKeys jsonWebKeys = new JsonWebKeys();
+ private boolean refreshInProgress = false;
+ private long refreshCount = 0;
+ private long queuedGetCount = 0;
+ private long recentRefreshCount = 0;
+ private long refreshTime = 0;
+ private Throwable lastRefreshFailure = null;
+ private int requestTimeoutMs = 5000;
+ private int queuedThreadTimeoutMs = 2500;
+ private int refreshRateLimitTimeWindowMs = 10000;
+ private int refreshRateLimitCount = 10;
+
+ public SelfRefreshingKeySet(KeySetProvider refreshFunction) {
+ this.keySetProvider = refreshFunction;
+ }
+
+ public JsonWebKey getKey(String kid) throws AuthenticatorUnavailableException, BadCredentialsException {
+ if (Strings.isNullOrEmpty(kid)) {
+ return getKeyWithoutKeyId();
+ } else {
+ return getKeyWithKeyId(kid);
+ }
+ }
+
+ public synchronized JsonWebKey getKeyAfterRefresh(String kid) throws AuthenticatorUnavailableException, BadCredentialsException {
+ JsonWebKey result = getKeyAfterRefreshInternal(kid);
+
+ if (result != null) {
+ return result;
+ } else if (jsonWebKeys.getKeys().size() == 0) {
+ throw new AuthenticatorUnavailableException("No JWK are available from IdP");
+ } else {
+ throw new BadCredentialsException("JWT did not contain KID which is required if IdP provides multiple JWK");
+ }
+ }
+
+ private synchronized JsonWebKey getKeyAfterRefreshInternal(String kid) throws AuthenticatorUnavailableException {
+ if (refreshInProgress) {
+ return waitForRefreshToFinish(kid);
+ } else {
+ return performRefresh(kid);
+ }
+ }
+
+ private JsonWebKey getKeyWithoutKeyId() throws AuthenticatorUnavailableException, BadCredentialsException {
+ List keys = jsonWebKeys.getKeys();
+
+ if (keys == null || keys.size() == 0) {
+ JsonWebKey result = getKeyWithRefresh(null);
+
+ if (result != null) {
+ return result;
+ } else {
+ throw new AuthenticatorUnavailableException("No JWK are available from IdP");
+ }
+ } else if (keys.size() == 1) {
+ return keys.get(0);
+ } else {
+ JsonWebKey result = getKeyWithRefresh(null);
+
+ if (result != null) {
+ return result;
+ } else {
+ throw new BadCredentialsException("JWT did not contain KID which is required if IdP provides multiple JWK");
+ }
+ }
+ }
+
+ private JsonWebKey getKeyWithKeyId(String kid) throws AuthenticatorUnavailableException, BadCredentialsException {
+ JsonWebKey result = jsonWebKeys.getKey(kid);
+
+ if (result != null) {
+ return result;
+ }
+
+ result = getKeyWithRefresh(kid);
+
+ if (result == null) {
+ throw new BadCredentialsException("Unknown kid " + kid);
+ }
+
+ return result;
+ }
+
+ private synchronized JsonWebKey getKeyWithRefresh(String kid) throws AuthenticatorUnavailableException {
+
+ // Always re-check within synchronized to handle any races
+
+ JsonWebKey result = getKeySimple(kid);
+
+ if (result != null) {
+ return result;
+ }
+
+ return getKeyAfterRefreshInternal(kid);
+ }
+
+ private JsonWebKey getKeySimple(String kid) {
+ if (Strings.isNullOrEmpty(kid)) {
+ List keys = jsonWebKeys.getKeys();
+
+ if (keys != null && keys.size() == 1) {
+ return keys.get(0);
+ } else {
+ return null;
+ }
+
+ } else {
+ return jsonWebKeys.getKey(kid);
+ }
+ }
+
+ private synchronized JsonWebKey waitForRefreshToFinish(String kid) {
+ queuedGetCount++;
+ long currentRefreshCount = refreshCount;
+
+ try {
+ wait(queuedThreadTimeoutMs);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ log.debug(e.toString());
+ }
+
+ // Just be optimistic and re-check the key
+
+ JsonWebKey result = getKeySimple(kid);
+
+ if (result != null) {
+ return result;
+ }
+
+ if (refreshInProgress && currentRefreshCount == refreshCount) {
+ // The wait() call returned due to the timeout.
+ throw new AuthenticatorUnavailableException("Authentication backend timed out");
+ } else if (lastRefreshFailure != null) {
+ throw new AuthenticatorUnavailableException("Authentication backend failed", lastRefreshFailure);
+ } else {
+ // Refresh was successful, but we did not get a matching key
+ return null;
+ }
+ }
+
+ private synchronized JsonWebKey performRefresh(String kid) {
+ if (log.isDebugEnabled()) {
+ log.debug("performRefresh({})", kid);
+ }
+
+ final boolean recentRefresh;
+
+ if (System.currentTimeMillis() - refreshTime < refreshRateLimitTimeWindowMs) {
+ recentRefreshCount++;
+ recentRefresh = true;
+
+ if (recentRefreshCount > refreshRateLimitCount) {
+ throw new AuthenticatorUnavailableException("Too many unknown kids recently: " + recentRefreshCount);
+ }
+ } else {
+ recentRefresh = false;
+ }
+
+ refreshInProgress = true;
+ refreshCount++;
+
+ log.info("Performing refresh {}", refreshCount);
+
+ long currentRefreshCount = refreshCount;
+
+ try {
+
+ Future> future = threadPoolExecutor.submit(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ JsonWebKeys newKeys = keySetProvider.get();
+
+ if (newKeys == null) {
+ throw new RuntimeException("Refresh function " + keySetProvider + " yielded null");
+ }
+
+ log.info("KeySetProvider finished");
+
+ synchronized (SelfRefreshingKeySet.this) {
+ jsonWebKeys = newKeys;
+ refreshInProgress = false;
+ lastRefreshFailure = null;
+ SelfRefreshingKeySet.this.notifyAll();
+ }
+ } catch (Throwable e) {
+ synchronized (SelfRefreshingKeySet.this) {
+ lastRefreshFailure = e;
+ refreshInProgress = false;
+ SelfRefreshingKeySet.this.notifyAll();
+ }
+ log.warn("KeySetProvider threw error", e);
+ } finally {
+ if (!recentRefresh) {
+ recentRefreshCount = 0;
+ refreshTime = System.currentTimeMillis();
+ }
+ }
+
+ }
+ });
+
+ try {
+ wait(requestTimeoutMs);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ log.debug(e.toString());
+ }
+
+ JsonWebKey result = getKeySimple(kid);
+
+ if (result != null) {
+ return result;
+ }
+
+ if (refreshInProgress && currentRefreshCount == refreshCount) {
+ if (!future.isDone()) {
+ future.cancel(true);
+ }
+
+ lastRefreshFailure = new AuthenticatorUnavailableException("Authentication backend timed out");
+
+ throw new AuthenticatorUnavailableException("Authentication backend timed out");
+ }
+
+ if (lastRefreshFailure != null) {
+ throw new AuthenticatorUnavailableException("Authentication backend failed", lastRefreshFailure);
+ }
+
+ return null;
+
+ } catch (RejectedExecutionException e) {
+ throw new AuthenticatorUnavailableException(
+ "Did not try to call authentication backend because of " + threadPoolExecutor.getActiveCount() + " pending threads",
+ e
+ );
+ } finally {
+ if (refreshInProgress && currentRefreshCount == refreshCount) {
+ refreshInProgress = false;
+ notifyAll();
+ }
+ }
+ }
+
+ public int getRequestTimeoutMs() {
+ return requestTimeoutMs;
+ }
+
+ public void setRequestTimeoutMs(int requestTimeoutMs) {
+ this.requestTimeoutMs = requestTimeoutMs;
+ }
+
+ public int getQueuedThreadTimeoutMs() {
+ return queuedThreadTimeoutMs;
+ }
+
+ public void setQueuedThreadTimeoutMs(int queuedThreadTimeoutMs) {
+ this.queuedThreadTimeoutMs = queuedThreadTimeoutMs;
+ }
+
+ public long getRefreshCount() {
+ return refreshCount;
+ }
+
+ public long getQueuedGetCount() {
+ return queuedGetCount;
+ }
+
+ public int getRefreshRateLimitTimeWindowMs() {
+ return refreshRateLimitTimeWindowMs;
+ }
+
+ public void setRefreshRateLimitTimeWindowMs(int refreshRateLimitTimeWindowMs) {
+ this.refreshRateLimitTimeWindowMs = refreshRateLimitTimeWindowMs;
+ }
+
+ public int getRefreshRateLimitCount() {
+ return refreshRateLimitCount;
+ }
+
+ public void setRefreshRateLimitCount(int refreshRateLimitCount) {
+ this.refreshRateLimitCount = refreshRateLimitCount;
+ }
}
diff --git a/src/main/java/com/amazon/dlic/auth/http/jwt/oidc/json/OpenIdProviderConfiguration.java b/src/main/java/com/amazon/dlic/auth/http/jwt/oidc/json/OpenIdProviderConfiguration.java
index 58a4310a2d..3bcfb796b0 100644
--- a/src/main/java/com/amazon/dlic/auth/http/jwt/oidc/json/OpenIdProviderConfiguration.java
+++ b/src/main/java/com/amazon/dlic/auth/http/jwt/oidc/json/OpenIdProviderConfiguration.java
@@ -17,15 +17,15 @@
@JsonIgnoreProperties(ignoreUnknown = true)
public class OpenIdProviderConfiguration {
- @JsonProperty("jwks_uri")
- private String jwksUri;
+ @JsonProperty("jwks_uri")
+ private String jwksUri;
- public String getJwksUri() {
- return jwksUri;
- }
+ public String getJwksUri() {
+ return jwksUri;
+ }
- public void setJwksUri(String jwksUri) {
- this.jwksUri = jwksUri;
- }
+ public void setJwksUri(String jwksUri) {
+ this.jwksUri = jwksUri;
+ }
}
diff --git a/src/main/java/com/amazon/dlic/auth/http/kerberos/HTTPSpnegoAuthenticator.java b/src/main/java/com/amazon/dlic/auth/http/kerberos/HTTPSpnegoAuthenticator.java
index 15aff90f1a..d8e11960d6 100644
--- a/src/main/java/com/amazon/dlic/auth/http/kerberos/HTTPSpnegoAuthenticator.java
+++ b/src/main/java/com/amazon/dlic/auth/http/kerberos/HTTPSpnegoAuthenticator.java
@@ -58,7 +58,7 @@
public class HTTPSpnegoAuthenticator implements HTTPAuthenticator {
private static final String EMPTY_STRING = "";
- private static final Oid[] KRB_OIDS = new Oid[] {KrbConstants.SPNEGO, KrbConstants.KRB5MECH};
+ private static final Oid[] KRB_OIDS = new Oid[] { KrbConstants.SPNEGO, KrbConstants.KRB5MECH };
protected final Logger log = LogManager.getLogger(this.getClass());
@@ -98,17 +98,17 @@ public Void run() {
}
} catch (Throwable e) {
log.error("Unable to enable krb_debug due to ", e);
- System.err.println("Unable to enable krb_debug due to "+ExceptionsHelper.stackTrace(e));
- System.out.println("Unable to enable krb_debug due to "+ExceptionsHelper.stackTrace(e));
+ System.err.println("Unable to enable krb_debug due to " + ExceptionsHelper.stackTrace(e));
+ System.out.println("Unable to enable krb_debug due to " + ExceptionsHelper.stackTrace(e));
}
System.setProperty(KrbConstants.USE_SUBJECT_CREDS_ONLY_PROP, "false");
String krb5Path = krb5PathSetting;
- if(!Strings.isNullOrEmpty(krb5Path)) {
+ if (!Strings.isNullOrEmpty(krb5Path)) {
- if(Paths.get(krb5Path).isAbsolute()) {
+ if (Paths.get(krb5Path).isAbsolute()) {
log.debug("krb5_filepath: {}", krb5Path);
System.setProperty(KrbConstants.KRB5_CONF_PROP, krb5Path);
} else {
@@ -118,29 +118,36 @@ public Void run() {
System.setProperty(KrbConstants.KRB5_CONF_PROP, krb5Path);
} else {
- if(Strings.isNullOrEmpty(System.getProperty(KrbConstants.KRB5_CONF_PROP))) {
+ if (Strings.isNullOrEmpty(System.getProperty(KrbConstants.KRB5_CONF_PROP))) {
System.setProperty(KrbConstants.KRB5_CONF_PROP, "/etc/krb5.conf");
log.debug("krb5_filepath (was not set or configured, set to default): /etc/krb5.conf");
}
}
stripRealmFromPrincipalName = settings.getAsBoolean("strip_realm_from_principal", true);
- acceptorPrincipal = new HashSet<>(settings.getAsList("plugins.security.kerberos.acceptor_principal", Collections.emptyList()));
+ acceptorPrincipal = new HashSet<>(
+ settings.getAsList("plugins.security.kerberos.acceptor_principal", Collections.emptyList())
+ );
final String _acceptorKeyTabPath = settings.get("plugins.security.kerberos.acceptor_keytab_filepath");
- if(acceptorPrincipal == null || acceptorPrincipal.size() == 0) {
+ if (acceptorPrincipal == null || acceptorPrincipal.size() == 0) {
log.error("acceptor_principal must not be null or empty. Kerberos authentication will not work");
acceptorPrincipal = null;
}
- if(_acceptorKeyTabPath == null || _acceptorKeyTabPath.length() == 0) {
- log.error("plugins.security.kerberos.acceptor_keytab_filepath must not be null or empty. Kerberos authentication will not work");
+ if (_acceptorKeyTabPath == null || _acceptorKeyTabPath.length() == 0) {
+ log.error(
+ "plugins.security.kerberos.acceptor_keytab_filepath must not be null or empty. Kerberos authentication will not work"
+ );
acceptorKeyTabPath = null;
} else {
acceptorKeyTabPath = configDir.resolve(settings.get("plugins.security.kerberos.acceptor_keytab_filepath"));
- if(!Files.exists(acceptorKeyTabPath)) {
- log.error("Unable to read keytab from {} - Maybe the file does not exist or is not readable. Kerberos authentication will not work", acceptorKeyTabPath);
+ if (!Files.exists(acceptorKeyTabPath)) {
+ log.error(
+ "Unable to read keytab from {} - Maybe the file does not exist or is not readable. Kerberos authentication will not work",
+ acceptorKeyTabPath
+ );
acceptorKeyTabPath = null;
}
}
@@ -155,7 +162,9 @@ public Void run() {
} catch (Throwable e) {
log.error("Cannot construct HTTPSpnegoAuthenticator due to {}", e.getMessage(), e);
- log.error("Please make sure you configured 'plugins.security.kerberos.acceptor_keytab_filepath' realtive to the ES config/ dir!");
+ log.error(
+ "Please make sure you configured 'plugins.security.kerberos.acceptor_keytab_filepath' realtive to the ES config/ dir!"
+ );
throw e;
}
@@ -252,11 +261,13 @@ public GSSCredential run() throws GSSException {
return new AuthCredentials("_incomplete_", (Object) outToken);
}
-
final String username = ((SimpleUserPrincipal) principal).getName();
- if(username == null || username.length() == 0) {
- log.error("Got empty or null user from kerberos. Normally this means that you acceptor principal {} does not match the server hostname", acceptorPrincipal);
+ if (username == null || username.length() == 0) {
+ log.error(
+ "Got empty or null user from kerberos. Normally this means that you acceptor principal {} does not match the server hostname",
+ acceptorPrincipal
+ );
}
return new AuthCredentials(username, (Object) outToken).markComplete();
@@ -272,19 +283,22 @@ public GSSCredential run() throws GSSException {
@Override
public boolean reRequestAuthentication(final RestChannel channel, AuthCredentials creds) {
- final BytesRestResponse wwwAuthenticateResponse;
- XContentBuilder response = getNegotiateResponseBody();
+ final BytesRestResponse wwwAuthenticateResponse;
+ XContentBuilder response = getNegotiateResponseBody();
- if (response != null) {
- wwwAuthenticateResponse = new BytesRestResponse(RestStatus.UNAUTHORIZED, response);
+ if (response != null) {
+ wwwAuthenticateResponse = new BytesRestResponse(RestStatus.UNAUTHORIZED, response);
} else {
- wwwAuthenticateResponse = new BytesRestResponse(RestStatus.UNAUTHORIZED, EMPTY_STRING);
+ wwwAuthenticateResponse = new BytesRestResponse(RestStatus.UNAUTHORIZED, EMPTY_STRING);
}
- if(creds == null || creds.getNativeCredentials() == null) {
+ if (creds == null || creds.getNativeCredentials() == null) {
wwwAuthenticateResponse.addHeader("WWW-Authenticate", "Negotiate");
} else {
- wwwAuthenticateResponse.addHeader("WWW-Authenticate", "Negotiate "+Base64.getEncoder().encodeToString((byte[]) creds.getNativeCredentials()));
+ wwwAuthenticateResponse.addHeader(
+ "WWW-Authenticate",
+ "Negotiate " + Base64.getEncoder().encodeToString((byte[]) creds.getNativeCredentials())
+ );
}
channel.sendResponse(wwwAuthenticateResponse);
return true;
@@ -298,7 +312,7 @@ public String getType() {
/**
* This class gets a gss credential via a privileged action.
*/
- //borrowed from Apache Tomcat 8 http://svn.apache.org/repos/asf/tomcat/tc8.0.x/trunk/
+ // borrowed from Apache Tomcat 8 http://svn.apache.org/repos/asf/tomcat/tc8.0.x/trunk/
private static class AcceptAction implements PrivilegedExceptionAction {
GSSContext gssContext;
@@ -316,7 +330,7 @@ public byte[] run() throws GSSException {
}
}
- //borrowed from Apache Tomcat 8 http://svn.apache.org/repos/asf/tomcat/tc8.0.x/trunk/
+ // borrowed from Apache Tomcat 8 http://svn.apache.org/repos/asf/tomcat/tc8.0.x/trunk/
private static class AuthenticateAction implements PrivilegedAction {
private final Logger logger;
@@ -336,7 +350,7 @@ public Principal run() {
}
}
- //borrowed from Apache Tomcat 8 http://svn.apache.org/repos/asf/tomcat/tc8.0.x/trunk/
+ // borrowed from Apache Tomcat 8 http://svn.apache.org/repos/asf/tomcat/tc8.0.x/trunk/
private static String getUsernameFromGSSContext(final GSSContext gssContext, final boolean strip, final Logger logger) {
if (gssContext.isEstablished()) {
GSSName gssName = null;
@@ -359,26 +373,26 @@ private static String getUsernameFromGSSContext(final GSSContext gssContext, fin
return null;
}
- private XContentBuilder getNegotiateResponseBody() {
- try {
- XContentBuilder negotiateResponseBody = XContentFactory.jsonBuilder();
- negotiateResponseBody.startObject();
- negotiateResponseBody.field("error");
- negotiateResponseBody.startObject();
- negotiateResponseBody.field("header");
- negotiateResponseBody.startObject();
- negotiateResponseBody.field("WWW-Authenticate", "Negotiate");
- negotiateResponseBody.endObject();
- negotiateResponseBody.endObject();
- negotiateResponseBody.endObject();
- return negotiateResponseBody;
- } catch (Exception ex) {
- log.error("Can't construct response body", ex);
- return null;
- }
- }
-
- private static String stripRealmName(String name, boolean strip){
+ private XContentBuilder getNegotiateResponseBody() {
+ try {
+ XContentBuilder negotiateResponseBody = XContentFactory.jsonBuilder();
+ negotiateResponseBody.startObject();
+ negotiateResponseBody.field("error");
+ negotiateResponseBody.startObject();
+ negotiateResponseBody.field("header");
+ negotiateResponseBody.startObject();
+ negotiateResponseBody.field("WWW-Authenticate", "Negotiate");
+ negotiateResponseBody.endObject();
+ negotiateResponseBody.endObject();
+ negotiateResponseBody.endObject();
+ return negotiateResponseBody;
+ } catch (Exception ex) {
+ log.error("Can't construct response body", ex);
+ return null;
+ }
+ }
+
+ private static String stripRealmName(String name, boolean strip) {
if (strip && name != null) {
final int i = name.indexOf('@');
if (i > 0) {
diff --git a/src/main/java/com/amazon/dlic/auth/http/kerberos/util/JaasKrbUtil.java b/src/main/java/com/amazon/dlic/auth/http/kerberos/util/JaasKrbUtil.java
index 6574728da4..619c780027 100644
--- a/src/main/java/com/amazon/dlic/auth/http/kerberos/util/JaasKrbUtil.java
+++ b/src/main/java/com/amazon/dlic/auth/http/kerberos/util/JaasKrbUtil.java
@@ -38,177 +38,177 @@
*/
public final class JaasKrbUtil {
- private static boolean debug = false;
-
- private JaasKrbUtil() {
- }
-
- public static void setDebug(final boolean debug) {
- JaasKrbUtil.debug = debug;
- }
-
- public static Subject loginUsingPassword(final String principal, final String password) throws LoginException {
- final Set principals = new HashSet();
- principals.add(new KerberosPrincipal(principal));
-
- final Subject subject = new Subject(false, principals, new HashSet
* @param user The authenticated user to populate with backend roles, never null
* @param credentials Credentials to authenticate to the authorization backend, maybe null.
- * This parameter is for future usage, currently always empty credentials are passed!
+ * This parameter is for future usage, currently always empty credentials are passed!
* @throws OpenSearchSecurityException in case when the authorization backend cannot be reached
* or the {@code credentials} are insufficient to authenticate to the authorization backend.
*/
diff --git a/src/main/java/org/opensearch/security/auth/BackendRegistry.java b/src/main/java/org/opensearch/security/auth/BackendRegistry.java
index 635811a7ae..51e93978bd 100644
--- a/src/main/java/org/opensearch/security/auth/BackendRegistry.java
+++ b/src/main/java/org/opensearch/security/auth/BackendRegistry.java
@@ -181,7 +181,7 @@ public boolean authenticate(final RestRequest request, final RestChannel channel
if (isDebugEnabled) {
log.debug("Rejecting REST request because of blocked address: {}", request.getHttpChannel().getRemoteAddress());
}
-
+
channel.sendResponse(new BytesRestResponse(RestStatus.UNAUTHORIZED, "Authentication finally failed"));
return false;
@@ -200,14 +200,14 @@ public boolean authenticate(final RestRequest request, final RestChannel channel
// ThreadContext injected user
return true;
}
-
+
if (!isInitialized()) {
log.error("Not yet initialized (you may need to run securityadmin)");
channel.sendResponse(new BytesRestResponse(RestStatus.SERVICE_UNAVAILABLE,
"OpenSearch Security not initialized."));
return false;
}
-
+
final TransportAddress remoteAddress = xffResolver.resolve(request);
final boolean isTraceEnabled = log.isTraceEnabled();
if (isTraceEnabled) {
@@ -291,7 +291,7 @@ public boolean authenticate(final RestRequest request, final RestChannel channel
}
}
- //http completed
+ //http completed
authenticatedUser = authcz(userCache, restRoleCache, ac, authDomain.getBackend(), restAuthorizers);
if(authenticatedUser == null) {
@@ -479,7 +479,7 @@ private User authcz(final Cache cache, Cache
* A HTTP authenticator extracts {@link AuthCredentials} from a {@link RestRequest}
*
- *
+ *
* Implementation classes must provide a public constructor
*
* {@code public MyHTTPAuthenticator(org.opensearch.common.settings.Settings settings, java.nio.file.Path configPath)}
@@ -51,14 +51,14 @@
public interface HTTPAuthenticator {
/**
- * The type (name) of the authenticator. Only for logging.
+ * The type (name) of the authenticator. Only for logging.
* @return the type
*/
String getType();
-
+
/**
* Extract {@link AuthCredentials} from {@link RestRequest}
- *
+ *
* @param request The rest request
* @param context The current thread context
* @return The authentication credentials (complete or incomplete) or null when no credentials are found in the request
@@ -68,17 +68,17 @@ public interface HTTPAuthenticator {
* @throws OpenSearchSecurityException
*/
AuthCredentials extractCredentials(RestRequest request, ThreadContext context) throws OpenSearchSecurityException;
-
+
/**
* If the {@code extractCredentials()} call was not successful or the authentication flow needs another roundtrip this method
* will be called. If the custom HTTP authenticator does not support this method is a no-op and false should be returned.
- *
+ *
* If the custom HTTP authenticator does support re-request authentication or supports authentication flows with multiple roundtrips
* then the response should be sent (through the channel) and true must be returned.
- *
+ *
* @param channel The rest channel to sent back the response via {@code channel.sendResponse()}
* @param credentials The credentials from the prior authentication attempt
- * @return false if re-request is not supported/necessary, true otherwise.
+ * @return false if re-request is not supported/necessary, true otherwise.
* If true is returned {@code channel.sendResponse()} must be called so that the request completes.
*/
boolean reRequestAuthentication(final RestChannel channel, AuthCredentials credentials);
diff --git a/src/main/java/org/opensearch/security/auth/blocking/ClientBlockRegistry.java b/src/main/java/org/opensearch/security/auth/blocking/ClientBlockRegistry.java
index a5eba40353..e74c3ad70a 100644
--- a/src/main/java/org/opensearch/security/auth/blocking/ClientBlockRegistry.java
+++ b/src/main/java/org/opensearch/security/auth/blocking/ClientBlockRegistry.java
@@ -1,10 +1,10 @@
/*
* Copyright 2015-2019 floragunn GmbH
- *
+ *
* 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
@@ -12,7 +12,7 @@
* 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.opensearch.security.auth.blocking;
diff --git a/src/main/java/org/opensearch/security/auth/blocking/HeapBasedClientBlockRegistry.java b/src/main/java/org/opensearch/security/auth/blocking/HeapBasedClientBlockRegistry.java
index 363645cd90..450dda54db 100644
--- a/src/main/java/org/opensearch/security/auth/blocking/HeapBasedClientBlockRegistry.java
+++ b/src/main/java/org/opensearch/security/auth/blocking/HeapBasedClientBlockRegistry.java
@@ -1,10 +1,10 @@
/*
* Copyright 2015-2019 floragunn GmbH
- *
+ *
* 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
@@ -12,7 +12,7 @@
* 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.opensearch.security.auth.blocking;
diff --git a/src/main/java/org/opensearch/security/auth/limiting/AbstractRateLimiter.java b/src/main/java/org/opensearch/security/auth/limiting/AbstractRateLimiter.java
index 3f603437a0..a4d596b61d 100644
--- a/src/main/java/org/opensearch/security/auth/limiting/AbstractRateLimiter.java
+++ b/src/main/java/org/opensearch/security/auth/limiting/AbstractRateLimiter.java
@@ -1,10 +1,10 @@
/*
* Copyright 2015-2019 floragunn GmbH
- *
+ *
* 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
@@ -12,7 +12,7 @@
* 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.opensearch.security.auth.limiting;
diff --git a/src/main/java/org/opensearch/security/auth/limiting/AddressBasedRateLimiter.java b/src/main/java/org/opensearch/security/auth/limiting/AddressBasedRateLimiter.java
index 42f1d1f165..35a6571f8f 100644
--- a/src/main/java/org/opensearch/security/auth/limiting/AddressBasedRateLimiter.java
+++ b/src/main/java/org/opensearch/security/auth/limiting/AddressBasedRateLimiter.java
@@ -1,10 +1,10 @@
/*
* Copyright 2015-2019 floragunn GmbH
- *
+ *
* 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
@@ -12,7 +12,7 @@
* 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.opensearch.security.auth.limiting;
diff --git a/src/main/java/org/opensearch/security/auth/limiting/UserNameBasedRateLimiter.java b/src/main/java/org/opensearch/security/auth/limiting/UserNameBasedRateLimiter.java
index 7fe5ac05d6..3fd0c12246 100644
--- a/src/main/java/org/opensearch/security/auth/limiting/UserNameBasedRateLimiter.java
+++ b/src/main/java/org/opensearch/security/auth/limiting/UserNameBasedRateLimiter.java
@@ -1,10 +1,10 @@
/*
* Copyright 2015-2019 floragunn GmbH
- *
+ *
* 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
@@ -12,7 +12,7 @@
* 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.opensearch.security.auth.limiting;
diff --git a/src/main/java/org/opensearch/security/configuration/AdminDNs.java b/src/main/java/org/opensearch/security/configuration/AdminDNs.java
index ced262d543..72a4485e9f 100644
--- a/src/main/java/org/opensearch/security/configuration/AdminDNs.java
+++ b/src/main/java/org/opensearch/security/configuration/AdminDNs.java
@@ -62,7 +62,7 @@ public AdminDNs(final Settings settings) {
this.injectAdminUserEnabled = settings.getAsBoolean(ConfigConstants.SECURITY_UNSUPPORTED_INJECT_ADMIN_USER_ENABLED, false);
final List adminDnsA = settings.getAsList(ConfigConstants.SECURITY_AUTHCZ_ADMIN_DN, Collections.emptyList());
-
+
for (String dn:adminDnsA) {
try {
log.debug("{} is registered as an admin dn", dn);
@@ -73,13 +73,13 @@ public AdminDNs(final Settings settings) {
if (log.isDebugEnabled()) {
log.debug("Admin DN not an LDAP name, but admin user injection enabled. Will add {} to admin usernames", dn);
}
- adminUsernames.add(dn);
+ adminUsernames.add(dn);
} else {
- log.error("Unable to parse admin dn {}",dn, e);
+ log.error("Unable to parse admin dn {}",dn, e);
}
}
}
-
+
log.debug("Loaded {} admin DN's {}",adminDn.size(), adminDn);
final Settings impersonationDns = settings.getByPrefix(ConfigConstants.SECURITY_AUTHCZ_IMPERSONATION_DN+".");
@@ -95,7 +95,7 @@ public AdminDNs(final Settings settings) {
);
log.debug("Loaded {} impersonation DN's {}", allowedDnsImpersonations.size(), allowedDnsImpersonations);
-
+
final Settings impersonationUsersRest = settings.getByPrefix(ConfigConstants.SECURITY_AUTHCZ_REST_IMPERSONATION_USERS+".");
allowedRestImpersonations = impersonationUsersRest.keySet().stream()
@@ -103,9 +103,9 @@ public AdminDNs(final Settings settings) {
ImmutableMap.toImmutableMap(
Function.identity(),
user -> WildcardMatcher.from(settings.getAsList(ConfigConstants.SECURITY_AUTHCZ_REST_IMPERSONATION_USERS+"."+user))
- )
- );
-
+ )
+ );
+
log.debug("Loaded {} impersonation users for REST {}",allowedRestImpersonations.size(), allowedRestImpersonations);
}
@@ -129,11 +129,11 @@ public boolean isAdmin(User user) {
}
return false;
}
-
+
public boolean isAdminDN(String dn) {
-
+
if(dn == null) return false;
-
+
try {
return isAdminDN(new LdapName(dn));
} catch (InvalidNameException e) {
@@ -143,16 +143,16 @@ public boolean isAdminDN(String dn) {
private boolean isAdminDN(LdapName dn) {
if(dn == null) return false;
-
+
boolean isAdmin = adminDn.contains(dn);
-
+
if (log.isTraceEnabled()) {
log.trace("Is principal {} an admin cert? {}", dn.toString(), isAdmin);
}
-
+
return isAdmin;
}
-
+
public boolean isRestImpersonationAllowed(final String originalUser, final String impersonated) {
return (originalUser != null) ? allowedRestImpersonations.getOrDefault(originalUser, WildcardMatcher.NONE).test(impersonated) : false;
}
diff --git a/src/main/java/org/opensearch/security/configuration/ClusterInfoHolder.java b/src/main/java/org/opensearch/security/configuration/ClusterInfoHolder.java
index 61877f2bf2..1c42321986 100644
--- a/src/main/java/org/opensearch/security/configuration/ClusterInfoHolder.java
+++ b/src/main/java/org/opensearch/security/configuration/ClusterInfoHolder.java
@@ -40,7 +40,7 @@ public class ClusterInfoHolder implements ClusterStateListener {
private volatile DiscoveryNodes nodes = null;
private volatile Boolean isLocalNodeElectedClusterManager = null;
private volatile boolean initialized;
-
+
@Override
public void clusterChanged(ClusterChangedEvent event) {
if(nodes == null || event.nodesChanged()) {
@@ -50,7 +50,7 @@ public void clusterChanged(ClusterChangedEvent event) {
}
initialized = true;
}
-
+
isLocalNodeElectedClusterManager = event.localNodeClusterManager()?Boolean.TRUE:Boolean.FALSE;
}
@@ -69,7 +69,7 @@ public Boolean hasNode(DiscoveryNode node) {
}
return null;
}
-
+
return nodes.nodeExists(node)?Boolean.TRUE:Boolean.FALSE;
}
}
diff --git a/src/main/java/org/opensearch/security/configuration/CompatConfig.java b/src/main/java/org/opensearch/security/configuration/CompatConfig.java
index 6912cb4fbb..48f91b10be 100644
--- a/src/main/java/org/opensearch/security/configuration/CompatConfig.java
+++ b/src/main/java/org/opensearch/security/configuration/CompatConfig.java
@@ -50,13 +50,13 @@ public CompatConfig(final Environment environment, final OpensearchDynamicSettin
this.staticSettings = environment.settings();
this.transportPassiveAuthSetting = transportPassiveAuthSetting;
}
-
+
@Subscribe
public void onDynamicConfigModelChanged(DynamicConfigModel dcm) {
this.dcm = dcm;
log.debug("dynamicSecurityConfig updated?: {}", (dcm != null));
}
-
+
//true is default
public boolean restAuthEnabled() {
final boolean restInitiallyDisabled = staticSettings.getAsBoolean(ConfigConstants.SECURITY_UNSUPPORTED_DISABLE_REST_AUTH_INITIALLY, false);
@@ -79,7 +79,7 @@ public boolean restAuthEnabled() {
}
}
-
+
//true is default
public boolean transportInterClusterAuthEnabled() {
final boolean interClusterAuthInitiallyDisabled = staticSettings.getAsBoolean(ConfigConstants.SECURITY_UNSUPPORTED_DISABLE_INTERTRANSPORT_AUTH_INITIALLY, false);
diff --git a/src/main/java/org/opensearch/security/configuration/ConfigCallback.java b/src/main/java/org/opensearch/security/configuration/ConfigCallback.java
index d7d1ed0cee..cb8fc1eedf 100644
--- a/src/main/java/org/opensearch/security/configuration/ConfigCallback.java
+++ b/src/main/java/org/opensearch/security/configuration/ConfigCallback.java
@@ -30,7 +30,7 @@
import org.opensearch.security.securityconf.impl.SecurityDynamicConfiguration;
public interface ConfigCallback {
-
+
void success(SecurityDynamicConfiguration> dConf);
void noData(String id);
void singleFailure(Failure failure);
diff --git a/src/main/java/org/opensearch/security/configuration/ConfigUpdateAlreadyInProgressException.java b/src/main/java/org/opensearch/security/configuration/ConfigUpdateAlreadyInProgressException.java
index ea7799e014..c628a3156e 100644
--- a/src/main/java/org/opensearch/security/configuration/ConfigUpdateAlreadyInProgressException.java
+++ b/src/main/java/org/opensearch/security/configuration/ConfigUpdateAlreadyInProgressException.java
@@ -1,10 +1,10 @@
/*
* Copyright 2015-2019 floragunn GmbH
- *
+ *
* 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
@@ -12,7 +12,7 @@
* 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.opensearch.security.configuration;
diff --git a/src/main/java/org/opensearch/security/configuration/DlsFlsRequestValve.java b/src/main/java/org/opensearch/security/configuration/DlsFlsRequestValve.java
index 4aa9fadcae..f5751efcae 100644
--- a/src/main/java/org/opensearch/security/configuration/DlsFlsRequestValve.java
+++ b/src/main/java/org/opensearch/security/configuration/DlsFlsRequestValve.java
@@ -36,7 +36,7 @@
import org.opensearch.threadpool.ThreadPool;
public interface DlsFlsRequestValve {
-
+
boolean invoke(String action, ActionRequest request, ActionListener> listener, EvaluatedDlsFlsConfig evaluatedDlsFlsConfig, Resolved resolved);
void handleSearchContext(SearchContext context, ThreadPool threadPool, NamedXContentRegistry namedXContentRegistry);
@@ -61,5 +61,5 @@ public void onQueryPhase(QuerySearchResult queryResult) {
}
}
-
+
}
diff --git a/src/main/java/org/opensearch/security/configuration/DlsFlsValveImpl.java b/src/main/java/org/opensearch/security/configuration/DlsFlsValveImpl.java
index 532f820210..947557d342 100644
--- a/src/main/java/org/opensearch/security/configuration/DlsFlsValveImpl.java
+++ b/src/main/java/org/opensearch/security/configuration/DlsFlsValveImpl.java
@@ -266,7 +266,7 @@ public boolean invoke(String action, ActionRequest request, final ActionListener
RestStatus.FORBIDDEN));
return false;
}
-
+
if (evaluatedDlsFlsConfig.hasDls()) {
if (request instanceof SearchRequest) {
@@ -317,7 +317,7 @@ public void handleSearchContext(SearchContext context, ThreadPool threadPool, Na
assert context.parsedQuery() != null;
final Set unparsedDlsQueries = queries.get(dlsEval);
-
+
if (unparsedDlsQueries != null && !unparsedDlsQueries.isEmpty()) {
BooleanQuery.Builder queryBuilder = dlsQueryParser.parse(unparsedDlsQueries, context.getQueryShardContext(),
(q) -> new ConstantScoreQuery(q));
@@ -390,7 +390,7 @@ private void setDlsHeaders(EvaluatedDlsFlsConfig dlsFls, ActionRequest request)
} else {
if (threadContext.getHeader(ConfigConstants.OPENDISTRO_SECURITY_DLS_QUERY_HEADER) != null) {
Object deserializedDlsQueries = Base64Helper.deserializeObject(threadContext.getHeader(ConfigConstants.OPENDISTRO_SECURITY_DLS_QUERY_HEADER));
- if (!dlsQueries.equals(deserializedDlsQueries)) {
+ if (!dlsQueries.equals(deserializedDlsQueries)) {
throw new OpenSearchSecurityException(ConfigConstants.OPENDISTRO_SECURITY_DLS_QUERY_HEADER + " does not match (SG 900D)");
}
} else {
diff --git a/src/main/java/org/opensearch/security/configuration/DlsQueryParser.java b/src/main/java/org/opensearch/security/configuration/DlsQueryParser.java
index fd3b3aee98..a5f07541c8 100644
--- a/src/main/java/org/opensearch/security/configuration/DlsQueryParser.java
+++ b/src/main/java/org/opensearch/security/configuration/DlsQueryParser.java
@@ -99,7 +99,7 @@ public BooleanQuery.Builder parse(Set unparsedDlsQueries, QueryShardCont
return dlsQueryBuilder;
}
-
+
private static void handleNested(final QueryShardContext queryShardContext, final BooleanQuery.Builder dlsQueryBuilder,
final Query parentQuery) {
final BitSetProducer parentDocumentsFilter = queryShardContext.bitsetFilter(NON_NESTED_QUERY);
@@ -131,7 +131,7 @@ boolean containsTermLookupQuery(Set unparsedQueries) {
if (log.isDebugEnabled()) {
log.debug("containsTermLookupQuery() returns true due to " + query + "\nqueries: " + unparsedQueries);
}
-
+
return true;
}
}
@@ -139,7 +139,7 @@ boolean containsTermLookupQuery(Set unparsedQueries) {
if (log.isDebugEnabled()) {
log.debug("containsTermLookupQuery() returns false\nqueries: " + unparsedQueries);
}
-
+
return false;
}
@@ -156,5 +156,5 @@ boolean containsTermLookupQuery(String query) {
}
}
-
+
}
diff --git a/src/main/java/org/opensearch/security/configuration/EmptyFilterLeafReader.java b/src/main/java/org/opensearch/security/configuration/EmptyFilterLeafReader.java
index 4b603fa804..79069ef53e 100644
--- a/src/main/java/org/opensearch/security/configuration/EmptyFilterLeafReader.java
+++ b/src/main/java/org/opensearch/security/configuration/EmptyFilterLeafReader.java
@@ -102,7 +102,7 @@ public EmptyDirectoryReader(final DirectoryReader in) throws IOException {
protected DirectoryReader doWrapDirectoryReader(final DirectoryReader in) throws IOException {
return new EmptyDirectoryReader(in);
}
-
+
@Override
public CacheHelper getReaderCacheHelper() {
return in.getReaderCacheHelper();
diff --git a/src/main/java/org/opensearch/security/configuration/InvalidConfigException.java b/src/main/java/org/opensearch/security/configuration/InvalidConfigException.java
index 5e96af6449..ba6a29b08a 100644
--- a/src/main/java/org/opensearch/security/configuration/InvalidConfigException.java
+++ b/src/main/java/org/opensearch/security/configuration/InvalidConfigException.java
@@ -29,7 +29,7 @@
public class InvalidConfigException extends Exception {
/**
- *
+ *
*/
private static final long serialVersionUID = 1L;
diff --git a/src/main/java/org/opensearch/security/configuration/StaticResourceException.java b/src/main/java/org/opensearch/security/configuration/StaticResourceException.java
index b4d787aa0f..8574a170bb 100644
--- a/src/main/java/org/opensearch/security/configuration/StaticResourceException.java
+++ b/src/main/java/org/opensearch/security/configuration/StaticResourceException.java
@@ -1,10 +1,10 @@
/*
* Copyright 2015-2019 floragunn GmbH
- *
+ *
* 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
@@ -12,7 +12,7 @@
* 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.opensearch.security.configuration;
diff --git a/src/main/java/org/opensearch/security/filter/SecurityFilter.java b/src/main/java/org/opensearch/security/filter/SecurityFilter.java
index 7bdd5946d5..4dd629c010 100644
--- a/src/main/java/org/opensearch/security/filter/SecurityFilter.java
+++ b/src/main/java/org/opensearch/security/filter/SecurityFilter.java
@@ -192,7 +192,7 @@ private void ap
if (user != null) {
org.apache.logging.log4j.ThreadContext.put("user", user.getName());
}
-
+
if (isActionTraceEnabled()) {
String count = "";
@@ -232,12 +232,12 @@ private void ap
chain.proceed(task, action, request, listener);
return;
}
-
-
+
+
if(immutableIndicesMatcher != WildcardMatcher.NONE) {
-
+
boolean isImmutable = false;
-
+
if(request instanceof BulkShardRequest) {
for(BulkItemRequest bsr: ((BulkShardRequest) request).items()) {
isImmutable = checkImmutableIndices(bsr.request(), listener);
@@ -248,7 +248,7 @@ private void ap
} else {
isImmutable = checkImmutableIndices(request, listener);
}
-
+
if(isImmutable) {
return;
}
@@ -301,7 +301,7 @@ private void ap
}
final PrivilegesEvaluatorResponse pres = eval.evaluate(user, action, request, task, injectedRoles);
-
+
if (log.isDebugEnabled()) {
log.debug(pres.toString());
}
@@ -384,7 +384,7 @@ private static boolean isUserAdmin(User user, final AdminDNs adminDns) {
}
private void attachSourceFieldContext(ActionRequest request) {
-
+
if(request instanceof SearchRequest && SourceFieldsContext.isNeeded((SearchRequest) request)) {
if(threadContext.getHeader("_opendistro_security_source_field_context") == null) {
final String serializedSourceFieldContext = Base64Helper.serializeObject(new SourceFieldsContext((SearchRequest) request));
@@ -397,7 +397,7 @@ private void attachSourceFieldContext(ActionRequest request) {
}
}
}
-
+
@SuppressWarnings("rawtypes")
private boolean checkImmutableIndices(Object request, ActionListener listener) {
final boolean isModifyIndexRequest = request instanceof DeleteRequest
@@ -413,11 +413,11 @@ private boolean checkImmutableIndices(Object request, ActionListener listener) {
listener.onFailure(new OpenSearchSecurityException("Index is immutable", RestStatus.FORBIDDEN));
return true;
}
-
+
if ((request instanceof IndexRequest) && isRequestIndexImmutable(request)) {
((IndexRequest) request).opType(OpType.CREATE);
}
-
+
return false;
}
diff --git a/src/main/java/org/opensearch/security/filter/SecurityRestFilter.java b/src/main/java/org/opensearch/security/filter/SecurityRestFilter.java
index 2fec235f3e..a5a23957ed 100644
--- a/src/main/java/org/opensearch/security/filter/SecurityRestFilter.java
+++ b/src/main/java/org/opensearch/security/filter/SecurityRestFilter.java
@@ -117,7 +117,7 @@ public SecurityRestFilter(final BackendRegistry registry, final AuditLog auditLo
*/
public RestHandler wrap(RestHandler original, AdminDNs adminDNs) {
return new RestHandler() {
-
+
@Override
public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
org.apache.logging.log4j.ThreadContext.clearAll();
@@ -142,7 +142,7 @@ private boolean checkAndAuthenticateRequest(RestRequest request, RestChannel cha
NodeClient client) throws Exception {
threadContext.putTransient(ConfigConstants.OPENDISTRO_SECURITY_ORIGIN, Origin.REST.toString());
-
+
if(HTTPHelper.containsBadHeader(request)) {
final OpenSearchException exception = ExceptionUtils.createBadHeaderException();
log.error(exception.toString());
@@ -150,7 +150,7 @@ private boolean checkAndAuthenticateRequest(RestRequest request, RestChannel cha
channel.sendResponse(new BytesRestResponse(channel, RestStatus.FORBIDDEN, exception));
return true;
}
-
+
if(SSLRequestHelper.containsBadHeader(threadContext, ConfigConstants.OPENDISTRO_SECURITY_CONFIG_PREFIX)) {
final OpenSearchException exception = ExceptionUtils.createBadHeaderException();
log.error(exception.toString());
@@ -165,7 +165,7 @@ private boolean checkAndAuthenticateRequest(RestRequest request, RestChannel cha
if(sslInfo.getPrincipal() != null) {
threadContext.putTransient("_opendistro_security_ssl_principal", sslInfo.getPrincipal());
}
-
+
if(sslInfo.getX509Certs() != null) {
threadContext.putTransient("_opendistro_security_ssl_peer_certificates", sslInfo.getX509Certs());
}
@@ -178,7 +178,7 @@ private boolean checkAndAuthenticateRequest(RestRequest request, RestChannel cha
channel.sendResponse(new BytesRestResponse(channel, RestStatus.FORBIDDEN, e));
return true;
}
-
+
if(!compatConfig.restAuthEnabled()) {
return false;
}
@@ -197,7 +197,7 @@ private boolean checkAndAuthenticateRequest(RestRequest request, RestChannel cha
org.apache.logging.log4j.ThreadContext.put("user", ((User)threadContext.getTransient(ConfigConstants.OPENDISTRO_SECURITY_USER)).getName());
}
}
-
+
return false;
}
diff --git a/src/main/java/org/opensearch/security/http/HTTPBasicAuthenticator.java b/src/main/java/org/opensearch/security/http/HTTPBasicAuthenticator.java
index 35278d261f..30e6134381 100644
--- a/src/main/java/org/opensearch/security/http/HTTPBasicAuthenticator.java
+++ b/src/main/java/org/opensearch/security/http/HTTPBasicAuthenticator.java
@@ -47,20 +47,20 @@ public class HTTPBasicAuthenticator implements HTTPAuthenticator {
protected final Logger log = LogManager.getLogger(this.getClass());
public HTTPBasicAuthenticator(final Settings settings, final Path configPath) {
-
+
}
@Override
public AuthCredentials extractCredentials(final RestRequest request, ThreadContext threadContext) {
final boolean forceLogin = request.paramAsBoolean("force_login", false);
-
+
if(forceLogin) {
return null;
}
-
+
final String authorizationHeader = request.header("Authorization");
-
+
return HTTPHelper.extractCredentials(authorizationHeader, log);
}
diff --git a/src/main/java/org/opensearch/security/http/HTTPClientCertAuthenticator.java b/src/main/java/org/opensearch/security/http/HTTPClientCertAuthenticator.java
index 51ff6304b1..373919669d 100644
--- a/src/main/java/org/opensearch/security/http/HTTPClientCertAuthenticator.java
+++ b/src/main/java/org/opensearch/security/http/HTTPClientCertAuthenticator.java
@@ -48,7 +48,7 @@
import org.opensearch.security.user.AuthCredentials;
public class HTTPClientCertAuthenticator implements HTTPAuthenticator {
-
+
protected final Logger log = LogManager.getLogger(this.getClass());
protected final Settings settings;
@@ -62,29 +62,29 @@ public AuthCredentials extractCredentials(final RestRequest request, final Threa
final String principal = threadContext.getTransient(ConfigConstants.OPENDISTRO_SECURITY_SSL_PRINCIPAL);
if (!Strings.isNullOrEmpty(principal)) {
-
+
final String usernameAttribute = settings.get("username_attribute");
final String rolesAttribute = settings.get("roles_attribute");
-
+
try {
final LdapName rfc2253dn = new LdapName(principal);
String username = principal.trim();
String[] backendRoles = null;
-
+
if(usernameAttribute != null && usernameAttribute.length() > 0) {
final List usernames = getDnAttribute(rfc2253dn, usernameAttribute);
if(usernames.isEmpty() == false) {
username = usernames.get(0);
}
}
-
+
if(rolesAttribute != null && rolesAttribute.length() > 0) {
final List roles = getDnAttribute(rfc2253dn, rolesAttribute);
if(roles.isEmpty() == false) {
backendRoles = roles.toArray(new String[0]);
}
}
-
+
return new AuthCredentials(username, backendRoles).markComplete();
} catch (InvalidNameException e) {
log.error("Client cert had no properly formed DN (was: {})", principal);
@@ -106,8 +106,8 @@ public boolean reRequestAuthentication(final RestChannel channel, AuthCredential
public String getType() {
return "clientcert";
}
-
- private List getDnAttribute(LdapName rfc2253dn, String attribute) {
+
+ private List getDnAttribute(LdapName rfc2253dn, String attribute) {
final List attrValues = new ArrayList<>(rfc2253dn.size());
final List reverseRdn = new ArrayList<>(rfc2253dn.getRdns());
Collections.reverse(reverseRdn);
@@ -117,7 +117,7 @@ private List getDnAttribute(LdapName rfc2253dn, String attribute) {
attrValues.add(rdn.getValue().toString());
}
}
-
+
return Collections.unmodifiableList(attrValues);
}
}
diff --git a/src/main/java/org/opensearch/security/http/HTTPProxyAuthenticator.java b/src/main/java/org/opensearch/security/http/HTTPProxyAuthenticator.java
index 28fb80e0db..348811b694 100644
--- a/src/main/java/org/opensearch/security/http/HTTPProxyAuthenticator.java
+++ b/src/main/java/org/opensearch/security/http/HTTPProxyAuthenticator.java
@@ -57,14 +57,14 @@ public HTTPProxyAuthenticator(Settings settings, final Path configPath) {
@Override
public AuthCredentials extractCredentials(final RestRequest request, ThreadContext context) {
-
+
if(context.getTransient(ConfigConstants.OPENDISTRO_SECURITY_XFF_DONE) != Boolean.TRUE) {
throw new OpenSearchSecurityException("xff not done");
}
-
+
final String userHeader = settings.get("user_header");
final String rolesHeader = settings.get("roles_header");
-
+
if (log.isDebugEnabled()) {
log.debug("Headers {}", request.getHeaders());
log.debug("UserHeader {}, value {}", userHeader, userHeader == null ? null : request.header(userHeader));
diff --git a/src/main/java/org/opensearch/security/http/RemoteIpDetector.java b/src/main/java/org/opensearch/security/http/RemoteIpDetector.java
index 404fd2dcc2..5d9e933c8f 100644
--- a/src/main/java/org/opensearch/security/http/RemoteIpDetector.java
+++ b/src/main/java/org/opensearch/security/http/RemoteIpDetector.java
@@ -120,23 +120,23 @@ String detect(RestRequest request, ThreadContext threadContext){
if (isTraceEnabled) {
log.trace("originalRemoteAddr {}", originalRemoteAddr);
}
-
+
//X-Forwarded-For: client1, proxy1, proxy2
// ^^^^^^ originalRemoteAddr
-
+
//originalRemoteAddr need to be in the list of internalProxies
if (internalProxies !=null &&
internalProxies.matcher(originalRemoteAddr).matches()) {
String remoteIp = null;
final StringBuilder concatRemoteIpHeaderValue = new StringBuilder();
-
+
//client1, proxy1, proxy2
final List remoteIpHeaders = request.getHeaders().get(remoteIpHeader); //X-Forwarded-For
if(remoteIpHeaders == null || remoteIpHeaders.isEmpty()) {
return originalRemoteAddr;
}
-
+
for (String rh:remoteIpHeaders) {
if (concatRemoteIpHeaderValue.length() > 0) {
concatRemoteIpHeaderValue.append(", ");
@@ -144,7 +144,7 @@ String detect(RestRequest request, ThreadContext threadContext){
concatRemoteIpHeaderValue.append(rh);
}
-
+
if (isTraceEnabled) {
log.trace("concatRemoteIpHeaderValue {}", concatRemoteIpHeaderValue.toString());
}
@@ -162,14 +162,14 @@ String detect(RestRequest request, ThreadContext threadContext){
break;
}
}
-
+
// continue to loop on remoteIpHeaderValue to build the new value of the remoteIpHeader
final LinkedList newRemoteIpHeaderValue = new LinkedList<>();
for (; idx >= 0; idx--) {
String currentRemoteIp = remoteIpHeaderValue[idx];
newRemoteIpHeaderValue.addFirst(currentRemoteIp);
}
-
+
if (remoteIp != null) {
if (isTraceEnabled) {
final String originalRemoteHost = ((InetSocketAddress)request.getHttpChannel().getRemoteAddress()).getAddress().getHostName();
@@ -178,17 +178,17 @@ String detect(RestRequest request, ThreadContext threadContext){
threadContext.putTransient(ConfigConstants.OPENDISTRO_SECURITY_XFF_DONE, Boolean.TRUE);
return remoteIp;
-
+
} else {
log.warn("Remote ip could not be detected, this should normally not happen");
}
-
+
} else {
if (isTraceEnabled) {
log.trace("Skip RemoteIpDetector for request {} with originalRemoteAddr '{}' cause no internal proxy matches", request.uri(), request.getHttpChannel().getRemoteAddress());
}
}
-
+
return originalRemoteAddr;
}
diff --git a/src/main/java/org/opensearch/security/http/SecurityHttpServerTransport.java b/src/main/java/org/opensearch/security/http/SecurityHttpServerTransport.java
index 3d977dcc7e..6f2f57053f 100644
--- a/src/main/java/org/opensearch/security/http/SecurityHttpServerTransport.java
+++ b/src/main/java/org/opensearch/security/http/SecurityHttpServerTransport.java
@@ -39,7 +39,7 @@
import org.opensearch.transport.SharedGroupFactory;
public class SecurityHttpServerTransport extends SecuritySSLNettyHttpServerTransport {
-
+
public SecurityHttpServerTransport(final Settings settings, final NetworkService networkService,
final BigArrays bigArrays, final ThreadPool threadPool, final SecurityKeyStore odsks,
final SslExceptionHandler sslExceptionHandler, final NamedXContentRegistry namedXContentRegistry, final ValidatingDispatcher dispatcher, final ClusterSettings clusterSettings, SharedGroupFactory sharedGroupFactory) {
diff --git a/src/main/java/org/opensearch/security/http/SecurityNonSslHttpServerTransport.java b/src/main/java/org/opensearch/security/http/SecurityNonSslHttpServerTransport.java
index b05153db4c..3c1dedc55e 100644
--- a/src/main/java/org/opensearch/security/http/SecurityNonSslHttpServerTransport.java
+++ b/src/main/java/org/opensearch/security/http/SecurityNonSslHttpServerTransport.java
@@ -54,7 +54,7 @@ public ChannelHandler configureServerChannelHandler() {
}
protected class NonSslHttpChannelHandler extends Netty4HttpServerTransport.HttpChannelHandler {
-
+
protected NonSslHttpChannelHandler(Netty4HttpServerTransport transport, final HttpHandlingSettings handlingSettings) {
super(transport, handlingSettings);
}
diff --git a/src/main/java/org/opensearch/security/http/XFFResolver.java b/src/main/java/org/opensearch/security/http/XFFResolver.java
index 23de8e3676..c44e98537d 100644
--- a/src/main/java/org/opensearch/security/http/XFFResolver.java
+++ b/src/main/java/org/opensearch/security/http/XFFResolver.java
@@ -47,7 +47,7 @@ public class XFFResolver {
private volatile boolean enabled;
private volatile RemoteIpDetector detector;
private final ThreadContext threadContext;
-
+
public XFFResolver(final ThreadPool threadPool) {
super();
this.threadContext = threadPool.getThreadContext();
@@ -58,16 +58,16 @@ public TransportAddress resolve(final RestRequest request) throws OpenSearchSecu
if (isTraceEnabled) {
log.trace("resolve {}", request.getHttpChannel().getRemoteAddress());
}
-
+
if(enabled && request.getHttpChannel().getRemoteAddress() instanceof InetSocketAddress && request.getHttpChannel() instanceof Netty4HttpChannel) {
final InetSocketAddress isa = new InetSocketAddress(detector.detect(request, threadContext), ((InetSocketAddress)request.getHttpChannel().getRemoteAddress()).getPort());
-
- if(isa.isUnresolved()) {
+
+ if(isa.isUnresolved()) {
throw new OpenSearchSecurityException("Cannot resolve address "+isa.getHostString());
}
-
-
+
+
if (isTraceEnabled) {
if(threadContext.getTransient(ConfigConstants.OPENDISTRO_SECURITY_XFF_DONE) == Boolean.TRUE) {
log.trace("xff resolved {} to {}", request.getHttpChannel().getRemoteAddress(), isa);
@@ -77,7 +77,7 @@ public TransportAddress resolve(final RestRequest request) throws OpenSearchSecu
}
return new TransportAddress(isa);
} else if(request.getHttpChannel().getRemoteAddress() instanceof InetSocketAddress){
-
+
if (isTraceEnabled) {
log.trace("no xff done (enabled or no netty request) {},{},{},{}",enabled, request.getClass());
diff --git a/src/main/java/org/opensearch/security/http/proxy/HTTPExtendedProxyAuthenticator.java b/src/main/java/org/opensearch/security/http/proxy/HTTPExtendedProxyAuthenticator.java
index d792158fea..e98f26d85a 100644
--- a/src/main/java/org/opensearch/security/http/proxy/HTTPExtendedProxyAuthenticator.java
+++ b/src/main/java/org/opensearch/security/http/proxy/HTTPExtendedProxyAuthenticator.java
@@ -60,7 +60,7 @@ public AuthCredentials extractCredentials(final RestRequest request, ThreadConte
if(credentials == null) {
return null;
}
-
+
String attrHeaderPrefix = settings.get("attr_header_prefix");
if(Strings.isNullOrEmpty(attrHeaderPrefix)) {
log.debug("attr_header_prefix is null. Skipping additional attribute extraction");
@@ -68,7 +68,7 @@ public AuthCredentials extractCredentials(final RestRequest request, ThreadConte
} else if(log.isDebugEnabled()) {
log.debug("attrHeaderPrefix {}", attrHeaderPrefix);
}
-
+
credentials.addAttribute(ATTR_PROXY_USERNAME, credentials.getUsername());
attrHeaderPrefix = attrHeaderPrefix.toLowerCase();
for (Entry> entry : request.getHeaders().entrySet()) {
diff --git a/src/main/java/org/opensearch/security/httpclient/HttpClient.java b/src/main/java/org/opensearch/security/httpclient/HttpClient.java
index d032ca3544..ad507ea47c 100644
--- a/src/main/java/org/opensearch/security/httpclient/HttpClient.java
+++ b/src/main/java/org/opensearch/security/httpclient/HttpClient.java
@@ -195,7 +195,7 @@ public boolean index(final String content, final String index, final String type
try {
final IndexRequest ir = new IndexRequest(index);
-
+
final IndexResponse response = rclient.index(ir
.setRefreshPolicy(refresh?RefreshPolicy.IMMEDIATE:RefreshPolicy.NONE)
.source(content, XContentType.JSON), RequestOptions.DEFAULT);
diff --git a/src/main/java/org/opensearch/security/privileges/DocumentAllowList.java b/src/main/java/org/opensearch/security/privileges/DocumentAllowList.java
index 8bfbb7c0db..129233a007 100644
--- a/src/main/java/org/opensearch/security/privileges/DocumentAllowList.java
+++ b/src/main/java/org/opensearch/security/privileges/DocumentAllowList.java
@@ -193,7 +193,7 @@ public static class Entry {
if (index.indexOf('/') != -1 || index.indexOf('|') != -1) {
throw new IllegalArgumentException("Invalid index name: " + index);
}
-
+
this.index = index;
this.id = id;
}
diff --git a/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java b/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java
index 36d53b2a9e..278dc86b7c 100644
--- a/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java
+++ b/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java
@@ -134,7 +134,7 @@ public class PrivilegesEvaluator {
private final boolean dfmEmptyOverwritesAll;
private DynamicConfigModel dcm;
private final NamedXContentRegistry namedXContentRegistry;
-
+
public PrivilegesEvaluator(final ClusterService clusterService, final ThreadPool threadPool,
final ConfigurationRepository configurationRepository, final IndexNameExpressionResolver resolver,
AuditLog auditLog, final Settings settings, final PrivilegesInterceptor privilegesInterceptor, final ClusterInfoHolder clusterInfoHolder,
@@ -309,7 +309,7 @@ public PrivilegesEvaluatorResponse evaluate(final User user, String action0, fin
}
presponse.evaluatedDlsFlsConfig = getSecurityRoles(mappedRoles).getDlsFls(user, dfmEmptyOverwritesAll, resolver, clusterService, namedXContentRegistry);
-
+
if (isClusterPerm(action0)) {
if(!securityRoles.impliesClusterPermissionPermission(action0)) {
@@ -384,7 +384,7 @@ public PrivilegesEvaluatorResponse evaluate(final User user, String action0, fin
presponse.allowed = true;
return presponse;
}
-
+
// term aggregations
if (termsAggregationEvaluator.evaluate(requestedResolved, request, clusterService, user, securityRoles, resolver, presponse) .isComplete()) {
return presponse;
@@ -728,7 +728,7 @@ private boolean checkDocAllowListHeader(User user, String action, ActionRequest
if (log.isDebugEnabled()) {
log.debug("Request " + request + " is allowed by " + documentAllowList);
}
-
+
return true;
} else {
return false;
@@ -739,7 +739,7 @@ private boolean checkDocAllowListHeader(User user, String action, ActionRequest
return false;
}
}
-
+
private List toString(List aliases) {
if(aliases == null || aliases.size() == 0) {
return Collections.emptyList();
diff --git a/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluatorResponse.java b/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluatorResponse.java
index 8b3e51f045..31ce7095d2 100644
--- a/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluatorResponse.java
+++ b/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluatorResponse.java
@@ -42,11 +42,11 @@ public class PrivilegesEvaluatorResponse {
PrivilegesEvaluatorResponseState state = PrivilegesEvaluatorResponseState.PENDING;
Resolved resolved;
CreateIndexRequestBuilder createIndexRequestBuilder;
-
+
public Resolved getResolved() {
return resolved;
}
-
+
public boolean isAllowed() {
return allowed;
}
@@ -61,11 +61,11 @@ public Set getMissingPrivileges() {
public EvaluatedDlsFlsConfig getEvaluatedDlsFlsConfig() {
return evaluatedDlsFlsConfig;
}
-
+
public CreateIndexRequestBuilder getCreateIndexRequestBuilder() {
return createIndexRequestBuilder;
}
-
+
public PrivilegesEvaluatorResponse markComplete() {
this.state = PrivilegesEvaluatorResponseState.COMPLETE;
return this;
@@ -89,10 +89,10 @@ public String toString() {
return "PrivEvalResponse [allowed=" + allowed + ", missingPrivileges=" + missingPrivileges + ", evaluatedDlsFlsConfig="
+ evaluatedDlsFlsConfig + "]";
}
-
+
public static enum PrivilegesEvaluatorResponseState {
PENDING,
COMPLETE;
}
-
+
}
diff --git a/src/main/java/org/opensearch/security/privileges/PrivilegesInterceptor.java b/src/main/java/org/opensearch/security/privileges/PrivilegesInterceptor.java
index c76910474f..dd569b05fb 100644
--- a/src/main/java/org/opensearch/security/privileges/PrivilegesInterceptor.java
+++ b/src/main/java/org/opensearch/security/privileges/PrivilegesInterceptor.java
@@ -65,7 +65,7 @@ protected static ReplaceResult newAccessGrantedReplaceResult(CreateIndexRequestB
protected final Client client;
protected final ThreadPool threadPool;
- public PrivilegesInterceptor(final IndexNameExpressionResolver resolver, final ClusterService clusterService,
+ public PrivilegesInterceptor(final IndexNameExpressionResolver resolver, final ClusterService clusterService,
final Client client, ThreadPool threadPool) {
this.resolver = resolver;
this.clusterService = clusterService;
@@ -77,7 +77,7 @@ public ReplaceResult replaceDashboardsIndex(final ActionRequest request, final S
final Resolved requestedResolved, final Map tenants) {
throw new RuntimeException("not implemented");
}
-
+
protected final ThreadContext getThreadContext() {
return threadPool.getThreadContext();
}
diff --git a/src/main/java/org/opensearch/security/privileges/SecurityIndexAccessEvaluator.java b/src/main/java/org/opensearch/security/privileges/SecurityIndexAccessEvaluator.java
index 60456a4eb3..a74ea17ccd 100644
--- a/src/main/java/org/opensearch/security/privileges/SecurityIndexAccessEvaluator.java
+++ b/src/main/java/org/opensearch/security/privileges/SecurityIndexAccessEvaluator.java
@@ -47,9 +47,9 @@
import org.opensearch.tasks.Task;
public class SecurityIndexAccessEvaluator {
-
+
Logger log = LogManager.getLogger(this.getClass());
-
+
private final String securityIndex;
private final AuditLog auditLog;
private final WildcardMatcher securityDeniedActionMatcher;
@@ -86,7 +86,7 @@ public SecurityIndexAccessEvaluator(final Settings settings, AuditLog auditLog,
securityDeniedActionMatcher = WildcardMatcher.from(restoreSecurityIndexEnabled ? securityIndexDeniedActionPatternsList : securityIndexDeniedActionPatternsListNoSnapshot);
}
-
+
public PrivilegesEvaluatorResponse evaluate(final ActionRequest request, final Task task, final String action, final Resolved requestedResolved,
final PrivilegesEvaluatorResponse presponse) {
final boolean isDebugEnabled = log.isDebugEnabled();
diff --git a/src/main/java/org/opensearch/security/privileges/SnapshotRestoreEvaluator.java b/src/main/java/org/opensearch/security/privileges/SnapshotRestoreEvaluator.java
index c457b42624..c536ae2d2e 100644
--- a/src/main/java/org/opensearch/security/privileges/SnapshotRestoreEvaluator.java
+++ b/src/main/java/org/opensearch/security/privileges/SnapshotRestoreEvaluator.java
@@ -47,7 +47,7 @@ public class SnapshotRestoreEvaluator {
private final String securityIndex;
private final AuditLog auditLog;
private final boolean restoreSecurityIndexEnabled;
-
+
public SnapshotRestoreEvaluator(final Settings settings, AuditLog auditLog) {
this.enableSnapshotRestorePrivilege = settings.getAsBoolean(ConfigConstants.SECURITY_ENABLE_SNAPSHOT_RESTORE_PRIVILEGE,
ConfigConstants.SECURITY_DEFAULT_ENABLE_SNAPSHOT_RESTORE_PRIVILEGE);
@@ -63,27 +63,27 @@ public PrivilegesEvaluatorResponse evaluate(final ActionRequest request, final T
if (!(request instanceof RestoreSnapshotRequest)) {
return presponse;
}
-
+
// snapshot restore for regular users not enabled
if (!enableSnapshotRestorePrivilege) {
log.warn("{} is not allowed for a regular user", action);
presponse.allowed = false;
- return presponse.markComplete();
+ return presponse.markComplete();
}
// if this feature is enabled, users can also snapshot and restore
// the Security index and the global state
if (restoreSecurityIndexEnabled) {
presponse.allowed = true;
- return presponse;
+ return presponse;
}
-
+
if (clusterInfoHolder.isLocalNodeElectedClusterManager() == Boolean.FALSE) {
presponse.allowed = true;
- return presponse.markComplete();
+ return presponse.markComplete();
}
-
+
final RestoreSnapshotRequest restoreRequest = (RestoreSnapshotRequest) request;
// Do not allow restore of global state
@@ -91,7 +91,7 @@ public PrivilegesEvaluatorResponse evaluate(final ActionRequest request, final T
auditLog.logSecurityIndexAttempt(request, action, task);
log.warn("{} with 'include_global_state' enabled is not allowed", action);
presponse.allowed = false;
- return presponse.markComplete();
+ return presponse.markComplete();
}
final List rs = SnapshotRestoreHelper.resolveOriginalIndices(restoreRequest);
@@ -100,7 +100,7 @@ public PrivilegesEvaluatorResponse evaluate(final ActionRequest request, final T
auditLog.logSecurityIndexAttempt(request, action, task);
log.warn("{} for '{}' as source index is not allowed", action, securityIndex);
presponse.allowed = false;
- return presponse.markComplete();
+ return presponse.markComplete();
}
return presponse;
}
diff --git a/src/main/java/org/opensearch/security/privileges/TermsAggregationEvaluator.java b/src/main/java/org/opensearch/security/privileges/TermsAggregationEvaluator.java
index 1d1d048350..53709458fd 100644
--- a/src/main/java/org/opensearch/security/privileges/TermsAggregationEvaluator.java
+++ b/src/main/java/org/opensearch/security/privileges/TermsAggregationEvaluator.java
@@ -56,12 +56,12 @@ public class TermsAggregationEvaluator {
"indices:data/read/field_caps*"
//"indices:admin/mappings/fields/get*"
};
-
+
private static final QueryBuilder NONE_QUERY = new MatchNoneQueryBuilder();
-
+
public TermsAggregationEvaluator() {
}
-
+
public PrivilegesEvaluatorResponse evaluate(final Resolved resolved, final ActionRequest request, ClusterService clusterService, User user, SecurityRoles securityRoles, IndexNameExpressionResolver resolver, PrivilegesEvaluatorResponse presponse) {
try {
if(request instanceof SearchRequest) {
@@ -81,14 +81,14 @@ public PrivilegesEvaluatorResponse evaluate(final Resolved resolved, final Actio
&& ab.getPipelineAggregations().isEmpty()
&& ab.getSubAggregations().isEmpty()) {
-
+
final Set allPermittedIndices = securityRoles.getAllPermittedIndicesForDashboards(resolved, user, READ_ACTIONS, resolver, clusterService);
if(allPermittedIndices == null || allPermittedIndices.isEmpty()) {
sr.source().query(NONE_QUERY);
} else {
sr.source().query(new TermsQueryBuilder("_index", allPermittedIndices));
- }
-
+ }
+
presponse.allowed = true;
return presponse.markComplete();
}
@@ -99,7 +99,7 @@ public PrivilegesEvaluatorResponse evaluate(final Resolved resolved, final Actio
log.warn("Unable to evaluate terms aggregation",e);
return presponse;
}
-
+
return presponse;
}
}
diff --git a/src/main/java/org/opensearch/security/resolver/IndexResolverReplacer.java b/src/main/java/org/opensearch/security/resolver/IndexResolverReplacer.java
index d2d0685860..5892a91a30 100644
--- a/src/main/java/org/opensearch/security/resolver/IndexResolverReplacer.java
+++ b/src/main/java/org/opensearch/security/resolver/IndexResolverReplacer.java
@@ -369,7 +369,7 @@ public final static class Resolved {
private final Set remoteIndices;
private final boolean isLocalAll;
private final IndicesOptions indicesOptions;
-
+
public Resolved(final ImmutableSet aliases,
final ImmutableSet allIndices,
final ImmutableSet originalRequested,
@@ -394,15 +394,15 @@ public Set getAliases() {
public Set getAllIndices() {
return allIndices;
}
-
+
public Set getAllIndicesResolved(ClusterService clusterService, IndexNameExpressionResolver resolver) {
- if (isLocalAll) {
+ if (isLocalAll) {
return new HashSet<>(Arrays.asList(resolver.concreteIndexNames(clusterService.state(), indicesOptions, "*")));
- } else {
+ } else {
return allIndices;
}
}
-
+
public boolean isAllIndicesEmpty() {
return allIndices.isEmpty();
}
@@ -711,7 +711,7 @@ private boolean getOrReplaceAllIndices(final Object request, final IndicesProvid
}
private IndicesOptions indicesOptionsFrom(Object localRequest) {
-
+
if(!respectRequestIndicesOptions) {
return IndicesOptions.fromOptions(false, true, true, false, true);
}
diff --git a/src/main/java/org/opensearch/security/rest/DashboardsInfoAction.java b/src/main/java/org/opensearch/security/rest/DashboardsInfoAction.java
index 0fd88e7565..a7620f6bdc 100644
--- a/src/main/java/org/opensearch/security/rest/DashboardsInfoAction.java
+++ b/src/main/java/org/opensearch/security/rest/DashboardsInfoAction.java
@@ -92,9 +92,9 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
public void accept(RestChannel channel) throws Exception {
XContentBuilder builder = channel.newBuilder(); //NOSONAR
BytesRestResponse response = null;
-
+
try {
-
+
final User user = (User)threadContext.getTransient(ConfigConstants.OPENDISTRO_SECURITY_USER);
builder.startObject();
@@ -131,6 +131,6 @@ public void accept(RestChannel channel) throws Exception {
public String getName() {
return "Kibana Info Action";
}
-
-
+
+
}
diff --git a/src/main/java/org/opensearch/security/rest/SecurityHealthAction.java b/src/main/java/org/opensearch/security/rest/SecurityHealthAction.java
index b88d2700c9..17d5ee122f 100644
--- a/src/main/java/org/opensearch/security/rest/SecurityHealthAction.java
+++ b/src/main/java/org/opensearch/security/rest/SecurityHealthAction.java
@@ -67,7 +67,7 @@ public List routes() {
@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
return new RestChannelConsumer() {
-
+
final String mode = request.param("mode","strict");
@Override
@@ -76,8 +76,8 @@ public void accept(RestChannel channel) throws Exception {
RestStatus restStatus = RestStatus.OK;
BytesRestResponse response = null;
try {
-
-
+
+
String status = "UP";
String message = null;
@@ -98,12 +98,12 @@ public void accept(RestChannel channel) throws Exception {
} finally {
builder.close();
}
-
-
+
+
channel.sendResponse(response);
}
-
-
+
+
};
}
diff --git a/src/main/java/org/opensearch/security/rest/SecurityInfoAction.java b/src/main/java/org/opensearch/security/rest/SecurityInfoAction.java
index f8e03da5d2..7867e8790d 100644
--- a/src/main/java/org/opensearch/security/rest/SecurityInfoAction.java
+++ b/src/main/java/org/opensearch/security/rest/SecurityInfoAction.java
@@ -88,12 +88,12 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
public void accept(RestChannel channel) throws Exception {
XContentBuilder builder = channel.newBuilder(); //NOSONAR
BytesRestResponse response = null;
-
+
try {
-
+
final boolean verbose = request.paramAsBoolean("verbose", false);
-
+
final X509Certificate[] certs = threadContext.getTransient(ConfigConstants.OPENDISTRO_SECURITY_SSL_PEER_CERTIFICATES);
final User user = threadContext.getTransient(ConfigConstants.OPENDISTRO_SECURITY_USER);
final TransportAddress remoteAddress = threadContext.getTransient(ConfigConstants.OPENDISTRO_SECURITY_REMOTE_ADDRESS);
@@ -112,7 +112,7 @@ public void accept(RestChannel channel) throws Exception {
builder.field("principal", (String)threadContext.getTransient(ConfigConstants.OPENDISTRO_SECURITY_SSL_PRINCIPAL));
builder.field("peer_certificates", certs != null && certs.length > 0 ? certs.length + "" : "0");
builder.field("sso_logout_url", (String)threadContext.getTransient(ConfigConstants.SSO_LOGOUT_URL));
-
+
if(user != null && verbose) {
try {
builder.field("size_of_user", RamUsageEstimator.humanReadableUnits(Base64Helper.serializeObject(user).length()));
@@ -122,8 +122,8 @@ public void accept(RestChannel channel) throws Exception {
//ignore
}
}
-
-
+
+
builder.endObject();
response = new BytesRestResponse(RestStatus.OK, builder);
@@ -144,7 +144,7 @@ public void accept(RestChannel channel) throws Exception {
}
};
}
-
+
@Override
public String getName() {
return "OpenSearch Security Info Action";
diff --git a/src/main/java/org/opensearch/security/rest/TenantInfoAction.java b/src/main/java/org/opensearch/security/rest/TenantInfoAction.java
index 266d2edf49..f7b2a606c6 100644
--- a/src/main/java/org/opensearch/security/rest/TenantInfoAction.java
+++ b/src/main/java/org/opensearch/security/rest/TenantInfoAction.java
@@ -78,7 +78,7 @@ public class TenantInfoAction extends BaseRestHandler {
private final AdminDNs adminDns;
private final ConfigurationRepository configurationRepository;
- public TenantInfoAction(final Settings settings, final RestController controller,
+ public TenantInfoAction(final Settings settings, final RestController controller,
final PrivilegesEvaluator evaluator, final ThreadPool threadPool, final ClusterService clusterService, final AdminDNs adminDns,
final ConfigurationRepository configurationRepository) {
super();
@@ -102,18 +102,18 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
public void accept(RestChannel channel) throws Exception {
XContentBuilder builder = channel.newBuilder(); //NOSONAR
BytesRestResponse response = null;
-
+
try {
final User user = (User)threadContext.getTransient(ConfigConstants.OPENDISTRO_SECURITY_USER);
-
+
//only allowed for admins or the kibanaserveruser
if(!isAuthorized()) {
response = new BytesRestResponse(RestStatus.FORBIDDEN,"");
} else {
builder.startObject();
-
+
final SortedMap lookup = clusterService.state().metadata().getIndicesLookup();
for(final String indexOrAlias: lookup.keySet()) {
final String tenant = tenantNameForIndex(indexOrAlias);
@@ -123,7 +123,7 @@ public void accept(RestChannel channel) throws Exception {
}
builder.endObject();
-
+
response = new BytesRestResponse(RestStatus.OK, builder);
}
} catch (final Exception e1) {
@@ -179,21 +179,21 @@ private final SecurityDynamicConfiguration> load(final CType config, boolean l
private String tenantNameForIndex(String index) {
String[] indexParts;
- if(index == null
+ if(index == null
|| (indexParts = index.split("_")).length != 3
) {
return null;
}
-
-
+
+
if(!indexParts[0].equals(evaluator.dashboardsIndex())) {
return null;
}
-
+
try {
final int expectedHash = Integer.parseInt(indexParts[1]);
final String sanitizedName = indexParts[2];
-
+
for(String tenant: evaluator.getAllConfiguredTenantNames()) {
if(tenant.hashCode() == expectedHash && sanitizedName.equals(tenant.toLowerCase().replaceAll("[^a-z0-9]+",""))) {
return tenant;
@@ -211,6 +211,6 @@ private String tenantNameForIndex(String index) {
public String getName() {
return "Tenant Info Action";
}
-
-
+
+
}
diff --git a/src/main/java/org/opensearch/security/securityconf/ConfigModelV6.java b/src/main/java/org/opensearch/security/securityconf/ConfigModelV6.java
index 987b8fac64..7a978034f1 100644
--- a/src/main/java/org/opensearch/security/securityconf/ConfigModelV6.java
+++ b/src/main/java/org/opensearch/security/securityconf/ConfigModelV6.java
@@ -83,9 +83,9 @@ public ConfigModelV6(
SecurityDynamicConfiguration rolesmapping,
DynamicConfigModel dcm,
Settings opensearchSettings) {
-
+
this.roles = roles;
-
+
try {
rolesMappingResolution = ConfigConstants.RolesMappingResolution.valueOf(
opensearchSettings.get(ConfigConstants.SECURITY_ROLES_MAPPING_RESOLUTION, ConfigConstants.RolesMappingResolution.MAPPING_ONLY.toString())
@@ -94,13 +94,13 @@ public ConfigModelV6(
log.error("Cannot apply roles mapping resolution", e);
rolesMappingResolution = ConfigConstants.RolesMappingResolution.MAPPING_ONLY;
}
-
+
agr = reloadActionGroups(actiongroups);
securityRoles = reload(roles);
tenantHolder = new TenantHolder(roles);
roleMappingHolder = new RoleMappingHolder(rolesmapping, dcm.getHostsResolverMode());
}
-
+
public Set getAllConfiguredTenantNames() {
final Set configuredTenants = new HashSet<>();
for (Entry securityRole : roles.getCEntries().entrySet()) {
@@ -114,18 +114,18 @@ public Set getAllConfiguredTenantNames() {
return Collections.unmodifiableSet(configuredTenants);
}
-
+
public SecurityRoles getSecurityRoles() {
return securityRoles;
}
-
+
private static interface ActionGroupResolver {
Set resolvedActions(final List actions);
}
-
+
private ActionGroupResolver reloadActionGroups(SecurityDynamicConfiguration actionGroups) {
return new ActionGroupResolver() {
-
+
private Set getGroupMembers(final String groupname) {
if (actionGroups == null) {
@@ -134,27 +134,27 @@ private Set getGroupMembers(final String groupname) {
return Collections.unmodifiableSet(resolve(actionGroups, groupname));
}
-
+
private Set resolve(final SecurityDynamicConfiguration> actionGroups, final String entry) {
-
+
// SG5 format, plain array
//List en = actionGroups.getAsList(DotPath.of(entry));
//if (en.isEmpty()) {
// try SG6 format including readonly and permissions key
// en = actionGroups.getAsList(DotPath.of(entry + "." + ConfigConstants.CONFIGKEY_ACTION_GROUPS_PERMISSIONS));
//}
-
+
if(!actionGroups.getCEntries().containsKey(entry)) {
return Collections.emptySet();
}
-
+
final Set ret = new HashSet();
-
+
final Object actionGroupAsObject = actionGroups.getCEntries().get(entry);
-
+
if(actionGroupAsObject != null && actionGroupAsObject instanceof List) {
-
+
for (final String perm: ((List) actionGroupAsObject)) {
if (actionGroups.getCEntries().keySet().contains(perm)) {
ret.addAll(resolve(actionGroups,perm));
@@ -162,8 +162,8 @@ private Set resolve(final SecurityDynamicConfiguration> actionGroups,
ret.add(perm);
}
}
-
-
+
+
} else if(actionGroupAsObject != null && actionGroupAsObject instanceof ActionGroupsV6) {
for (final String perm: ((ActionGroupsV6) actionGroupAsObject).getPermissions()) {
if (actionGroups.getCEntries().keySet().contains(perm)) {
@@ -175,10 +175,10 @@ private Set resolve(final SecurityDynamicConfiguration> actionGroups,
} else {
throw new RuntimeException("Unable to handle "+actionGroupAsObject);
}
-
+
return Collections.unmodifiableSet(ret);
}
-
+
@Override
public Set resolvedActions(final List actions) {
final Set resolvedActions = new HashSet();
@@ -208,7 +208,7 @@ private SecurityRoles reload(SecurityDynamicConfiguration settings) {
@Override
public SecurityRole call() throws Exception {
SecurityRole _securityRole = new SecurityRole(securityRole.getKey());
-
+
if(securityRole.getValue() == null) {
return null;
}
@@ -261,8 +261,8 @@ public SecurityRole call() throws Exception {
_securityRole.addIndexPattern(_indexPattern);
}
-
-
+
+
return _securityRole;
}
});
@@ -352,7 +352,7 @@ public Set getRoles() {
public Set getRoleNames() {
return getRoles().stream().map(r -> r.getName()).collect(Collectors.toSet());
}
-
+
public SecurityRoles filter(Set keep) {
final SecurityRoles retVal = new SecurityRoles(roles.size());
for (SecurityRole sr : roles) {
@@ -371,7 +371,7 @@ public EvaluatedDlsFlsConfig getDlsFls(User user, boolean dfmEmptyOverwritesAll,
final Map> dlsQueries = new HashMap>();
final Map> flsFields = new HashMap>();
final Map> maskedFieldsMap = new HashMap>();
-
+
for (SecurityRole sr : roles) {
for (IndexPattern ip : sr.getIpatterns()) {
final Set fls = ip.getFls();
@@ -423,7 +423,7 @@ public EvaluatedDlsFlsConfig getDlsFls(User user, boolean dfmEmptyOverwritesAll,
}
}
}
-
+
if (maskedFields != null && maskedFields.size() > 0) {
if (maskedFieldsMap.containsKey(indexPattern)) {
@@ -444,7 +444,7 @@ public EvaluatedDlsFlsConfig getDlsFls(User user, boolean dfmEmptyOverwritesAll,
}
}
}
-
+
return new EvaluatedDlsFlsConfig(dlsQueries, flsFields, maskedFieldsMap);
}
@@ -1010,10 +1010,10 @@ private static boolean impliesTypePerm(Set ipatterns, Resolved res
);
}
-
-
+
+
//#######
-
+
private class TenantHolder {
private SetMultimap> tenantsMM = null;
@@ -1024,7 +1024,7 @@ public TenantHolder(SecurityDynamicConfiguration roles) {
final ExecutorService execs = Executors.newFixedThreadPool(10);
for(Entry securityRole: roles.getCEntries().entrySet()) {
-
+
if(securityRole.getValue() == null) {
continue;
}
@@ -1036,7 +1036,7 @@ public Tuple>> call() throws Exception {
final Map tenants = securityRole.getValue().getTenants();
if (tenants != null) {
-
+
for (String tenant : tenants.keySet()) {
if ("RW".equalsIgnoreCase(tenants.get(tenant))) {
@@ -1125,7 +1125,7 @@ private class RoleMappingHolder {
private RoleMappingHolder(final SecurityDynamicConfiguration rolesMapping, final String hostResolverMode) {
this.hostResolverMode = hostResolverMode;
-
+
if (rolesMapping != null) {
users = ArrayListMultimap.create();
@@ -1228,10 +1228,10 @@ private Set map(final User user, final TransportAddress caller) {
}
}
-
-
-
-
+
+
+
+
public Map mapTenants(User user, Set roles) {
return tenantHolder.mapTenants(user, roles);
diff --git a/src/main/java/org/opensearch/security/securityconf/ConfigModelV7.java b/src/main/java/org/opensearch/security/securityconf/ConfigModelV7.java
index 1e2adee1db..560cfb8a6d 100644
--- a/src/main/java/org/opensearch/security/securityconf/ConfigModelV7.java
+++ b/src/main/java/org/opensearch/security/securityconf/ConfigModelV7.java
@@ -92,7 +92,7 @@ public ConfigModelV7(
this.roles = roles;
this.tenants = tenants;
-
+
try {
rolesMappingResolution = ConfigConstants.RolesMappingResolution.valueOf(
opensearchSettings.get(ConfigConstants.SECURITY_ROLES_MAPPING_RESOLUTION, ConfigConstants.RolesMappingResolution.MAPPING_ONLY.toString())
@@ -111,18 +111,18 @@ public ConfigModelV7(
public Set getAllConfiguredTenantNames() {
return Collections.unmodifiableSet(tenants.getCEntries().keySet());
}
-
+
public SecurityRoles getSecurityRoles() {
return securityRoles;
}
-
+
private static interface ActionGroupResolver {
Set resolvedActions(final List actions);
}
private ActionGroupResolver reloadActionGroups(SecurityDynamicConfiguration actionGroups) {
return new ActionGroupResolver() {
-
+
private Set getGroupMembers(final String groupname) {
if (actionGroups == null) {
@@ -131,27 +131,27 @@ private Set getGroupMembers(final String groupname) {
return Collections.unmodifiableSet(resolve(actionGroups, groupname));
}
-
+
private Set resolve(final SecurityDynamicConfiguration> actionGroups, final String entry) {
-
+
// SG5 format, plain array
//List en = actionGroups.getAsList(DotPath.of(entry));
//if (en.isEmpty()) {
// try SG6 format including readonly and permissions key
// en = actionGroups.getAsList(DotPath.of(entry + "." + ConfigConstants.CONFIGKEY_ACTION_GROUPS_PERMISSIONS));
//}
-
+
if(!actionGroups.getCEntries().containsKey(entry)) {
return Collections.emptySet();
}
-
+
final Set ret = new HashSet();
-
+
final Object actionGroupAsObject = actionGroups.getCEntries().get(entry);
-
+
if(actionGroupAsObject != null && actionGroupAsObject instanceof List) {
-
+
for (final String perm: ((List) actionGroupAsObject)) {
if (actionGroups.getCEntries().keySet().contains(perm)) {
ret.addAll(resolve(actionGroups,perm));
@@ -159,8 +159,8 @@ private Set resolve(final SecurityDynamicConfiguration> actionGroups,
ret.add(perm);
}
}
-
-
+
+
} else if(actionGroupAsObject != null && actionGroupAsObject instanceof ActionGroupsV7) {
for (final String perm: ((ActionGroupsV7) actionGroupAsObject).getAllowed_actions()) {
if (actionGroups.getCEntries().keySet().contains(perm)) {
@@ -172,10 +172,10 @@ private Set resolve(final SecurityDynamicConfiguration> actionGroups,
} else {
throw new RuntimeException("Unable to handle "+actionGroupAsObject);
}
-
+
return Collections.unmodifiableSet(ret);
}
-
+
@Override
public Set resolvedActions(final List actions) {
final Set resolvedActions = new HashSet();
@@ -205,7 +205,7 @@ private SecurityRoles reload(SecurityDynamicConfiguration settings) {
@Override
public SecurityRole call() throws Exception {
SecurityRole.Builder _securityRole = new SecurityRole.Builder(securityRole.getKey());
-
+
if(securityRole.getValue() == null) {
return null;
}
@@ -238,21 +238,21 @@ public SecurityRole call() throws Exception {
_indexPattern.addFlsFields(fls);
_indexPattern.addMaskedFields(maskedFields);
_indexPattern.addPerm(agr.resolvedActions(permittedAliasesIndex.getAllowed_actions()));
-
+
/*for(Entry> type: permittedAliasesIndex.getValue().getTypes(-).entrySet()) {
TypePerm typePerm = new TypePerm(type.getKey());
final List perms = type.getValue();
typePerm.addPerms(agr.resolvedActions(perms));
_indexPattern.addTypePerms(typePerm);
}*/
-
+
_securityRole.addIndexPattern(_indexPattern);
-
+
}
}
-
-
+
+
return _securityRole.build();
}
});
@@ -339,7 +339,7 @@ public String toString() {
public Set getRoles() {
return Collections.unmodifiableSet(roles);
}
-
+
public Set getRoleNames() {
return getRoles().stream().map(r -> r.getName()).collect(Collectors.toSet());
}
@@ -367,8 +367,8 @@ public EvaluatedDlsFlsConfig getDlsFls(User user, boolean dfmEmptyOverwritesAll,
return EvaluatedDlsFlsConfig.EMPTY;
}
-
- Map> dlsQueriesByIndex = new HashMap>();
+
+ Map> dlsQueriesByIndex = new HashMap>();
Map> flsFields = new HashMap>();
Map> maskedFieldsMap = new HashMap>();
@@ -379,7 +379,7 @@ public EvaluatedDlsFlsConfig getDlsFls(User user, boolean dfmEmptyOverwritesAll,
Set noDlsConcreteIndices = new HashSet<>();
Set noFlsConcreteIndices = new HashSet<>();
Set noMaskedFieldConcreteIndices = new HashSet<>();
-
+
for (SecurityRole role : roles) {
for (IndexPattern ip : role.getIpatterns()) {
final Set concreteIndices = ip.concreteIndexNames(user, resolver, cs);
@@ -409,12 +409,12 @@ public EvaluatedDlsFlsConfig getDlsFls(User user, boolean dfmEmptyOverwritesAll,
} else if (dfmEmptyOverwritesAll) {
noFlsConcreteIndices.addAll(concreteIndices);
}
-
+
Set maskedFields = ip.getMaskedFields();
if (maskedFields != null && maskedFields.size() > 0) {
- for (String concreteIndex : concreteIndices) {
+ for (String concreteIndex : concreteIndices) {
if (maskedFieldsMap.containsKey(concreteIndex)) {
maskedFieldsMap.get(concreteIndex).addAll(Sets.newHashSet(maskedFields));
} else {
@@ -498,7 +498,7 @@ public boolean impliesTypePermGlobal(Resolved resolved, User user, String[] acti
roles.stream().forEach(p -> ipatterns.addAll(p.getIpatterns()));
return ConfigModelV7.impliesTypePerm(ipatterns, resolved, user, actions, resolver, cs);
}
-
+
private boolean containsDlsFlsConfig() {
for (SecurityRole role : roles) {
for (IndexPattern ip : role.getIpatterns()) {
@@ -562,7 +562,7 @@ private Set getAllResolvedPermittedIndices(Resolved resolved, User user,
for (IndexPattern p : ipatterns) {
//what if we cannot resolve one (for create purposes)
final boolean patternMatch = p.getPerms().matchAll(actions);
-
+
// final Set tperms = p.getTypePerms();
// for (TypePerm tp : tperms) {
// if (WildcardMatcher.matchAny(tp.typePattern, resolved.getTypes(-).toArray(new String[0]))) {
@@ -810,7 +810,7 @@ public String getDlsQuery(User user) {
public boolean hasDlsQuery() {
return dlsQuery != null && !dlsQuery.isEmpty();
}
-
+
public Set getFls() {
return Collections.unmodifiableSet(fls);
}
@@ -818,7 +818,7 @@ public Set getFls() {
public boolean hasFlsFields() {
return fls != null && !fls.isEmpty();
}
-
+
public Set getMaskedFields() {
return Collections.unmodifiableSet(maskedFields);
}
@@ -826,12 +826,12 @@ public Set getMaskedFields() {
public boolean hasMaskedFields() {
return maskedFields != null && !maskedFields.isEmpty();
}
-
+
public WildcardMatcher getPerms() {
return WildcardMatcher.from(perms);
}
-
+
}
/*public static class TypePerm {
@@ -1033,7 +1033,7 @@ private static boolean impliesTypePerm(Set ipatterns, Resolved res
)
);
}
-
+
private class TenantHolder {
private SetMultimap> tenantsMM = null;
@@ -1055,7 +1055,7 @@ public Tuple>> call() throws Exception {
final Set> tuples = new HashSet<>();
final List tenants = securityRole.getValue().getTenant_permissions();
if (tenants != null) {
-
+
for (RoleV7.Tenant tenant : tenants) {
// find Wildcarded tenant patterns
@@ -1166,7 +1166,7 @@ private class RoleMappingHolder {
private RoleMappingHolder(final SecurityDynamicConfiguration rolemappings, final String hostResolverMode) {
this.hostResolverMode = hostResolverMode;
-
+
if (roles != null) {
users = ArrayListMultimap.create();
@@ -1267,10 +1267,10 @@ private Set map(final User user, final TransportAddress caller) {
}
}
-
-
-
-
+
+
+
+
public Map mapTenants(User user, Set roles) {
return tenantHolder.mapTenants(user, roles);
diff --git a/src/main/java/org/opensearch/security/securityconf/DynamicConfigFactory.java b/src/main/java/org/opensearch/security/securityconf/DynamicConfigFactory.java
index 262eb37cf8..9d8c36576c 100644
--- a/src/main/java/org/opensearch/security/securityconf/DynamicConfigFactory.java
+++ b/src/main/java/org/opensearch/security/securityconf/DynamicConfigFactory.java
@@ -117,7 +117,7 @@ public final static SecurityDynamicConfiguration> addStatics(SecurityDynamicCo
return original;
}
-
+
protected final Logger log = LogManager.getLogger(this.getClass());
private final ConfigurationRepository cr;
private final AtomicBoolean initialized = new AtomicBoolean();
@@ -127,7 +127,7 @@ public final static SecurityDynamicConfiguration> addStatics(SecurityDynamicCo
private final InternalAuthenticationBackend iab = new InternalAuthenticationBackend();
SecurityDynamicConfiguration> config;
-
+
public DynamicConfigFactory(ConfigurationRepository cr, final Settings opensearchSettings,
final Path configPath, Client client, ThreadPool threadPool, ClusterInfoHolder cih) {
super();
@@ -144,11 +144,11 @@ public DynamicConfigFactory(ConfigurationRepository cr, final Settings opensearc
} else {
log.info("Static resources will not be loaded.");
}
-
+
registerDCFListener(this.iab);
this.cr.subscribeOnChange(this);
}
-
+
@Override
public void onChange(Map> typeToConfig) {
@@ -187,7 +187,7 @@ public void onChange(Map> typeToConfig) {
if(config.getImplementingClass() == ConfigV7.class) {
//statics
-
+
if(roles.containsAny(staticRoles)) {
throw new StaticResourceException("Cannot override static roles");
}
@@ -205,24 +205,24 @@ public void onChange(Map> typeToConfig) {
if(!actionGroups.add(staticActionGroups) && !staticActionGroups.getCEntries().isEmpty()) {
throw new StaticResourceException("Unable to load static action groups");
}
-
+
log.debug("Static action groups loaded ({})", staticActionGroups.getCEntries().size());
-
+
if(tenants.containsAny(staticTenants)) {
throw new StaticResourceException("Cannot override static tenants");
}
if(!tenants.add(staticTenants) && !staticTenants.getCEntries().isEmpty()) {
throw new StaticResourceException("Unable to load static tenants");
}
-
+
log.debug("Static tenants loaded ({})", staticTenants.getCEntries().size());
log.debug("Static configuration loaded (total roles: {}/total action groups: {}/total tenants: {})",
roles.getCEntries().size(), actionGroups.getCEntries().size(), tenants.getCEntries().size());
-
+
//rebuild v7 Models
dcm = new DynamicConfigModelV7(getConfigV7(config), opensearchSettings, configPath, iab);
@@ -252,26 +252,26 @@ public void onChange(Map> typeToConfig) {
}
initialized.set(true);
-
+
}
-
+
private static ConfigV6 getConfigV6(SecurityDynamicConfiguration> sdc) {
@SuppressWarnings("unchecked")
SecurityDynamicConfiguration c = (SecurityDynamicConfiguration) sdc;
return c.getCEntry("opendistro_security");
}
-
+
private static ConfigV7 getConfigV7(SecurityDynamicConfiguration> sdc) {
@SuppressWarnings("unchecked")
SecurityDynamicConfiguration c = (SecurityDynamicConfiguration) sdc;
return c.getCEntry("config");
}
-
+
@Override
public final boolean isInitialized() {
return initialized.get();
}
-
+
public void registerDCFListener(Object listener) {
eventBus.register(listener);
}
@@ -279,15 +279,15 @@ public void registerDCFListener(Object listener) {
public void unregisterDCFListener(Object listener) {
eventBus.unregister(listener);
}
-
+
private static class InternalUsersModelV7 extends InternalUsersModel {
-
+
private final SecurityDynamicConfiguration internalUserV7SecurityDynamicConfiguration;
private final SecurityDynamicConfiguration rolesV7SecurityDynamicConfiguration;
private final SecurityDynamicConfiguration rolesMappingsV7SecurityDynamicConfiguration;
-
+
public InternalUsersModelV7(SecurityDynamicConfiguration internalUserV7SecurityDynamicConfiguration,
SecurityDynamicConfiguration rolesV7SecurityDynamicConfiguration,
SecurityDynamicConfiguration rolesMappingsV7SecurityDynamicConfiguration) {
@@ -325,7 +325,7 @@ public String getHash(String user) {
InternalUserV7 tmp = internalUserV7SecurityDynamicConfiguration.getCEntry(user);
return tmp==null?null:tmp.getHash();
}
-
+
public List getSecurityRoles(String user) {
InternalUserV7 tmp = internalUserV7SecurityDynamicConfiguration.getCEntry(user);
@@ -341,11 +341,11 @@ private boolean isRolesMappingHidden(String rolename) {
return roleMapping!=null && roleMapping.isHidden();
}
}
-
+
private static class InternalUsersModelV6 extends InternalUsersModel {
-
+
SecurityDynamicConfiguration configuration;
-
+
public InternalUsersModelV6(SecurityDynamicConfiguration configuration) {
super();
@@ -379,7 +379,7 @@ public String getHash(String user) {
InternalUserV6 tmp = configuration.getCEntry(user);
return tmp==null?null:tmp.getHash();
}
-
+
public List getSecurityRoles(String user) {
return Collections.emptyList();
}
diff --git a/src/main/java/org/opensearch/security/securityconf/DynamicConfigModel.java b/src/main/java/org/opensearch/security/securityconf/DynamicConfigModel.java
index f91e768283..22121bca7f 100644
--- a/src/main/java/org/opensearch/security/securityconf/DynamicConfigModel.java
+++ b/src/main/java/org/opensearch/security/securityconf/DynamicConfigModel.java
@@ -53,7 +53,7 @@
import org.opensearch.security.http.proxy.HTTPExtendedProxyAuthenticator;
public abstract class DynamicConfigModel {
-
+
protected final Logger log = LogManager.getLogger(this.getClass());
public abstract SortedSet getRestAuthDomains();
public abstract Set getRestAuthorizers();
@@ -75,17 +75,17 @@ public abstract class DynamicConfigModel {
public abstract String getFilteredAliasMode();
public abstract String getHostsResolverMode();
public abstract boolean isDnfofForEmptyResultsEnabled();
-
+
public abstract List getIpAuthFailureListeners();
public abstract Multimap getAuthBackendFailureListeners();
public abstract List> getIpClientBlockRegistries();
public abstract Multimap> getAuthBackendClientBlockRegistries();
-
+
protected final Map authImplMap = new HashMap<>();
public DynamicConfigModel() {
super();
-
+
authImplMap.put("intern_c", InternalAuthenticationBackend.class.getName());
authImplMap.put("intern_z", NoOpAuthorizationBackend.class.getName());
@@ -97,7 +97,7 @@ public DynamicConfigModel() {
authImplMap.put("ldap_c", "com.amazon.dlic.auth.ldap.backend.LDAPAuthenticationBackend");
authImplMap.put("ldap_z", "com.amazon.dlic.auth.ldap.backend.LDAPAuthorizationBackend");
-
+
authImplMap.put("ldap2_c", "com.amazon.dlic.auth.ldap2.LDAPAuthenticationBackend2");
authImplMap.put("ldap2_z", "com.amazon.dlic.auth.ldap2.LDAPAuthorizationBackend2");
@@ -109,11 +109,11 @@ public DynamicConfigModel() {
authImplMap.put("jwt_h", "com.amazon.dlic.auth.http.jwt.HTTPJwtAuthenticator");
authImplMap.put("openid_h", "com.amazon.dlic.auth.http.jwt.keybyoidc.HTTPJwtKeyByOpenIdConnectAuthenticator");
authImplMap.put("saml_h", "com.amazon.dlic.auth.http.saml.HTTPSamlAuthenticator");
-
+
authImplMap.put("ip_authFailureListener", AddressBasedRateLimiter.class.getName());
authImplMap.put("username_authFailureListener", UserNameBasedRateLimiter.class.getName());
}
-
-
-
+
+
+
}
diff --git a/src/main/java/org/opensearch/security/securityconf/DynamicConfigModelV6.java b/src/main/java/org/opensearch/security/securityconf/DynamicConfigModelV6.java
index 40b3e3319a..2dce89ba7c 100644
--- a/src/main/java/org/opensearch/security/securityconf/DynamicConfigModelV6.java
+++ b/src/main/java/org/opensearch/security/securityconf/DynamicConfigModelV6.java
@@ -62,7 +62,7 @@
import org.opensearch.security.support.ReflectionHelper;
public class DynamicConfigModelV6 extends DynamicConfigModel {
-
+
private final ConfigV6 config;
private final Settings opensearchSettings;
private final Path configPath;
@@ -72,12 +72,12 @@ public class DynamicConfigModelV6 extends DynamicConfigModel {
private Set transportAuthorizers;
private List destroyableComponents;
private final InternalAuthenticationBackend iab;
-
+
private List ipAuthFailureListeners;
private Multimap authBackendFailureListeners;
private List> ipClientBlockRegistries;
private Multimap> authBackendClientBlockRegistries;
-
+
public DynamicConfigModelV6(ConfigV6 config, Settings opensearchSettings, Path configPath, InternalAuthenticationBackend iab) {
super();
this.config = config;
@@ -158,7 +158,7 @@ public boolean isMultiRolespanEnabled() {
public String getFilteredAliasMode() {
return config.dynamic.filtered_alias_mode;
}
-
+
@Override
public boolean isDnfofForEmptyResultsEnabled() {
return config.dynamic.do_not_fail_on_forbidden_empty;
@@ -168,29 +168,29 @@ public boolean isDnfofForEmptyResultsEnabled() {
public String getHostsResolverMode() {
return config.dynamic.hosts_resolver_mode;
}
-
+
@Override
public List getIpAuthFailureListeners() {
return Collections.unmodifiableList(ipAuthFailureListeners);
}
-
+
@Override
public Multimap getAuthBackendFailureListeners() {
return Multimaps.unmodifiableMultimap(authBackendFailureListeners);
}
-
+
@Override
public List> getIpClientBlockRegistries() {
return Collections.unmodifiableList(ipClientBlockRegistries);
}
-
+
@Override
public Multimap> getAuthBackendClientBlockRegistries() {
return Multimaps.unmodifiableMultimap(authBackendClientBlockRegistries);
}
-
+
private void buildAAA() {
-
+
final SortedSet restAuthDomains0 = new TreeSet<>();
final Set restAuthorizers0 = new HashSet<>();
final SortedSet transportAuthDomains0 = new TreeSet<>();
@@ -214,7 +214,7 @@ private void buildAAA() {
final String authzBackendClazz = ad.getValue().authorization_backend.type;
final AuthorizationBackend authorizationBackend;
-
+
if(authzBackendClazz.equals(InternalAuthenticationBackend.class.getName()) //NOSONAR
|| authzBackendClazz.equals("internal")
|| authzBackendClazz.equals("intern")) {
@@ -229,7 +229,7 @@ private void buildAAA() {
.put(Settings.builder().loadFromSource(ad.getValue().authorization_backend.configAsJson(), XContentType.JSON).build()).build()
, configPath);
}
-
+
if (httpEnabled) {
restAuthorizers0.add(authorizationBackend);
}
@@ -237,7 +237,7 @@ private void buildAAA() {
if (transportEnabled) {
transportAuthorizers0.add(authorizationBackend);
}
-
+
if (authorizationBackend instanceof Destroyable) {
destroyableComponents0.add((Destroyable) authorizationBackend);
}
@@ -276,7 +276,7 @@ private void buildAAA() {
String httpAuthenticatorType = ad.getValue().http_authenticator.type; //no default
HTTPAuthenticator httpAuthenticator = httpAuthenticatorType==null?null: (HTTPAuthenticator) newInstance(httpAuthenticatorType,"h",
Settings.builder().put(opensearchSettings)
- //.putProperties(ads.getAsStringMap(DotPath.of("http_authenticator.config")), DynamicConfiguration.checkKeyFunction()).build(),
+ //.putProperties(ads.getAsStringMap(DotPath.of("http_authenticator.config")), DynamicConfiguration.checkKeyFunction()).build(),
.put(Settings.builder().loadFromSource(ad.getValue().http_authenticator.configAsJson(), XContentType.JSON).build()).build()
, configPath);
@@ -291,15 +291,15 @@ private void buildAAA() {
if (transportEnabled) {
transportAuthDomains0.add(_ad);
}
-
+
if (httpAuthenticator instanceof Destroyable) {
destroyableComponents0.add((Destroyable) httpAuthenticator);
}
-
+
if (authenticationBackend instanceof Destroyable) {
destroyableComponents0.add((Destroyable) authenticationBackend);
}
-
+
} catch (final Exception e) {
log.error("Unable to initialize auth domain {} due to {}", ad, e.toString(), e);
}
@@ -308,30 +308,30 @@ private void buildAAA() {
}
List originalDestroyableComponents = destroyableComponents;
-
+
restAuthDomains = Collections.unmodifiableSortedSet(restAuthDomains0);
transportAuthDomains = Collections.unmodifiableSortedSet(transportAuthDomains0);
restAuthorizers = Collections.unmodifiableSet(restAuthorizers0);
transportAuthorizers = Collections.unmodifiableSet(transportAuthorizers0);
-
+
destroyableComponents = Collections.unmodifiableList(destroyableComponents0);
-
+
if(originalDestroyableComponents != null) {
destroyDestroyables(originalDestroyableComponents);
}
-
+
originalDestroyableComponents = null;
-
+
createAuthFailureListeners(ipAuthFailureListeners0,
authBackendFailureListeners0, ipClientBlockRegistries0, authBackendClientBlockRegistries0, destroyableComponents0);
-
+
ipAuthFailureListeners = Collections.unmodifiableList(ipAuthFailureListeners0);
ipClientBlockRegistries = Collections.unmodifiableList(ipClientBlockRegistries0);
authBackendClientBlockRegistries = Multimaps.unmodifiableMultimap(authBackendClientBlockRegistries0);
authBackendFailureListeners = Multimaps.unmodifiableMultimap(authBackendFailureListeners0);
}
-
+
private void destroyDestroyables(List destroyableComponents) {
for (Destroyable destroyable : destroyableComponents) {
try {
@@ -341,7 +341,7 @@ private void destroyDestroyables(List destroyableComponents) {
}
}
}
-
+
private T newInstance(final String clazzOrShortcut, String type, final Settings settings, final Path configPath) {
String clazz = clazzOrShortcut;
@@ -352,7 +352,7 @@ private T newInstance(final String clazzOrShortcut, String type, final Setti
return ReflectionHelper.instantiateAAA(clazz, settings, configPath);
}
-
+
private String translateShortcutToClassName(final String clazzOrShortcut, final String type) {
if (authImplMap.containsKey(clazzOrShortcut + "_" + type)) {
@@ -361,17 +361,17 @@ private String translateShortcutToClassName(final String clazzOrShortcut, final
return clazzOrShortcut;
}
}
-
+
private void createAuthFailureListeners(List ipAuthFailureListeners,
Multimap authBackendFailureListeners, List> ipClientBlockRegistries,
Multimap> authBackendUserClientBlockRegistries, List destroyableComponents0) {
for (Entry entry : config.dynamic.auth_failure_listeners.getListeners().entrySet()) {
-
+
Settings entrySettings = Settings.builder()
.put(opensearchSettings)
.put(Settings.builder().loadFromSource(entry.getValue().asJson(), XContentType.JSON).build()).build();
-
+
String type = entry.getValue().type;
String authenticationBackend = entry.getValue().authentication_backend;
diff --git a/src/main/java/org/opensearch/security/securityconf/DynamicConfigModelV7.java b/src/main/java/org/opensearch/security/securityconf/DynamicConfigModelV7.java
index 6db5fba0a7..8e92675dcc 100644
--- a/src/main/java/org/opensearch/security/securityconf/DynamicConfigModelV7.java
+++ b/src/main/java/org/opensearch/security/securityconf/DynamicConfigModelV7.java
@@ -62,7 +62,7 @@
import org.opensearch.security.support.ReflectionHelper;
public class DynamicConfigModelV7 extends DynamicConfigModel {
-
+
private final ConfigV7 config;
private final Settings opensearchSettings;
private final Path configPath;
@@ -77,7 +77,7 @@ public class DynamicConfigModelV7 extends DynamicConfigModel {
private Multimap authBackendFailureListeners;
private List> ipClientBlockRegistries;
private Multimap> authBackendClientBlockRegistries;
-
+
public DynamicConfigModelV7(ConfigV7 config, Settings opensearchSettings, Path configPath, InternalAuthenticationBackend iab) {
super();
this.config = config;
@@ -163,35 +163,35 @@ public String getFilteredAliasMode() {
public String getHostsResolverMode() {
return config.dynamic.hosts_resolver_mode;
}
-
+
@Override
public boolean isDnfofForEmptyResultsEnabled() {
return config.dynamic.do_not_fail_on_forbidden_empty;
}
-
+
@Override
public List getIpAuthFailureListeners() {
return Collections.unmodifiableList(ipAuthFailureListeners);
}
-
+
@Override
public Multimap getAuthBackendFailureListeners() {
return Multimaps.unmodifiableMultimap(authBackendFailureListeners);
}
-
+
@Override
public List> getIpClientBlockRegistries() {
return Collections.unmodifiableList(ipClientBlockRegistries);
}
-
+
@Override
public Multimap> getAuthBackendClientBlockRegistries() {
return Multimaps.unmodifiableMultimap(authBackendClientBlockRegistries);
}
-
-
+
+
private void buildAAA() {
-
+
final SortedSet restAuthDomains0 = new TreeSet<>();
final Set restAuthorizers0 = new HashSet<>();
final SortedSet transportAuthDomains0 = new TreeSet<>();
@@ -214,7 +214,7 @@ private void buildAAA() {
final String authzBackendClazz = ad.getValue().authorization_backend.type;
final AuthorizationBackend authorizationBackend;
-
+
if(authzBackendClazz.equals(InternalAuthenticationBackend.class.getName()) //NOSONAR
|| authzBackendClazz.equals("internal")
|| authzBackendClazz.equals("intern")) {
@@ -229,7 +229,7 @@ private void buildAAA() {
.put(Settings.builder().loadFromSource(ad.getValue().authorization_backend.configAsJson(), XContentType.JSON).build()).build()
, configPath);
}
-
+
if (httpEnabled) {
restAuthorizers0.add(authorizationBackend);
}
@@ -237,7 +237,7 @@ private void buildAAA() {
if (transportEnabled) {
transportAuthorizers0.add(authorizationBackend);
}
-
+
if (authorizationBackend instanceof Destroyable) {
destroyableComponents0.add((Destroyable) authorizationBackend);
}
@@ -275,7 +275,7 @@ private void buildAAA() {
String httpAuthenticatorType = ad.getValue().http_authenticator.type; //no default
HTTPAuthenticator httpAuthenticator = httpAuthenticatorType==null?null: (HTTPAuthenticator) newInstance(httpAuthenticatorType,"h",
Settings.builder().put(opensearchSettings)
- //.putProperties(ads.getAsStringMap(DotPath.of("http_authenticator.config")), DynamicConfiguration.checkKeyFunction()).build(),
+ //.putProperties(ads.getAsStringMap(DotPath.of("http_authenticator.config")), DynamicConfiguration.checkKeyFunction()).build(),
.put(Settings.builder().loadFromSource(ad.getValue().http_authenticator.configAsJson(), XContentType.JSON).build()).build()
, configPath);
@@ -290,15 +290,15 @@ private void buildAAA() {
if (transportEnabled) {
transportAuthDomains0.add(_ad);
}
-
+
if (httpAuthenticator instanceof Destroyable) {
destroyableComponents0.add((Destroyable) httpAuthenticator);
}
-
+
if (authenticationBackend instanceof Destroyable) {
destroyableComponents0.add((Destroyable) authenticationBackend);
}
-
+
} catch (final Exception e) {
log.error("Unable to initialize auth domain {} due to {}", ad, e.toString(), e);
}
@@ -307,23 +307,23 @@ private void buildAAA() {
}
List originalDestroyableComponents = destroyableComponents;
-
+
restAuthDomains = Collections.unmodifiableSortedSet(restAuthDomains0);
transportAuthDomains = Collections.unmodifiableSortedSet(transportAuthDomains0);
restAuthorizers = Collections.unmodifiableSet(restAuthorizers0);
transportAuthorizers = Collections.unmodifiableSet(transportAuthorizers0);
-
+
destroyableComponents = Collections.unmodifiableList(destroyableComponents0);
-
+
if(originalDestroyableComponents != null) {
destroyDestroyables(originalDestroyableComponents);
}
-
+
originalDestroyableComponents = null;
createAuthFailureListeners(ipAuthFailureListeners0,
authBackendFailureListeners0, ipClientBlockRegistries0, authBackendClientBlockRegistries0, destroyableComponents0);
-
+
ipAuthFailureListeners = Collections.unmodifiableList(ipAuthFailureListeners0);
ipClientBlockRegistries = Collections.unmodifiableList(ipClientBlockRegistries0);
authBackendClientBlockRegistries = Multimaps.unmodifiableMultimap(authBackendClientBlockRegistries0);
@@ -340,7 +340,7 @@ private void destroyDestroyables(List destroyableComponents) {
}
}
}
-
+
private T newInstance(final String clazzOrShortcut, String type, final Settings settings, final Path configPath) {
String clazz = clazzOrShortcut;
@@ -351,7 +351,7 @@ private T newInstance(final String clazzOrShortcut, String type, final Setti
return ReflectionHelper.instantiateAAA(clazz, settings, configPath);
}
-
+
private String translateShortcutToClassName(final String clazzOrShortcut, final String type) {
if (authImplMap.containsKey(clazzOrShortcut + "_" + type)) {
@@ -360,17 +360,17 @@ private String translateShortcutToClassName(final String clazzOrShortcut, final
return clazzOrShortcut;
}
}
-
+
private void createAuthFailureListeners(List ipAuthFailureListeners,
Multimap authBackendFailureListeners, List> ipClientBlockRegistries,
Multimap> authBackendUserClientBlockRegistries, List destroyableComponents0) {
for (Entry entry : config.dynamic.auth_failure_listeners.getListeners().entrySet()) {
-
+
Settings entrySettings = Settings.builder()
.put(opensearchSettings)
.put(Settings.builder().loadFromSource(entry.getValue().asJson(), XContentType.JSON).build()).build();
-
+
String type = entry.getValue().type;
String authenticationBackend = entry.getValue().authentication_backend;
diff --git a/src/main/java/org/opensearch/security/securityconf/EvaluatedDlsFlsConfig.java b/src/main/java/org/opensearch/security/securityconf/EvaluatedDlsFlsConfig.java
index 9100e7dd02..8870cb3aad 100644
--- a/src/main/java/org/opensearch/security/securityconf/EvaluatedDlsFlsConfig.java
+++ b/src/main/java/org/opensearch/security/securityconf/EvaluatedDlsFlsConfig.java
@@ -87,7 +87,7 @@ public EvaluatedDlsFlsConfig filter(Resolved indices) {
return this;
} else {
Set allIndices = indices.getAllIndices();
-
+
return new EvaluatedDlsFlsConfig(filter(dlsQueriesByIndex, allIndices), filter(flsByIndex, allIndices),
filter(fieldMaskingByIndex, allIndices));
}
@@ -108,7 +108,7 @@ private Map> filter(Map> map, Set> result = new HashMap<>(map.size());
- for (Map.Entry> entry : map.entrySet()) {
+ for (Map.Entry> entry : map.entrySet()) {
if (WildcardMatcher.from(entry.getKey(), false).matchAny(allIndices)) {
result.put(entry.getKey(), entry.getValue());
}
diff --git a/src/main/java/org/opensearch/security/securityconf/Hideable.java b/src/main/java/org/opensearch/security/securityconf/Hideable.java
index 9b1df8f157..8744575d64 100644
--- a/src/main/java/org/opensearch/security/securityconf/Hideable.java
+++ b/src/main/java/org/opensearch/security/securityconf/Hideable.java
@@ -28,7 +28,7 @@
package org.opensearch.security.securityconf;
public interface Hideable {
-
+
boolean isHidden();
boolean isReserved();
diff --git a/src/main/java/org/opensearch/security/securityconf/Initializable.java b/src/main/java/org/opensearch/security/securityconf/Initializable.java
index fafc717866..ab1a1ebd4a 100644
--- a/src/main/java/org/opensearch/security/securityconf/Initializable.java
+++ b/src/main/java/org/opensearch/security/securityconf/Initializable.java
@@ -28,7 +28,7 @@
package org.opensearch.security.securityconf;
public interface Initializable {
-
+
boolean isInitialized();
}
diff --git a/src/main/java/org/opensearch/security/securityconf/InternalUsersModel.java b/src/main/java/org/opensearch/security/securityconf/InternalUsersModel.java
index 3ff1554a94..41c3116874 100644
--- a/src/main/java/org/opensearch/security/securityconf/InternalUsersModel.java
+++ b/src/main/java/org/opensearch/security/securityconf/InternalUsersModel.java
@@ -31,7 +31,7 @@
import java.util.Map;
public abstract class InternalUsersModel {
-
+
public abstract boolean exists(String user);
public abstract List getBackenRoles(String user);
public abstract Map getAttributes(String user);
diff --git a/src/main/java/org/opensearch/security/securityconf/Migration.java b/src/main/java/org/opensearch/security/securityconf/Migration.java
index 3cb111f11c..ec6a5525b9 100644
--- a/src/main/java/org/opensearch/security/securityconf/Migration.java
+++ b/src/main/java/org/opensearch/security/securityconf/Migration.java
@@ -55,15 +55,15 @@
public class Migration {
-
+
public static Tuple,SecurityDynamicConfiguration> migrateRoles(SecurityDynamicConfiguration r6cs, SecurityDynamicConfiguration rms6) throws MigrationException {
-
+
final SecurityDynamicConfiguration r7 = SecurityDynamicConfiguration.empty();
r7.setCType(r6cs.getCType());
r7.set_meta(new Meta());
r7.get_meta().setConfig_version(2);
r7.get_meta().setType("roles");
-
+
final SecurityDynamicConfiguration t7 = SecurityDynamicConfiguration.empty();
t7.setCType(CType.TENANTS);
t7.set_meta(new Meta());
@@ -71,11 +71,11 @@ public static Tuple,SecurityDynamicConfigur
t7.get_meta().setType("tenants");
Set dedupTenants = new HashSet<>();
-
+
for(final Entry r6e: r6cs.getCEntries().entrySet()) {
final String roleName = r6e.getKey();
final RoleV6 r6 = r6e.getValue();
-
+
if(r6 == null) {
RoleV7 noPermRole = new RoleV7();
noPermRole.setDescription("Migrated from v6, was empty");
@@ -84,52 +84,52 @@ public static Tuple,SecurityDynamicConfigur
}
r7.putCEntry(roleName, new RoleV7(r6));
-
+
for(Entry tenant: r6.getTenants().entrySet()) {
dedupTenants.add(tenant.getKey());
}
}
-
+
if(rms6 != null) {
for(final Entry r6m: rms6.getCEntries().entrySet()) {
final String roleName = r6m.getKey();
//final RoleMappingsV6 r6 = r6m.getValue();
-
+
if(!r7.exists(roleName)) {
//rolemapping but role does not exists
RoleV7 noPermRole = new RoleV7();
noPermRole.setDescription("Migrated from v6, was in rolemappings but no role existed");
r7.putCEntry(roleName, noPermRole);
}
-
+
}
}
-
+
for(String tenantName: dedupTenants) {
TenantV7 entry = new TenantV7();
entry.setDescription("Migrated from v6");
t7.putCEntry(tenantName, entry);
}
-
+
return new Tuple, SecurityDynamicConfiguration>(r7, t7);
-
+
}
-
+
public static SecurityDynamicConfiguration migrateConfig(SecurityDynamicConfiguration r6cs) throws MigrationException {
final SecurityDynamicConfiguration c7 = SecurityDynamicConfiguration.empty();
c7.setCType(r6cs.getCType());
c7.set_meta(new Meta());
c7.get_meta().setConfig_version(2);
c7.get_meta().setType("config");
-
+
if(r6cs.getCEntries().size() != 1) {
throw new MigrationException("Unable to migrate config because expected size was 1 but actual size is "+r6cs.getCEntries().size());
}
-
+
if(r6cs.getCEntries().get("opendistro_security") == null) {
throw new MigrationException("Unable to migrate config because 'opendistro_security' key not found");
}
-
+
for(final Entry r6c: r6cs.getCEntries().entrySet()) {
c7.putCEntry("config", new ConfigV7(r6c.getValue()));
}
@@ -181,23 +181,23 @@ public static SecurityDynamicConfiguration migrateInternalUsers
i7.set_meta(new Meta());
i7.get_meta().setConfig_version(2);
i7.get_meta().setType("internalusers");
-
+
for(final Entry r6i: r6is.getCEntries().entrySet()) {
final String username = !Strings.isNullOrEmpty(r6i.getValue().getUsername())?r6i.getValue().getUsername():r6i.getKey();
i7.putCEntry(username, new InternalUserV7(r6i.getValue()));
}
-
+
return i7;
}
-
+
public static SecurityDynamicConfiguration migrateActionGroups(SecurityDynamicConfiguration> r6as) throws MigrationException {
-
+
final SecurityDynamicConfiguration a7 = SecurityDynamicConfiguration.empty();
a7.setCType(r6as.getCType());
a7.set_meta(new Meta());
a7.get_meta().setConfig_version(2);
a7.get_meta().setType("actiongroups");
-
+
if(r6as.getImplementingClass().isAssignableFrom(List.class)) {
for(final Entry r6a: r6as.getCEntries().entrySet()) {
a7.putCEntry(r6a.getKey(), new ActionGroupsV7(r6a.getKey(), (List) r6a.getValue()));
@@ -210,18 +210,18 @@ public static SecurityDynamicConfiguration migrateActionGroups(
return a7;
}
-
+
public static SecurityDynamicConfiguration migrateRoleMappings(SecurityDynamicConfiguration r6rms) throws MigrationException {
final SecurityDynamicConfiguration rms7 = SecurityDynamicConfiguration.empty();
rms7.setCType(r6rms.getCType());
rms7.set_meta(new Meta());
rms7.get_meta().setConfig_version(2);
rms7.get_meta().setType("rolesmapping");
-
+
for(final Entry r6m: r6rms.getCEntries().entrySet()) {
rms7.putCEntry(r6m.getKey(), new RoleMappingsV7(r6m.getValue()));
}
-
+
return rms7;
}
diff --git a/src/main/java/org/opensearch/security/securityconf/StaticDefinable.java b/src/main/java/org/opensearch/security/securityconf/StaticDefinable.java
index d6ffb106cf..06b92100fa 100644
--- a/src/main/java/org/opensearch/security/securityconf/StaticDefinable.java
+++ b/src/main/java/org/opensearch/security/securityconf/StaticDefinable.java
@@ -28,7 +28,7 @@
package org.opensearch.security.securityconf;
public interface StaticDefinable {
-
+
boolean isStatic();
}
diff --git a/src/main/java/org/opensearch/security/securityconf/impl/Meta.java b/src/main/java/org/opensearch/security/securityconf/impl/Meta.java
index 42912c1dda..1e9060efa1 100644
--- a/src/main/java/org/opensearch/security/securityconf/impl/Meta.java
+++ b/src/main/java/org/opensearch/security/securityconf/impl/Meta.java
@@ -30,17 +30,17 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
public class Meta {
-
-
+
+
private String type;
private int config_version;
-
+
private CType cType;
-
+
public String getType() {
return type;
}
-
+
public void setType(String type) {
this.type = type;
cType = CType.fromString(type);
@@ -51,7 +51,7 @@ public int getConfig_version() {
public void setConfig_version(int config_version) {
this.config_version = config_version;
}
-
+
@JsonIgnore
public CType getCType() {
return cType;
@@ -61,6 +61,6 @@ public CType getCType() {
public String toString() {
return "Meta [type=" + type + ", config_version=" + config_version + ", cType=" + cType + "]";
}
-
-
+
+
}
diff --git a/src/main/java/org/opensearch/security/securityconf/impl/SecurityDynamicConfiguration.java b/src/main/java/org/opensearch/security/securityconf/impl/SecurityDynamicConfiguration.java
index 09eeee41e3..c282f439e8 100644
--- a/src/main/java/org/opensearch/security/securityconf/impl/SecurityDynamicConfiguration.java
+++ b/src/main/java/org/opensearch/security/securityconf/impl/SecurityDynamicConfiguration.java
@@ -52,7 +52,7 @@
import org.opensearch.security.securityconf.StaticDefinable;
public class SecurityDynamicConfiguration implements ToXContent {
-
+
private static final TypeReference> typeRefMSO = new TypeReference>() {};
@JsonIgnore
@@ -61,7 +61,7 @@ public class SecurityDynamicConfiguration implements ToXContent {
private long primaryTerm= -1;
private CType ctype;
private int version = -1;
-
+
public static SecurityDynamicConfiguration empty() {
return new SecurityDynamicConfiguration();
}
@@ -83,11 +83,11 @@ public static SecurityDynamicConfiguration fromJson(String json, CType ct
sdc = DefaultObjectMapper.readValue(json, DefaultObjectMapper.getTypeFactory().constructParametricType(SecurityDynamicConfiguration.class, implementationClass));
}
validate(sdc, version, ctype);
-
+
} else {
sdc = new SecurityDynamicConfiguration();
}
-
+
sdc.ctype = ctype;
sdc.seqNo = seqNo;
sdc.primaryTerm = primaryTerm;
@@ -95,35 +95,35 @@ public static SecurityDynamicConfiguration fromJson(String json, CType ct
return sdc;
}
-
+
public static void validate(SecurityDynamicConfiguration sdc, int version, CType ctype) throws IOException {
if(version < 2 && sdc.get_meta() != null) {
throw new IOException("A version of "+version+" can not have a _meta key for "+ctype);
}
-
+
if(version >= 2 && sdc.get_meta() == null) {
throw new IOException("A version of "+version+" must have a _meta key for "+ctype);
}
-
+
if(version < 2 && ctype == CType.CONFIG && (sdc.getCEntries().size() != 1 || !sdc.getCEntries().keySet().contains("opendistro_security"))) {
throw new IOException("A version of "+version+" must have a single toplevel key named 'opendistro_security' for "+ctype);
}
-
+
if(version >= 2 && ctype == CType.CONFIG && (sdc.getCEntries().size() != 1 || !sdc.getCEntries().keySet().contains("config"))) {
throw new IOException("A version of "+version+" must have a single toplevel key named 'config' for "+ctype);
}
-
+
}
public static SecurityDynamicConfiguration fromNode(JsonNode json, CType ctype, int version, long seqNo, long primaryTerm) throws IOException {
return fromJson(DefaultObjectMapper.writeValueAsString(json, false), ctype, version, seqNo, primaryTerm);
}
-
+
//for Jackson
private SecurityDynamicConfiguration() {
super();
}
-
+
private Meta _meta;
public Meta get_meta() {
@@ -134,17 +134,17 @@ public void set_meta(Meta _meta) {
this._meta = _meta;
}
-
+
@JsonAnySetter
void setCEntries(String key, T value) {
putCEntry(key, value);
}
-
+
@JsonAnyGetter
public Map getCEntries() {
return centries;
}
-
+
@JsonIgnore
public void removeHidden() {
for(Entry entry: new HashMap(centries).entrySet()) {
@@ -153,7 +153,7 @@ public void removeHidden() {
}
}
}
-
+
@JsonIgnore
public void removeStatic() {
for(Entry entry: new HashMap(centries).entrySet()) {
@@ -162,38 +162,38 @@ public void removeStatic() {
}
}
}
-
+
@JsonIgnore
public void clearHashes() {
for(Entry entry: centries.entrySet()) {
if(entry.getValue() instanceof Hashed) {
- ((Hashed) entry.getValue()).clearHash();
+ ((Hashed) entry.getValue()).clearHash();
}
}
}
-
+
public void removeOthers(String key) {
T tmp = this.centries.get(key);
this.centries.clear();
this.centries.put(key, tmp);
}
-
+
@JsonIgnore
public T putCEntry(String key, T value) {
return centries.put(key, value);
}
-
+
@JsonIgnore
public void putCObject(String key, Object value) {
centries.put(key, (T) value);
}
-
+
@JsonIgnore
public T getCEntry(String key) {
return centries.get(key);
}
-
+
@JsonIgnore
public boolean exists(String key) {
return centries.containsKey(key);
@@ -216,7 +216,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
final boolean omitDefaults = params != null && params.paramAsBoolean("omit_defaults", false);
return builder.map(DefaultObjectMapper.readValue(DefaultObjectMapper.writeValueAsString(this, omitDefaults), typeRefMSO));
}
-
+
@Override
@JsonIgnore
public boolean isFragment() {
@@ -237,7 +237,7 @@ public long getPrimaryTerm() {
public CType getCType() {
return ctype;
}
-
+
@JsonIgnore
public void setCType(CType ctype) {
this.ctype = ctype;
@@ -247,7 +247,7 @@ public void setCType(CType ctype) {
public int getVersion() {
return version;
}
-
+
@JsonIgnore
public Class> getImplementingClass() {
return ctype==null?null:ctype.getImplementationClass().get(getVersion());
@@ -265,7 +265,7 @@ public SecurityDynamicConfiguration