You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ranger.apache.org by ma...@apache.org on 2024/12/10 05:57:09 UTC
(ranger) branch RANGER-5025 created (now 3995a8fc8)
This is an automated email from the ASF dual-hosted git repository.
madhan pushed a change to branch RANGER-5025
in repository https://gitbox.apache.org/repos/asf/ranger.git
at 3995a8fc8 RANGER-5025: checkstyle complince updates - agents-common
This branch includes the following new commits:
new 3995a8fc8 RANGER-5025: checkstyle complince updates - agents-common
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(ranger) 01/01: RANGER-5025: checkstyle complince updates - agents-common
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
madhan pushed a commit to branch RANGER-5025
in repository https://gitbox.apache.org/repos/asf/ranger.git
commit 3995a8fc8383b247709c6f4da83dae1939b0a05e
Author: Madhan Neethiraj <ma...@apache.org>
AuthorDate: Mon Dec 9 21:50:05 2024 -0800
RANGER-5025: checkstyle complince updates - agents-common
---
agents-common/pom.xml | 2 +
.../security/KrbPasswordSaverLoginModule.java | 79 +-
.../apache/hadoop/security/SecureClientLogin.java | 355 +-
.../admin/client/AbstractRangerAdminClient.java | 20 +-
.../ranger/admin/client/RangerAdminClient.java | 39 +-
.../ranger/admin/client/RangerAdminRESTClient.java | 2069 +++---
.../admin/client/datatype/GrantRevokeData.java | 420 +-
.../ranger/admin/client/datatype/RESTResponse.java | 364 +-
.../hadoop/config/RangerAdminConfig.java | 46 +-
.../hadoop/config/RangerAuditConfig.java | 15 +-
.../hadoop/config/RangerChainedPluginConfig.java | 46 +-
.../hadoop/config/RangerConfigConstants.java | 43 +-
.../hadoop/config/RangerConfiguration.java | 141 +-
.../hadoop/config/RangerLegacyConfigBuilder.java | 425 +-
.../hadoop/config/RangerPluginConfig.java | 91 +-
.../hadoop/constants/RangerHadoopConstants.java | 158 +-
.../ranger/authorization/utils/JsonUtils.java | 152 +-
.../ranger/authorization/utils/StringUtil.java | 976 ++-
.../plugin/audit/RangerDefaultAuditHandler.java | 518 +-
.../audit/RangerMultiResourceAuditHandler.java | 77 +-
.../apache/ranger/plugin/client/BaseClient.java | 336 +-
.../ranger/plugin/client/HadoopConfigHolder.java | 873 ++-
.../ranger/plugin/client/HadoopException.java | 86 +-
.../RangerAbstractConditionEvaluator.java | 51 +-
.../RangerAccessedFromClusterCondition.java | 51 +-
.../RangerAccessedFromClusterTypeCondition.java | 52 +-
.../RangerAccessedNotFromClusterCondition.java | 51 +-
.../RangerAccessedNotFromClusterTypeCondition.java | 52 +-
...AnyOfExpectedTagsPresentConditionEvaluator.java | 71 +-
.../RangerConditionEvaluator.java | 10 +-
.../RangerContextAttributeValueInCondition.java | 58 +-
.../RangerContextAttributeValueNotInCondition.java | 58 +-
...ngerHiveResourcesAccessedTogetherCondition.java | 243 +-
...rHiveResourcesNotAccessedTogetherCondition.java | 243 +-
.../plugin/conditionevaluator/RangerIpMatcher.java | 354 +-
...oneOfExpectedTagsPresentConditionEvaluator.java | 70 +-
.../RangerScriptConditionEvaluator.java | 145 +-
.../RangerScriptTemplateConditionEvaluator.java | 78 +-
.../RangerTagsAllPresentConditionEvaluator.java | 77 +-
.../conditionevaluator/RangerTimeOfDayMatcher.java | 345 +-
.../RangerValidityScheduleConditionEvaluator.java | 18 +-
.../RangerAbstractContextEnricher.java | 515 +-
.../RangerAbstractGeolocationProvider.java | 207 +-
.../RangerAdminGdsInfoRetriever.java | 110 +-
.../contextenricher/RangerAdminTagRetriever.java | 84 +-
.../RangerAdminUserStoreRetriever.java | 9 +-
.../contextenricher/RangerContextEnricher.java | 22 +-
.../RangerFileBasedGeolocationProvider.java | 11 +-
.../RangerFileBasedTagRetriever.java | 365 +-
.../plugin/contextenricher/RangerGdsEnricher.java | 198 +-
.../contextenricher/RangerGdsInfoRetriever.java | 36 +-
.../RangerServiceResourceMatcher.java | 116 +-
.../plugin/contextenricher/RangerTagEnricher.java | 2025 +++---
.../plugin/contextenricher/RangerTagForEval.java | 151 +-
.../plugin/contextenricher/RangerTagRetriever.java | 68 +-
.../contextenricher/RangerUserStoreEnricher.java | 152 +-
.../contextenricher/RangerUserStoreRefresher.java | 284 +-
.../contextenricher/RangerUserStoreRetriever.java | 15 +-
.../externalretrievers/GetFromDataFile.java | 12 +-
.../externalretrievers/GetFromURL.java | 56 +-
.../RangerMultiSourceUserStoreRetriever.java | 197 +-
.../ranger/plugin/errors/ValidationErrorCode.java | 34 +-
.../apache/ranger/plugin/geo/BinarySearchTree.java | 414 +-
.../ranger/plugin/geo/GeolocationMetadata.java | 96 +-
.../org/apache/ranger/plugin/geo/RangeChecker.java | 2 +-
.../ranger/plugin/geo/RangerGeolocationData.java | 396 +-
.../plugin/geo/RangerGeolocationDatabase.java | 109 +-
.../org/apache/ranger/plugin/geo/ValuePrinter.java | 109 +-
.../apache/ranger/plugin/geo/ValueProcessor.java | 2 +-
.../apache/ranger/plugin/model/AuditFilter.java | 19 +-
.../org/apache/ranger/plugin/model/GroupInfo.java | 15 +-
.../ranger/plugin/model/RangerBaseModelObject.java | 552 +-
.../ranger/plugin/model/RangerDatasetHeader.java | 13 +-
.../org/apache/ranger/plugin/model/RangerGds.java | 737 ++-
.../apache/ranger/plugin/model/RangerGrant.java | 4 +-
.../apache/ranger/plugin/model/RangerMetrics.java | 10 +-
.../ranger/plugin/model/RangerPluginInfo.java | 961 +--
.../apache/ranger/plugin/model/RangerPolicy.java | 3526 ++++++-----
.../ranger/plugin/model/RangerPolicyDelta.java | 91 +-
.../ranger/plugin/model/RangerPolicyHeader.java | 198 +-
.../model/RangerPolicyResourceSignature.java | 596 +-
.../ranger/plugin/model/RangerPrincipal.java | 9 +-
.../org/apache/ranger/plugin/model/RangerRole.java | 223 +-
.../ranger/plugin/model/RangerSecurityZone.java | 115 +-
.../plugin/model/RangerSecurityZoneHeaderInfo.java | 5 +-
.../ranger/plugin/model/RangerSecurityZoneV2.java | 172 +-
.../ranger/plugin/model/RangerServerHealth.java | 55 +-
.../apache/ranger/plugin/model/RangerService.java | 507 +-
.../ranger/plugin/model/RangerServiceDef.java | 6672 ++++++++++----------
.../ranger/plugin/model/RangerServiceResource.java | 252 +-
.../model/RangerServiceResourceWithTags.java | 58 +-
.../ranger/plugin/model/RangerServiceTags.java | 84 +-
.../org/apache/ranger/plugin/model/RangerTag.java | 369 +-
.../apache/ranger/plugin/model/RangerTagDef.java | 30 +-
.../ranger/plugin/model/RangerTagResourceMap.java | 69 +-
.../plugin/model/RangerValidityRecurrence.java | 213 +-
.../plugin/model/RangerValiditySchedule.java | 56 +-
.../ranger/plugin/model/ServiceDeleteResponse.java | 80 +-
.../org/apache/ranger/plugin/model/UserInfo.java | 24 +-
.../model/validation/RangerPolicyValidator.java | 2383 +++----
.../model/validation/RangerRoleValidator.java | 394 +-
.../validation/RangerSecurityZoneValidator.java | 150 +-
.../model/validation/RangerServiceDefHelper.java | 1925 +++---
.../validation/RangerServiceDefValidator.java | 1669 ++---
.../model/validation/RangerServiceValidator.java | 631 +-
.../plugin/model/validation/RangerValidator.java | 1613 ++---
.../RangerValidityScheduleValidator.java | 270 +-
.../validation/RangerZoneResourceMatcher.java | 40 +-
.../model/validation/ValidationFailureDetails.java | 156 +-
.../ValidationFailureDetailsBuilder.java | 84 +-
.../ranger/plugin/policyengine/CacheMap.java | 6 +-
.../ranger/plugin/policyengine/PolicyEngine.java | 609 +-
.../plugin/policyengine/PolicyEvaluatorForTag.java | 75 +-
.../plugin/policyengine/RangerAccessRequest.java | 58 +-
.../policyengine/RangerAccessRequestImpl.java | 763 ++-
.../policyengine/RangerAccessRequestReadOnly.java | 211 +-
.../policyengine/RangerAccessRequestWrapper.java | 92 +-
.../plugin/policyengine/RangerAccessResource.java | 29 +-
.../policyengine/RangerAccessResourceImpl.java | 462 +-
.../policyengine/RangerAccessResourceReadOnly.java | 81 +-
.../plugin/policyengine/RangerAccessResult.java | 793 +--
.../policyengine/RangerAccessResultProcessor.java | 5 +-
.../plugin/policyengine/RangerMutableResource.java | 8 +-
.../plugin/policyengine/RangerPluginContext.java | 288 +-
.../plugin/policyengine/RangerPolicyEngine.java | 84 +-
.../policyengine/RangerPolicyEngineImpl.java | 2215 ++++---
.../policyengine/RangerPolicyEngineOptions.java | 453 +-
.../policyengine/RangerPolicyRepository.java | 781 ++-
.../policyengine/RangerRequestScriptEvaluator.java | 2328 +++----
.../plugin/policyengine/RangerResourceACLs.java | 1122 ++--
.../policyengine/RangerResourceAccessInfo.java | 32 +-
.../plugin/policyengine/RangerResourceTrie.java | 786 ++-
.../policyengine/RangerSecurityZoneMatcher.java | 77 +-
.../policyengine/RangerTagAccessRequest.java | 65 +-
.../plugin/policyengine/RangerTagResource.java | 22 +-
.../plugin/policyengine/gds/GdsAccessResult.java | 32 +-
.../policyengine/gds/GdsDataShareEvaluator.java | 12 +-
.../policyengine/gds/GdsDatasetEvaluator.java | 15 +-
.../plugin/policyengine/gds/GdsDipEvaluator.java | 4 +-
.../plugin/policyengine/gds/GdsDshidEvaluator.java | 2 +-
.../plugin/policyengine/gds/GdsPolicyEngine.java | 149 +-
.../policyengine/gds/GdsProjectEvaluator.java | 14 +-
.../gds/GdsSharedResourceEvaluator.java | 34 +-
.../RangerAbstractPolicyEvaluator.java | 960 +--
.../RangerAbstractPolicyItemEvaluator.java | 326 +-
.../RangerAuditPolicyEvaluator.java | 161 +-
.../RangerCustomConditionEvaluator.java | 28 +-
.../RangerDataMaskPolicyItemEvaluator.java | 5 +-
.../RangerDefaultDataMaskPolicyItemEvaluator.java | 88 +-
.../RangerDefaultPolicyEvaluator.java | 2484 ++++----
.../RangerDefaultPolicyItemEvaluator.java | 471 +-
.../RangerDefaultRowFilterPolicyItemEvaluator.java | 75 +-
.../RangerOptimizedPolicyEvaluator.java | 204 +-
.../policyevaluator/RangerPolicyEvaluator.java | 1308 ++--
.../policyevaluator/RangerPolicyItemEvaluator.java | 62 +-
.../RangerRowFilterPolicyItemEvaluator.java | 5 +-
.../RangerValidityScheduleEvaluator.java | 255 +-
.../RangerDefaultPolicyResourceMatcher.java | 822 ++-
.../RangerPolicyResourceMatcher.java | 127 +-
.../RangerResourceEvaluator.java | 1 -
.../RangerAbstractResourceMatcher.java | 1326 ++--
.../RangerDefaultResourceMatcher.java | 199 +-
.../resourcematcher/RangerPathResourceMatcher.java | 1314 ++--
.../resourcematcher/RangerResourceMatcher.java | 19 +-
.../resourcematcher/RangerURLResourceMatcher.java | 373 +-
.../plugin/resourcematcher/ResourceMatcher.java | 183 +-
.../resourcematcher/ScheduledTimeExactMatcher.java | 3 +-
.../resourcematcher/ScheduledTimeRangeMatcher.java | 5 +-
.../ranger/plugin/service/RangerAuthContext.java | 6 +-
.../plugin/service/RangerAuthContextListener.java | 1 -
.../ranger/plugin/service/RangerBasePlugin.java | 2627 ++++----
.../ranger/plugin/service/RangerBaseService.java | 901 ++-
.../ranger/plugin/service/RangerChainedPlugin.java | 20 +-
.../service/RangerDefaultRequestProcessor.java | 32 +-
.../plugin/service/RangerDefaultService.java | 44 +-
.../plugin/service/ResourceLookupContext.java | 107 +-
.../ranger/plugin/store/AbstractGdsStore.java | 140 +-
.../ranger/plugin/store/AbstractPredicateUtil.java | 1908 +++---
.../ranger/plugin/store/AbstractServiceStore.java | 1215 ++--
.../ranger/plugin/store/AbstractTagStore.java | 36 +-
.../plugin/store/EmbeddedServiceDefsUtil.java | 739 +--
.../org/apache/ranger/plugin/store/GdsStore.java | 5 -
.../ranger/plugin/store/GeolocationStore.java | 7 +-
.../java/org/apache/ranger/plugin/store/PList.java | 371 +-
.../store/RangerServiceResourceSignature.java | 158 +-
.../ranger/plugin/store/RolePredicateUtil.java | 236 +-
.../org/apache/ranger/plugin/store/RoleStore.java | 24 +-
.../plugin/store/SecurityZonePredicateUtil.java | 207 +-
.../ranger/plugin/store/SecurityZoneStore.java | 9 +-
.../ranger/plugin/store/ServicePredicateUtil.java | 391 +-
.../apache/ranger/plugin/store/ServiceStore.java | 93 +-
.../ranger/plugin/store/StoredServiceResource.java | 12 +-
.../ranger/plugin/store/TagPredicateUtil.java | 493 +-
.../org/apache/ranger/plugin/store/TagStore.java | 23 +-
.../apache/ranger/plugin/store/TagValidator.java | 459 +-
.../plugin/store/file/GeolocationFileStore.java | 344 +-
.../ranger/plugin/util/AutoClosableLock.java | 8 +-
.../plugin/util/CachedResourceEvaluators.java | 79 +-
.../apache/ranger/plugin/util/DownloadTrigger.java | 4 +-
.../apache/ranger/plugin/util/DownloaderTask.java | 6 +-
.../plugin/util/GraalScriptEngineCreator.java | 22 +-
.../ranger/plugin/util/GrantRevokeRequest.java | 820 ++-
.../ranger/plugin/util/GrantRevokeRoleRequest.java | 531 +-
.../apache/ranger/plugin/util/JavaScriptEdits.java | 13 +-
.../plugin/util/JavaScriptEngineCreator.java | 6 +-
.../org/apache/ranger/plugin/util/JsonUtilsV2.java | 35 +-
.../apache/ranger/plugin/util/KeySearchFilter.java | 216 +-
.../apache/ranger/plugin/util/MacroProcessor.java | 8 +-
.../plugin/util/NashornScriptEngineCreator.java | 6 +-
.../apache/ranger/plugin/util/PasswordUtils.java | 346 +-
.../ranger/plugin/util/PerfDataRecorder.java | 437 +-
.../apache/ranger/plugin/util/PolicyRefresher.java | 1032 ++-
.../plugin/util/RangerAccessRequestUtil.java | 836 +--
.../org/apache/ranger/plugin/util/RangerCache.java | 206 +-
.../ranger/plugin/util/RangerCommonConstants.java | 315 +-
.../ranger/plugin/util/RangerMetricsUtil.java | 174 +-
.../ranger/plugin/util/RangerObjectFactory.java | 20 +-
.../plugin/util/RangerPerfCollectorTracer.java | 48 +-
.../ranger/plugin/util/RangerPerfTracer.java | 189 +-
.../plugin/util/RangerPerfTracerFactory.java | 94 +-
.../ranger/plugin/util/RangerPluginCapability.java | 171 +-
.../ranger/plugin/util/RangerPolicyDeltaUtil.java | 86 +-
.../ranger/plugin/util/RangerPurgeResult.java | 10 +-
.../ranger/plugin/util/RangerRESTClient.java | 1476 ++---
.../apache/ranger/plugin/util/RangerRESTUtils.java | 213 +-
.../ranger/plugin/util/RangerReadWriteLock.java | 7 +-
.../plugin/util/RangerRequestExprResolver.java | 159 +-
.../plugin/util/RangerRequestedResources.java | 165 +-
.../util/RangerResourceEvaluatorsRetriever.java | 21 +-
.../org/apache/ranger/plugin/util/RangerRoles.java | 18 +-
.../ranger/plugin/util/RangerRolesProvider.java | 602 +-
.../apache/ranger/plugin/util/RangerRolesUtil.java | 24 +-
.../plugin/util/RangerSecurityZoneHelper.java | 31 +-
.../util/RangerServiceNotFoundException.java | 10 +-
.../plugin/util/RangerServiceTagsDeltaUtil.java | 73 +-
.../apache/ranger/plugin/util/RangerSslHelper.java | 489 +-
.../ranger/plugin/util/RangerTimeRangeChecker.java | 19 +-
.../apache/ranger/plugin/util/RangerUserStore.java | 40 +-
.../ranger/plugin/util/RangerUserStoreUtil.java | 84 +-
.../ranger/plugin/util/ScriptEngineUtil.java | 43 +-
.../apache/ranger/plugin/util/SearchFilter.java | 637 +-
.../apache/ranger/plugin/util/ServiceDefUtil.java | 664 +-
.../apache/ranger/plugin/util/ServiceGdsInfo.java | 159 +-
.../apache/ranger/plugin/util/ServicePolicies.java | 1042 +--
.../org/apache/ranger/plugin/util/ServiceTags.java | 611 +-
.../ranger/plugin/util/StringTokenReplacer.java | 34 +-
.../apache/ranger/plugin/util/TimedEventUtil.java | 75 +-
.../apache/ranger/plugin/util/URLEncoderUtil.java | 22 +-
.../org/apache/ranger/plugin/util/XMLUtils.java | 216 +-
.../ranger/services/gds/RangerServiceGds.java | 52 +-
.../ranger/services/tag/RangerServiceTag.java | 224 +-
.../src/main/resources/resourcenamemap.properties | 2 +-
.../ranger/authorization/utils/TestStringUtil.java | 61 +-
.../RangerCustomConditionMatcherTest.java | 541 +-
.../conditionevaluator/RangerIpMatcherTest.java | 444 +-
.../RangerRequestScriptEvaluatorTest.java | 331 +-
.../conditionevaluator/RangerSimpleMatcher.java | 179 +-
.../RangerTimeOfDayMatcherTest.java | 494 +-
...stRangerValidityScheduleConditionEvaluator.java | 5 +-
.../plugin/contextenricher/TestTagEnricher.java | 29 +-
.../plugin/errors/TestValidationErrorCode.java | 21 +-
.../ranger/plugin/model/TestRangerHealth.java | 65 +-
.../ranger/plugin/model/TestRangerPolicy.java | 11 +-
.../model/TestRangerPolicyResourceSignature.java | 439 +-
.../ranger/plugin/model/TestRangerService.java | 8 +-
.../RangerSecurityZoneValidatorTest.java | 1120 ++--
.../plugin/model/validation/TestDirectedGraph.java | 96 +-
.../validation/TestRangerPolicyValidator.java | 1775 +++---
.../validation/TestRangerServiceDefHelper.java | 620 +-
.../validation/TestRangerServiceDefValidator.java | 1117 ++--
.../validation/TestRangerServiceValidator.java | 1066 ++--
.../model/validation/TestRangerValidator.java | 938 +--
.../model/validation/ValidationTestUtils.java | 820 +--
.../ranger/plugin/policyengine/TestCacheMap.java | 160 +-
.../plugin/policyengine/TestPathResourceTrie.java | 320 +-
.../ranger/plugin/policyengine/TestPolicyACLs.java | 561 +-
.../plugin/policyengine/TestPolicyEngine.java | 1830 +++---
.../policyengine/TestPolicyEngineComparison.java | 67 +-
.../policyengine/TestPolicyEngineForDeltas.java | 805 ++-
.../plugin/policyengine/TestProjectProvider.java | 114 +-
.../plugin/policyengine/TestRangerAuthContext.java | 177 +-
.../policyengine/TestRangerPluginCapability.java | 20 +-
.../TestRangerSecurityZoneMatcher.java | 41 +-
.../policyengine/gds/TestGdsPolicyEngine.java | 45 +-
.../RangerDefaultPolicyEvaluatorTest.java | 215 +-
.../RangerAbstractResourceMatcherTest.java | 24 +-
.../RangerDefaultResourceMatcherTest.java | 159 +-
.../RangerPathResourceMatcherTest.java | 256 +-
.../RangerURLResourceMatcherTest.java | 164 +-
.../TestDefaultPolicyResourceMatcher.java | 296 +-
.../TestDefaultPolicyResourceMatcherForPolicy.java | 306 +-
.../resourcematcher/TestResourceMatcher.java | 210 +-
.../plugin/service/TestRangerBasePlugin.java | 57 +-
.../ranger/plugin/util/JavaScriptEditsTest.java | 33 +-
.../ranger/plugin/util/MacroProcessorTest.java | 44 +-
.../ranger/plugin/util/PasswordUtilsTest.java | 333 +-
.../apache/ranger/plugin/util/RangerCacheTest.java | 114 +-
.../plugin/util/RangerRequestExprResolverTest.java | 22 +-
.../plugin/util/RangerTimeRangeCheckerTest.java | 94 +-
.../ranger/plugin/util/ServiceDefUtilTest.java | 947 +--
.../apache/ranger/plugin/util/TestServiceTags.java | 9 +-
dev-support/checkstyle-suppressions.xml | 7 +-
302 files changed, 52157 insertions(+), 51685 deletions(-)
diff --git a/agents-common/pom.xml b/agents-common/pom.xml
index 84396bba5..b83f9cfc7 100644
--- a/agents-common/pom.xml
+++ b/agents-common/pom.xml
@@ -28,6 +28,8 @@
<name>Common library for Plugins</name>
<description>Plugins Common</description>
<properties>
+ <checkstyle.failOnViolation>true</checkstyle.failOnViolation>
+ <checkstyle.skip>false</checkstyle.skip>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
diff --git a/agents-common/src/main/java/org/apache/hadoop/security/KrbPasswordSaverLoginModule.java b/agents-common/src/main/java/org/apache/hadoop/security/KrbPasswordSaverLoginModule.java
index 521d2b9a3..1e59afd67 100644
--- a/agents-common/src/main/java/org/apache/hadoop/security/KrbPasswordSaverLoginModule.java
+++ b/agents-common/src/main/java/org/apache/hadoop/security/KrbPasswordSaverLoginModule.java
@@ -17,60 +17,59 @@
* under the License.
*/
- package org.apache.hadoop.security;
-
-import java.util.Map;
+package org.apache.hadoop.security;
import javax.security.auth.Subject;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.login.LoginException;
import javax.security.auth.spi.LoginModule;
+import java.util.Map;
+
public class KrbPasswordSaverLoginModule implements LoginModule {
public static final String USERNAME_PARAM = "javax.security.auth.login.name";
public static final String PASSWORD_PARAM = "javax.security.auth.login.password";
- @SuppressWarnings("rawtypes")
- private Map sharedState;
-
- public KrbPasswordSaverLoginModule() {
- }
+ @SuppressWarnings("rawtypes")
+ private Map sharedState;
+
+ public KrbPasswordSaverLoginModule() {
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void initialize(Subject subject, CallbackHandler callbackhandler, Map<String, ?> sharedMap, Map<String, ?> options) {
+ this.sharedState = sharedMap;
+
+ String userName = (options != null) ? (String) options.get(USERNAME_PARAM) : null;
+ String password = (options != null) ? (String) options.get(PASSWORD_PARAM) : null;
- @Override
- public boolean abort() throws LoginException {
- return true;
- }
+ if (userName != null) {
+ this.sharedState.put(USERNAME_PARAM, userName);
+ }
- @Override
- public boolean commit() throws LoginException {
- return true;
- }
+ if (password != null) {
+ this.sharedState.put(PASSWORD_PARAM, password.toCharArray());
+ }
+ }
- @SuppressWarnings("unchecked")
- @Override
- public void initialize(Subject subject, CallbackHandler callbackhandler, Map<String, ?> sharedMap, Map<String, ?> options) {
-
- this.sharedState = sharedMap;
-
- String userName = (options != null) ? (String)options.get(USERNAME_PARAM) : null;
- if (userName != null) {
- this.sharedState.put(USERNAME_PARAM,userName);
- }
- String password = (options != null) ? (String)options.get(PASSWORD_PARAM) : null;
-
- if (password != null) {
- this.sharedState.put(PASSWORD_PARAM,password.toCharArray());
- }
- }
+ @Override
+ public boolean login() throws LoginException {
+ return true;
+ }
- @Override
- public boolean login() throws LoginException {
- return true;
- }
+ @Override
+ public boolean commit() throws LoginException {
+ return true;
+ }
- @Override
- public boolean logout() throws LoginException {
- return true;
- }
+ @Override
+ public boolean abort() throws LoginException {
+ return true;
+ }
+ @Override
+ public boolean logout() throws LoginException {
+ return true;
+ }
}
diff --git a/agents-common/src/main/java/org/apache/hadoop/security/SecureClientLogin.java b/agents-common/src/main/java/org/apache/hadoop/security/SecureClientLogin.java
index 8c2a0babb..6cffda199 100644
--- a/agents-common/src/main/java/org/apache/hadoop/security/SecureClientLogin.java
+++ b/agents-common/src/main/java/org/apache/hadoop/security/SecureClientLogin.java
@@ -18,6 +18,19 @@
*/
package org.apache.hadoop.security;
+import org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod;
+import org.apache.hadoop.security.authentication.util.KerberosName;
+import org.apache.hadoop.security.authentication.util.KerberosUtil;
+import org.apache.hadoop.util.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.security.auth.Subject;
+import javax.security.auth.login.AppConfigurationEntry;
+import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag;
+import javax.security.auth.login.LoginContext;
+import javax.security.auth.login.LoginException;
+
import java.io.File;
import java.io.IOException;
import java.security.Principal;
@@ -26,172 +39,186 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import javax.security.auth.Subject;
-import javax.security.auth.login.AppConfigurationEntry;
-import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag;
-import javax.security.auth.login.LoginContext;
-import javax.security.auth.login.LoginException;
+public class SecureClientLogin {
+ private static final Logger LOG = LoggerFactory.getLogger(SecureClientLogin.class);
-import org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod;
-import org.apache.hadoop.security.authentication.util.KerberosUtil;
-import org.apache.hadoop.security.authentication.util.KerberosName;
-import org.apache.hadoop.util.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+ public static final String HOSTNAME_PATTERN = "_HOST";
-public class SecureClientLogin {
- private static final Logger LOG = LoggerFactory.getLogger(SecureClientLogin.class);
- public static final String HOSTNAME_PATTERN = "_HOST";
-
- public synchronized static Subject loginUserFromKeytab(String user, String path) throws IOException {
- try {
- Subject subject = new Subject();
- SecureClientLoginConfiguration loginConf = new SecureClientLoginConfiguration(true, user, path);
- LoginContext login = new LoginContext("hadoop-keytab-kerberos", subject, null, loginConf);
- subject.getPrincipals().add(new User(user, AuthenticationMethod.KERBEROS, login));
- login.login();
- return login.getSubject();
- } catch (LoginException le) {
- throw new IOException("Login failure for " + user + " from keytab " + path, le);
- }
- }
-
- public synchronized static Subject loginUserFromKeytab(String user, String path, String nameRules) throws IOException {
- try {
- Subject subject = new Subject();
- SecureClientLoginConfiguration loginConf = new SecureClientLoginConfiguration(true, user, path);
- LoginContext login = new LoginContext("hadoop-keytab-kerberos", subject, null, loginConf);
- KerberosName.setRules(nameRules);
- subject.getPrincipals().add(new User(user, AuthenticationMethod.KERBEROS, login));
- login.login();
- return login.getSubject();
- } catch (LoginException le) {
- throw new IOException("Login failure for " + user + " from keytab " + path, le);
- }
- }
-
- public synchronized static Subject loginUserWithPassword(String user, String password) throws IOException {
- try {
- Subject subject = new Subject();
- SecureClientLoginConfiguration loginConf = new SecureClientLoginConfiguration(false, user, password);
- LoginContext login = new LoginContext("hadoop-keytab-kerberos", subject, null, loginConf);
- subject.getPrincipals().add(new User(user, AuthenticationMethod.KERBEROS, login));
- login.login();
- return login.getSubject();
- } catch (LoginException le) {
- throw new IOException("Login failure for " + user + " using password ****", le);
- }
- }
-
- public synchronized static Subject login(String user) throws IOException {
- Subject subject = new Subject();
- subject.getPrincipals().add(new User(user));
- return subject;
- }
-
- public static Set<Principal> getUserPrincipals(Subject aSubject) {
- if (aSubject != null) {
- Set<User> list = aSubject.getPrincipals(User.class);
- if (list != null) {
- Set<Principal> ret = new HashSet<>();
- ret.addAll(list);
- return ret;
- } else {
- return null;
- }
- } else {
- return null;
- }
- }
-
- public static Principal createUserPrincipal(String aLoginName) {
- return new User(aLoginName);
- }
-
- public static boolean isKerberosCredentialExists(String principal, String keytabPath){
- boolean isValid = false;
- if (keytabPath != null && !keytabPath.isEmpty()) {
- File keytabFile = new File(keytabPath);
- if (!keytabFile.exists()) {
- LOG.warn(keytabPath + " doesn't exist.");
- } else if (!keytabFile.canRead()) {
- LOG.warn("Unable to read " + keytabPath + ". Please check the file access permissions for user");
- }else{
- isValid = true;
- }
- } else {
- LOG.warn("Can't find keyTab Path : "+keytabPath);
- }
- if (!(principal != null && !principal.isEmpty() && isValid)) {
- isValid = false;
- LOG.warn("Can't find principal : "+principal);
- }
- return isValid;
- }
-
- public static String getPrincipal(String principalConfig, String hostName) throws IOException {
- String[] components = getComponents(principalConfig);
- if (components == null || components.length != 3 || !HOSTNAME_PATTERN.equals(components[1])) {
- return principalConfig;
- } else {
- if (hostName == null) {
- throw new IOException("Can't replace " + HOSTNAME_PATTERN + " pattern since client ranger.service.host is null");
- }
- return replacePattern(components, hostName);
- }
- }
-
- private static String[] getComponents(String principalConfig) {
- if (principalConfig == null)
- return null;
- return principalConfig.split("[/@]");
- }
-
- private static String replacePattern(String[] components, String hostname)
- throws IOException {
- String fqdn = hostname;
- if (fqdn == null || fqdn.isEmpty() || "0.0.0.0".equals(fqdn)) {
- fqdn = java.net.InetAddress.getLocalHost().getCanonicalHostName();
- }
- return components[0] + "/" + StringUtils.toLowerCase(fqdn) + "@" + components[2];
- }
-}
+ private SecureClientLogin() {
+ // to block instantiation
+ }
+
+ public static synchronized Subject loginUserFromKeytab(String user, String path) throws IOException {
+ try {
+ Subject subject = new Subject();
+ SecureClientLoginConfiguration loginConf = new SecureClientLoginConfiguration(true, user, path);
+ LoginContext login = new LoginContext("hadoop-keytab-kerberos", subject, null, loginConf);
+
+ subject.getPrincipals().add(new User(user, AuthenticationMethod.KERBEROS, login));
+
+ login.login();
+
+ return login.getSubject();
+ } catch (LoginException le) {
+ throw new IOException("Login failure for " + user + " from keytab " + path, le);
+ }
+ }
+
+ public static synchronized Subject loginUserFromKeytab(String user, String path, String nameRules) throws IOException {
+ try {
+ Subject subject = new Subject();
+ SecureClientLoginConfiguration loginConf = new SecureClientLoginConfiguration(true, user, path);
+ LoginContext login = new LoginContext("hadoop-keytab-kerberos", subject, null, loginConf);
+
+ KerberosName.setRules(nameRules);
+
+ subject.getPrincipals().add(new User(user, AuthenticationMethod.KERBEROS, login));
+
+ login.login();
+
+ return login.getSubject();
+ } catch (LoginException le) {
+ throw new IOException("Login failure for " + user + " from keytab " + path, le);
+ }
+ }
+
+ public static synchronized Subject loginUserWithPassword(String user, String password) throws IOException {
+ try {
+ Subject subject = new Subject();
+ SecureClientLoginConfiguration loginConf = new SecureClientLoginConfiguration(false, user, password);
+ LoginContext login = new LoginContext("hadoop-keytab-kerberos", subject, null, loginConf);
+
+ subject.getPrincipals().add(new User(user, AuthenticationMethod.KERBEROS, login));
+
+ login.login();
+
+ return login.getSubject();
+ } catch (LoginException le) {
+ throw new IOException("Login failure for " + user + " using password ****", le);
+ }
+ }
+
+ public static synchronized Subject login(String user) throws IOException {
+ Subject subject = new Subject();
+
+ subject.getPrincipals().add(new User(user));
+
+ return subject;
+ }
+
+ public static Set<Principal> getUserPrincipals(Subject aSubject) {
+ if (aSubject != null) {
+ Set<User> list = aSubject.getPrincipals(User.class);
+
+ if (list != null) {
+ return new HashSet<>(list);
+ } else {
+ return null;
+ }
+ } else {
+ return null;
+ }
+ }
+
+ public static Principal createUserPrincipal(String aLoginName) {
+ return new User(aLoginName);
+ }
+
+ public static boolean isKerberosCredentialExists(String principal, String keytabPath) {
+ boolean isValid = false;
+
+ if (keytabPath != null && !keytabPath.isEmpty()) {
+ File keytabFile = new File(keytabPath);
+
+ if (!keytabFile.exists()) {
+ LOG.warn("{} doesn't exist.", keytabPath);
+ } else if (!keytabFile.canRead()) {
+ LOG.warn("Unable to read {}. Please check the file access permissions for user", keytabPath);
+ } else {
+ isValid = true;
+ }
+ } else {
+ LOG.warn("Can't find keyTab Path : {}", keytabPath);
+ }
+ if (!(principal != null && !principal.isEmpty() && isValid)) {
+ isValid = false;
+
+ LOG.warn("Can't find principal : {}", principal);
+ }
+
+ return isValid;
+ }
+
+ public static String getPrincipal(String principalConfig, String hostName) throws IOException {
+ String[] components = getComponents(principalConfig);
+
+ if (components == null || components.length != 3 || !HOSTNAME_PATTERN.equals(components[1])) {
+ return principalConfig;
+ } else {
+ if (hostName == null) {
+ throw new IOException("Can't replace " + HOSTNAME_PATTERN + " pattern since client ranger.service.host is null");
+ }
+
+ return replacePattern(components, hostName);
+ }
+ }
+
+ private static String[] getComponents(String principalConfig) {
+ if (principalConfig == null) {
+ return null;
+ }
+
+ return principalConfig.split("[/@]");
+ }
+
+ private static String replacePattern(String[] components, String hostname) throws IOException {
+ String fqdn = hostname;
+
+ if (fqdn == null || fqdn.isEmpty() || "0.0.0.0".equals(fqdn)) {
+ fqdn = java.net.InetAddress.getLocalHost().getCanonicalHostName();
+ }
+
+ return components[0] + "/" + StringUtils.toLowerCase(fqdn) + "@" + components[2];
+ }
+
+ static class SecureClientLoginConfiguration extends javax.security.auth.login.Configuration {
+ private final Map<String, String> kerberosOptions = new HashMap<>();
+ private boolean usePassword;
+
+ public SecureClientLoginConfiguration(boolean useKeyTab, String principal, String credential) {
+ kerberosOptions.put("principal", principal);
+ kerberosOptions.put("debug", "false");
+
+ if (useKeyTab) {
+ kerberosOptions.put("useKeyTab", "true");
+ kerberosOptions.put("keyTab", credential);
+ kerberosOptions.put("doNotPrompt", "true");
+ } else {
+ usePassword = true;
+
+ kerberosOptions.put("useKeyTab", "false");
+ kerberosOptions.put(KrbPasswordSaverLoginModule.USERNAME_PARAM, principal);
+ kerberosOptions.put(KrbPasswordSaverLoginModule.PASSWORD_PARAM, credential);
+ kerberosOptions.put("doNotPrompt", "false");
+ kerberosOptions.put("useFirstPass", "true");
+ kerberosOptions.put("tryFirstPass", "false");
+ }
+
+ kerberosOptions.put("storeKey", "true");
+ kerberosOptions.put("refreshKrb5Config", "true");
+ }
+
+ @Override
+ public AppConfigurationEntry[] getAppConfigurationEntry(String appName) {
+ AppConfigurationEntry keytabKerberosLogin = new AppConfigurationEntry(KerberosUtil.getKrb5LoginModuleName(), LoginModuleControlFlag.REQUIRED, kerberosOptions);
-class SecureClientLoginConfiguration extends javax.security.auth.login.Configuration {
- private Map<String, String> kerberosOptions = new HashMap<>();
- private boolean usePassword;
-
- public SecureClientLoginConfiguration(boolean useKeyTab, String principal, String credential) {
- kerberosOptions.put("principal", principal);
- kerberosOptions.put("debug", "false");
- if (useKeyTab) {
- kerberosOptions.put("useKeyTab", "true");
- kerberosOptions.put("keyTab", credential);
- kerberosOptions.put("doNotPrompt", "true");
- } else {
- usePassword = true;
- kerberosOptions.put("useKeyTab", "false");
- kerberosOptions.put(KrbPasswordSaverLoginModule.USERNAME_PARAM, principal);
- kerberosOptions.put(KrbPasswordSaverLoginModule.PASSWORD_PARAM, credential);
- kerberosOptions.put("doNotPrompt", "false");
- kerberosOptions.put("useFirstPass", "true");
- kerberosOptions.put("tryFirstPass","false");
- }
- kerberosOptions.put("storeKey", "true");
- kerberosOptions.put("refreshKrb5Config", "true");
- }
-
- @Override
- public AppConfigurationEntry[] getAppConfigurationEntry(String appName) {
- AppConfigurationEntry KEYTAB_KERBEROS_LOGIN = new AppConfigurationEntry(KerberosUtil.getKrb5LoginModuleName(), LoginModuleControlFlag.REQUIRED, kerberosOptions);
- if (usePassword) {
- AppConfigurationEntry KERBEROS_PWD_SAVER = new AppConfigurationEntry(KrbPasswordSaverLoginModule.class.getName(), LoginModuleControlFlag.REQUIRED, kerberosOptions);
- return new AppConfigurationEntry[] { KERBEROS_PWD_SAVER, KEYTAB_KERBEROS_LOGIN };
- }
- else {
- return new AppConfigurationEntry[] { KEYTAB_KERBEROS_LOGIN };
- }
- }
-
+ if (usePassword) {
+ AppConfigurationEntry kerberosPwdSaver = new AppConfigurationEntry(KrbPasswordSaverLoginModule.class.getName(), LoginModuleControlFlag.REQUIRED, kerberosOptions);
+ return new AppConfigurationEntry[] {kerberosPwdSaver, keytabKerberosLogin};
+ } else {
+ return new AppConfigurationEntry[] {keytabKerberosLogin};
+ }
+ }
+ }
}
diff --git a/agents-common/src/main/java/org/apache/ranger/admin/client/AbstractRangerAdminClient.java b/agents-common/src/main/java/org/apache/ranger/admin/client/AbstractRangerAdminClient.java
index 90e3e6eb8..d22a87d42 100644
--- a/agents-common/src/main/java/org/apache/ranger/admin/client/AbstractRangerAdminClient.java
+++ b/agents-common/src/main/java/org/apache/ranger/admin/client/AbstractRangerAdminClient.java
@@ -24,7 +24,13 @@ import com.google.gson.GsonBuilder;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.ranger.plugin.model.RangerRole;
-import org.apache.ranger.plugin.util.*;
+import org.apache.ranger.plugin.util.GrantRevokeRequest;
+import org.apache.ranger.plugin.util.GrantRevokeRoleRequest;
+import org.apache.ranger.plugin.util.RangerRoles;
+import org.apache.ranger.plugin.util.RangerUserStore;
+import org.apache.ranger.plugin.util.ServiceGdsInfo;
+import org.apache.ranger.plugin.util.ServicePolicies;
+import org.apache.ranger.plugin.util.ServiceTags;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -35,7 +41,7 @@ public abstract class AbstractRangerAdminClient implements RangerAdminClient {
protected Gson gson;
- private boolean forceNonKerberos = false;
+ private boolean forceNonKerberos;
@Override
public void init(String serviceName, String appId, String configPropertyPrefix, Configuration config) {
@@ -43,11 +49,11 @@ public abstract class AbstractRangerAdminClient implements RangerAdminClient {
try {
gson = new GsonBuilder().setDateFormat("yyyyMMdd-HH:mm:ss.SSS-Z").setPrettyPrinting().create();
- } catch(Throwable excp) {
+ } catch (Throwable excp) {
LOG.error("AbstractRangerAdminClient: failed to create GsonBuilder object", excp);
}
- this.gson = gson;
+ this.gson = gson;
this.forceNonKerberos = config.getBoolean(configPropertyPrefix + ".forceNonKerberos", false);
}
@@ -68,7 +74,6 @@ public abstract class AbstractRangerAdminClient implements RangerAdminClient {
@Override
public void dropRole(String execUser, String roleName) throws Exception {
-
}
@Override
@@ -88,22 +93,18 @@ public abstract class AbstractRangerAdminClient implements RangerAdminClient {
@Override
public void grantRole(GrantRevokeRoleRequest request) throws Exception {
-
}
@Override
public void revokeRole(GrantRevokeRoleRequest request) throws Exception {
-
}
@Override
public void grantAccess(GrantRevokeRequest request) throws Exception {
-
}
@Override
public void revokeAccess(GrantRevokeRequest request) throws Exception {
-
}
@Override
@@ -126,7 +127,6 @@ public abstract class AbstractRangerAdminClient implements RangerAdminClient {
return null;
}
-
public boolean isKerberosEnabled(UserGroupInformation user) {
final boolean ret;
diff --git a/agents-common/src/main/java/org/apache/ranger/admin/client/RangerAdminClient.java b/agents-common/src/main/java/org/apache/ranger/admin/client/RangerAdminClient.java
index 4f08d40f6..448fdf9f1 100644
--- a/agents-common/src/main/java/org/apache/ranger/admin/client/RangerAdminClient.java
+++ b/agents-common/src/main/java/org/apache/ranger/admin/client/RangerAdminClient.java
@@ -17,53 +17,50 @@
* under the License.
*/
- package org.apache.ranger.admin.client;
-
+package org.apache.ranger.admin.client;
import org.apache.hadoop.conf.Configuration;
import org.apache.ranger.plugin.model.RangerRole;
import org.apache.ranger.plugin.util.GrantRevokeRequest;
import org.apache.ranger.plugin.util.GrantRevokeRoleRequest;
import org.apache.ranger.plugin.util.RangerRoles;
+import org.apache.ranger.plugin.util.RangerUserStore;
import org.apache.ranger.plugin.util.ServiceGdsInfo;
import org.apache.ranger.plugin.util.ServicePolicies;
import org.apache.ranger.plugin.util.ServiceTags;
-import org.apache.ranger.plugin.util.RangerUserStore;
import java.util.List;
-
public interface RangerAdminClient {
+ void init(String serviceName, String appId, String configPropertyPrefix, Configuration config);
- void init(String serviceName, String appId, String configPropertyPrefix, Configuration config);
-
- ServicePolicies getServicePoliciesIfUpdated(long lastKnownVersion, long lastActivationTimeInMillis) throws Exception;
+ ServicePolicies getServicePoliciesIfUpdated(long lastKnownVersion, long lastActivationTimeInMillis) throws Exception;
- RangerRoles getRolesIfUpdated(long lastKnownRoleVersion, long lastActivationTimeInMills) throws Exception;
+ RangerRoles getRolesIfUpdated(long lastKnownRoleVersion, long lastActivationTimeInMills) throws Exception;
- RangerRole createRole(RangerRole request) throws Exception;
+ RangerRole createRole(RangerRole request) throws Exception;
- void dropRole(String execUser, String roleName) throws Exception;
+ void dropRole(String execUser, String roleName) throws Exception;
- List<String> getAllRoles(String execUser) throws Exception;
+ List<String> getAllRoles(String execUser) throws Exception;
- List<String> getUserRoles(String execUser) throws Exception;
+ List<String> getUserRoles(String execUser) throws Exception;
- RangerRole getRole(String execUser, String roleName) throws Exception;
+ RangerRole getRole(String execUser, String roleName) throws Exception;
- void grantRole(GrantRevokeRoleRequest request) throws Exception;
+ void grantRole(GrantRevokeRoleRequest request) throws Exception;
- void revokeRole(GrantRevokeRoleRequest request) throws Exception;
+ void revokeRole(GrantRevokeRoleRequest request) throws Exception;
- void grantAccess(GrantRevokeRequest request) throws Exception;
+ void grantAccess(GrantRevokeRequest request) throws Exception;
- void revokeAccess(GrantRevokeRequest request) throws Exception;
+ void revokeAccess(GrantRevokeRequest request) throws Exception;
- ServiceTags getServiceTagsIfUpdated(long lastKnownVersion, long lastActivationTimeInMillis) throws Exception;
+ ServiceTags getServiceTagsIfUpdated(long lastKnownVersion, long lastActivationTimeInMillis) throws Exception;
- List<String> getTagTypes(String tagTypePattern) throws Exception;
+ List<String> getTagTypes(String tagTypePattern) throws Exception;
- RangerUserStore getUserStoreIfUpdated(long lastKnownUserStoreVersion, long lastActivationTimeInMillis) throws Exception;
+ RangerUserStore getUserStoreIfUpdated(long lastKnownUserStoreVersion, long lastActivationTimeInMillis) throws Exception;
- ServiceGdsInfo getGdsInfoIfUpdated(long lastKnownVersion, long lastActivationTimeInMillis) throws Exception;
+ ServiceGdsInfo getGdsInfoIfUpdated(long lastKnownVersion, long lastActivationTimeInMillis) throws Exception;
}
diff --git a/agents-common/src/main/java/org/apache/ranger/admin/client/RangerAdminRESTClient.java b/agents-common/src/main/java/org/apache/ranger/admin/client/RangerAdminRESTClient.java
index 653ae63d5..3e0397d0a 100644
--- a/agents-common/src/main/java/org/apache/ranger/admin/client/RangerAdminRESTClient.java
+++ b/agents-common/src/main/java/org/apache/ranger/admin/client/RangerAdminRESTClient.java
@@ -17,12 +17,10 @@
* under the License.
*/
- package org.apache.ranger.admin.client;
-
+package org.apache.ranger.admin.client;
import com.fasterxml.jackson.core.type.TypeReference;
import com.sun.jersey.api.client.ClientResponse;
-
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.security.AccessControlException;
import org.apache.hadoop.security.UserGroupInformation;
@@ -32,13 +30,27 @@ import org.apache.ranger.audit.provider.MiscUtil;
import org.apache.ranger.authorization.hadoop.config.RangerPluginConfig;
import org.apache.ranger.authorization.utils.StringUtil;
import org.apache.ranger.plugin.model.RangerRole;
-import org.apache.ranger.plugin.util.*;
+import org.apache.ranger.plugin.util.GrantRevokeRequest;
+import org.apache.ranger.plugin.util.GrantRevokeRoleRequest;
+import org.apache.ranger.plugin.util.JsonUtilsV2;
+import org.apache.ranger.plugin.util.RangerCommonConstants;
+import org.apache.ranger.plugin.util.RangerPluginCapability;
+import org.apache.ranger.plugin.util.RangerRESTClient;
+import org.apache.ranger.plugin.util.RangerRESTUtils;
+import org.apache.ranger.plugin.util.RangerRoles;
+import org.apache.ranger.plugin.util.RangerServiceNotFoundException;
+import org.apache.ranger.plugin.util.RangerUserStore;
+import org.apache.ranger.plugin.util.ServiceGdsInfo;
+import org.apache.ranger.plugin.util.ServicePolicies;
+import org.apache.ranger.plugin.util.ServiceTags;
+import org.apache.ranger.plugin.util.URLEncoderUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.Cookie;
import javax.ws.rs.core.NewCookie;
+
import java.io.UnsupportedEncodingException;
import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
@@ -46,1071 +58,1030 @@ import java.util.List;
import java.util.Map;
public class RangerAdminRESTClient extends AbstractRangerAdminClient {
- private static final Logger LOG = LoggerFactory.getLogger(RangerAdminRESTClient.class);
-
- private static final TypeReference<List<String>> TYPE_LIST_STRING = new TypeReference<List<String>>() {};
-
- private String serviceName;
- private String serviceNameUrlParam;
- private String pluginId;
- private String clusterName;
- private RangerRESTClient restClient;
- private RangerRESTUtils restUtils = new RangerRESTUtils();
- private boolean supportsPolicyDeltas;
- private boolean supportsTagDeltas;
- private boolean isRangerCookieEnabled;
- private String rangerAdminCookieName;
- private Cookie sessionId = null;
- private final String pluginCapabilities = Long.toHexString(new RangerPluginCapability().getPluginCapabilities());
-
- @Override
- public void init(String serviceName, String appId, String propertyPrefix, Configuration config) {
- super.init(serviceName, appId, propertyPrefix, config);
-
- this.serviceName = serviceName;
- this.pluginId = restUtils.getPluginId(serviceName, appId);
-
- String url = "";
- String tmpUrl = config.get(propertyPrefix + ".policy.rest.url");
- String sslConfigFileName = config.get(propertyPrefix + ".policy.rest.ssl.config.file");
- clusterName = config.get(propertyPrefix + ".access.cluster.name", "");
- if(StringUtil.isEmpty(clusterName)){
- clusterName =config.get(propertyPrefix + ".ambari.cluster.name", "");
- if (StringUtil.isEmpty(clusterName)) {
- if (config instanceof RangerPluginConfig) {
- clusterName = ((RangerPluginConfig)config).getClusterName();
- }
- }
- }
- int restClientConnTimeOutMs = config.getInt(propertyPrefix + ".policy.rest.client.connection.timeoutMs", 120 * 1000);
- int restClientReadTimeOutMs = config.getInt(propertyPrefix + ".policy.rest.client.read.timeoutMs", 30 * 1000);
- int restClientMaxRetryAttempts = config.getInt(propertyPrefix + ".policy.rest.client.max.retry.attempts", 3);
- int restClientRetryIntervalMs = config.getInt(propertyPrefix + ".policy.rest.client.retry.interval.ms", 1 * 1000);
-
- supportsPolicyDeltas = config.getBoolean(propertyPrefix + RangerCommonConstants.PLUGIN_CONFIG_SUFFIX_POLICY_DELTA, RangerCommonConstants.PLUGIN_CONFIG_SUFFIX_POLICY_DELTA_DEFAULT);
- supportsTagDeltas = config.getBoolean(propertyPrefix + RangerCommonConstants.PLUGIN_CONFIG_SUFFIX_TAG_DELTA, RangerCommonConstants.PLUGIN_CONFIG_SUFFIX_TAG_DELTA_DEFAULT);
- isRangerCookieEnabled = config.getBoolean(propertyPrefix + ".policy.rest.client.cookie.enabled", RangerCommonConstants.POLICY_REST_CLIENT_SESSION_COOKIE_ENABLED);
- rangerAdminCookieName = config.get(propertyPrefix + ".policy.rest.client.session.cookie.name", RangerCommonConstants.DEFAULT_COOKIE_NAME);
+ private static final Logger LOG = LoggerFactory.getLogger(RangerAdminRESTClient.class);
+
+ private static final TypeReference<List<String>> TYPE_LIST_STRING = new TypeReference<List<String>>() {};
+
+ private final String pluginCapabilities = Long.toHexString(new RangerPluginCapability().getPluginCapabilities());
+ private final RangerRESTUtils restUtils = new RangerRESTUtils();
+ private String serviceName;
+ private String serviceNameUrlParam;
+ private String pluginId;
+ private String clusterName;
+ private RangerRESTClient restClient;
+ private boolean supportsPolicyDeltas;
+ private boolean supportsTagDeltas;
+ private boolean isRangerCookieEnabled;
+ private String rangerAdminCookieName;
+ private Cookie sessionId;
+
+ @Override
+ public void init(String serviceName, String appId, String propertyPrefix, Configuration config) {
+ super.init(serviceName, appId, propertyPrefix, config);
+
+ this.serviceName = serviceName;
+ this.pluginId = restUtils.getPluginId(serviceName, appId);
+
+ String url = "";
+ String tmpUrl = config.get(propertyPrefix + ".policy.rest.url");
+ String sslConfigFileName = config.get(propertyPrefix + ".policy.rest.ssl.config.file");
+
+ clusterName = config.get(propertyPrefix + ".access.cluster.name", "");
+
+ if (StringUtil.isEmpty(clusterName)) {
+ clusterName = config.get(propertyPrefix + ".ambari.cluster.name", "");
+
+ if (StringUtil.isEmpty(clusterName)) {
+ if (config instanceof RangerPluginConfig) {
+ clusterName = ((RangerPluginConfig) config).getClusterName();
+ }
+ }
+ }
+
+ int restClientConnTimeOutMs = config.getInt(propertyPrefix + ".policy.rest.client.connection.timeoutMs", 120 * 1000);
+ int restClientReadTimeOutMs = config.getInt(propertyPrefix + ".policy.rest.client.read.timeoutMs", 30 * 1000);
+ int restClientMaxRetryAttempts = config.getInt(propertyPrefix + ".policy.rest.client.max.retry.attempts", 3);
+ int restClientRetryIntervalMs = config.getInt(propertyPrefix + ".policy.rest.client.retry.interval.ms", 1 * 1000);
+
+ supportsPolicyDeltas = config.getBoolean(propertyPrefix + RangerCommonConstants.PLUGIN_CONFIG_SUFFIX_POLICY_DELTA, RangerCommonConstants.PLUGIN_CONFIG_SUFFIX_POLICY_DELTA_DEFAULT);
+ supportsTagDeltas = config.getBoolean(propertyPrefix + RangerCommonConstants.PLUGIN_CONFIG_SUFFIX_TAG_DELTA, RangerCommonConstants.PLUGIN_CONFIG_SUFFIX_TAG_DELTA_DEFAULT);
+ isRangerCookieEnabled = config.getBoolean(propertyPrefix + ".policy.rest.client.cookie.enabled", RangerCommonConstants.POLICY_REST_CLIENT_SESSION_COOKIE_ENABLED);
+ rangerAdminCookieName = config.get(propertyPrefix + ".policy.rest.client.session.cookie.name", RangerCommonConstants.DEFAULT_COOKIE_NAME);
if (!StringUtil.isEmpty(tmpUrl)) {
url = tmpUrl.trim();
}
+
if (url.endsWith("/")) {
url = url.substring(0, url.length() - 1);
}
- init(url, sslConfigFileName, restClientConnTimeOutMs , restClientReadTimeOutMs, restClientMaxRetryAttempts, restClientRetryIntervalMs, config);
+ init(url, sslConfigFileName, restClientConnTimeOutMs, restClientReadTimeOutMs, restClientMaxRetryAttempts, restClientRetryIntervalMs, config);
try {
this.serviceNameUrlParam = URLEncoderUtil.encodeURIParam(serviceName);
} catch (UnsupportedEncodingException e) {
- LOG.warn("Unsupported encoding, serviceName=" + serviceName);
+ LOG.warn("Unsupported encoding, serviceName={}", serviceName);
this.serviceNameUrlParam = serviceName;
}
- }
-
- @Override
- public ServicePolicies getServicePoliciesIfUpdated(final long lastKnownVersion, final long lastActivationTimeInMillis) throws Exception {
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAdminRESTClient.getServicePoliciesIfUpdated(" + lastKnownVersion + ", " + lastActivationTimeInMillis + ")");
- }
-
- final ServicePolicies ret;
- final UserGroupInformation user = MiscUtil.getUGILoginUser();
- final boolean isSecureMode = isKerberosEnabled(user);
- final Cookie sessionId = this.sessionId;
- final ClientResponse response;
-
- Map<String, String> queryParams = new HashMap<String, String>();
- queryParams.put(RangerRESTUtils.REST_PARAM_LAST_KNOWN_POLICY_VERSION, Long.toString(lastKnownVersion));
- queryParams.put(RangerRESTUtils.REST_PARAM_LAST_ACTIVATION_TIME, Long.toString(lastActivationTimeInMillis));
- queryParams.put(RangerRESTUtils.REST_PARAM_PLUGIN_ID, pluginId);
- queryParams.put(RangerRESTUtils.REST_PARAM_CLUSTER_NAME, clusterName);
- queryParams.put(RangerRESTUtils.REST_PARAM_SUPPORTS_POLICY_DELTAS, Boolean.toString(supportsPolicyDeltas));
- queryParams.put(RangerRESTUtils.REST_PARAM_CAPABILITIES, pluginCapabilities);
-
- if (isSecureMode) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Checking Service policy if updated as user : " + user);
- }
-
- response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
- try {
- String relativeURL = RangerRESTUtils.REST_URL_POLICY_GET_FOR_SECURE_SERVICE_IF_UPDATED + serviceNameUrlParam;
-
- return restClient.get(relativeURL, queryParams, sessionId);
- } catch (Exception e) {
- LOG.error("Failed to get response, Error is : "+e.getMessage());
- }
-
- return null;
- });
- } else {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Checking Service policy if updated with old api call");
- }
- String relativeURL = RangerRESTUtils.REST_URL_POLICY_GET_FOR_SERVICE_IF_UPDATED + serviceNameUrlParam;
- response = restClient.get(relativeURL, queryParams, sessionId);
- }
-
- checkAndResetSessionCookie(response);
-
- if (response == null || response.getStatus() == HttpServletResponse.SC_NOT_MODIFIED || response.getStatus() == HttpServletResponse.SC_NO_CONTENT) {
- if (response == null) {
- LOG.error("Error getting policies; Received NULL response!!. secureMode=" + isSecureMode + ", user=" + user + ", serviceName=" + serviceName);
- } else {
- RESTResponse resp = RESTResponse.fromClientResponse(response);
- if (LOG.isDebugEnabled()) {
- LOG.debug("No change in policies. secureMode=" + isSecureMode + ", user=" + user
- + ", response=" + resp + ", serviceName=" + serviceName
- + ", " + "lastKnownVersion=" + lastKnownVersion
- + ", " + "lastActivationTimeInMillis=" + lastActivationTimeInMillis);
- }
- }
- ret = null;
- } else if (response.getStatus() == HttpServletResponse.SC_OK) {
- ret = JsonUtilsV2.readResponse(response, ServicePolicies.class);
- } else if (response.getStatus() == HttpServletResponse.SC_NOT_FOUND) {
- ret = null;
- LOG.error("Error getting policies; service not found. secureMode=" + isSecureMode + ", user=" + user
- + ", response=" + response.getStatus() + ", serviceName=" + serviceName
- + ", " + "lastKnownVersion=" + lastKnownVersion
- + ", " + "lastActivationTimeInMillis=" + lastActivationTimeInMillis);
- String exceptionMsg = response.hasEntity() ? response.getEntity(String.class) : null;
-
- RangerServiceNotFoundException.throwExceptionIfServiceNotFound(serviceName, exceptionMsg);
-
- LOG.warn("Received 404 error code with body:[" + exceptionMsg + "], Ignoring");
- } else {
- RESTResponse resp = RESTResponse.fromClientResponse(response);
- LOG.warn("Error getting policies. secureMode=" + isSecureMode + ", user=" + user + ", response=" + resp + ", serviceName=" + serviceName);
- ret = null;
- }
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAdminRESTClient.getServicePoliciesIfUpdated(" + lastKnownVersion + ", " + lastActivationTimeInMillis + "): " + ret);
- }
-
- return ret;
- }
-
- @Override
- public RangerRoles getRolesIfUpdated(final long lastKnownRoleVersion, final long lastActivationTimeInMillis) throws Exception {
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAdminRESTClient.getRolesIfUpdated(" + lastKnownRoleVersion + ", " + lastActivationTimeInMillis + ")");
- }
-
- final RangerRoles ret;
-
- final UserGroupInformation user = MiscUtil.getUGILoginUser();
- final boolean isSecureMode = isKerberosEnabled(user);
- final Cookie sessionId = this.sessionId;
- final ClientResponse response;
-
- Map<String, String> queryParams = new HashMap<String, String>();
- queryParams.put(RangerRESTUtils.REST_PARAM_LAST_KNOWN_ROLE_VERSION, Long.toString(lastKnownRoleVersion));
- queryParams.put(RangerRESTUtils.REST_PARAM_LAST_ACTIVATION_TIME, Long.toString(lastActivationTimeInMillis));
- queryParams.put(RangerRESTUtils.REST_PARAM_PLUGIN_ID, pluginId);
- queryParams.put(RangerRESTUtils.REST_PARAM_CLUSTER_NAME, clusterName);
- queryParams.put(RangerRESTUtils.REST_PARAM_CAPABILITIES, pluginCapabilities);
-
- if (isSecureMode) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Checking Roles updated as user : " + user);
- }
- response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
- try {
- String relativeURL = RangerRESTUtils.REST_URL_SERVICE_SERCURE_GET_USER_GROUP_ROLES + serviceNameUrlParam;
-
- return restClient.get(relativeURL, queryParams, sessionId);
- } catch (Exception e) {
- LOG.error("Failed to get response, Error is : "+e.getMessage());
- }
-
- return null;
- });
- } else {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Checking Roles updated as user : " + user);
- }
- String relativeURL = RangerRESTUtils.REST_URL_SERVICE_GET_USER_GROUP_ROLES + serviceNameUrlParam;
- response = restClient.get(relativeURL, queryParams, sessionId);
- }
-
- checkAndResetSessionCookie(response);
-
- if (response == null || response.getStatus() == HttpServletResponse.SC_NOT_MODIFIED || response.getStatus() == HttpServletResponse.SC_NO_CONTENT) {
- if (response == null) {
- LOG.error("Error getting Roles; Received NULL response!!. secureMode=" + isSecureMode + ", user=" + user + ", serviceName=" + serviceName);
- } else {
- RESTResponse resp = RESTResponse.fromClientResponse(response);
- if (LOG.isDebugEnabled()) {
- LOG.debug("No change in Roles. secureMode=" + isSecureMode + ", user=" + user
- + ", response=" + resp + ", serviceName=" + serviceName
- + ", " + "lastKnownRoleVersion=" + lastKnownRoleVersion
- + ", " + "lastActivationTimeInMillis=" + lastActivationTimeInMillis);
- }
- }
- ret = null;
- } else if (response.getStatus() == HttpServletResponse.SC_OK) {
- ret = JsonUtilsV2.readResponse(response, RangerRoles.class);
- } else if (response.getStatus() == HttpServletResponse.SC_NOT_FOUND) {
- ret = null;
- LOG.error("Error getting Roles; service not found. secureMode=" + isSecureMode + ", user=" + user
- + ", response=" + response.getStatus() + ", serviceName=" + serviceName
- + ", " + "lastKnownRoleVersion=" + lastKnownRoleVersion
- + ", " + "lastActivationTimeInMillis=" + lastActivationTimeInMillis);
- String exceptionMsg = response.hasEntity() ? response.getEntity(String.class) : null;
-
- RangerServiceNotFoundException.throwExceptionIfServiceNotFound(serviceName, exceptionMsg);
-
- LOG.warn("Received 404 error code with body:[" + exceptionMsg + "], Ignoring");
- } else {
- RESTResponse resp = RESTResponse.fromClientResponse(response);
- LOG.warn("Error getting Roles. secureMode=" + isSecureMode + ", user=" + user + ", response=" + resp + ", serviceName=" + serviceName);
- ret = null;
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAdminRESTClient.getRolesIfUpdated(" + lastKnownRoleVersion + ", " + lastActivationTimeInMillis + "): ");
- }
-
- return ret;
- }
-
- @Override
- public RangerRole createRole(final RangerRole request) throws Exception {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAdminRESTClient.createRole(" + request + ")");
- }
-
- RangerRole ret = null;
-
- final ClientResponse response;
- UserGroupInformation user = MiscUtil.getUGILoginUser();
- boolean isSecureMode = isKerberosEnabled(user);
- String relativeURL = RangerRESTUtils.REST_URL_SERVICE_CREATE_ROLE;
- Cookie sessionId = this.sessionId;
-
- Map <String, String> queryParams = new HashMap<String, String> ();
- queryParams.put(RangerRESTUtils.SERVICE_NAME_PARAM, serviceNameUrlParam);
-
- if (isSecureMode) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("create role as user " + user);
- }
-
- response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
- try {
- return restClient.post(relativeURL, queryParams, request, sessionId);
- } catch (Exception e) {
- LOG.error("Failed to get response, Error is : "+e.getMessage());
- }
-
- return null;
- });
- } else {
- response = restClient.post(relativeURL, queryParams, request, sessionId);
- }
-
- checkAndResetSessionCookie(response);
-
- if(response != null && response.getStatus() != HttpServletResponse.SC_OK) {
- RESTResponse resp = RESTResponse.fromClientResponse(response);
- LOG.error("createRole() failed: HTTP status=" + response.getStatus() + ", message=" + resp.getMessage() + ", isSecure=" + isSecureMode + (isSecureMode ? (", user=" + user) : ""));
-
- if(response.getStatus()==HttpServletResponse.SC_UNAUTHORIZED) {
- throw new AccessControlException();
- }
-
- throw new Exception("HTTP " + response.getStatus() + " Error: " + resp.getMessage());
- } else if(response == null) {
- throw new Exception("unknown error during createRole. roleName=" + request.getName());
- } else {
- ret = JsonUtilsV2.readResponse(response, RangerRole.class);
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAdminRESTClient.createRole(" + request + ")");
- }
- return ret;
- }
-
- @Override
- public void dropRole(final String execUser, final String roleName) throws Exception {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAdminRESTClient.dropRole(" + roleName + ")");
- }
-
- final ClientResponse response;
- UserGroupInformation user = MiscUtil.getUGILoginUser();
- boolean isSecureMode = isKerberosEnabled(user);
- Cookie sessionId = this.sessionId;
-
- Map<String, String> queryParams = new HashMap<String, String>();
- queryParams.put(RangerRESTUtils.SERVICE_NAME_PARAM, serviceNameUrlParam);
- queryParams.put(RangerRESTUtils.REST_PARAM_EXEC_USER, execUser);
-
- String relativeURL = RangerRESTUtils.REST_URL_SERVICE_DROP_ROLE + roleName;
-
- if (isSecureMode) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("drop role as user " + user);
- }
- response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
- try {
- return restClient.delete(relativeURL, queryParams, sessionId);
- } catch (Exception e) {
- LOG.error("Failed to get response, Error is : "+e.getMessage());
- }
-
- return null;
- });
- } else {
- response = restClient.delete(relativeURL, queryParams, sessionId);
- }
-
- checkAndResetSessionCookie(response);
-
- if(response == null) {
- throw new Exception("unknown error during deleteRole. roleName=" + roleName);
- } else if(response.getStatus() != HttpServletResponse.SC_OK && response.getStatus() != HttpServletResponse.SC_NO_CONTENT) {
- RESTResponse resp = RESTResponse.fromClientResponse(response);
- LOG.error("createRole() failed: HTTP status=" + response.getStatus() + ", message=" + resp.getMessage() + ", isSecure=" + isSecureMode + (isSecureMode ? (", user=" + user) : ""));
-
- if(response.getStatus()==HttpServletResponse.SC_UNAUTHORIZED) {
- throw new AccessControlException();
- }
-
- throw new Exception("HTTP " + response.getStatus() + " Error: " + resp.getMessage());
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAdminRESTClient.deleteRole(" + roleName + ")");
- }
- }
-
- @Override
- public List<String> getUserRoles(final String execUser) throws Exception {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAdminRESTClient.getUserRoles(" + execUser + ")");
- }
-
- List<String> ret = null;
- String emptyString = "";
- final ClientResponse response;
- UserGroupInformation user = MiscUtil.getUGILoginUser();
- boolean isSecureMode = isKerberosEnabled(user);
- String relativeURL = RangerRESTUtils.REST_URL_SERVICE_GET_USER_ROLES + execUser;
- Cookie sessionId = this.sessionId;
-
- if (isSecureMode) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("get roles as user " + user);
- }
- response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
- try {
- return restClient.get(relativeURL, null, sessionId);
- } catch (Exception e) {
- LOG.error("Failed to get response, Error is : "+e.getMessage());
- }
-
- return null;
- });
- } else {
- response = restClient.get(relativeURL, null, sessionId);
- }
-
- checkAndResetSessionCookie(response);
-
- if(response != null) {
- if (response.getStatus() != HttpServletResponse.SC_OK) {
- RESTResponse resp = RESTResponse.fromClientResponse(response);
- LOG.error("getUserRoles() failed: HTTP status=" + response.getStatus() + ", message=" + resp.getMessage() + ", isSecure=" + isSecureMode + (isSecureMode ? (", user=" + user) : ""));
-
- if (response.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) {
- throw new AccessControlException();
- }
-
- throw new Exception("HTTP " + response.getStatus() + " Error: " + resp.getMessage());
- } else {
- ret = JsonUtilsV2.readResponse(response, TYPE_LIST_STRING);
- }
- } else {
- throw new Exception("unknown error during getUserRoles. execUser=" + execUser);
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAdminRESTClient.getUserRoles(" + execUser + ")");
- }
- return ret;
- }
-
- @Override
- public List<String> getAllRoles(final String execUser) throws Exception {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAdminRESTClient.getAllRoles()");
- }
-
- List<String> ret = null;
- String emptyString = "";
- final ClientResponse response;
- UserGroupInformation user = MiscUtil.getUGILoginUser();
- boolean isSecureMode = isKerberosEnabled(user);
- String relativeURL = RangerRESTUtils.REST_URL_SERVICE_GET_ALL_ROLES;
- Cookie sessionId = this.sessionId;
-
- Map<String, String> queryParams = new HashMap<String, String>();
- queryParams.put(RangerRESTUtils.SERVICE_NAME_PARAM, serviceNameUrlParam);
- queryParams.put(RangerRESTUtils.REST_PARAM_EXEC_USER, execUser);
-
- if (isSecureMode) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("get roles as user " + user);
- }
- response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
- try {
- return restClient.get(relativeURL, queryParams, sessionId);
- } catch (Exception e) {
- LOG.error("Failed to get response, Error is : "+e.getMessage());
- }
-
- return null;
- });
- } else {
- response = restClient.get(relativeURL, queryParams, sessionId);
- }
-
- checkAndResetSessionCookie(response);
-
- if(response != null) {
- if (response.getStatus() != HttpServletResponse.SC_OK) {
- RESTResponse resp = RESTResponse.fromClientResponse(response);
- LOG.error("getAllRoles() failed: HTTP status=" + response.getStatus() + ", message=" + resp.getMessage() + ", isSecure=" + isSecureMode + (isSecureMode ? (", user=" + user) : ""));
-
- if (response.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) {
- throw new AccessControlException();
- }
-
- throw new Exception("HTTP " + response.getStatus() + " Error: " + resp.getMessage());
- } else {
- ret = JsonUtilsV2.readResponse(response, TYPE_LIST_STRING);
- }
- } else {
- throw new Exception("unknown error during getAllRoles.");
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAdminRESTClient.getAllRoles()");
- }
- return ret;
- }
-
- @Override
- public RangerRole getRole(final String execUser, final String roleName) throws Exception {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAdminRESTClient.getPrincipalsForRole(" + roleName + ")");
- }
-
- RangerRole ret = null;
- final ClientResponse response;
- UserGroupInformation user = MiscUtil.getUGILoginUser();
- boolean isSecureMode = isKerberosEnabled(user);
- String relativeURL = RangerRESTUtils.REST_URL_SERVICE_GET_ROLE_INFO + roleName;
- Cookie sessionId = this.sessionId;
-
- Map<String, String> queryParams = new HashMap<String, String>();
- queryParams.put(RangerRESTUtils.SERVICE_NAME_PARAM, serviceNameUrlParam);
- queryParams.put(RangerRESTUtils.REST_PARAM_EXEC_USER, execUser);
-
- if (isSecureMode) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("get role info as user " + user);
- }
- response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
- try {
- return restClient.get(relativeURL, queryParams, sessionId);
- } catch (Exception e) {
- LOG.error("Failed to get response, Error is : "+e.getMessage());
- }
-
- return null;
- });
- } else {
- response = restClient.get(relativeURL, queryParams, sessionId);
- }
-
- checkAndResetSessionCookie(response);
-
- if(response != null) {
- if (response.getStatus() != HttpServletResponse.SC_OK) {
- RESTResponse resp = RESTResponse.fromClientResponse(response);
- LOG.error("getPrincipalsForRole() failed: HTTP status=" + response.getStatus() + ", message=" + resp.getMessage() + ", isSecure=" + isSecureMode + (isSecureMode ? (", user=" + user) : ""));
-
- if (response.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) {
- throw new AccessControlException();
- }
-
- throw new Exception("HTTP " + response.getStatus() + " Error: " + resp.getMessage());
- } else {
- ret = JsonUtilsV2.readResponse(response, RangerRole.class);
- }
- } else {
- throw new Exception("unknown error during getPrincipalsForRole. roleName=" + roleName);
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAdminRESTClient.getPrincipalsForRole(" + roleName + ")");
- }
- return ret;
- }
-
-
- @Override
- public void grantRole(final GrantRevokeRoleRequest request) throws Exception {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAdminRESTClient.grantRole(" + request + ")");
- }
-
- final ClientResponse response;
- UserGroupInformation user = MiscUtil.getUGILoginUser();
- boolean isSecureMode = isKerberosEnabled(user);
- String relativeURL = RangerRESTUtils.REST_URL_SERVICE_GRANT_ROLE + serviceNameUrlParam;
- Cookie sessionId = this.sessionId;
-
- if (isSecureMode) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("grant role as user " + user);
- }
- response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
- try {
- return restClient.put(relativeURL, request, sessionId);
- } catch (Exception e) {
- LOG.error("Failed to get response, Error is : "+e.getMessage());
- }
-
- return null;
- });
- } else {
- response = restClient.put(relativeURL, request, sessionId);
- }
-
- checkAndResetSessionCookie(response);
-
- if(response != null && response.getStatus() != HttpServletResponse.SC_OK) {
- RESTResponse resp = RESTResponse.fromClientResponse(response);
- LOG.error("grantRole() failed: HTTP status=" + response.getStatus() + ", message=" + resp.getMessage() + ", isSecure=" + isSecureMode + (isSecureMode ? (", user=" + user) : ""));
-
- if(response.getStatus()==HttpServletResponse.SC_UNAUTHORIZED) {
- throw new AccessControlException();
- }
-
- throw new Exception("HTTP " + response.getStatus() + " Error: " + resp.getMessage());
- } else if(response == null) {
- throw new Exception("unknown error during grantRole. serviceName=" + serviceName);
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAdminRESTClient.grantRole(" + request + ")");
- }
- }
-
- @Override
- public void revokeRole(final GrantRevokeRoleRequest request) throws Exception {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAdminRESTClient.revokeRole(" + request + ")");
- }
-
- final ClientResponse response;
- UserGroupInformation user = MiscUtil.getUGILoginUser();
- boolean isSecureMode = isKerberosEnabled(user);
- String relativeURL = RangerRESTUtils.REST_URL_SERVICE_REVOKE_ROLE + serviceNameUrlParam;
- Cookie sessionId = this.sessionId;
-
- if (isSecureMode) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("revoke role as user " + user);
- }
- response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
- try {
- return restClient.put(relativeURL, request, sessionId);
- } catch (Exception e) {
- LOG.error("Failed to get response, Error is : "+e.getMessage());
- }
-
- return null;
- });
- } else {
- response = restClient.put(relativeURL, request, sessionId);
- }
-
- checkAndResetSessionCookie(response);
-
- if(response != null && response.getStatus() != HttpServletResponse.SC_OK) {
- RESTResponse resp = RESTResponse.fromClientResponse(response);
- LOG.error("revokeRole() failed: HTTP status=" + response.getStatus() + ", message=" + resp.getMessage() + ", isSecure=" + isSecureMode + (isSecureMode ? (", user=" + user) : ""));
-
- if(response.getStatus()==HttpServletResponse.SC_UNAUTHORIZED) {
- throw new AccessControlException();
- }
-
- throw new Exception("HTTP " + response.getStatus() + " Error: " + resp.getMessage());
- } else if(response == null) {
- throw new Exception("unknown error during revokeRole. serviceName=" + serviceName);
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAdminRESTClient.revokeRole(" + request + ")");
- }
- }
-
- @Override
- public void grantAccess(final GrantRevokeRequest request) throws Exception {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAdminRESTClient.grantAccess(" + request + ")");
- }
-
- final ClientResponse response;
- UserGroupInformation user = MiscUtil.getUGILoginUser();
- boolean isSecureMode = isKerberosEnabled(user);
- Cookie sessionId = this.sessionId;
-
- Map<String, String> queryParams = new HashMap<String, String>();
- queryParams.put(RangerRESTUtils.REST_PARAM_PLUGIN_ID, pluginId);
-
- if (isSecureMode) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("grantAccess as user " + user);
- }
- response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
- try {
- String relativeURL = RangerRESTUtils.REST_URL_SECURE_SERVICE_GRANT_ACCESS + serviceNameUrlParam;
-
- return restClient.post(relativeURL, queryParams, request, sessionId);
- } catch (Exception e) {
- LOG.error("Failed to get response, Error is : "+e.getMessage());
- }
-
- return null;
- });
- } else {
- String relativeURL = RangerRESTUtils.REST_URL_SERVICE_GRANT_ACCESS + serviceNameUrlParam;
- response = restClient.post(relativeURL, queryParams, request, sessionId);
- }
-
- checkAndResetSessionCookie(response);
-
- if(response != null && response.getStatus() != HttpServletResponse.SC_OK) {
- RESTResponse resp = RESTResponse.fromClientResponse(response);
- LOG.error("grantAccess() failed: HTTP status=" + response.getStatus() + ", message=" + resp.getMessage() + ", isSecure=" + isSecureMode + (isSecureMode ? (", user=" + user) : ""));
-
- if(response.getStatus()==HttpServletResponse.SC_UNAUTHORIZED) {
- throw new AccessControlException();
- }
-
- throw new Exception("HTTP " + response.getStatus() + " Error: " + resp.getMessage());
- } else if(response == null) {
- throw new Exception("unknown error during grantAccess. serviceName=" + serviceName);
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAdminRESTClient.grantAccess(" + request + ")");
- }
- }
-
- @Override
- public void revokeAccess(final GrantRevokeRequest request) throws Exception {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAdminRESTClient.revokeAccess(" + request + ")");
- }
-
- final ClientResponse response;
- UserGroupInformation user = MiscUtil.getUGILoginUser();
- boolean isSecureMode = isKerberosEnabled(user);
- Cookie sessionId = this.sessionId;
-
- Map<String, String> queryParams = new HashMap<String, String>();
- queryParams.put(RangerRESTUtils.REST_PARAM_PLUGIN_ID, pluginId);
-
- if (isSecureMode) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("revokeAccess as user " + user);
- }
- response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
- try {
- String relativeURL = RangerRESTUtils.REST_URL_SECURE_SERVICE_REVOKE_ACCESS + serviceNameUrlParam;
-
- return restClient.post(relativeURL, queryParams, request, sessionId);
- } catch (Exception e) {
- LOG.error("Failed to get response, Error is : "+e.getMessage());
- }
-
- return null;
- });
- } else {
- String relativeURL = RangerRESTUtils.REST_URL_SERVICE_REVOKE_ACCESS + serviceNameUrlParam;
- response = restClient.post(relativeURL, queryParams, request, sessionId);
- }
-
- checkAndResetSessionCookie(response);
-
- if(response != null && response.getStatus() != HttpServletResponse.SC_OK) {
- RESTResponse resp = RESTResponse.fromClientResponse(response);
- LOG.error("revokeAccess() failed: HTTP status=" + response.getStatus() + ", message=" + resp.getMessage() + ", isSecure=" + isSecureMode + (isSecureMode ? (", user=" + user) : ""));
-
- if(response.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) {
- throw new AccessControlException();
- }
-
- throw new Exception("HTTP " + response.getStatus() + " Error: " + resp.getMessage());
- } else if(response == null) {
- throw new Exception("unknown error. revokeAccess(). serviceName=" + serviceName);
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAdminRESTClient.revokeAccess(" + request + ")");
- }
- }
-
- private void init(String url, String sslConfigFileName, int restClientConnTimeOutMs , int restClientReadTimeOutMs, int restClientMaxRetryAttempts, int restClientRetryIntervalMs, Configuration config) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAdminRESTClient.init(" + url + ", " + sslConfigFileName + ")");
- }
-
- restClient = new RangerRESTClient(url, sslConfigFileName, config);
- restClient.setRestClientConnTimeOutMs(restClientConnTimeOutMs);
- restClient.setRestClientReadTimeOutMs(restClientReadTimeOutMs);
- restClient.setMaxRetryAttempts(restClientMaxRetryAttempts);
- restClient.setRetryIntervalMs(restClientRetryIntervalMs);
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAdminRESTClient.init(" + url + ", " + sslConfigFileName + ")");
- }
- }
-
- @Override
- public ServiceTags getServiceTagsIfUpdated(final long lastKnownVersion, final long lastActivationTimeInMillis) throws Exception {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAdminRESTClient.getServiceTagsIfUpdated(" + lastKnownVersion + ", " + lastActivationTimeInMillis + "): ");
- }
-
- final ServiceTags ret;
-
- final UserGroupInformation user = MiscUtil.getUGILoginUser();
- final boolean isSecureMode = isKerberosEnabled(user);
- final ClientResponse response;
- final Cookie sessionId = this.sessionId;
-
- Map<String, String> queryParams = new HashMap<String, String>();
- queryParams.put(RangerRESTUtils.LAST_KNOWN_TAG_VERSION_PARAM, Long.toString(lastKnownVersion));
- queryParams.put(RangerRESTUtils.REST_PARAM_LAST_ACTIVATION_TIME, Long.toString(lastActivationTimeInMillis));
- queryParams.put(RangerRESTUtils.REST_PARAM_PLUGIN_ID, pluginId);
- queryParams.put(RangerRESTUtils.REST_PARAM_SUPPORTS_TAG_DELTAS, Boolean.toString(supportsTagDeltas));
- queryParams.put(RangerRESTUtils.REST_PARAM_CAPABILITIES, pluginCapabilities);
-
- if (isSecureMode) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("getServiceTagsIfUpdated as user " + user);
- }
- response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
- try {
- String relativeURL = RangerRESTUtils.REST_URL_GET_SECURE_SERVICE_TAGS_IF_UPDATED + serviceNameUrlParam;
-
- return restClient.get(relativeURL, queryParams, sessionId);
- } catch (Exception e) {
- LOG.error("Failed to get response, Error is : "+e.getMessage());
- }
-
- return null;
- });
- } else {
- String relativeURL = RangerRESTUtils.REST_URL_GET_SERVICE_TAGS_IF_UPDATED + serviceNameUrlParam;
- response = restClient.get(relativeURL, queryParams, sessionId);
- }
-
- checkAndResetSessionCookie(response);
-
- if (response == null || response.getStatus() == HttpServletResponse.SC_NOT_MODIFIED) {
- if (response == null) {
- LOG.error("Error getting tags; Received NULL response!!. secureMode=" + isSecureMode + ", user=" + user + ", serviceName=" + serviceName);
- } else {
- RESTResponse resp = RESTResponse.fromClientResponse(response);
- if (LOG.isDebugEnabled()) {
- LOG.debug("No change in tags. secureMode=" + isSecureMode + ", user=" + user
- + ", response=" + resp + ", serviceName=" + serviceName
- + ", " + "lastKnownVersion=" + lastKnownVersion
- + ", " + "lastActivationTimeInMillis=" + lastActivationTimeInMillis);
- }
- }
- ret = null;
- } else if (response.getStatus() == HttpServletResponse.SC_OK) {
- ret = JsonUtilsV2.readResponse(response, ServiceTags.class);
- } else if (response.getStatus() == HttpServletResponse.SC_NOT_FOUND) {
- ret = null;
- LOG.error("Error getting tags; service not found. secureMode=" + isSecureMode + ", user=" + user
- + ", response=" + response.getStatus() + ", serviceName=" + serviceName
- + ", " + "lastKnownVersion=" + lastKnownVersion
- + ", " + "lastActivationTimeInMillis=" + lastActivationTimeInMillis);
-
- String exceptionMsg = response.hasEntity() ? response.getEntity(String.class) : null;
- RangerServiceNotFoundException.throwExceptionIfServiceNotFound(serviceName, exceptionMsg);
- LOG.warn("Received 404 error code with body:[" + exceptionMsg + "], Ignoring");
- } else {
- RESTResponse resp = RESTResponse.fromClientResponse(response);
- LOG.warn("Error getting tags. secureMode=" + isSecureMode + ", user=" + user + ", response=" + resp + ", serviceName=" + serviceName);
- ret = null;
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAdminRESTClient.getServiceTagsIfUpdated(" + lastKnownVersion + ", " + lastActivationTimeInMillis + "): ");
- }
-
- return ret;
- }
-
- @Override
- public List<String> getTagTypes(String pattern) throws Exception {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAdminRESTClient.getTagTypes(" + pattern + "): ");
- }
-
- List<String> ret = null;
- String emptyString = "";
- UserGroupInformation user = MiscUtil.getUGILoginUser();
- boolean isSecureMode = isKerberosEnabled(user);
- Cookie sessionId = this.sessionId;
-
- Map<String, String> queryParams = new HashMap<String, String>();
- queryParams.put(RangerRESTUtils.SERVICE_NAME_PARAM, serviceNameUrlParam);
- queryParams.put(RangerRESTUtils.PATTERN_PARAM, pattern);
- String relativeURL = RangerRESTUtils.REST_URL_LOOKUP_TAG_NAMES;
-
- final ClientResponse response;
- if (isSecureMode) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("getTagTypes as user " + user);
- }
- response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
- try {
- return restClient.get(relativeURL, queryParams, sessionId);
- } catch (Exception e) {
- LOG.error("Failed to get response, Error is : "+e.getMessage());
- }
-
- return null;
- });
- } else {
- response = restClient.get(relativeURL, queryParams, sessionId);
- }
-
- checkAndResetSessionCookie(response);
-
- if(response != null && response.getStatus() == HttpServletResponse.SC_OK) {
- ret = JsonUtilsV2.readResponse(response, TYPE_LIST_STRING);
- } else {
- RESTResponse resp = RESTResponse.fromClientResponse(response);
- LOG.error("Error getting tags. response=" + resp + ", serviceName=" + serviceName + ", " + "pattern=" + pattern);
- throw new Exception(resp.getMessage());
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAdminRESTClient.getTagTypes(" + pattern + "): " + ret);
- }
-
- return ret;
- }
-
- @Override
- public RangerUserStore getUserStoreIfUpdated(long lastKnownUserStoreVersion, long lastActivationTimeInMillis) throws Exception {
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAdminRESTClient.getUserStoreIfUpdated(" + lastKnownUserStoreVersion + ", " + lastActivationTimeInMillis + ")");
- }
-
- final RangerUserStore ret;
- final UserGroupInformation user = MiscUtil.getUGILoginUser();
- final boolean isSecureMode = isKerberosEnabled(user);
- final ClientResponse response;
- final Cookie sessionId = this.sessionId;
-
- Map<String, String> queryParams = new HashMap<String, String>();
- queryParams.put(RangerRESTUtils.REST_PARAM_LAST_KNOWN_USERSTORE_VERSION, Long.toString(lastKnownUserStoreVersion));
- queryParams.put(RangerRESTUtils.REST_PARAM_LAST_ACTIVATION_TIME, Long.toString(lastActivationTimeInMillis));
- queryParams.put(RangerRESTUtils.REST_PARAM_PLUGIN_ID, pluginId);
- queryParams.put(RangerRESTUtils.REST_PARAM_CLUSTER_NAME, clusterName);
- queryParams.put(RangerRESTUtils.REST_PARAM_CAPABILITIES, pluginCapabilities);
-
- if (isSecureMode) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Checking UserStore updated as user : " + user);
- }
- response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
- try {
- String relativeURL = RangerRESTUtils.REST_URL_SERVICE_SERCURE_GET_USERSTORE + serviceNameUrlParam;
-
- return restClient.get(relativeURL, queryParams, sessionId);
- } catch (Exception e) {
- LOG.error("Failed to get response, Error is : "+e.getMessage());
- }
-
- return null;
- });
- } else {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Checking UserStore updated as user : " + user);
- }
- String relativeURL = RangerRESTUtils.REST_URL_SERVICE_GET_USERSTORE + serviceNameUrlParam;
- response = restClient.get(relativeURL, queryParams, sessionId);
- }
-
- checkAndResetSessionCookie(response);
-
- if (response == null || response.getStatus() == HttpServletResponse.SC_NOT_MODIFIED) {
- if (response == null) {
- LOG.error("Error getting UserStore; Received NULL response!!. secureMode=" + isSecureMode + ", user=" + user + ", serviceName=" + serviceName);
- } else {
- RESTResponse resp = RESTResponse.fromClientResponse(response);
- if (LOG.isDebugEnabled()) {
- LOG.debug("No change in UserStore. secureMode=" + isSecureMode + ", user=" + user
- + ", response=" + resp + ", serviceName=" + serviceName
- + ", " + "lastKnownUserStoreVersion=" + lastKnownUserStoreVersion
- + ", " + "lastActivationTimeInMillis=" + lastActivationTimeInMillis);
- }
- }
- ret = null;
- } else if (response.getStatus() == HttpServletResponse.SC_OK) {
- ret = JsonUtilsV2.readResponse(response, RangerUserStore.class);
- } else if (response.getStatus() == HttpServletResponse.SC_NOT_FOUND) {
- ret = null;
- LOG.error("Error getting UserStore; service not found. secureMode=" + isSecureMode + ", user=" + user
- + ", response=" + response.getStatus() + ", serviceName=" + serviceName
- + ", " + "lastKnownUserStoreVersion=" + lastKnownUserStoreVersion
- + ", " + "lastActivationTimeInMillis=" + lastActivationTimeInMillis);
- String exceptionMsg = response.hasEntity() ? response.getEntity(String.class) : null;
-
- RangerServiceNotFoundException.throwExceptionIfServiceNotFound(serviceName, exceptionMsg);
-
- LOG.warn("Received 404 error code with body:[" + exceptionMsg + "], Ignoring");
- } else {
- RESTResponse resp = RESTResponse.fromClientResponse(response);
- LOG.warn("Error getting UserStore. secureMode=" + isSecureMode + ", user=" + user + ", response=" + resp + ", serviceName=" + serviceName);
- ret = null;
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAdminRESTClient.getUserStoreIfUpdated(" + lastKnownUserStoreVersion + ", " + lastActivationTimeInMillis + "): ");
- }
-
- return ret;
- }
-
- @Override
- public ServiceGdsInfo getGdsInfoIfUpdated(long lastKnownVersion, long lastActivationTimeInMillis) throws Exception {
- LOG.debug("==> RangerAdminRESTClient.getGdsInfoIfUpdated({}, {})", lastKnownVersion, lastActivationTimeInMillis);
-
- final ServiceGdsInfo ret;
- final UserGroupInformation user = MiscUtil.getUGILoginUser();
- final boolean isSecureMode = isKerberosEnabled(user);
- final Map<String, String> queryParams = new HashMap<>();
- final ClientResponse response;
- Cookie sessionId = this.sessionId;
-
- queryParams.put(RangerRESTUtils.REST_PARAM_LAST_KNOWN_GDS_VERSION, Long.toString(lastKnownVersion));
- queryParams.put(RangerRESTUtils.REST_PARAM_LAST_ACTIVATION_TIME, Long.toString(lastActivationTimeInMillis));
- queryParams.put(RangerRESTUtils.REST_PARAM_PLUGIN_ID, pluginId);
- queryParams.put(RangerRESTUtils.REST_PARAM_CLUSTER_NAME, clusterName);
- queryParams.put(RangerRESTUtils.REST_PARAM_CAPABILITIES, pluginCapabilities);
-
- LOG.debug("Checking for updated GdsInfo: secureMode={}, user={}, serviceName={}" , isSecureMode, user, serviceName);
-
- if (isSecureMode) {
- response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
- try {
- String relativeURL = RangerRESTUtils.REST_URL_SERVICE_SECURE_GET_GDSINFO + serviceNameUrlParam;
-
- return restClient.get(relativeURL, queryParams, sessionId);
- } catch (Exception e) {
- LOG.error("Failed to get response", e);
- }
-
- return null;
- });
- } else {
- String relativeURL = RangerRESTUtils.REST_URL_SERVICE_GET_GDSINFO + serviceNameUrlParam;
-
- response = restClient.get(relativeURL, queryParams, sessionId);
- }
-
- checkAndResetSessionCookie(response);
-
- if (response == null) {
- ret = null;
-
- LOG.error("Error getting GdsInfo - received NULL response: secureMode={}, user={}, serviceName={}", isSecureMode, user, serviceName);
- } else if (response.getStatus() == HttpServletResponse.SC_NOT_MODIFIED) {
- ret = null;
-
- RESTResponse resp = RESTResponse.fromClientResponse(response);
-
- LOG.debug("No change in GdsInfo: secureMode={}, user={}, response={}, serviceName={}, lastKnownGdsVersion={}, lastActivationTimeInMillis={}",
- isSecureMode, user, resp, serviceName, lastKnownVersion, lastActivationTimeInMillis);
- } else if (response.getStatus() == HttpServletResponse.SC_OK) {
- ret = JsonUtilsV2.readResponse(response, ServiceGdsInfo.class);
- } else if (response.getStatus() == HttpServletResponse.SC_NOT_FOUND) {
- ret = null;
-
- LOG.error("Error getting GdsInfo - service not found: secureMode={}, user={}, response={}, serviceName={}, lastKnownGdsVersion={},lastActivationTimeInMillis={}",
- isSecureMode, user, response.getStatus(), serviceName, lastKnownVersion, lastActivationTimeInMillis);
-
- String exceptionMsg = response.hasEntity() ? response.getEntity(String.class) : null;
-
- RangerServiceNotFoundException.throwExceptionIfServiceNotFound(serviceName, exceptionMsg);
-
- LOG.warn("Received 404 error code with body:[{}], Ignoring", exceptionMsg);
- } else {
- ret = null;
-
- RESTResponse resp = RESTResponse.fromClientResponse(response);
-
- LOG.warn("Error getting GdsInfo: unexpected status code {}: secureMode={}, user={}, response={}, serviceName={}",
- response.getStatus(), isSecureMode, user, resp, serviceName);
- }
-
- LOG.debug("<== RangerAdminRESTClient.getGdsInfoIfUpdated({}, {}): ret={}", lastKnownVersion, lastActivationTimeInMillis, ret);
-
- return ret;
- }
+ }
+
+ @Override
+ public ServicePolicies getServicePoliciesIfUpdated(final long lastKnownVersion, final long lastActivationTimeInMillis) throws Exception {
+ LOG.debug("==> RangerAdminRESTClient.getServicePoliciesIfUpdated({}, {})", lastKnownVersion, lastActivationTimeInMillis);
+
+ final ServicePolicies ret;
+ final UserGroupInformation user = MiscUtil.getUGILoginUser();
+ final boolean isSecureMode = isKerberosEnabled(user);
+ final Cookie sessionId = this.sessionId;
+ final Map<String, String> queryParams = new HashMap<>();
+
+ queryParams.put(RangerRESTUtils.REST_PARAM_LAST_KNOWN_POLICY_VERSION, Long.toString(lastKnownVersion));
+ queryParams.put(RangerRESTUtils.REST_PARAM_LAST_ACTIVATION_TIME, Long.toString(lastActivationTimeInMillis));
+ queryParams.put(RangerRESTUtils.REST_PARAM_PLUGIN_ID, pluginId);
+ queryParams.put(RangerRESTUtils.REST_PARAM_CLUSTER_NAME, clusterName);
+ queryParams.put(RangerRESTUtils.REST_PARAM_SUPPORTS_POLICY_DELTAS, Boolean.toString(supportsPolicyDeltas));
+ queryParams.put(RangerRESTUtils.REST_PARAM_CAPABILITIES, pluginCapabilities);
+
+ final ClientResponse response;
+
+ if (isSecureMode) {
+ LOG.debug("Checking Service policy if updated as user : {}", user);
+
+ response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
+ try {
+ String relativeURL = RangerRESTUtils.REST_URL_POLICY_GET_FOR_SECURE_SERVICE_IF_UPDATED + serviceNameUrlParam;
+
+ return restClient.get(relativeURL, queryParams, sessionId);
+ } catch (Exception e) {
+ LOG.error("Failed to get response, Error is : {}", e.getMessage());
+ }
+
+ return null;
+ });
+ } else {
+ LOG.debug("Checking Service policy if updated with old api call");
+
+ String relativeURL = RangerRESTUtils.REST_URL_POLICY_GET_FOR_SERVICE_IF_UPDATED + serviceNameUrlParam;
+
+ response = restClient.get(relativeURL, queryParams, sessionId);
+ }
+
+ checkAndResetSessionCookie(response);
+
+ if (response == null || response.getStatus() == HttpServletResponse.SC_NOT_MODIFIED || response.getStatus() == HttpServletResponse.SC_NO_CONTENT) {
+ if (response == null) {
+ LOG.error("Error getting policies; Received NULL response!!. secureMode={}, user={}, serviceName={}", isSecureMode, user, serviceName);
+ } else {
+ RESTResponse resp = RESTResponse.fromClientResponse(response);
+
+ LOG.debug("No change in policies. secureMode={}, user={}, response={}, serviceName={}, lastKnownVersion={}, lastActivationTimeInMillis={}",
+ isSecureMode, user, resp, serviceName, lastKnownVersion, lastActivationTimeInMillis);
+ }
+
+ ret = null;
+ } else if (response.getStatus() == HttpServletResponse.SC_OK) {
+ ret = JsonUtilsV2.readResponse(response, ServicePolicies.class);
+ } else if (response.getStatus() == HttpServletResponse.SC_NOT_FOUND) {
+ ret = null;
+
+ LOG.error("Error getting policies; service not found. secureMode={}, user={}, response={}, serviceName={}, lastKnownVersion={}, lastActivationTimeInMillis={}",
+ isSecureMode, user, response.getStatus(), serviceName, lastKnownVersion, lastActivationTimeInMillis);
+
+ String exceptionMsg = response.hasEntity() ? response.getEntity(String.class) : null;
+
+ RangerServiceNotFoundException.throwExceptionIfServiceNotFound(serviceName, exceptionMsg);
+
+ LOG.warn("Received 404 error code with body:[{}], Ignoring", exceptionMsg);
+ } else {
+ RESTResponse resp = RESTResponse.fromClientResponse(response);
+
+ LOG.warn("Error getting policies. secureMode={}, user={}, response={}, serviceName={}", isSecureMode, user, resp, serviceName);
+
+ ret = null;
+ }
+
+ LOG.debug("<== RangerAdminRESTClient.getServicePoliciesIfUpdated({}, {}): {}", lastKnownVersion, lastActivationTimeInMillis, ret);
+
+ return ret;
+ }
+
+ @Override
+ public RangerRoles getRolesIfUpdated(final long lastKnownRoleVersion, final long lastActivationTimeInMillis) throws Exception {
+ LOG.debug("==> RangerAdminRESTClient.getRolesIfUpdated({}, {})", lastKnownRoleVersion, lastActivationTimeInMillis);
+
+ final RangerRoles ret;
+ final UserGroupInformation user = MiscUtil.getUGILoginUser();
+ final boolean isSecureMode = isKerberosEnabled(user);
+ final Cookie sessionId = this.sessionId;
+ final Map<String, String> queryParams = new HashMap<>();
+
+ queryParams.put(RangerRESTUtils.REST_PARAM_LAST_KNOWN_ROLE_VERSION, Long.toString(lastKnownRoleVersion));
+ queryParams.put(RangerRESTUtils.REST_PARAM_LAST_ACTIVATION_TIME, Long.toString(lastActivationTimeInMillis));
+ queryParams.put(RangerRESTUtils.REST_PARAM_PLUGIN_ID, pluginId);
+ queryParams.put(RangerRESTUtils.REST_PARAM_CLUSTER_NAME, clusterName);
+ queryParams.put(RangerRESTUtils.REST_PARAM_CAPABILITIES, pluginCapabilities);
+
+ final ClientResponse response;
+
+ if (isSecureMode) {
+ LOG.debug("Checking Roles updated as user : {}", user);
+
+ response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
+ try {
+ String relativeURL = RangerRESTUtils.REST_URL_SERVICE_SERCURE_GET_USER_GROUP_ROLES + serviceNameUrlParam;
+
+ return restClient.get(relativeURL, queryParams, sessionId);
+ } catch (Exception e) {
+ LOG.error("Failed to get response, Error is : {}", e.getMessage());
+ }
+
+ return null;
+ });
+ } else {
+ LOG.debug("Checking Roles updated as user : {}", user);
+
+ String relativeURL = RangerRESTUtils.REST_URL_SERVICE_GET_USER_GROUP_ROLES + serviceNameUrlParam;
+
+ response = restClient.get(relativeURL, queryParams, sessionId);
+ }
+
+ checkAndResetSessionCookie(response);
+
+ if (response == null || response.getStatus() == HttpServletResponse.SC_NOT_MODIFIED || response.getStatus() == HttpServletResponse.SC_NO_CONTENT) {
+ if (response == null) {
+ LOG.error("Error getting Roles; Received NULL response!!. secureMode={}, user={}, serviceName={}", isSecureMode, user, serviceName);
+ } else {
+ RESTResponse resp = RESTResponse.fromClientResponse(response);
+
+ LOG.debug("No change in Roles. secureMode={}, user={}, response={}, serviceName={}, lastKnownRoleVersion={}, lastActivationTimeInMillis={}",
+ isSecureMode, user, resp, serviceName, lastKnownRoleVersion, lastActivationTimeInMillis);
+ }
+
+ ret = null;
+ } else if (response.getStatus() == HttpServletResponse.SC_OK) {
+ ret = JsonUtilsV2.readResponse(response, RangerRoles.class);
+ } else if (response.getStatus() == HttpServletResponse.SC_NOT_FOUND) {
+ ret = null;
+
+ LOG.error("Error getting Roles; service not found. secureMode={}, user={}, response={}, serviceName={}, lastKnownRoleVersion={}, lastActivationTimeInMillis={}",
+ isSecureMode, user, response.getStatus(), serviceName, lastKnownRoleVersion, lastActivationTimeInMillis);
+
+ String exceptionMsg = response.hasEntity() ? response.getEntity(String.class) : null;
+
+ RangerServiceNotFoundException.throwExceptionIfServiceNotFound(serviceName, exceptionMsg);
+
+ LOG.warn("Received 404 error code with body:[{}], Ignoring", exceptionMsg);
+ } else {
+ RESTResponse resp = RESTResponse.fromClientResponse(response);
+
+ LOG.warn("Error getting Roles. secureMode={}, user={}, response={}, serviceName={}", isSecureMode, user, resp, serviceName);
+
+ ret = null;
+ }
+
+ LOG.debug("<== RangerAdminRESTClient.getRolesIfUpdated({}, {}): ", lastKnownRoleVersion, lastActivationTimeInMillis);
+
+ return ret;
+ }
+
+ @Override
+ public RangerRole createRole(final RangerRole request) throws Exception {
+ LOG.debug("==> RangerAdminRESTClient.createRole({})", request);
+
+ final RangerRole ret;
+ final UserGroupInformation user = MiscUtil.getUGILoginUser();
+ final boolean isSecureMode = isKerberosEnabled(user);
+ final String relativeURL = RangerRESTUtils.REST_URL_SERVICE_CREATE_ROLE;
+ final Cookie sessionId = this.sessionId;
+ final Map<String, String> queryParams = new HashMap<>();
+
+ queryParams.put(RangerRESTUtils.SERVICE_NAME_PARAM, serviceNameUrlParam);
+
+ final ClientResponse response;
+
+ if (isSecureMode) {
+ LOG.debug("create role as user {}", user);
+
+ response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
+ try {
+ return restClient.post(relativeURL, queryParams, request, sessionId);
+ } catch (Exception e) {
+ LOG.error("Failed to get response, Error is : {}", e.getMessage());
+ }
+
+ return null;
+ });
+ } else {
+ response = restClient.post(relativeURL, queryParams, request, sessionId);
+ }
+
+ checkAndResetSessionCookie(response);
+
+ if (response != null && response.getStatus() != HttpServletResponse.SC_OK) {
+ RESTResponse resp = RESTResponse.fromClientResponse(response);
+
+ LOG.error("createRole() failed: HTTP status={}, message={}, isSecure={}{}", response.getStatus(), resp.getMessage(), isSecureMode, (isSecureMode ? (", user=" + user) : ""));
+
+ if (response.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) {
+ throw new AccessControlException();
+ }
+
+ throw new Exception("HTTP " + response.getStatus() + " Error: " + resp.getMessage());
+ } else if (response == null) {
+ throw new Exception("unknown error during createRole. roleName=" + request.getName());
+ } else {
+ ret = JsonUtilsV2.readResponse(response, RangerRole.class);
+ }
+
+ LOG.debug("<== RangerAdminRESTClient.createRole({})", request);
+
+ return ret;
+ }
+
+ @Override
+ public void dropRole(final String execUser, final String roleName) throws Exception {
+ LOG.debug("==> RangerAdminRESTClient.dropRole({})", roleName);
+
+ final UserGroupInformation user = MiscUtil.getUGILoginUser();
+ final boolean isSecureMode = isKerberosEnabled(user);
+ final Cookie sessionId = this.sessionId;
+ final Map<String, String> queryParams = new HashMap<>();
+
+ queryParams.put(RangerRESTUtils.SERVICE_NAME_PARAM, serviceNameUrlParam);
+ queryParams.put(RangerRESTUtils.REST_PARAM_EXEC_USER, execUser);
+
+ final String relativeURL = RangerRESTUtils.REST_URL_SERVICE_DROP_ROLE + roleName;
+ final ClientResponse response;
+
+ if (isSecureMode) {
+ LOG.debug("drop role as user {}", user);
+
+ response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
+ try {
+ return restClient.delete(relativeURL, queryParams, sessionId);
+ } catch (Exception e) {
+ LOG.error("Failed to get response, Error is : {}", e.getMessage());
+ }
+
+ return null;
+ });
+ } else {
+ response = restClient.delete(relativeURL, queryParams, sessionId);
+ }
+
+ checkAndResetSessionCookie(response);
+
+ if (response == null) {
+ throw new Exception("unknown error during deleteRole. roleName=" + roleName);
+ } else if (response.getStatus() != HttpServletResponse.SC_OK && response.getStatus() != HttpServletResponse.SC_NO_CONTENT) {
+ RESTResponse resp = RESTResponse.fromClientResponse(response);
+
+ LOG.error("createRole() failed: HTTP status={}, message={}, isSecure={}{}", response.getStatus(), resp.getMessage(), isSecureMode, (isSecureMode ? (", user=" + user) : ""));
+
+ if (response.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) {
+ throw new AccessControlException();
+ }
+
+ throw new Exception("HTTP " + response.getStatus() + " Error: " + resp.getMessage());
+ }
+
+ LOG.debug("<== RangerAdminRESTClient.deleteRole({})", roleName);
+ }
+
+ @Override
+ public List<String> getAllRoles(final String execUser) throws Exception {
+ LOG.debug("==> RangerAdminRESTClient.getAllRoles()");
+
+ final UserGroupInformation user = MiscUtil.getUGILoginUser();
+ final boolean isSecureMode = isKerberosEnabled(user);
+ final String relativeURL = RangerRESTUtils.REST_URL_SERVICE_GET_ALL_ROLES;
+ final Cookie sessionId = this.sessionId;
+ final Map<String, String> queryParams = new HashMap<>();
+
+ queryParams.put(RangerRESTUtils.SERVICE_NAME_PARAM, serviceNameUrlParam);
+ queryParams.put(RangerRESTUtils.REST_PARAM_EXEC_USER, execUser);
+
+ final ClientResponse response;
+
+ if (isSecureMode) {
+ LOG.debug("get roles as user {}", user);
+
+ response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
+ try {
+ return restClient.get(relativeURL, queryParams, sessionId);
+ } catch (Exception e) {
+ LOG.error("Failed to get response, Error is : {}", e.getMessage());
+ }
+
+ return null;
+ });
+ } else {
+ response = restClient.get(relativeURL, queryParams, sessionId);
+ }
+
+ checkAndResetSessionCookie(response);
+
+ List<String> ret;
+
+ if (response != null) {
+ if (response.getStatus() != HttpServletResponse.SC_OK) {
+ RESTResponse resp = RESTResponse.fromClientResponse(response);
+
+ LOG.error("getAllRoles() failed: HTTP status={}, message={}, isSecure={}{}", response.getStatus(), resp.getMessage(), isSecureMode, (isSecureMode ? (", user=" + user) : ""));
+
+ if (response.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) {
+ throw new AccessControlException();
+ }
+
+ throw new Exception("HTTP " + response.getStatus() + " Error: " + resp.getMessage());
+ } else {
+ ret = JsonUtilsV2.readResponse(response, TYPE_LIST_STRING);
+ }
+ } else {
+ throw new Exception("unknown error during getAllRoles.");
+ }
+
+ LOG.debug("<== RangerAdminRESTClient.getAllRoles()");
+
+ return ret;
+ }
+
+ @Override
+ public List<String> getUserRoles(final String execUser) throws Exception {
+ LOG.debug("==> RangerAdminRESTClient.getUserRoles({})", execUser);
+
+ final UserGroupInformation user = MiscUtil.getUGILoginUser();
+ final boolean isSecureMode = isKerberosEnabled(user);
+ final String relativeURL = RangerRESTUtils.REST_URL_SERVICE_GET_USER_ROLES + execUser;
+ final Cookie sessionId = this.sessionId;
+ final ClientResponse response;
+
+ if (isSecureMode) {
+ LOG.debug("get roles as user {}", user);
+
+ response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
+ try {
+ return restClient.get(relativeURL, null, sessionId);
+ } catch (Exception e) {
+ LOG.error("Failed to get response, Error is : {}", e.getMessage());
+ }
+
+ return null;
+ });
+ } else {
+ response = restClient.get(relativeURL, null, sessionId);
+ }
+
+ checkAndResetSessionCookie(response);
+
+ List<String> ret;
+
+ if (response != null) {
+ if (response.getStatus() != HttpServletResponse.SC_OK) {
+ RESTResponse resp = RESTResponse.fromClientResponse(response);
+
+ LOG.error("getUserRoles() failed: HTTP status={}, message={}, isSecure={}{}", response.getStatus(), resp.getMessage(), isSecureMode, (isSecureMode ? (", user=" + user) : ""));
+
+ if (response.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) {
+ throw new AccessControlException();
+ }
+
+ throw new Exception("HTTP " + response.getStatus() + " Error: " + resp.getMessage());
+ } else {
+ ret = JsonUtilsV2.readResponse(response, TYPE_LIST_STRING);
+ }
+ } else {
+ throw new Exception("unknown error during getUserRoles. execUser=" + execUser);
+ }
+
+ LOG.debug("<== RangerAdminRESTClient.getUserRoles({})", execUser);
+
+ return ret;
+ }
+
+ @Override
+ public RangerRole getRole(final String execUser, final String roleName) throws Exception {
+ LOG.debug("==> RangerAdminRESTClient.getPrincipalsForRole({})", roleName);
+
+ final UserGroupInformation user = MiscUtil.getUGILoginUser();
+ final boolean isSecureMode = isKerberosEnabled(user);
+ final String relativeURL = RangerRESTUtils.REST_URL_SERVICE_GET_ROLE_INFO + roleName;
+ final Cookie sessionId = this.sessionId;
+ final Map<String, String> queryParams = new HashMap<>();
+ final ClientResponse response;
+
+ queryParams.put(RangerRESTUtils.SERVICE_NAME_PARAM, serviceNameUrlParam);
+ queryParams.put(RangerRESTUtils.REST_PARAM_EXEC_USER, execUser);
+
+ if (isSecureMode) {
+ LOG.debug("get role info as user {}", user);
+
+ response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
+ try {
+ return restClient.get(relativeURL, queryParams, sessionId);
+ } catch (Exception e) {
+ LOG.error("Failed to get response, Error is : {}", e.getMessage());
+ }
+
+ return null;
+ });
+ } else {
+ response = restClient.get(relativeURL, queryParams, sessionId);
+ }
+
+ checkAndResetSessionCookie(response);
+
+ RangerRole ret;
+
+ if (response != null) {
+ if (response.getStatus() != HttpServletResponse.SC_OK) {
+ RESTResponse resp = RESTResponse.fromClientResponse(response);
+
+ LOG.error("getPrincipalsForRole() failed: HTTP status={}, message={}, isSecure={}{}", response.getStatus(), resp.getMessage(), isSecureMode, (isSecureMode ? (", user=" + user) : ""));
+
+ if (response.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) {
+ throw new AccessControlException();
+ }
+
+ throw new Exception("HTTP " + response.getStatus() + " Error: " + resp.getMessage());
+ } else {
+ ret = JsonUtilsV2.readResponse(response, RangerRole.class);
+ }
+ } else {
+ throw new Exception("unknown error during getPrincipalsForRole. roleName=" + roleName);
+ }
+
+ LOG.debug("<== RangerAdminRESTClient.getPrincipalsForRole({})", roleName);
+
+ return ret;
+ }
+
+ @Override
+ public void grantRole(final GrantRevokeRoleRequest request) throws Exception {
+ LOG.debug("==> RangerAdminRESTClient.grantRole({})", request);
+
+ final UserGroupInformation user = MiscUtil.getUGILoginUser();
+ final boolean isSecureMode = isKerberosEnabled(user);
+ final String relativeURL = RangerRESTUtils.REST_URL_SERVICE_GRANT_ROLE + serviceNameUrlParam;
+ final Cookie sessionId = this.sessionId;
+ final ClientResponse response;
+
+ if (isSecureMode) {
+ LOG.debug("grant role as user {}", user);
+
+ response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
+ try {
+ return restClient.put(relativeURL, request, sessionId);
+ } catch (Exception e) {
+ LOG.error("Failed to get response, Error is : {}", e.getMessage());
+ }
+
+ return null;
+ });
+ } else {
+ response = restClient.put(relativeURL, request, sessionId);
+ }
+
+ checkAndResetSessionCookie(response);
+
+ if (response != null && response.getStatus() != HttpServletResponse.SC_OK) {
+ RESTResponse resp = RESTResponse.fromClientResponse(response);
+
+ LOG.error("grantRole() failed: HTTP status={}, message={}, isSecure={}{}", response.getStatus(), resp.getMessage(), isSecureMode, (isSecureMode ? (", user=" + user) : ""));
+
+ if (response.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) {
+ throw new AccessControlException();
+ }
+
+ throw new Exception("HTTP " + response.getStatus() + " Error: " + resp.getMessage());
+ } else if (response == null) {
+ throw new Exception("unknown error during grantRole. serviceName=" + serviceName);
+ }
+
+ LOG.debug("<== RangerAdminRESTClient.grantRole({})", request);
+ }
+
+ @Override
+ public void revokeRole(final GrantRevokeRoleRequest request) throws Exception {
+ LOG.debug("==> RangerAdminRESTClient.revokeRole({})", request);
+
+ final UserGroupInformation user = MiscUtil.getUGILoginUser();
+ final boolean isSecureMode = isKerberosEnabled(user);
+ final String relativeURL = RangerRESTUtils.REST_URL_SERVICE_REVOKE_ROLE + serviceNameUrlParam;
+ final Cookie sessionId = this.sessionId;
+ final ClientResponse response;
+
+ if (isSecureMode) {
+ LOG.debug("revoke role as user {}", user);
+
+ response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
+ try {
+ return restClient.put(relativeURL, request, sessionId);
+ } catch (Exception e) {
+ LOG.error("Failed to get response, Error is : {}", e.getMessage());
+ }
+
+ return null;
+ });
+ } else {
+ response = restClient.put(relativeURL, request, sessionId);
+ }
+
+ checkAndResetSessionCookie(response);
+
+ if (response != null && response.getStatus() != HttpServletResponse.SC_OK) {
+ RESTResponse resp = RESTResponse.fromClientResponse(response);
+
+ LOG.error("revokeRole() failed: HTTP status={}, message={}, isSecure={}{}", response.getStatus(), resp.getMessage(), isSecureMode, (isSecureMode ? (", user=" + user) : ""));
+
+ if (response.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) {
+ throw new AccessControlException();
+ }
+
+ throw new Exception("HTTP " + response.getStatus() + " Error: " + resp.getMessage());
+ } else if (response == null) {
+ throw new Exception("unknown error during revokeRole. serviceName=" + serviceName);
+ }
+
+ LOG.debug("<== RangerAdminRESTClient.revokeRole({})", request);
+ }
+
+ @Override
+ public void grantAccess(final GrantRevokeRequest request) throws Exception {
+ LOG.debug("==> RangerAdminRESTClient.grantAccess({})", request);
+
+ final UserGroupInformation user = MiscUtil.getUGILoginUser();
+ final boolean isSecureMode = isKerberosEnabled(user);
+ final Cookie sessionId = this.sessionId;
+ final Map<String, String> queryParams = new HashMap<>();
+
+ queryParams.put(RangerRESTUtils.REST_PARAM_PLUGIN_ID, pluginId);
+
+ final ClientResponse response;
+
+ if (isSecureMode) {
+ LOG.debug("grantAccess as user {}", user);
+
+ response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
+ try {
+ String relativeURL = RangerRESTUtils.REST_URL_SECURE_SERVICE_GRANT_ACCESS + serviceNameUrlParam;
+
+ return restClient.post(relativeURL, queryParams, request, sessionId);
+ } catch (Exception e) {
+ LOG.error("Failed to get response, Error is : {}", e.getMessage());
+ }
+
+ return null;
+ });
+ } else {
+ String relativeURL = RangerRESTUtils.REST_URL_SERVICE_GRANT_ACCESS + serviceNameUrlParam;
+
+ response = restClient.post(relativeURL, queryParams, request, sessionId);
+ }
+
+ checkAndResetSessionCookie(response);
+
+ if (response != null && response.getStatus() != HttpServletResponse.SC_OK) {
+ RESTResponse resp = RESTResponse.fromClientResponse(response);
+
+ LOG.error("grantAccess() failed: HTTP status={}, message={}, isSecure={}{}", response.getStatus(), resp.getMessage(), isSecureMode, (isSecureMode ? (", user=" + user) : ""));
+
+ if (response.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) {
+ throw new AccessControlException();
+ }
+
+ throw new Exception("HTTP " + response.getStatus() + " Error: " + resp.getMessage());
+ } else if (response == null) {
+ throw new Exception("unknown error during grantAccess. serviceName=" + serviceName);
+ }
+
+ LOG.debug("<== RangerAdminRESTClient.grantAccess({})", request);
+ }
+
+ @Override
+ public void revokeAccess(final GrantRevokeRequest request) throws Exception {
+ LOG.debug("==> RangerAdminRESTClient.revokeAccess({})", request);
+
+ final UserGroupInformation user = MiscUtil.getUGILoginUser();
+ final boolean isSecureMode = isKerberosEnabled(user);
+ final Cookie sessionId = this.sessionId;
+ final Map<String, String> queryParams = new HashMap<>();
+
+ queryParams.put(RangerRESTUtils.REST_PARAM_PLUGIN_ID, pluginId);
+
+ final ClientResponse response;
+
+ if (isSecureMode) {
+ LOG.debug("revokeAccess as user {}", user);
+
+ response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
+ try {
+ String relativeURL = RangerRESTUtils.REST_URL_SECURE_SERVICE_REVOKE_ACCESS + serviceNameUrlParam;
+
+ return restClient.post(relativeURL, queryParams, request, sessionId);
+ } catch (Exception e) {
+ LOG.error("Failed to get response, Error is : {}", e.getMessage());
+ }
+
+ return null;
+ });
+ } else {
+ String relativeURL = RangerRESTUtils.REST_URL_SERVICE_REVOKE_ACCESS + serviceNameUrlParam;
+
+ response = restClient.post(relativeURL, queryParams, request, sessionId);
+ }
+
+ checkAndResetSessionCookie(response);
+
+ if (response != null && response.getStatus() != HttpServletResponse.SC_OK) {
+ RESTResponse resp = RESTResponse.fromClientResponse(response);
+
+ LOG.error("revokeAccess() failed: HTTP status={}, message={}, isSecure={}{}", response.getStatus(), resp.getMessage(), isSecureMode, (isSecureMode ? (", user=" + user) : ""));
+
+ if (response.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) {
+ throw new AccessControlException();
+ }
+
+ throw new Exception("HTTP " + response.getStatus() + " Error: " + resp.getMessage());
+ } else if (response == null) {
+ throw new Exception("unknown error. revokeAccess(). serviceName=" + serviceName);
+ }
+
+ LOG.debug("<== RangerAdminRESTClient.revokeAccess({})", request);
+ }
+
+ @Override
+ public ServiceTags getServiceTagsIfUpdated(final long lastKnownVersion, final long lastActivationTimeInMillis) throws Exception {
+ LOG.debug("==> RangerAdminRESTClient.getServiceTagsIfUpdated({}, {}): ", lastKnownVersion, lastActivationTimeInMillis);
+
+ final UserGroupInformation user = MiscUtil.getUGILoginUser();
+ final boolean isSecureMode = isKerberosEnabled(user);
+ final Cookie sessionId = this.sessionId;
+ final Map<String, String> queryParams = new HashMap<>();
+
+ queryParams.put(RangerRESTUtils.LAST_KNOWN_TAG_VERSION_PARAM, Long.toString(lastKnownVersion));
+ queryParams.put(RangerRESTUtils.REST_PARAM_LAST_ACTIVATION_TIME, Long.toString(lastActivationTimeInMillis));
+ queryParams.put(RangerRESTUtils.REST_PARAM_PLUGIN_ID, pluginId);
+ queryParams.put(RangerRESTUtils.REST_PARAM_SUPPORTS_TAG_DELTAS, Boolean.toString(supportsTagDeltas));
+ queryParams.put(RangerRESTUtils.REST_PARAM_CAPABILITIES, pluginCapabilities);
+
+ final ClientResponse response;
+
+ if (isSecureMode) {
+ LOG.debug("getServiceTagsIfUpdated as user {}", user);
+
+ response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
+ try {
+ String relativeURL = RangerRESTUtils.REST_URL_GET_SECURE_SERVICE_TAGS_IF_UPDATED + serviceNameUrlParam;
+
+ return restClient.get(relativeURL, queryParams, sessionId);
+ } catch (Exception e) {
+ LOG.error("Failed to get response, Error is : {}", e.getMessage());
+ }
+
+ return null;
+ });
+ } else {
+ String relativeURL = RangerRESTUtils.REST_URL_GET_SERVICE_TAGS_IF_UPDATED + serviceNameUrlParam;
+
+ response = restClient.get(relativeURL, queryParams, sessionId);
+ }
+
+ checkAndResetSessionCookie(response);
+
+ final ServiceTags ret;
+
+ if (response == null || response.getStatus() == HttpServletResponse.SC_NOT_MODIFIED) {
+ if (response == null) {
+ LOG.error("Error getting tags; Received NULL response!!. secureMode={}, user={}, serviceName={}", isSecureMode, user, serviceName);
+ } else {
+ RESTResponse resp = RESTResponse.fromClientResponse(response);
+
+ LOG.debug("No change in tags. secureMode={}, user={}, response={}, serviceName={}, lastKnownVersion={}, lastActivationTimeInMillis={}",
+ isSecureMode, user, resp, serviceName, lastKnownVersion, lastActivationTimeInMillis);
+ }
+
+ ret = null;
+ } else if (response.getStatus() == HttpServletResponse.SC_OK) {
+ ret = JsonUtilsV2.readResponse(response, ServiceTags.class);
+ } else if (response.getStatus() == HttpServletResponse.SC_NOT_FOUND) {
+ ret = null;
+
+ LOG.error("Error getting tags; service not found. secureMode={}, user={}, response={}, serviceName={}, lastKnownVersion={}, lastActivationTimeInMillis={}",
+ isSecureMode, user, response.getStatus(), serviceName, lastKnownVersion, lastActivationTimeInMillis);
+
+ String exceptionMsg = response.hasEntity() ? response.getEntity(String.class) : null;
+
+ RangerServiceNotFoundException.throwExceptionIfServiceNotFound(serviceName, exceptionMsg);
+
+ LOG.warn("Received 404 error code with body:[{}], Ignoring", exceptionMsg);
+ } else {
+ RESTResponse resp = RESTResponse.fromClientResponse(response);
+
+ LOG.warn("Error getting tags. secureMode={}, user={}, response={}, serviceName={}", isSecureMode, user, resp, serviceName);
+
+ ret = null;
+ }
+
+ LOG.debug("<== RangerAdminRESTClient.getServiceTagsIfUpdated({}, {})", lastKnownVersion, lastActivationTimeInMillis);
+
+ return ret;
+ }
+
+ @Override
+ public List<String> getTagTypes(String pattern) throws Exception {
+ LOG.debug("==> RangerAdminRESTClient.getTagTypes({}): ", pattern);
+
+ final String relativeURL = RangerRESTUtils.REST_URL_LOOKUP_TAG_NAMES;
+ final UserGroupInformation user = MiscUtil.getUGILoginUser();
+ final boolean isSecureMode = isKerberosEnabled(user);
+ final Cookie sessionId = this.sessionId;
+ final Map<String, String> queryParams = new HashMap<>();
+
+ queryParams.put(RangerRESTUtils.SERVICE_NAME_PARAM, serviceNameUrlParam);
+ queryParams.put(RangerRESTUtils.PATTERN_PARAM, pattern);
+
+ final ClientResponse response;
+
+ if (isSecureMode) {
+ LOG.debug("getTagTypes as user {}", user);
+
+ response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
+ try {
+ return restClient.get(relativeURL, queryParams, sessionId);
+ } catch (Exception e) {
+ LOG.error("Failed to get response, Error is : {}", e.getMessage());
+ }
+
+ return null;
+ });
+ } else {
+ response = restClient.get(relativeURL, queryParams, sessionId);
+ }
+
+ checkAndResetSessionCookie(response);
+
+ List<String> ret;
+
+ if (response != null && response.getStatus() == HttpServletResponse.SC_OK) {
+ ret = JsonUtilsV2.readResponse(response, TYPE_LIST_STRING);
+ } else {
+ RESTResponse resp = RESTResponse.fromClientResponse(response);
+
+ LOG.error("Error getting tags. response={}, serviceName={}, pattern={}", resp, serviceName, pattern);
+
+ throw new Exception(resp.getMessage());
+ }
+
+ LOG.debug("<== RangerAdminRESTClient.getTagTypes({}): {}", pattern, ret);
+
+ return ret;
+ }
+
+ @Override
+ public RangerUserStore getUserStoreIfUpdated(long lastKnownUserStoreVersion, long lastActivationTimeInMillis) throws Exception {
+ LOG.debug("==> RangerAdminRESTClient.getUserStoreIfUpdated({}, {})", lastKnownUserStoreVersion, lastActivationTimeInMillis);
+
+ final UserGroupInformation user = MiscUtil.getUGILoginUser();
+ final boolean isSecureMode = isKerberosEnabled(user);
+ final Cookie sessionId = this.sessionId;
+ final Map<String, String> queryParams = new HashMap<>();
+
+ queryParams.put(RangerRESTUtils.REST_PARAM_LAST_KNOWN_USERSTORE_VERSION, Long.toString(lastKnownUserStoreVersion));
+ queryParams.put(RangerRESTUtils.REST_PARAM_LAST_ACTIVATION_TIME, Long.toString(lastActivationTimeInMillis));
+ queryParams.put(RangerRESTUtils.REST_PARAM_PLUGIN_ID, pluginId);
+ queryParams.put(RangerRESTUtils.REST_PARAM_CLUSTER_NAME, clusterName);
+ queryParams.put(RangerRESTUtils.REST_PARAM_CAPABILITIES, pluginCapabilities);
+
+ final ClientResponse response;
+
+ if (isSecureMode) {
+ LOG.debug("Checking UserStore updated as user : {}", user);
+
+ response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
+ try {
+ String relativeURL = RangerRESTUtils.REST_URL_SERVICE_SERCURE_GET_USERSTORE + serviceNameUrlParam;
+
+ return restClient.get(relativeURL, queryParams, sessionId);
+ } catch (Exception e) {
+ LOG.error("Failed to get response, Error is : {}", e.getMessage());
+ }
+
+ return null;
+ });
+ } else {
+ LOG.debug("Checking UserStore updated as user : {}", user);
+
+ String relativeURL = RangerRESTUtils.REST_URL_SERVICE_GET_USERSTORE + serviceNameUrlParam;
+
+ response = restClient.get(relativeURL, queryParams, sessionId);
+ }
- private void checkAndResetSessionCookie(ClientResponse response) {
- if (isRangerCookieEnabled) {
- if (response == null) {
- LOG.debug("checkAndResetSessionCookie(): RESETTING sessionId - response is null");
+ checkAndResetSessionCookie(response);
- sessionId = null;
- } else {
- int status = response.getStatus();
+ final RangerUserStore ret;
- if (status == HttpStatus.SC_OK || status == HttpStatus.SC_NO_CONTENT || status == HttpStatus.SC_NOT_MODIFIED) {
- Cookie newCookie = null;
+ if (response == null || response.getStatus() == HttpServletResponse.SC_NOT_MODIFIED) {
+ if (response == null) {
+ LOG.error("Error getting UserStore; Received NULL response!!. secureMode={}, user={}, serviceName={}", isSecureMode, user, serviceName);
+ } else {
+ RESTResponse resp = RESTResponse.fromClientResponse(response);
+
+ LOG.debug("No change in UserStore. secureMode={}, user={}, response={}, serviceName={}, lastKnownUserStoreVersion={}, lastActivationTimeInMillis={}",
+ isSecureMode, user, resp, serviceName, lastKnownUserStoreVersion, lastActivationTimeInMillis);
+ }
+
+ ret = null;
+ } else if (response.getStatus() == HttpServletResponse.SC_OK) {
+ ret = JsonUtilsV2.readResponse(response, RangerUserStore.class);
+ } else if (response.getStatus() == HttpServletResponse.SC_NOT_FOUND) {
+ ret = null;
+
+ LOG.error("Error getting UserStore; service not found. secureMode={}, user={}, response={}, serviceName={}, lastKnownUserStoreVersion={}, lastActivationTimeInMillis={}",
+ isSecureMode, user, response.getStatus(), serviceName, lastKnownUserStoreVersion, lastActivationTimeInMillis);
+
+ String exceptionMsg = response.hasEntity() ? response.getEntity(String.class) : null;
+
+ RangerServiceNotFoundException.throwExceptionIfServiceNotFound(serviceName, exceptionMsg);
+
+ LOG.warn("Received 404 error code with body:[{}], Ignoring", exceptionMsg);
+ } else {
+ RESTResponse resp = RESTResponse.fromClientResponse(response);
+
+ LOG.warn("Error getting UserStore. secureMode={}, user={}, response={}, serviceName={}", isSecureMode, user, resp, serviceName);
+
+ ret = null;
+ }
- for (NewCookie cookie : response.getCookies()) {
- if (cookie.getName().equalsIgnoreCase(rangerAdminCookieName)) {
- newCookie = cookie;
+ LOG.debug("<== RangerAdminRESTClient.getUserStoreIfUpdated({}, {}): ", lastKnownUserStoreVersion, lastActivationTimeInMillis);
- break;
- }
- }
+ return ret;
+ }
- if (sessionId == null || newCookie != null) {
- LOG.debug("checkAndResetSessionCookie(): status={}, sessionIdCookie={}, newCookie={}", status, sessionId, newCookie);
+ @Override
+ public ServiceGdsInfo getGdsInfoIfUpdated(long lastKnownVersion, long lastActivationTimeInMillis) throws Exception {
+ LOG.debug("==> RangerAdminRESTClient.getGdsInfoIfUpdated({}, {})", lastKnownVersion, lastActivationTimeInMillis);
- sessionId = newCookie;
- }
- } else {
- LOG.debug("checkAndResetSessionCookie(): RESETTING sessionId - status={}", status);
+ final UserGroupInformation user = MiscUtil.getUGILoginUser();
+ final boolean isSecureMode = isKerberosEnabled(user);
+ final Cookie sessionId = this.sessionId;
+ final Map<String, String> queryParams = new HashMap<>();
- sessionId = null;
- }
- }
- }
- }
+ queryParams.put(RangerRESTUtils.REST_PARAM_LAST_KNOWN_GDS_VERSION, Long.toString(lastKnownVersion));
+ queryParams.put(RangerRESTUtils.REST_PARAM_LAST_ACTIVATION_TIME, Long.toString(lastActivationTimeInMillis));
+ queryParams.put(RangerRESTUtils.REST_PARAM_PLUGIN_ID, pluginId);
+ queryParams.put(RangerRESTUtils.REST_PARAM_CLUSTER_NAME, clusterName);
+ queryParams.put(RangerRESTUtils.REST_PARAM_CAPABILITIES, pluginCapabilities);
+
+ LOG.debug("Checking for updated GdsInfo: secureMode={}, user={}, serviceName={}", isSecureMode, user, serviceName);
+
+ final ClientResponse response;
+
+ if (isSecureMode) {
+ response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
+ try {
+ String relativeURL = RangerRESTUtils.REST_URL_SERVICE_SECURE_GET_GDSINFO + serviceNameUrlParam;
+
+ return restClient.get(relativeURL, queryParams, sessionId);
+ } catch (Exception e) {
+ LOG.error("Failed to get response", e);
+ }
+
+ return null;
+ });
+ } else {
+ String relativeURL = RangerRESTUtils.REST_URL_SERVICE_GET_GDSINFO + serviceNameUrlParam;
+
+ response = restClient.get(relativeURL, queryParams, sessionId);
+ }
+
+ checkAndResetSessionCookie(response);
+
+ final ServiceGdsInfo ret;
+
+ if (response == null) {
+ ret = null;
+
+ LOG.error("Error getting GdsInfo - received NULL response: secureMode={}, user={}, serviceName={}", isSecureMode, user, serviceName);
+ } else if (response.getStatus() == HttpServletResponse.SC_NOT_MODIFIED) {
+ ret = null;
+
+ RESTResponse resp = RESTResponse.fromClientResponse(response);
+
+ LOG.debug("No change in GdsInfo: secureMode={}, user={}, response={}, serviceName={}, lastKnownGdsVersion={}, lastActivationTimeInMillis={}",
+ isSecureMode, user, resp, serviceName, lastKnownVersion, lastActivationTimeInMillis);
+ } else if (response.getStatus() == HttpServletResponse.SC_OK) {
+ ret = JsonUtilsV2.readResponse(response, ServiceGdsInfo.class);
+ } else if (response.getStatus() == HttpServletResponse.SC_NOT_FOUND) {
+ ret = null;
+
+ LOG.error("Error getting GdsInfo - service not found: secureMode={}, user={}, response={}, serviceName={}, lastKnownGdsVersion={},lastActivationTimeInMillis={}",
+ isSecureMode, user, response.getStatus(), serviceName, lastKnownVersion, lastActivationTimeInMillis);
+
+ String exceptionMsg = response.hasEntity() ? response.getEntity(String.class) : null;
+
+ RangerServiceNotFoundException.throwExceptionIfServiceNotFound(serviceName, exceptionMsg);
+
+ LOG.warn("Received 404 error code with body:[{}], Ignoring", exceptionMsg);
+ } else {
+ ret = null;
+
+ RESTResponse resp = RESTResponse.fromClientResponse(response);
+
+ LOG.warn("Error getting GdsInfo: unexpected status code {}: secureMode={}, user={}, response={}, serviceName={}",
+ response.getStatus(), isSecureMode, user, resp, serviceName);
+ }
+
+ LOG.debug("<== RangerAdminRESTClient.getGdsInfoIfUpdated({}, {}): ret={}", lastKnownVersion, lastActivationTimeInMillis, ret);
+
+ return ret;
+ }
+
+ private void init(String url, String sslConfigFileName, int restClientConnTimeOutMs, int restClientReadTimeOutMs, int restClientMaxRetryAttempts, int restClientRetryIntervalMs, Configuration config) {
+ LOG.debug("==> RangerAdminRESTClient.init({}, {})", url, sslConfigFileName);
+
+ restClient = new RangerRESTClient(url, sslConfigFileName, config);
+
+ restClient.setRestClientConnTimeOutMs(restClientConnTimeOutMs);
+ restClient.setRestClientReadTimeOutMs(restClientReadTimeOutMs);
+ restClient.setMaxRetryAttempts(restClientMaxRetryAttempts);
+ restClient.setRetryIntervalMs(restClientRetryIntervalMs);
+
+ LOG.debug("<== RangerAdminRESTClient.init({}, {})", url, sslConfigFileName);
+ }
+
+ private void checkAndResetSessionCookie(ClientResponse response) {
+ if (isRangerCookieEnabled) {
+ if (response == null) {
+ LOG.debug("checkAndResetSessionCookie(): RESETTING sessionId - response is null");
+
+ sessionId = null;
+ } else {
+ int status = response.getStatus();
+
+ if (status == HttpStatus.SC_OK || status == HttpStatus.SC_NO_CONTENT || status == HttpStatus.SC_NOT_MODIFIED) {
+ Cookie newCookie = null;
+
+ for (NewCookie cookie : response.getCookies()) {
+ if (cookie.getName().equalsIgnoreCase(rangerAdminCookieName)) {
+ newCookie = cookie;
+
+ break;
+ }
+ }
+
+ if (sessionId == null || newCookie != null) {
+ LOG.debug("checkAndResetSessionCookie(): status={}, sessionIdCookie={}, newCookie={}", status, sessionId, newCookie);
+
+ sessionId = newCookie;
+ }
+ } else {
+ LOG.debug("checkAndResetSessionCookie(): RESETTING sessionId - status={}", status);
+
+ sessionId = null;
+ }
+ }
+ }
+ }
}
diff --git a/agents-common/src/main/java/org/apache/ranger/admin/client/datatype/GrantRevokeData.java b/agents-common/src/main/java/org/apache/ranger/admin/client/datatype/GrantRevokeData.java
index 6d094e0ce..a2123715a 100644
--- a/agents-common/src/main/java/org/apache/ranger/admin/client/datatype/GrantRevokeData.java
+++ b/agents-common/src/main/java/org/apache/ranger/admin/client/datatype/GrantRevokeData.java
@@ -17,230 +17,218 @@
* under the License.
*/
- package org.apache.ranger.admin.client.datatype;
+package org.apache.ranger.admin.client.datatype;
-
-import java.util.List;
-import java.util.ArrayList;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-import org.apache.ranger.authorization.utils.StringUtil;
-import org.apache.ranger.plugin.util.JsonUtilsV2;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import org.apache.ranger.authorization.utils.StringUtil;
+import org.apache.ranger.plugin.util.JsonUtilsV2;
+import java.util.ArrayList;
+import java.util.List;
@JsonAutoDetect(getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE, fieldVisibility = Visibility.ANY)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonIgnoreProperties(ignoreUnknown = true)
public class GrantRevokeData implements java.io.Serializable {
- private static final long serialVersionUID = 1L;
-
- private String grantor;
- private String repositoryName;
- private String repositoryType;
- private String databases;
- private String tables;
- private String columns;
- private String columnFamilies;
- private List<PermMap> permMapList = new ArrayList<>();
-
- private static String WILDCARD_ASTERISK = "*";
-
- public GrantRevokeData() {
- }
-
- public String getGrantor() {
- return grantor;
- }
-
- public void setGrantor(String grantor) {
- this.grantor = grantor;
- }
-
- public String getRepositoryName() {
- return repositoryName;
- }
-
- public void setRepositoryName(String repositoryName) {
- this.repositoryName = repositoryName;
- }
-
- public String getRepositoryType() {
- return repositoryType;
- }
-
- public void setRepositoryType(String repositoryType) {
- this.repositoryType = repositoryType;
- }
-
- public String getDatabases() {
- return databases;
- }
-
- public void setDatabases(String databases) {
- this.databases = databases;
- }
-
- public String getTables() {
- return tables;
- }
-
- public void setTables(String tables) {
- this.tables = tables;
- }
-
- public String getColumns() {
- return columns;
- }
-
- public void setColumns(String columns) {
- this.columns = columns;
- }
-
- public String getColumnFamilies() {
- return columnFamilies;
- }
-
- public void setColumnFamilies(String columnFamilies) {
- this.columnFamilies = columnFamilies;
- }
-
- public List<PermMap> getPermMapList() {
- return permMapList;
- }
-
- public void setPermMapList(List<PermMap> permMapList) {
- this.permMapList = permMapList;
- }
-
-
- public void setHiveData(String grantor,
- String repositoryName,
- String databases,
- String tables,
- String columns,
- PermMap permMap) {
- this.grantor = grantor;
- this.repositoryName = repositoryName;
- this.repositoryType = "hive";
- this.databases = StringUtil.isEmpty(databases) ? WILDCARD_ASTERISK : databases;
- this.tables = StringUtil.isEmpty(tables) ? WILDCARD_ASTERISK : tables;
- this.columns = StringUtil.isEmpty(columns) ? WILDCARD_ASTERISK : columns;
- this.permMapList.add(permMap);
- }
-
- public void setHBaseData(String grantor,
- String repositoryName,
- String tables,
- String columns,
- String columnFamilies,
- PermMap permMap) {
- this.grantor = grantor;
- this.repositoryName = repositoryName;
- this.repositoryType = "hbase";
- this.tables = StringUtil.isEmpty(tables) ? WILDCARD_ASTERISK : tables;
- this.columns = StringUtil.isEmpty(columns) ? WILDCARD_ASTERISK : columns;
- this.columnFamilies = StringUtil.isEmpty(columnFamilies) ? WILDCARD_ASTERISK : columnFamilies;
- this.permMapList.add(permMap);
- }
-
- public String toJson() {
- try {
- return JsonUtilsV2.objToJson(this);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- return "";
- }
-
- @Override
- public String toString() {
- return toJson();
- }
-
- @JsonAutoDetect(getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE, fieldVisibility = Visibility.ANY)
- @JsonInclude(JsonInclude.Include.NON_EMPTY)
- @JsonIgnoreProperties(ignoreUnknown = true)
- public static class PermMap implements java.io.Serializable {
- private List<String> userList = new ArrayList<>();
- private List<String> groupList = new ArrayList<>();
- private List<String> permList = new ArrayList<>();
-
- public PermMap() {
- }
-
- public PermMap(String user, String group, String perm) {
- addUser(user);
- addGroup(group);
- addPerm(perm);
- }
-
- public PermMap(List<String> userList, List<String> groupList, List<String> permList) {
- copyList(userList, this.userList);
- copyList(groupList, this.groupList);
- copyList(permList, this.permList);
- }
-
- public List<String> getUserList() {
- return userList;
- }
-
- public List<String> getGroupList() {
- return groupList;
- }
-
- public List<String> getPermList() {
- return permList;
- }
-
- public void addUser(String user) {
- addToList(user, userList);
- }
-
- public void addGroup(String group) {
- addToList(group, groupList);
- }
-
- public void addPerm(String perm) {
- addToList(perm, permList);
- }
-
- private void addToList(String str, List<String> list) {
- if(list != null && !StringUtil.isEmpty(str)) {
- list.add(str);
- }
- }
-
- private void copyList(List<String> fromList, List<String> toList) {
- if(fromList != null && toList != null) {
- for(String str : fromList) {
- addToList(str, toList);
- }
- }
- }
-
- public String toJson() {
- try {
- return JsonUtilsV2.objToJson(this);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- return "";
- }
-
- @Override
- public String toString() {
- return toJson();
- }
- }
-
- public static void main(String[] args) {
- GrantRevokeData grData = new GrantRevokeData();
-
- System.out.println(grData.toString());
- }
+ private static final long serialVersionUID = 1L;
+ private static final String WILDCARD_ASTERISK = "*";
+
+ private String grantor;
+ private String repositoryName;
+ private String repositoryType;
+ private String databases;
+ private String tables;
+ private String columns;
+ private String columnFamilies;
+ private List<PermMap> permMapList = new ArrayList<>();
+
+ public GrantRevokeData() {
+ }
+
+ public static void main(String[] args) {
+ GrantRevokeData grData = new GrantRevokeData();
+
+ System.out.println(grData);
+ }
+
+ public String getGrantor() {
+ return grantor;
+ }
+
+ public void setGrantor(String grantor) {
+ this.grantor = grantor;
+ }
+
+ public String getRepositoryName() {
+ return repositoryName;
+ }
+
+ public void setRepositoryName(String repositoryName) {
+ this.repositoryName = repositoryName;
+ }
+
+ public String getRepositoryType() {
+ return repositoryType;
+ }
+
+ public void setRepositoryType(String repositoryType) {
+ this.repositoryType = repositoryType;
+ }
+
+ public String getDatabases() {
+ return databases;
+ }
+
+ public void setDatabases(String databases) {
+ this.databases = databases;
+ }
+
+ public String getTables() {
+ return tables;
+ }
+
+ public void setTables(String tables) {
+ this.tables = tables;
+ }
+
+ public String getColumns() {
+ return columns;
+ }
+
+ public void setColumns(String columns) {
+ this.columns = columns;
+ }
+
+ public String getColumnFamilies() {
+ return columnFamilies;
+ }
+
+ public void setColumnFamilies(String columnFamilies) {
+ this.columnFamilies = columnFamilies;
+ }
+
+ public List<PermMap> getPermMapList() {
+ return permMapList;
+ }
+
+ public void setPermMapList(List<PermMap> permMapList) {
+ this.permMapList = permMapList;
+ }
+
+ public void setHiveData(String grantor, String repositoryName, String databases, String tables, String columns, PermMap permMap) {
+ this.grantor = grantor;
+ this.repositoryName = repositoryName;
+ this.repositoryType = "hive";
+ this.databases = StringUtil.isEmpty(databases) ? WILDCARD_ASTERISK : databases;
+ this.tables = StringUtil.isEmpty(tables) ? WILDCARD_ASTERISK : tables;
+ this.columns = StringUtil.isEmpty(columns) ? WILDCARD_ASTERISK : columns;
+
+ this.permMapList.add(permMap);
+ }
+
+ public void setHBaseData(String grantor, String repositoryName, String tables, String columns, String columnFamilies, PermMap permMap) {
+ this.grantor = grantor;
+ this.repositoryName = repositoryName;
+ this.repositoryType = "hbase";
+ this.tables = StringUtil.isEmpty(tables) ? WILDCARD_ASTERISK : tables;
+ this.columns = StringUtil.isEmpty(columns) ? WILDCARD_ASTERISK : columns;
+ this.columnFamilies = StringUtil.isEmpty(columnFamilies) ? WILDCARD_ASTERISK : columnFamilies;
+
+ this.permMapList.add(permMap);
+ }
+
+ public String toJson() {
+ try {
+ return JsonUtilsV2.objToJson(this);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return "";
+ }
+
+ @Override
+ public String toString() {
+ return toJson();
+ }
+
+ @JsonAutoDetect(getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE, fieldVisibility = Visibility.ANY)
+ @JsonInclude(JsonInclude.Include.NON_EMPTY)
+ @JsonIgnoreProperties(ignoreUnknown = true)
+ public static class PermMap implements java.io.Serializable {
+ private List<String> userList = new ArrayList<>();
+ private List<String> groupList = new ArrayList<>();
+ private List<String> permList = new ArrayList<>();
+
+ public PermMap() {
+ }
+
+ public PermMap(String user, String group, String perm) {
+ addUser(user);
+ addGroup(group);
+ addPerm(perm);
+ }
+
+ public PermMap(List<String> userList, List<String> groupList, List<String> permList) {
+ copyList(userList, this.userList);
+ copyList(groupList, this.groupList);
+ copyList(permList, this.permList);
+ }
+
+ public List<String> getUserList() {
+ return userList;
+ }
+
+ public List<String> getGroupList() {
+ return groupList;
+ }
+
+ public List<String> getPermList() {
+ return permList;
+ }
+
+ public void addUser(String user) {
+ addToList(user, userList);
+ }
+
+ public void addGroup(String group) {
+ addToList(group, groupList);
+ }
+
+ public void addPerm(String perm) {
+ addToList(perm, permList);
+ }
+
+ public String toJson() {
+ try {
+ return JsonUtilsV2.objToJson(this);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return "";
+ }
+
+ @Override
+ public String toString() {
+ return toJson();
+ }
+
+ private void addToList(String str, List<String> list) {
+ if (list != null && !StringUtil.isEmpty(str)) {
+ list.add(str);
+ }
+ }
+
+ private void copyList(List<String> fromList, List<String> toList) {
+ if (fromList != null && toList != null) {
+ for (String str : fromList) {
+ addToList(str, toList);
+ }
+ }
+ }
+ }
}
diff --git a/agents-common/src/main/java/org/apache/ranger/admin/client/datatype/RESTResponse.java b/agents-common/src/main/java/org/apache/ranger/admin/client/datatype/RESTResponse.java
index 574f84f50..17c3628be 100644
--- a/agents-common/src/main/java/org/apache/ranger/admin/client/datatype/RESTResponse.java
+++ b/agents-common/src/main/java/org/apache/ranger/admin/client/datatype/RESTResponse.java
@@ -1,5 +1,4 @@
/**
- *
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -7,9 +6,9 @@
* 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
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* 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.
@@ -18,195 +17,192 @@
*/
package org.apache.ranger.admin.client.datatype;
-import java.util.List;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-import org.apache.ranger.authorization.utils.StringUtil;
-import org.apache.ranger.plugin.util.JsonUtilsV2;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.sun.jersey.api.client.ClientResponse;
+import org.apache.ranger.authorization.utils.StringUtil;
+import org.apache.ranger.plugin.util.JsonUtilsV2;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.sun.jersey.api.client.ClientResponse;
-
+import java.util.List;
@JsonAutoDetect(getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE, fieldVisibility = Visibility.ANY)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonIgnoreProperties(ignoreUnknown = true)
public class RESTResponse implements java.io.Serializable {
- private static final Logger LOG = LoggerFactory.getLogger(RESTResponse.class);
-
- /**
- * values for statusCode
- */
- public static final int STATUS_SUCCESS = 0;
- public static final int STATUS_ERROR = 1;
- public static final int STATUS_VALIDATION = 2;
- public static final int STATUS_WARN = 3;
- public static final int STATUS_INFO = 4;
- public static final int STATUS_PARTIAL_SUCCESS = 5;
- public static final int ResponseStatus_MAX = 5;
-
- private int httpStatusCode;
- private int statusCode;
- private String msgDesc;
- private List<Message> messageList;
-
-
- public int getHttpStatusCode() {
- return httpStatusCode;
- }
-
- public void setHttpStatusCode(int httpStatusCode) {
- this.httpStatusCode = httpStatusCode;
- }
-
- public int getStatusCode() {
- return statusCode;
- }
-
- public void setStatusCode(int statusCode) {
- this.statusCode = statusCode;
- }
-
- public String getMsgDesc() {
- return msgDesc;
- }
-
- public void setMsgDesc(String msgDesc) {
- this.msgDesc = msgDesc;
- }
-
- public List<Message> getMessageList() {
- return messageList;
- }
-
- public void setMessageList(List<Message> messageList) {
- this.messageList = messageList;
- }
-
- public String getMessage() {
- return StringUtil.isEmpty(msgDesc) ? ("HTTP " + httpStatusCode) : msgDesc;
- }
-
- public static RESTResponse fromClientResponse(ClientResponse response) {
- RESTResponse ret = null;
-
- String jsonString = response == null ? null : response.getEntity(String.class);
- int httpStatus = response == null ? 0 : response.getStatus();
-
- if(! StringUtil.isEmpty(jsonString)) {
- ret = RESTResponse.fromJson(jsonString);
- }
-
- if(ret == null) {
- ret = new RESTResponse();
- }
-
- ret.setHttpStatusCode(httpStatus);
-
- return ret;
- }
-
- public String toJson() {
- try {
- return JsonUtilsV2.objToJson(this);
- } catch (Exception e) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("toJson() failed", e);
- }
- }
-
- return "";
- }
-
- public static RESTResponse fromJson(String jsonString) {
- try {
- return JsonUtilsV2.jsonToObj(jsonString, RESTResponse.class);
- } catch (Exception e) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("fromJson('" + jsonString + "') failed", e);
- }
- }
-
- return null;
- }
-
- @Override
- public String toString() {
- return toJson();
- }
-
- @JsonAutoDetect(getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE, fieldVisibility = Visibility.ANY)
- @JsonInclude(JsonInclude.Include.NON_EMPTY)
- @JsonIgnoreProperties(ignoreUnknown = true)
- public static class Message implements java.io.Serializable {
- private String name;
- private String rbKey;
- private String message;
- private Long objectId;
- private String fieldName;
-
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getRbKey() {
- return rbKey;
- }
- public void setRbKey(String rbKey) {
- this.rbKey = rbKey;
- }
- public String getMessage() {
- return message;
- }
- public void setMessage(String message) {
- this.message = message;
- }
- public Long getObjectId() {
- return objectId;
- }
- public void setObjectId(Long objectId) {
- this.objectId = objectId;
- }
- public String getFieldName() {
- return fieldName;
- }
- public void setFieldName(String fieldName) {
- this.fieldName = fieldName;
- }
-
- public String toJson() {
- try {
- return JsonUtilsV2.objToJson(this);
- } catch (Exception e) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("toJson() failed", e);
- }
- }
-
- return "";
- }
-
- public static RESTResponse fromJson(String jsonString) {
- try {
- return JsonUtilsV2.jsonToObj(jsonString, RESTResponse.class);
- } catch (Exception e) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("fromJson('" + jsonString + "') failed", e);
- }
- }
-
- return null;
- }
-
- @Override
- public String toString() {
- return toJson();
- }
- }
+ private static final Logger LOG = LoggerFactory.getLogger(RESTResponse.class);
+
+ /**
+ * values for statusCode
+ */
+ public static final int STATUS_SUCCESS = 0;
+ public static final int STATUS_ERROR = 1;
+ public static final int STATUS_VALIDATION = 2;
+ public static final int STATUS_WARN = 3;
+ public static final int STATUS_INFO = 4;
+ public static final int STATUS_PARTIAL_SUCCESS = 5;
+ public static final int ResponseStatus_MAX = 5;
+
+ private int httpStatusCode;
+ private int statusCode;
+ private String msgDesc;
+ private List<Message> messageList;
+
+ public static RESTResponse fromClientResponse(ClientResponse response) {
+ RESTResponse ret = null;
+ String jsonString = response == null ? null : response.getEntity(String.class);
+ int httpStatus = response == null ? 0 : response.getStatus();
+
+ if (!StringUtil.isEmpty(jsonString)) {
+ ret = RESTResponse.fromJson(jsonString);
+ }
+
+ if (ret == null) {
+ ret = new RESTResponse();
+ }
+
+ ret.setHttpStatusCode(httpStatus);
+
+ return ret;
+ }
+
+ public static RESTResponse fromJson(String jsonString) {
+ try {
+ return JsonUtilsV2.jsonToObj(jsonString, RESTResponse.class);
+ } catch (Exception e) {
+ LOG.debug("fromJson('{}') failed", jsonString, e);
+ }
+
+ return null;
+ }
+
+ public int getHttpStatusCode() {
+ return httpStatusCode;
+ }
+
+ public void setHttpStatusCode(int httpStatusCode) {
+ this.httpStatusCode = httpStatusCode;
+ }
+
+ public int getStatusCode() {
+ return statusCode;
+ }
+
+ public void setStatusCode(int statusCode) {
+ this.statusCode = statusCode;
+ }
+
+ public String getMsgDesc() {
+ return msgDesc;
+ }
+
+ public void setMsgDesc(String msgDesc) {
+ this.msgDesc = msgDesc;
+ }
+
+ public List<Message> getMessageList() {
+ return messageList;
+ }
+
+ public void setMessageList(List<Message> messageList) {
+ this.messageList = messageList;
+ }
+
+ public String getMessage() {
+ return StringUtil.isEmpty(msgDesc) ? ("HTTP " + httpStatusCode) : msgDesc;
+ }
+
+ public String toJson() {
+ try {
+ return JsonUtilsV2.objToJson(this);
+ } catch (Exception e) {
+ LOG.debug("toJson() failed", e);
+ }
+
+ return "";
+ }
+
+ @Override
+ public String toString() {
+ return toJson();
+ }
+
+ @JsonAutoDetect(getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE, fieldVisibility = Visibility.ANY)
+ @JsonInclude(JsonInclude.Include.NON_EMPTY)
+ @JsonIgnoreProperties(ignoreUnknown = true)
+ public static class Message implements java.io.Serializable {
+ private String name;
+ private String rbKey;
+ private String message;
+ private Long objectId;
+ private String fieldName;
+
+ public static RESTResponse fromJson(String jsonString) {
+ try {
+ return JsonUtilsV2.jsonToObj(jsonString, RESTResponse.class);
+ } catch (Exception e) {
+ LOG.debug("fromJson('{}') failed", jsonString, e);
+ }
+
+ return null;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getRbKey() {
+ return rbKey;
+ }
+
+ public void setRbKey(String rbKey) {
+ this.rbKey = rbKey;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public Long getObjectId() {
+ return objectId;
+ }
+
+ public void setObjectId(Long objectId) {
+ this.objectId = objectId;
+ }
+
+ public String getFieldName() {
+ return fieldName;
+ }
+
+ public void setFieldName(String fieldName) {
+ this.fieldName = fieldName;
+ }
+
+ public String toJson() {
+ try {
+ return JsonUtilsV2.objToJson(this);
+ } catch (Exception e) {
+ LOG.debug("toJson() failed", e);
+ }
+
+ return "";
+ }
+
+ @Override
+ public String toString() {
+ return toJson();
+ }
+ }
}
diff --git a/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerAdminConfig.java b/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerAdminConfig.java
index 30a80f262..e8aaa3905 100644
--- a/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerAdminConfig.java
+++ b/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerAdminConfig.java
@@ -28,9 +28,20 @@ import java.security.KeyStore;
public class RangerAdminConfig extends RangerConfiguration {
private static final Logger LOG = LoggerFactory.getLogger(RangerAdminConfig.class);
- private static volatile RangerAdminConfig sInstance = null;
+ private static volatile RangerAdminConfig sInstance;
+
private final boolean isFipsEnabled;
+ private RangerAdminConfig() {
+ super();
+
+ addAdminResources();
+
+ String storeType = get(RangerConfigConstants.RANGER_KEYSTORE_TYPE, KeyStore.getDefaultType());
+
+ isFipsEnabled = StringUtils.equalsIgnoreCase("bcfks", storeType);
+ }
+
public static RangerAdminConfig getInstance() {
RangerAdminConfig ret = RangerAdminConfig.sInstance;
@@ -39,7 +50,8 @@ public class RangerAdminConfig extends RangerConfiguration {
ret = RangerAdminConfig.sInstance;
if (ret == null) {
- ret = RangerAdminConfig.sInstance = new RangerAdminConfig();
+ ret = new RangerAdminConfig();
+ RangerAdminConfig.sInstance = ret;
}
}
}
@@ -47,49 +59,33 @@ public class RangerAdminConfig extends RangerConfiguration {
return ret;
}
- private RangerAdminConfig() {
- super();
- addAdminResources();
- String storeType = get(RangerConfigConstants.RANGER_KEYSTORE_TYPE, KeyStore.getDefaultType());
- isFipsEnabled = StringUtils.equalsIgnoreCase("bcfks", storeType) ? true : false;
-
+ public boolean isFipsEnabled() {
+ return isFipsEnabled;
}
private boolean addAdminResources() {
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> addAdminResources()");
- }
+ LOG.debug("==> addAdminResources()");
String defaultCfg = "ranger-admin-default-site.xml";
String addlCfg = "ranger-admin-site.xml";
String coreCfg = "core-site.xml";
- boolean ret = true;
-
- if (!addResourceIfReadable(defaultCfg)) {
- ret = false;
- }
+ boolean ret = addResourceIfReadable(defaultCfg);
if (!addResourceIfReadable(addlCfg)) {
ret = false;
}
- if (!addResourceIfReadable(coreCfg)){
+ if (!addResourceIfReadable(coreCfg)) {
ret = false;
}
- if (! ret) {
+ if (!ret) {
LOG.error("Could not add ranger-admin resources to RangerAdminConfig.");
}
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== addAdminResources(), result=" + ret);
- }
+ LOG.debug("<== addAdminResources(), result={}", ret);
return ret;
}
-
- public boolean isFipsEnabled() {
- return isFipsEnabled;
- }
}
diff --git a/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerAuditConfig.java b/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerAuditConfig.java
index b1322074b..cd9751edd 100644
--- a/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerAuditConfig.java
+++ b/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerAuditConfig.java
@@ -37,25 +37,24 @@ public class RangerAuditConfig extends RangerConfiguration {
initSuccess = addAuditResources(serviceName);
}
- public boolean isInitSuccess() { return initSuccess; }
+ public boolean isInitSuccess() {
+ return initSuccess;
+ }
private boolean addAuditResources(String serviceName) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> addAuditResources()");
- }
+ LOG.debug("==> addAuditResources()");
String defaultCfg = "ranger-" + serviceName + "-audit.xml";
boolean ret = true;
if (!addResourceIfReadable(defaultCfg)) {
- LOG.error("Could not add " + defaultCfg + " to RangerAuditConfig.");
+ LOG.error("Could not add {} to RangerAuditConfig.", defaultCfg);
+
ret = false;
}
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== addAuditResources(), result=" + ret);
- }
+ LOG.debug("<== addAuditResources(), result={}", ret);
return ret;
}
diff --git a/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerChainedPluginConfig.java b/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerChainedPluginConfig.java
index ae8f01fed..b95e5b490 100644
--- a/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerChainedPluginConfig.java
+++ b/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerChainedPluginConfig.java
@@ -24,11 +24,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RangerChainedPluginConfig extends RangerPluginConfig {
-
private static final Logger LOG = LoggerFactory.getLogger(RangerChainedPluginConfig.class);
- private final String[] legacySSLProperties = new String[] {"xasecure.policymgr.clientssl.keystore", "xasecure.policymgr.clientssl.keystore.type", "xasecure.policymgr.clientssl.keystore.credential.file","xasecure.policymgr.clientssl.truststore", "xasecure.policymgr.clientssl.truststore.credential.file", "hadoop.security.credential.provider.path"};
- private final String[] chainedPluginPropertyPrefixes = new String[] { ".chained.services"};
+ private final String[] legacySSLProperties = new String[] {"xasecure.policymgr.clientssl.keystore", "xasecure.policymgr.clientssl.keystore.type", "xasecure.policymgr.clientssl.keystore.credential.file", "xasecure.policymgr.clientssl.truststore", "xasecure.policymgr.clientssl.truststore.credential.file", "hadoop.security.credential.provider.path"};
+ private final String[] chainedPluginPropertyPrefixes = new String[] {".chained.services"};
public RangerChainedPluginConfig(String serviceType, String serviceName, String appId, RangerPluginConfig sourcePluginConfig) {
super(serviceType, serviceName, appId, sourcePluginConfig);
@@ -48,35 +47,37 @@ public class RangerChainedPluginConfig extends RangerPluginConfig {
set(getPropertyPrefix() + ".service.name", serviceName);
}
+ @Override
+ public String toString() {
+ return this.getClass().getSimpleName() + " : { " + printProperties() + " }";
+ }
+
private void copyProperties(RangerPluginConfig sourcePluginConfig, String propertyPrefix) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> copyProperties: propertyPrefix:[" + propertyPrefix + "]");
- }
+ LOG.debug("==> copyProperties: propertyPrefix:[{}]", propertyPrefix);
+
for (String propName : sourcePluginConfig.getProperties().stringPropertyNames()) {
String value = sourcePluginConfig.get(propName);
if (value != null && propName.startsWith(propertyPrefix)) {
String suffix = propName.substring(propertyPrefix.length());
+
if (!isExcludedSuffix(suffix)) {
set(getPropertyPrefix() + suffix, value);
- if (LOG.isDebugEnabled()) {
- LOG.debug("set property:[" + getPropertyPrefix() + suffix + "] to value:[" + value + "]");
- }
+
+ LOG.debug("set property:[{}{}] to value:[{}]", getPropertyPrefix(), suffix, value);
} else {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Not copying property :[" + propName + "] value from sourcePluginConfig");
- }
+ LOG.debug("Not copying property :[{}] value from sourcePluginConfig", propName);
}
}
}
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== copyProperties: propertyPrefix:[" + propertyPrefix + "]");
- }
+
+ LOG.debug("<== copyProperties: propertyPrefix:[{}]", propertyPrefix);
}
private void copyLegacySSLProperties(RangerPluginConfig sourcePluginConfig) {
for (String legacyPropertyName : legacySSLProperties) {
String value = sourcePluginConfig.get(legacyPropertyName);
+
if (value != null) {
set(legacyPropertyName, value);
}
@@ -89,6 +90,7 @@ public class RangerChainedPluginConfig extends RangerPluginConfig {
if (value != null && propName.startsWith(propertyPrefix)) {
String suffix = propName.substring(propertyPrefix.length());
+
for (String chainedPropertyPrefix : chainedPluginPropertyPrefixes) {
if (StringUtils.startsWith(suffix, chainedPropertyPrefix)) {
set(getPropertyPrefix() + suffix, value);
@@ -104,26 +106,26 @@ public class RangerChainedPluginConfig extends RangerPluginConfig {
return true;
}
}
+
return false;
}
private String printProperties() {
- StringBuilder sb = new StringBuilder();
- boolean seenOneProp = false;
+ StringBuilder sb = new StringBuilder();
+ boolean seenOneProp = false;
+
for (String propName : this.getProperties().stringPropertyNames()) {
String value = this.get(propName);
+
if (!seenOneProp) {
seenOneProp = true;
} else {
sb.append(",\n");
}
+
sb.append("{ propertyName:[").append(propName).append("], propertyValue:[").append(value).append("] }");
}
- return sb.toString();
- }
- @Override
- public String toString() {
- return this.getClass().getSimpleName() + " : { " + printProperties() + " }";
+ return sb.toString();
}
}
diff --git a/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerConfigConstants.java b/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerConfigConstants.java
index 374c78c5e..1e999343e 100644
--- a/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerConfigConstants.java
+++ b/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerConfigConstants.java
@@ -20,30 +20,33 @@
package org.apache.ranger.authorization.hadoop.config;
public class RangerConfigConstants {
- //SECURITY CONFIG DEFAULTS
- public static final String RANGER_SERVICE_NAME = "ranger.plugin.<ServiceType>.service.name";
- public static final String RANGER_PLUGIN_POLICY_SOURCE_IMPL = "ranger.plugin.<ServiceType>.policy.source.impl";
- public static final String RANGER_PLUGIN_POLICY_SOURCE_IMPL_DEFAULT = "org.apache.ranger.admin.client.RangerAdminRESTClient";
- public static final String RANGER_PLUGIN_POLICY_REST_URL = "ranger.plugin.<ServiceType>.policy.rest.url";
- public static final String RANGER_PLUGIN_REST_SSL_CONFIG_FILE = "ranger.plugin.<ServiceType>.policy.rest.ssl.config.file";
- public static final String RANGER_PLUGIN_POLICY_POLLINVETERVALMS = "ranger.plugin.<ServiceType>.policy.pollIntervalMs";
- public static final String RANGER_PLUGIN_POLICY_CACHE_DIR = "ranger.plugin.<ServiceType>.policy.cache.dir";
- public static final String RANGER_PLUGIN_ADD_HADDOOP_AUTHORIZATION = "xasecure.add-hadoop-authorization";
- public static final String RANGER_KEYSTORE_TYPE = "ranger.keystore.file.type";
+ //SECURITY CONFIG DEFAULTS
+ public static final String RANGER_SERVICE_NAME = "ranger.plugin.<ServiceType>.service.name";
+ public static final String RANGER_PLUGIN_POLICY_SOURCE_IMPL = "ranger.plugin.<ServiceType>.policy.source.impl";
+ public static final String RANGER_PLUGIN_POLICY_SOURCE_IMPL_DEFAULT = "org.apache.ranger.admin.client.RangerAdminRESTClient";
+ public static final String RANGER_PLUGIN_POLICY_REST_URL = "ranger.plugin.<ServiceType>.policy.rest.url";
+ public static final String RANGER_PLUGIN_REST_SSL_CONFIG_FILE = "ranger.plugin.<ServiceType>.policy.rest.ssl.config.file";
+ public static final String RANGER_PLUGIN_POLICY_POLLINVETERVALMS = "ranger.plugin.<ServiceType>.policy.pollIntervalMs";
+ public static final String RANGER_PLUGIN_POLICY_CACHE_DIR = "ranger.plugin.<ServiceType>.policy.cache.dir";
+ public static final String RANGER_PLUGIN_ADD_HADDOOP_AUTHORIZATION = "xasecure.add-hadoop-authorization";
+ public static final String RANGER_KEYSTORE_TYPE = "ranger.keystore.file.type";
//CHANGE MAP CONSTANTS
- public static final String XASECURE_POLICYMGR_URL = "xasecure.<ServiceType>.policymgr.url";
- public static final String XASECURE_POLICYMGR_URL_LASTSTOREDFILE = "xasecure.<ServiceType>.policymgr.url.laststoredfile";
- public static final String XASECURE_POLICYMGR_GRL_RELOADINTERVALINMILLIS = "xasecure.<ServiceType>.policymgr.url.reloadIntervalInMillis";
- public static final String XASECURE_ADD_HADDOP_AUTHORZATION = "xasecure.add-hadoop-authorization";
- public static final String XASECURE_UPDATE_XAPOLICIES_ON_GRANT = "xasecure.<ServiceType>.update.xapolicies.on.grant.revoke";
+ public static final String XASECURE_POLICYMGR_URL = "xasecure.<ServiceType>.policymgr.url";
+ public static final String XASECURE_POLICYMGR_URL_LASTSTOREDFILE = "xasecure.<ServiceType>.policymgr.url.laststoredfile";
+ public static final String XASECURE_POLICYMGR_GRL_RELOADINTERVALINMILLIS = "xasecure.<ServiceType>.policymgr.url.reloadIntervalInMillis";
+ public static final String XASECURE_ADD_HADDOP_AUTHORZATION = "xasecure.add-hadoop-authorization";
+ public static final String XASECURE_UPDATE_XAPOLICIES_ON_GRANT = "xasecure.<ServiceType>.update.xapolicies.on.grant.revoke";
//Legacy Files
- public static final String XASECURE_AUDIT_FILE = "xasecure-audit.xml";
- public static final String XASECURE_SECURITY_FILE = "xasecure-<ServiceType>-security.xml";
- public static final String XASECURE_POLICYMGR_SSL_FILE = "/etc/<ServiceType>/conf/xasecure-policymgr-ssl.xml";
+ public static final String XASECURE_AUDIT_FILE = "xasecure-audit.xml";
+ public static final String XASECURE_SECURITY_FILE = "xasecure-<ServiceType>-security.xml";
+ public static final String XASECURE_POLICYMGR_SSL_FILE = "/etc/<ServiceType>/conf/xasecure-policymgr-ssl.xml";
//KNOX
- public static final String RANGER_KNOX_PLUGIN_POLICY_SOURCE_IMPL_DEFAULT = "org.apache.ranger.admin.client.RangerAdminJersey2RESTClient";
-}
+ public static final String RANGER_KNOX_PLUGIN_POLICY_SOURCE_IMPL_DEFAULT = "org.apache.ranger.admin.client.RangerAdminJersey2RESTClient";
+ private RangerConfigConstants() {
+ // to block instantiation
+ }
+}
diff --git a/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerConfiguration.java b/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerConfiguration.java
index e8937edd5..6dc4c8da9 100644
--- a/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerConfiguration.java
+++ b/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerConfiguration.java
@@ -17,88 +17,79 @@
* under the License.
*/
-
package org.apache.ranger.authorization.hadoop.config;
-import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Properties;
-
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Properties;
public class RangerConfiguration extends Configuration {
- private static final Logger LOG = LoggerFactory.getLogger(RangerConfiguration.class);
-
- protected RangerConfiguration() {
- super(false);
- }
-
- public boolean addResourceIfReadable(String aResourceName) {
- boolean ret = false;
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> addResourceIfReadable(" + aResourceName + ")");
- }
-
- URL fUrl = getFileLocation(aResourceName);
- if (fUrl != null) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("addResourceIfReadable(" + aResourceName + "): resource file is " + fUrl);
- }
- try {
- addResource(fUrl);
- ret = true;
- } catch (Exception e) {
- LOG.error("Unable to load the resource name [" + aResourceName + "]. Ignoring the resource:" + fUrl);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Resource loading failed for " + fUrl, e);
- }
- }
- } else {
- if(LOG.isDebugEnabled()) {
- LOG.debug("addResourceIfReadable(" + aResourceName + "): couldn't find resource file location");
- }
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== addResourceIfReadable(" + aResourceName + "), result=" + ret);
- }
- return ret;
- }
-
- public Properties getProperties() {
- return getProps();
- }
-
- private URL getFileLocation(String fileName) {
- URL lurl = null;
- if (!StringUtils.isEmpty(fileName)) {
- lurl = RangerConfiguration.class.getClassLoader().getResource(fileName);
-
- if (lurl == null ) {
- lurl = RangerConfiguration.class.getClassLoader().getResource("/" + fileName);
- }
-
- if (lurl == null ) {
- File f = new File(fileName);
- if (f.exists()) {
- try {
- lurl=f.toURI().toURL();
- } catch (MalformedURLException e) {
- LOG.error("Unable to load the resource name [" + fileName + "]. Ignoring the resource:" + f.getPath());
- }
- } else {
- if(LOG.isDebugEnabled()) {
- LOG.debug("Conf file path " + fileName + " does not exists");
- }
- }
- }
- }
- return lurl;
- }
+ private static final Logger LOG = LoggerFactory.getLogger(RangerConfiguration.class);
+
+ protected RangerConfiguration() {
+ super(false);
+ }
+
+ public boolean addResourceIfReadable(String aResourceName) {
+ LOG.debug("==> addResourceIfReadable({})", aResourceName);
+
+ boolean ret = false;
+ URL fUrl = getFileLocation(aResourceName);
+
+ if (fUrl != null) {
+ LOG.debug("addResourceIfReadable({}): resource file is {}", aResourceName, fUrl);
+
+ try {
+ addResource(fUrl);
+
+ ret = true;
+ } catch (Exception e) {
+ LOG.error("Unable to load the resource name [{}]. Ignoring the resource:{}", aResourceName, fUrl);
+
+ LOG.debug("Resource loading failed for {}", fUrl, e);
+ }
+ } else {
+ LOG.debug("addResourceIfReadable({}): couldn't find resource file location", aResourceName);
+ }
+
+ LOG.debug("<== addResourceIfReadable({}), result={}", aResourceName, ret);
+
+ return ret;
+ }
+
+ public Properties getProperties() {
+ return getProps();
+ }
+
+ private URL getFileLocation(String fileName) {
+ URL lurl = null;
+
+ if (!StringUtils.isEmpty(fileName)) {
+ lurl = RangerConfiguration.class.getClassLoader().getResource(fileName);
+
+ if (lurl == null) {
+ lurl = RangerConfiguration.class.getClassLoader().getResource("/" + fileName);
+ }
+
+ if (lurl == null) {
+ File f = new File(fileName);
+ if (f.exists()) {
+ try {
+ lurl = f.toURI().toURL();
+ } catch (MalformedURLException e) {
+ LOG.error("Unable to load the resource name [{}]. Ignoring the resource:{}", fileName, f.getPath());
+ }
+ } else {
+ LOG.debug("Conf file path {} does not exists", fileName);
+ }
+ }
+ }
+ return lurl;
+ }
}
diff --git a/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerLegacyConfigBuilder.java b/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerLegacyConfigBuilder.java
index 95aa57c52..d3f4deaf3 100644
--- a/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerLegacyConfigBuilder.java
+++ b/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerLegacyConfigBuilder.java
@@ -19,227 +19,220 @@
package org.apache.ranger.authorization.hadoop.config;
-import java.io.File;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-
import org.apache.hadoop.conf.Configuration;
import org.apache.ranger.plugin.store.EmbeddedServiceDefsUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.File;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
public class RangerLegacyConfigBuilder {
+ private static final Logger LOG = LoggerFactory.getLogger(RangerLegacyConfigBuilder.class);
+
+ static String serviceType;
+ static String legacyResource;
+
+ private RangerLegacyConfigBuilder() {
+ // to block instantiation
+ }
+
+ public static Configuration getSecurityConfig(String serviceType) {
+ RangerLegacyConfigBuilder.legacyResource = getPropertyName(RangerConfigConstants.XASECURE_SECURITY_FILE, serviceType);
+ RangerLegacyConfigBuilder.serviceType = serviceType;
+
+ Configuration ret = null;
+ Configuration legacyConfig = new Configuration();
+ URL legacyFileUrl = getFileURL(legacyResource);
+
+ LOG.debug("==> getSecurityConfig() {} FileName: {}", legacyResource, legacyFileUrl);
+
+ if (legacyFileUrl != null) {
+ legacyConfig.addResource(legacyFileUrl);
+ Configuration rangerDefaultProp = buildRangerSecurityConf(serviceType);
+ ret = mapLegacyConfigToRanger(rangerDefaultProp, legacyConfig);
+ }
+
+ LOG.debug("<== getSecurityConfig() {} FileName: {}", legacyResource, legacyFileUrl);
+
+ return ret;
+ }
+
+ public static URL getAuditConfig(String serviceType) throws Throwable {
+ RangerLegacyConfigBuilder.legacyResource = getPropertyName(RangerConfigConstants.XASECURE_AUDIT_FILE, serviceType);
+ RangerLegacyConfigBuilder.serviceType = serviceType;
+
+ URL ret;
+
+ try {
+ ret = getAuditResource(legacyResource);
+ } catch (Throwable t) {
+ throw t;
+ }
+
+ return ret;
+ }
+
+ public static URL getAuditResource(String fName) throws Throwable {
+ URL ret = null;
+
+ try {
+ for (String cfgFile : new String[] {"hive-site.xml", "hbase-site.xml", "hdfs-site.xml"}) {
+ String loc = getFileLocation(cfgFile);
+ if (loc != null) {
+ File f = new File(loc);
+ if (f.exists() && f.canRead()) {
+ File parentFile = new File(loc).getParentFile();
+ ret = new File(parentFile, RangerConfigConstants.XASECURE_AUDIT_FILE).toURI().toURL();
+ break;
+ }
+ }
+ }
+ } catch (Throwable t) {
+ LOG.error("Missing Ranger Audit configuration files...");
+ throw t;
+ }
+ return ret;
+ }
+
+ public static Configuration buildRangerSecurityConf(String serviceType) {
+ Configuration rangerConf = new Configuration();
+
+ rangerConf.set(getPropertyName(RangerConfigConstants.RANGER_SERVICE_NAME, serviceType), "");
+ if (EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_KNOX_NAME.equals(serviceType)) {
+ rangerConf.set(getPropertyName(RangerConfigConstants.RANGER_PLUGIN_POLICY_SOURCE_IMPL, serviceType), RangerConfigConstants.RANGER_KNOX_PLUGIN_POLICY_SOURCE_IMPL_DEFAULT);
+ } else {
+ rangerConf.set(getPropertyName(RangerConfigConstants.RANGER_PLUGIN_POLICY_SOURCE_IMPL, serviceType), "");
+ }
+ rangerConf.set(getPropertyName(RangerConfigConstants.RANGER_PLUGIN_POLICY_REST_URL, serviceType), "");
+ rangerConf.set(getPropertyName(RangerConfigConstants.RANGER_PLUGIN_REST_SSL_CONFIG_FILE, serviceType), getPropertyName(RangerConfigConstants.XASECURE_POLICYMGR_SSL_FILE, serviceType));
+ rangerConf.set(getPropertyName(RangerConfigConstants.RANGER_PLUGIN_POLICY_POLLINVETERVALMS, serviceType), "");
+ rangerConf.set(getPropertyName(RangerConfigConstants.RANGER_PLUGIN_POLICY_CACHE_DIR, serviceType), "");
+ rangerConf.set(RangerConfigConstants.RANGER_PLUGIN_ADD_HADDOOP_AUTHORIZATION, "");
+
+ return rangerConf;
+ }
+
+ public static HashMap<String, String> getConfigChangeMap(String serviceType) {
+ // ConfigMap for moving legacy Configuration to Ranger Configuration
+ HashMap<String, String> changeMap = new HashMap<>();
+
+ changeMap.put(serviceType,
+ getPropertyName(RangerConfigConstants.RANGER_SERVICE_NAME, serviceType));
+ changeMap.put(getPropertyName(RangerConfigConstants.XASECURE_POLICYMGR_URL, serviceType),
+ getPropertyName(RangerConfigConstants.RANGER_PLUGIN_POLICY_REST_URL, serviceType));
+ changeMap.put(getPropertyName(RangerConfigConstants.XASECURE_POLICYMGR_GRL_RELOADINTERVALINMILLIS, serviceType),
+ getPropertyName(RangerConfigConstants.RANGER_PLUGIN_POLICY_POLLINVETERVALMS, serviceType));
+ changeMap.put(getPropertyName(RangerConfigConstants.XASECURE_POLICYMGR_URL_LASTSTOREDFILE, serviceType),
+ getPropertyName(RangerConfigConstants.RANGER_PLUGIN_POLICY_CACHE_DIR, serviceType));
+
+ if (EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_HDFS_NAME.equals(serviceType)) {
+ changeMap.put(RangerConfigConstants.XASECURE_ADD_HADDOP_AUTHORZATION,
+ RangerConfigConstants.RANGER_PLUGIN_ADD_HADDOOP_AUTHORIZATION);
+ }
+
+ if (EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_HBASE_NAME.equals(serviceType) ||
+ EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_HIVE_NAME.equals(serviceType)) {
+ changeMap.put(getPropertyName(RangerConfigConstants.XASECURE_UPDATE_XAPOLICIES_ON_GRANT, serviceType),
+ getPropertyName(RangerConfigConstants.XASECURE_UPDATE_XAPOLICIES_ON_GRANT, serviceType));
+ }
+
+ if (LOG.isDebugEnabled()) {
+ for (Map.Entry<String, String> entry : changeMap.entrySet()) {
+ String legacyKey = entry.getKey();
+ String rangerKey = entry.getValue();
+
+ LOG.debug("getConfigChangeMap() RangerConfig Key: {} Legacy Key: {}", rangerKey, legacyKey);
+ }
+ }
+
+ return changeMap;
+ }
+
+ public static String getFileLocation(String fileName) {
+ String ret = null;
+
+ URL lurl = RangerLegacyConfigBuilder.class.getClassLoader().getResource(fileName);
+ if (lurl == null) {
+ lurl = RangerLegacyConfigBuilder.class.getClassLoader().getResource("/" + fileName);
+ }
+ if (lurl != null) {
+ ret = lurl.getFile();
+ }
+ return ret;
+ }
+
+ public static URL getFileURL(String fileName) {
+ return RangerLegacyConfigBuilder.class.getClassLoader().getResource(fileName);
+ }
+
+ public static String getPropertyName(String rangerProp, String serviceType) {
+ return rangerProp.replace("<ServiceType>", serviceType);
+ }
+
+ public static String getPolicyMgrURL(String url) {
+ int index = url.indexOf("/", url.lastIndexOf(":"));
+
+ return url.substring(0, index);
+ }
+
+ public static String getServiceNameFromURL(String url) {
+ int index = url.lastIndexOf("/");
+
+ return url.substring(index + 1);
+ }
+
+ public static String getCacheFileURL(String cacheFile) {
+ int index = cacheFile.lastIndexOf("/");
+
+ return cacheFile.substring(0, index);
+ }
+
+ public static String fetchLegacyValue(String legacyVal, String rangerKey) {
+ String ret = null;
+
+ if (rangerKey.equals(getPropertyName(RangerConfigConstants.RANGER_SERVICE_NAME, serviceType))) {
+ // To Fetch ServiceName
+ ret = getServiceNameFromURL(legacyVal);
+ } else if (rangerKey.equals(getPropertyName(RangerConfigConstants.RANGER_PLUGIN_POLICY_REST_URL, serviceType))) {
+ // To Fetch PolicyMgr URL
+ ret = getPolicyMgrURL(legacyVal);
+ } else if (rangerKey.equals(getPropertyName(RangerConfigConstants.RANGER_PLUGIN_POLICY_CACHE_DIR, serviceType))) {
+ ret = getCacheFileURL(legacyVal);
+ }
+
+ return ret;
+ }
+
+ private static Configuration mapLegacyConfigToRanger(Configuration rangerInConf, Configuration legacyConf) {
+ Configuration ret = rangerInConf;
+ HashMap<String, String> chgMap = getConfigChangeMap(serviceType);
+
+ LOG.debug("<== mapLegacyConfigToRanger() MAP Size: {}", chgMap.size());
+
+ for (Map.Entry<String, String> entry : chgMap.entrySet()) {
+ final String legacyKey = entry.getKey();
+ final String rangerKey = entry.getValue();
+ final String legacyConfVal;
+
+ if (rangerKey.equals(getPropertyName(RangerConfigConstants.RANGER_SERVICE_NAME, serviceType))) {
+ String serviceURL = legacyConf.get(getPropertyName(RangerConfigConstants.XASECURE_POLICYMGR_URL, serviceType)); // For getting the service
+
+ legacyConfVal = fetchLegacyValue(serviceURL, rangerKey);
+ } else if (rangerKey.equals(getPropertyName(RangerConfigConstants.RANGER_PLUGIN_POLICY_REST_URL, serviceType)) ||
+ rangerKey.equals(getPropertyName(RangerConfigConstants.RANGER_PLUGIN_POLICY_CACHE_DIR, serviceType))) {
+ legacyConfVal = fetchLegacyValue(legacyConf.get(legacyKey), rangerKey); // For Getting Admin URL and CacheDir
+ } else {
+ legacyConfVal = legacyConf.get(legacyKey);
+ }
+
+ LOG.debug("<== mapLegacyConfigToRanger() Ranger Key: {} Legacy Key: {} Legacy Value:{}", rangerKey, legacyKey, legacyConfVal);
+
+ ret.set(rangerKey, legacyConfVal);
+ }
- private static final Logger LOG = LoggerFactory.getLogger(RangerLegacyConfigBuilder.class);
-
- static String serviceType;
- static String legacyResource;
-
- public static Configuration getSecurityConfig(String serviceType) {
-
- RangerLegacyConfigBuilder.legacyResource = getPropertyName(RangerConfigConstants.XASECURE_SECURITY_FILE,serviceType);
- RangerLegacyConfigBuilder.serviceType = serviceType;
-
- Configuration ret = null;
- Configuration legacyConfig = new Configuration();
- URL legacyFileUrl = getFileURL(legacyResource);
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> getSecurityConfig() " + legacyResource + " FileName: " + legacyFileUrl);
- }
-
- if ( legacyFileUrl != null) {
- legacyConfig.addResource(legacyFileUrl);
- Configuration rangerDefaultProp = buildRangerSecurityConf(serviceType);
- ret = mapLegacyConfigToRanger(rangerDefaultProp,legacyConfig);
- }
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== getSecurityConfig() " + legacyResource + " FileName: " + legacyFileUrl);
- }
-
- return ret;
- }
-
- public static URL getAuditConfig(String serviceType) throws Throwable {
-
- RangerLegacyConfigBuilder.legacyResource = getPropertyName(RangerConfigConstants.XASECURE_AUDIT_FILE,serviceType);
- RangerLegacyConfigBuilder.serviceType = serviceType;
-
- URL ret = null;
- try {
- ret = getAuditResource(legacyResource);
- } catch (Throwable t) {
- throw t;
- }
- return ret;
- }
-
- private static Configuration mapLegacyConfigToRanger(Configuration rangerInConf, Configuration legacyConf) {
-
- Configuration ret = rangerInConf;
-
- HashMap<String,String> chgMap = getConfigChangeMap(serviceType);
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== mapLegacyConfigToRanger() MAP Size: " + chgMap.size());
- }
- for(Map.Entry<String, String> entry : chgMap.entrySet()) {
- String legacyKey = entry.getKey();
- String rangerKey = entry.getValue();
-
- String legacyConfVal = null;
-
- if ( rangerKey.equals(getPropertyName(RangerConfigConstants.RANGER_SERVICE_NAME,serviceType)) ) {
- //For getting the service
- String serviceURL = legacyConf.get(getPropertyName(RangerConfigConstants.XASECURE_POLICYMGR_URL,serviceType));
- legacyConfVal = fetchLegacyValue(serviceURL,rangerKey);
- } else if ( rangerKey.equals(getPropertyName(RangerConfigConstants.RANGER_PLUGIN_POLICY_REST_URL,serviceType)) ||
- rangerKey.equals(getPropertyName(RangerConfigConstants.RANGER_PLUGIN_POLICY_CACHE_DIR,serviceType)) ) {
- // For Getting Admin URL and CacheDir
- legacyConfVal = fetchLegacyValue(legacyConf.get(legacyKey),rangerKey);
- } else {
- legacyConfVal = legacyConf.get(legacyKey);
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== mapLegacyConfigToRanger() Ranger Key: " + rangerKey + "Legacy Key:" + legacyKey + "Legacy Value:" + legacyConfVal);
- }
-
- ret.set(rangerKey, legacyConfVal);
- }
- return ret;
- }
-
-
- public static URL getAuditResource(String fName) throws Throwable {
- URL ret = null;
-
- try {
- for(String cfgFile : new String[] { "hive-site.xml", "hbase-site.xml", "hdfs-site.xml" } ) {
- String loc = getFileLocation(cfgFile);
- if (loc != null) {
- File f = new File(loc);
- if ( f.exists() && f.canRead()) {
- File parentFile = new File(loc).getParentFile();
- ret = new File(parentFile, RangerConfigConstants.XASECURE_AUDIT_FILE).toURI().toURL();
- break;
- }
- }
- }
- }
- catch(Throwable t) {
- LOG.error("Missing Ranger Audit configuration files...");
- throw t;
- }
- return ret;
- }
-
- public static Configuration buildRangerSecurityConf(String serviceType) {
- Configuration rangerConf = new Configuration();
-
- rangerConf.set(getPropertyName(RangerConfigConstants.RANGER_SERVICE_NAME,serviceType),"");
- if (EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_KNOX_NAME.equals(serviceType) ) {
- rangerConf.set(getPropertyName(RangerConfigConstants.RANGER_PLUGIN_POLICY_SOURCE_IMPL,serviceType),RangerConfigConstants.RANGER_KNOX_PLUGIN_POLICY_SOURCE_IMPL_DEFAULT);
- } else {
- rangerConf.set(getPropertyName(RangerConfigConstants.RANGER_PLUGIN_POLICY_SOURCE_IMPL,serviceType),"");
- }
- rangerConf.set(getPropertyName(RangerConfigConstants.RANGER_PLUGIN_POLICY_REST_URL,serviceType),"");
- rangerConf.set(getPropertyName(RangerConfigConstants.RANGER_PLUGIN_REST_SSL_CONFIG_FILE,serviceType), getPropertyName(RangerConfigConstants.XASECURE_POLICYMGR_SSL_FILE,serviceType));
- rangerConf.set(getPropertyName(RangerConfigConstants.RANGER_PLUGIN_POLICY_POLLINVETERVALMS,serviceType), "");
- rangerConf.set(getPropertyName(RangerConfigConstants.RANGER_PLUGIN_POLICY_CACHE_DIR,serviceType), "");
- rangerConf.set(RangerConfigConstants.RANGER_PLUGIN_ADD_HADDOOP_AUTHORIZATION,"");
-
- return rangerConf;
- }
-
- public static HashMap<String, String> getConfigChangeMap(String serviceType) {
- // ConfigMap for moving legacy Configuration to Ranger Configuration
- HashMap<String, String> changeMap = new HashMap<>();
-
- changeMap.put(serviceType,
- getPropertyName(RangerConfigConstants.RANGER_SERVICE_NAME,serviceType));
- changeMap.put(getPropertyName(RangerConfigConstants.XASECURE_POLICYMGR_URL,serviceType),
- getPropertyName(RangerConfigConstants.RANGER_PLUGIN_POLICY_REST_URL,serviceType));
- changeMap.put(getPropertyName(RangerConfigConstants.XASECURE_POLICYMGR_GRL_RELOADINTERVALINMILLIS,serviceType),
- getPropertyName(RangerConfigConstants.RANGER_PLUGIN_POLICY_POLLINVETERVALMS,serviceType));
- changeMap.put(getPropertyName(RangerConfigConstants.XASECURE_POLICYMGR_URL_LASTSTOREDFILE,serviceType),
- getPropertyName(RangerConfigConstants.RANGER_PLUGIN_POLICY_CACHE_DIR,serviceType));
-
- if (EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_HDFS_NAME.equals(serviceType)) {
- changeMap.put(RangerConfigConstants.XASECURE_ADD_HADDOP_AUTHORZATION,
- RangerConfigConstants.RANGER_PLUGIN_ADD_HADDOOP_AUTHORIZATION);
- }
-
- if (EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_HBASE_NAME.equals(serviceType) ||
- EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_HIVE_NAME.equals(serviceType)) {
- changeMap.put(getPropertyName(RangerConfigConstants.XASECURE_UPDATE_XAPOLICIES_ON_GRANT,serviceType),
- getPropertyName(RangerConfigConstants.XASECURE_UPDATE_XAPOLICIES_ON_GRANT,serviceType));
- }
-
- if ( LOG.isDebugEnabled()) {
- for(Map.Entry<String, String> entry : changeMap.entrySet()) {
- String legacyKey = entry.getKey();
- String rangerKey = entry.getValue();
- LOG.debug("<== getConfigChangeMap() RangerConfig Key: " + rangerKey + " Legacy Key: " + legacyKey);
- }
- }
-
- return changeMap;
- }
-
- public static String getFileLocation(String fileName) {
- String ret = null;
-
- URL lurl = RangerLegacyConfigBuilder.class.getClassLoader().getResource(fileName);
- if (lurl == null ) {
- lurl = RangerLegacyConfigBuilder.class.getClassLoader().getResource("/" + fileName);
- }
- if (lurl != null) {
- ret = lurl.getFile();
- }
- return ret;
- }
-
- public static URL getFileURL(String fileName) {
- return RangerLegacyConfigBuilder.class.getClassLoader().getResource(fileName);
- }
-
- public static String getPropertyName(String rangerProp, String serviceType) {
- return rangerProp.replace("<ServiceType>", serviceType);
- }
-
- public static String getPolicyMgrURL(String url) {
- int index = url.indexOf("/",url.lastIndexOf(":"));
-
- return url.substring(0,index);
- }
-
- public static String getServiceNameFromURL(String url) {
- int index = url.lastIndexOf("/");
-
- return url.substring(index+1);
- }
-
-
- public static String getCacheFileURL(String cacheFile) {
- int index = cacheFile.lastIndexOf("/");
-
- return cacheFile.substring(0,index);
- }
-
- public static String fetchLegacyValue(String legacyVal, String rangerKey) {
- String ret = null;
-
- if ( rangerKey.equals(getPropertyName(RangerConfigConstants.RANGER_SERVICE_NAME,serviceType)) ) {
- // To Fetch ServiceName
- ret = getServiceNameFromURL(legacyVal);
- } else if ( rangerKey.equals(getPropertyName(RangerConfigConstants.RANGER_PLUGIN_POLICY_REST_URL,serviceType)) ) {
- // To Fetch PolicyMgr URL
- ret = getPolicyMgrURL(legacyVal);
- } else if ( rangerKey.equals(getPropertyName(RangerConfigConstants.RANGER_PLUGIN_POLICY_CACHE_DIR,serviceType)) ) {
- ret = getCacheFileURL(legacyVal);
- }
-
- return ret;
- }
+ return ret;
+ }
}
diff --git a/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerPluginConfig.java b/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerPluginConfig.java
index 2a783331e..9c7cdb971 100644
--- a/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerPluginConfig.java
+++ b/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerPluginConfig.java
@@ -33,7 +33,6 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
-
public class RangerPluginConfig extends RangerConfiguration {
private static final Logger LOG = LoggerFactory.getLogger(RangerPluginConfig.class);
@@ -61,7 +60,6 @@ public class RangerPluginConfig extends RangerConfiguration {
private Set<String> superGroups = Collections.emptySet();
private Set<String> serviceAdmins = Collections.emptySet();
-
public RangerPluginConfig(String serviceType, String serviceName, String appId, String clusterName, String clusterType, RangerPolicyEngineOptions policyEngineOptions) {
super();
@@ -104,12 +102,12 @@ public class RangerPluginConfig extends RangerConfiguration {
}
if (LOG.isDebugEnabled()) {
- LOG.debug(propertyPrefix + ".use.x-forwarded-for.ipaddress:" + useForwardedIPAddress);
- LOG.debug(propertyPrefix + ".trusted.proxy.ipaddresses:[" + StringUtils.join(trustedProxyAddresses, ", ") + "]");
+ LOG.debug("{}.use.x-forwarded-for.ipaddress:{}", propertyPrefix, useForwardedIPAddress);
+ LOG.debug("{}.trusted.proxy.ipaddresses:[{}]", propertyPrefix, StringUtils.join(trustedProxyAddresses, ", "));
}
if (useForwardedIPAddress && StringUtils.isBlank(trustedProxyAddressString)) {
- LOG.warn("Property " + propertyPrefix + ".use.x-forwarded-for.ipaddress" + " is set to true, and Property " + propertyPrefix + ".trusted.proxy.ipaddresses" + " is not set");
+ LOG.warn("Property {}.use.x-forwarded-for.ipaddress is set to true, and Property {}.trusted.proxy.ipaddresses is not set", propertyPrefix, propertyPrefix);
LOG.warn("Ranger plugin will trust RemoteIPAddress and treat first X-Forwarded-Address in the access-request as the clientIPAddress");
}
@@ -127,7 +125,7 @@ public class RangerPluginConfig extends RangerConfiguration {
enableImplicitUserStoreEnricher = useRangerGroups || convertEmailToUsername || this.getBoolean(propertyPrefix + ".enable.implicit.userstore.enricher", false);
enableImplicitGdsInfoEnricher = this.getBoolean(propertyPrefix + ".enable.implicit.gdsinfo.enricher", true);
- LOG.info("" + policyEngineOptions);
+ LOG.info("{}", policyEngineOptions);
}
protected RangerPluginConfig(String serviceType, String serviceName, String appId, RangerPluginConfig sourcePluginConfig) {
@@ -138,8 +136,8 @@ public class RangerPluginConfig extends RangerConfiguration {
this.propertyPrefix = "ranger.plugin." + serviceType;
this.serviceName = serviceName;
- this.clusterName = sourcePluginConfig.getClusterName();
- this.clusterType = sourcePluginConfig.getClusterType();
+ this.clusterName = sourcePluginConfig.getClusterName();
+ this.clusterType = sourcePluginConfig.getClusterType();
this.useForwardedIPAddress = sourcePluginConfig.isUseForwardedIPAddress();
this.trustedProxyAddresses = sourcePluginConfig.getTrustedProxyAddresses();
this.isFallbackSupported = sourcePluginConfig.getIsFallbackSupported();
@@ -222,22 +220,18 @@ public class RangerPluginConfig extends RangerConfiguration {
auditExcludedGroups = CollectionUtils.isEmpty(groups) ? Collections.emptySet() : new HashSet<>(groups);
auditExcludedRoles = CollectionUtils.isEmpty(roles) ? Collections.emptySet() : new HashSet<>(roles);
- if (LOG.isDebugEnabled()) {
- LOG.debug("auditExcludedUsers=" + auditExcludedUsers + ", auditExcludedGroups=" + auditExcludedGroups + ", auditExcludedRoles=" + auditExcludedRoles);
- }
+ LOG.debug("auditExcludedUsers={}, auditExcludedGroups={}, auditExcludedRoles={}", auditExcludedUsers, auditExcludedGroups, auditExcludedRoles);
}
public void setSuperUsersGroups(Set<String> users, Set<String> groups) {
superUsers = CollectionUtils.isEmpty(users) ? Collections.emptySet() : new HashSet<>(users);
superGroups = CollectionUtils.isEmpty(groups) ? Collections.emptySet() : new HashSet<>(groups);
- if (LOG.isDebugEnabled()) {
- LOG.debug("superUsers=" + superUsers + ", superGroups=" + superGroups);
- }
+ LOG.debug("superUsers={}, superGroups={}", superUsers, superGroups);
}
public void setServiceAdmins(Set<String> users) {
- serviceAdmins = CollectionUtils.isEmpty(users) ? Collections.emptySet() : new HashSet<>(users);
+ serviceAdmins = CollectionUtils.isEmpty(users) ? Collections.emptySet() : new HashSet<>(users);
}
public boolean isAuditExcludedUser(String userName) {
@@ -245,11 +239,11 @@ public class RangerPluginConfig extends RangerConfiguration {
}
public boolean hasAuditExcludedGroup(Set<String> userGroups) {
- return userGroups != null && userGroups.size() > 0 && auditExcludedGroups.size() > 0 && CollectionUtils.containsAny(userGroups, auditExcludedGroups);
+ return userGroups != null && !userGroups.isEmpty() && !auditExcludedGroups.isEmpty() && CollectionUtils.containsAny(userGroups, auditExcludedGroups);
}
public boolean hasAuditExcludedRole(Set<String> userRoles) {
- return userRoles != null && userRoles.size() > 0 && auditExcludedRoles.size() > 0 && CollectionUtils.containsAny(userRoles, auditExcludedRoles);
+ return userRoles != null && !userRoles.isEmpty() && !auditExcludedRoles.isEmpty() && CollectionUtils.containsAny(userRoles, auditExcludedRoles);
}
public boolean isSuperUser(String userName) {
@@ -257,7 +251,7 @@ public class RangerPluginConfig extends RangerConfiguration {
}
public boolean hasSuperGroup(Set<String> userGroups) {
- return userGroups != null && userGroups.size() > 0 && superGroups.size() > 0 && CollectionUtils.containsAny(userGroups, superGroups);
+ return userGroups != null && !userGroups.isEmpty() && !superGroups.isEmpty() && CollectionUtils.containsAny(userGroups, superGroups);
}
public boolean isServiceAdmin(String userName) {
@@ -267,7 +261,7 @@ public class RangerPluginConfig extends RangerConfiguration {
private void addResourcesForServiceType(String serviceType) {
String auditCfg = "ranger-" + serviceType + "-audit.xml";
String securityCfg = "ranger-" + serviceType + "-security.xml";
- String sslCfg = "ranger-" + serviceType + "-policymgr-ssl.xml";
+ String sslCfg = "ranger-" + serviceType + "-policymgr-ssl.xml";
if (!addResourceIfReadable(auditCfg)) {
addAuditResource(serviceType);
@@ -295,31 +289,22 @@ public class RangerPluginConfig extends RangerConfiguration {
}
}
- private void addSecurityResource(String serviceType) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> addSecurityResource(Service Type: " + serviceType );
- }
+ private void addSecurityResource(String serviceType) {
+ LOG.debug("==> addSecurityResource(Service Type: {}", serviceType);
Configuration rangerConf = RangerLegacyConfigBuilder.getSecurityConfig(serviceType);
- if (rangerConf != null ) {
+ if (rangerConf != null) {
addResource(rangerConf);
} else {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Unable to add the Security Config for " + serviceType + ". Plugin won't be enabled!");
- }
+ LOG.debug("Unable to add the Security Config for {}. Plugin won't be enabled!", serviceType);
}
- if (LOG.isDebugEnabled()) {
- LOG.debug("<= addSecurityResource(Service Type: " + serviceType );
- }
+ LOG.debug("<= addSecurityResource(Service Type: {}", serviceType);
}
- private void addAuditResource(String serviceType) {
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> addAuditResource(Service Type: " + serviceType );
- }
+ private void addAuditResource(String serviceType) {
+ LOG.debug("==> addAuditResource(Service Type: {}", serviceType);
try {
URL url = RangerLegacyConfigBuilder.getAuditConfig(serviceType);
@@ -327,28 +312,18 @@ public class RangerPluginConfig extends RangerConfiguration {
if (url != null) {
addResource(url);
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> addAuditResource() URL" + url.getPath());
- }
+ LOG.debug("==> addAuditResource() URL {}", url.getPath());
}
-
} catch (Throwable t) {
- LOG.warn("Unable to find Audit Config for " + serviceType + " Auditing not enabled !" );
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("Unable to find Audit Config for " + serviceType + " Auditing not enabled !" + t);
- }
+ LOG.warn("Unable to find Audit Config for {} Auditing not enabled !", serviceType);
+ LOG.debug("Unable to find Audit Config for {} Auditing not enabled !", serviceType, t);
}
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== addAuditResource(Service Type: " + serviceType + ")");
- }
+ LOG.debug("<== addAuditResource(Service Type: {})", serviceType);
}
private void addSslConfigResource(String serviceType) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> addSslConfigResource(Service Type: " + serviceType);
- }
+ LOG.debug("==> addSslConfigResource(Service Type: {}", serviceType);
try {
String sslConfigFile = this.get(RangerLegacyConfigBuilder.getPropertyName(RangerConfigConstants.RANGER_PLUGIN_REST_SSL_CONFIG_FILE, serviceType));
@@ -356,21 +331,15 @@ public class RangerPluginConfig extends RangerConfiguration {
URL url = getSSLConfigResource(sslConfigFile);
if (url != null) {
addResource(url);
- if (LOG.isDebugEnabled()) {
- LOG.debug("SSL config file URL:" + url.getPath());
- }
+
+ LOG.debug("SSL config file URL: {}", url.getPath());
}
} catch (Throwable t) {
LOG.warn(" Unable to find SSL Configs");
-
- if (LOG.isDebugEnabled()) {
- LOG.debug(" Unable to find SSL Configs");
- }
+ LOG.debug(" Unable to find SSL Configs");
}
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== addSslConfigResource(Service Type: " + serviceType + ")");
- }
+ LOG.debug("<== addSslConfigResource(Service Type: {})", serviceType);
}
private URL getSSLConfigResource(String fileName) throws Throwable {
@@ -384,7 +353,7 @@ public class RangerPluginConfig extends RangerConfiguration {
}
}
} catch (Throwable t) {
- LOG.error("Unable to read SSL configuration file:" + fileName);
+ LOG.error("Unable to read SSL configuration file: {}", fileName);
throw t;
}
diff --git a/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/constants/RangerHadoopConstants.java b/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/constants/RangerHadoopConstants.java
index 86827e655..fdba1c563 100644
--- a/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/constants/RangerHadoopConstants.java
+++ b/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/constants/RangerHadoopConstants.java
@@ -6,9 +6,9 @@
* 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
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* 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.
@@ -19,79 +19,81 @@
package org.apache.ranger.authorization.hadoop.constants;
public class RangerHadoopConstants {
-
- public static final String RANGER_ADD_HDFS_PERMISSION_PROP = "xasecure.add-hadoop-authorization";
- public static final String RANGER_OPTIMIZE_SUBACCESS_AUTHORIZATION_PROP = "ranger.optimize-subaccess-authorization" ;
- public static final boolean RANGER_ADD_HDFS_PERMISSION_DEFAULT = false;
- public static final boolean RANGER_OPTIMIZE_SUBACCESS_AUTHORIZATION_DEFAULT = false ;
-
- public static final String RANGER_USE_LEGACY_SUBACCESS_AUTHORIZATION_PROP = "ranger.plugin.hdfs.use.legacy.subaccess.authorization";
- public static final boolean RANGER_USE_LEGACY_SUBACCESS_AUTHORIZATION_DEFAULT = true;
-
- public static final String READ_ACCCESS_TYPE = "read";
- public static final String WRITE_ACCCESS_TYPE = "write";
- public static final String EXECUTE_ACCCESS_TYPE = "execute";
-
- public static final String READ_EXECUTE_PERM = "READ_EXECUTE";
- public static final String WRITE_EXECUTE_PERM = "WRITE_EXECUTE";
- public static final String READ_WRITE_PERM = "READ_WRITE";
- public static final String ALL_PERM = "ALL";
-
- public static final String HDFS_ROOT_FOLDER_PATH_ALT = "";
- public static final String HDFS_ROOT_FOLDER_PATH = "/";
-
- public static final String HIVE_UPDATE_RANGER_POLICIES_ON_GRANT_REVOKE_PROP = "xasecure.hive.update.xapolicies.on.grant.revoke";
- public static final boolean HIVE_UPDATE_RANGER_POLICIES_ON_GRANT_REVOKE_DEFAULT_VALUE = true;
- public static final String HIVE_BLOCK_UPDATE_IF_ROWFILTER_COLUMNMASK_SPECIFIED_PROP = "xasecure.hive.block.update.if.rowfilter.columnmask.specified";
- public static final boolean HIVE_BLOCK_UPDATE_IF_ROWFILTER_COLUMNMASK_SPECIFIED_DEFAULT_VALUE = true;
- public static final String HIVE_DESCRIBE_TABLE_SHOW_COLUMNS_AUTH_OPTION_PROP = "xasecure.hive.describetable.showcolumns.authorization.option";
- public static final String HIVE_DESCRIBE_TABLE_SHOW_COLUMNS_AUTH_OPTION_PROP_DEFAULT_VALUE = "NONE";
- public static final String HIVE_URI_PERMISSION_COARSE_CHECK = "xasecure.hive.uri.permission.coarse.check";
- public static final boolean HIVE_URI_PERMISSION_COARSE_CHECK_DEFAULT_VALUE = false;
-
- public static final String HBASE_UPDATE_RANGER_POLICIES_ON_GRANT_REVOKE_PROP = "xasecure.hbase.update.xapolicies.on.grant.revoke";
- public static final boolean HBASE_UPDATE_RANGER_POLICIES_ON_GRANT_REVOKE_DEFAULT_VALUE = true;
- public static final String HBASE_COLUMN_AUTH_OPTIMIZATION = "ranger.plugin.hbase.column.auth.optimized";
-
- public static final String KNOX_ACCESS_VERIFIER_CLASS_NAME_PROP = "knox.authorization.verifier.classname";
- public static final String KNOX_ACCESS_VERIFIER_CLASS_NAME_DEFAULT_VALUE = "org.apache.ranger.pdp.knox.RangerAuthorizer";
-
- public static final String STORM_ACCESS_VERIFIER_CLASS_NAME_PROP = "storm.authorization.verifier.classname";
- public static final String STORM_ACCESS_VERIFIER_CLASS_NAME_DEFAULT_VALUE = "org.apache.ranger.pdp.storm.RangerAuthorizer";
-
- public static final String RANGER_ADD_YARN_PERMISSION_PROP = "ranger.add-yarn-authorization";
- public static final boolean RANGER_ADD_YARN_PERMISSION_DEFAULT = true;
-
- //
- // Logging constants
- //
- public static final String AUDITLOG_FIELD_DELIMITER_PROP = "xasecure.auditlog.fieldDelimiterString";
- public static final String AUDITLOG_RANGER_MODULE_ACL_NAME_PROP = "xasecure.auditlog.xasecureAcl.name";
- public static final String AUDITLOG_HADOOP_MODULE_ACL_NAME_PROP = "xasecure.auditlog.hadoopAcl.name";
- public static final String AUDITLOG_YARN_MODULE_ACL_NAME_PROP = "ranger.auditlog.yarnAcl.name";
-
- public static final String DEFAULT_LOG_FIELD_DELIMITOR = "|";
- public static final String DEFAULT_XASECURE_MODULE_ACL_NAME = "xasecure-acl";
- public static final String DEFAULT_RANGER_MODULE_ACL_NAME = "ranger-acl";
- public static final String DEFAULT_HADOOP_MODULE_ACL_NAME = "hadoop-acl";
- public static final String DEFAULT_YARN_MODULE_ACL_NAME = "yarn-acl";
-
-
- public static final String AUDITLOG_FIELDINFO_VISIBLE_PROP = "xasecure.auditlog.fieldInfoVisible";
- public static final boolean DEFAULT_AUDITLOG_FIELDINFO_VISIBLE = false;
-
- public static final String AUDITLOG_ACCESS_GRANTED_TEXT_PROP = "xasecure.auditlog.accessgranted.text";
- public static final String AUDITLOG_ACCESS_DENIED_TEXT_PROP = "xasecure.auditlog.accessdenied.text";
-
- public static final String DEFAULT_ACCESS_GRANTED_TEXT = "granted";
- public static final String DEFAULT_ACCESS_DENIED_TEXT = "denied";
-
- public static final String AUDITLOG_EMPTY_STRING = "";
-
- public static final String AUDITLOG_HDFS_EXCLUDE_LIST_PROP = "xasecure.auditlog.hdfs.excludeusers";
- public static final String AUDITLOG_REPOSITORY_NAME_PROP = "xasecure.audit.repository.name";
- public static final String AUDITLOG_IS_ENABLED_PROP = "xasecure.audit.is.enabled";
-
- public static final String KEYMGR_URL_PROP = "hdfs.keymanager.url";
- public static final String ACCESS_TYPE_MONITOR_HEALTH = "monitorHealth";
+ public static final String RANGER_ADD_HDFS_PERMISSION_PROP = "xasecure.add-hadoop-authorization";
+ public static final String RANGER_OPTIMIZE_SUBACCESS_AUTHORIZATION_PROP = "ranger.optimize-subaccess-authorization";
+ public static final boolean RANGER_ADD_HDFS_PERMISSION_DEFAULT = false;
+ public static final boolean RANGER_OPTIMIZE_SUBACCESS_AUTHORIZATION_DEFAULT = false;
+
+ public static final String RANGER_USE_LEGACY_SUBACCESS_AUTHORIZATION_PROP = "ranger.plugin.hdfs.use.legacy.subaccess.authorization";
+ public static final boolean RANGER_USE_LEGACY_SUBACCESS_AUTHORIZATION_DEFAULT = true;
+
+ public static final String READ_ACCCESS_TYPE = "read";
+ public static final String WRITE_ACCCESS_TYPE = "write";
+ public static final String EXECUTE_ACCCESS_TYPE = "execute";
+
+ public static final String READ_EXECUTE_PERM = "READ_EXECUTE";
+ public static final String WRITE_EXECUTE_PERM = "WRITE_EXECUTE";
+ public static final String READ_WRITE_PERM = "READ_WRITE";
+ public static final String ALL_PERM = "ALL";
+
+ public static final String HDFS_ROOT_FOLDER_PATH_ALT = "";
+ public static final String HDFS_ROOT_FOLDER_PATH = "/";
+
+ public static final String HIVE_UPDATE_RANGER_POLICIES_ON_GRANT_REVOKE_PROP = "xasecure.hive.update.xapolicies.on.grant.revoke";
+ public static final boolean HIVE_UPDATE_RANGER_POLICIES_ON_GRANT_REVOKE_DEFAULT_VALUE = true;
+ public static final String HIVE_BLOCK_UPDATE_IF_ROWFILTER_COLUMNMASK_SPECIFIED_PROP = "xasecure.hive.block.update.if.rowfilter.columnmask.specified";
+ public static final boolean HIVE_BLOCK_UPDATE_IF_ROWFILTER_COLUMNMASK_SPECIFIED_DEFAULT_VALUE = true;
+ public static final String HIVE_DESCRIBE_TABLE_SHOW_COLUMNS_AUTH_OPTION_PROP = "xasecure.hive.describetable.showcolumns.authorization.option";
+ public static final String HIVE_DESCRIBE_TABLE_SHOW_COLUMNS_AUTH_OPTION_PROP_DEFAULT_VALUE = "NONE";
+ public static final String HIVE_URI_PERMISSION_COARSE_CHECK = "xasecure.hive.uri.permission.coarse.check";
+ public static final boolean HIVE_URI_PERMISSION_COARSE_CHECK_DEFAULT_VALUE = false;
+
+ public static final String HBASE_UPDATE_RANGER_POLICIES_ON_GRANT_REVOKE_PROP = "xasecure.hbase.update.xapolicies.on.grant.revoke";
+ public static final boolean HBASE_UPDATE_RANGER_POLICIES_ON_GRANT_REVOKE_DEFAULT_VALUE = true;
+ public static final String HBASE_COLUMN_AUTH_OPTIMIZATION = "ranger.plugin.hbase.column.auth.optimized";
+
+ public static final String KNOX_ACCESS_VERIFIER_CLASS_NAME_PROP = "knox.authorization.verifier.classname";
+ public static final String KNOX_ACCESS_VERIFIER_CLASS_NAME_DEFAULT_VALUE = "org.apache.ranger.pdp.knox.RangerAuthorizer";
+
+ public static final String STORM_ACCESS_VERIFIER_CLASS_NAME_PROP = "storm.authorization.verifier.classname";
+ public static final String STORM_ACCESS_VERIFIER_CLASS_NAME_DEFAULT_VALUE = "org.apache.ranger.pdp.storm.RangerAuthorizer";
+
+ public static final String RANGER_ADD_YARN_PERMISSION_PROP = "ranger.add-yarn-authorization";
+ public static final boolean RANGER_ADD_YARN_PERMISSION_DEFAULT = true;
+
+ //
+ // Logging constants
+ //
+ public static final String AUDITLOG_FIELD_DELIMITER_PROP = "xasecure.auditlog.fieldDelimiterString";
+ public static final String AUDITLOG_RANGER_MODULE_ACL_NAME_PROP = "xasecure.auditlog.xasecureAcl.name";
+ public static final String AUDITLOG_HADOOP_MODULE_ACL_NAME_PROP = "xasecure.auditlog.hadoopAcl.name";
+ public static final String AUDITLOG_YARN_MODULE_ACL_NAME_PROP = "ranger.auditlog.yarnAcl.name";
+
+ public static final String DEFAULT_LOG_FIELD_DELIMITOR = "|";
+ public static final String DEFAULT_XASECURE_MODULE_ACL_NAME = "xasecure-acl";
+ public static final String DEFAULT_RANGER_MODULE_ACL_NAME = "ranger-acl";
+ public static final String DEFAULT_HADOOP_MODULE_ACL_NAME = "hadoop-acl";
+ public static final String DEFAULT_YARN_MODULE_ACL_NAME = "yarn-acl";
+
+ public static final String AUDITLOG_FIELDINFO_VISIBLE_PROP = "xasecure.auditlog.fieldInfoVisible";
+ public static final boolean DEFAULT_AUDITLOG_FIELDINFO_VISIBLE = false;
+
+ public static final String AUDITLOG_ACCESS_GRANTED_TEXT_PROP = "xasecure.auditlog.accessgranted.text";
+ public static final String AUDITLOG_ACCESS_DENIED_TEXT_PROP = "xasecure.auditlog.accessdenied.text";
+
+ public static final String DEFAULT_ACCESS_GRANTED_TEXT = "granted";
+ public static final String DEFAULT_ACCESS_DENIED_TEXT = "denied";
+
+ public static final String AUDITLOG_EMPTY_STRING = "";
+
+ public static final String AUDITLOG_HDFS_EXCLUDE_LIST_PROP = "xasecure.auditlog.hdfs.excludeusers";
+ public static final String AUDITLOG_REPOSITORY_NAME_PROP = "xasecure.audit.repository.name";
+ public static final String AUDITLOG_IS_ENABLED_PROP = "xasecure.audit.is.enabled";
+
+ public static final String KEYMGR_URL_PROP = "hdfs.keymanager.url";
+ public static final String ACCESS_TYPE_MONITOR_HEALTH = "monitorHealth";
+
+ private RangerHadoopConstants() {
+ // to block instantiation
+ }
}
diff --git a/agents-common/src/main/java/org/apache/ranger/authorization/utils/JsonUtils.java b/agents-common/src/main/java/org/apache/ranger/authorization/utils/JsonUtils.java
index fd4f68f07..ff0fe452d 100755
--- a/agents-common/src/main/java/org/apache/ranger/authorization/utils/JsonUtils.java
+++ b/agents-common/src/main/java/org/apache/ranger/authorization/utils/JsonUtils.java
@@ -20,18 +20,17 @@ package org.apache.ranger.authorization.utils;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.ranger.plugin.model.AuditFilter;
import org.apache.ranger.plugin.model.RangerGds.RangerGdsMaskInfo;
+import org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource;
import org.apache.ranger.plugin.model.RangerPrincipal;
import org.apache.ranger.plugin.model.RangerTag;
import org.apache.ranger.plugin.model.RangerValidityRecurrence;
import org.apache.ranger.plugin.model.RangerValiditySchedule;
-import org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -42,39 +41,43 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import static com.fasterxml.jackson.databind.DeserializationFeature.*;
+import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
public class JsonUtils {
private static final Logger LOG = LoggerFactory.getLogger(JsonUtils.class);
- private static final TypeReference TYPE_MAP_STRING_STRING = new TypeReference<Map<String, String>>() {};
- private static final TypeReference TYPE_SET_STRING = new TypeReference<Set<String>>() {};
- private static final TypeReference TYPE_LIST_STRING = new TypeReference<List<String>>() {};
- private static final TypeReference TYPE_LIST_RANGER_VALIDITY_SCHEDULE = new TypeReference<List<RangerValiditySchedule>>() {};
- private static final TypeReference TYPE_LIST_AUDIT_FILTER = new TypeReference<List<AuditFilter>>() {};
- private static final TypeReference TYPE_LIST_RANGER_VALIDITY_RECURRENCE = new TypeReference<List<RangerValidityRecurrence>>() {};
- private static final TypeReference TYPE_LIST_RANGER_PRINCIPAL = new TypeReference<List<RangerPrincipal>>() {};
- private static final TypeReference TYPE_LIST_RANGER_GDS_MASK_INFO = new TypeReference<List<RangerGdsMaskInfo>>() {};
- private static final TypeReference TYPE_MAP_RANGER_POLICY_RESOURCE = new TypeReference<Map<String, RangerPolicyResource>>() {};
- private static final TypeReference TYPE_LIST_RANGER_TAG = new TypeReference<List<RangerTag>>() {};
-
- static private final ThreadLocal<ObjectMapper> MAPPER = new ThreadLocal<ObjectMapper>() {
- @Override
- protected ObjectMapper initialValue() {
- ObjectMapper objectMapper = new ObjectMapper();
- objectMapper.setDateFormat(new SimpleDateFormat("yyyyMMdd-HH:mm:ss.SSS-Z"));
- objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
- objectMapper.configure(FAIL_ON_UNKNOWN_PROPERTIES, false);
- return objectMapper;
- }
- };
+ private static final TypeReference<Map<String, String>> TYPE_MAP_STRING_STRING = new TypeReference<Map<String, String>>() {};
+ private static final TypeReference<Set<String>> TYPE_SET_STRING = new TypeReference<Set<String>>() {};
+ private static final TypeReference<List<String>> TYPE_LIST_STRING = new TypeReference<List<String>>() {};
+ private static final TypeReference<List<RangerValiditySchedule>> TYPE_LIST_RANGER_VALIDITY_SCHEDULE = new TypeReference<List<RangerValiditySchedule>>() {};
+ private static final TypeReference<List<AuditFilter>> TYPE_LIST_AUDIT_FILTER = new TypeReference<List<AuditFilter>>() {};
+ private static final TypeReference<List<RangerValidityRecurrence>> TYPE_LIST_RANGER_VALIDITY_RECURRENCE = new TypeReference<List<RangerValidityRecurrence>>() {};
+ private static final TypeReference<List<RangerPrincipal>> TYPE_LIST_RANGER_PRINCIPAL = new TypeReference<List<RangerPrincipal>>() {};
+ private static final TypeReference<List<RangerGdsMaskInfo>> TYPE_LIST_RANGER_GDS_MASK_INFO = new TypeReference<List<RangerGdsMaskInfo>>() {};
+ private static final TypeReference<Map<String, RangerPolicyResource>> TYPE_MAP_RANGER_POLICY_RESOURCE = new TypeReference<Map<String, RangerPolicyResource>>() {};
+ private static final TypeReference<List<RangerTag>> TYPE_LIST_RANGER_TAG = new TypeReference<List<RangerTag>>() {};
+
+ private static final ThreadLocal<ObjectMapper> MAPPER = ThreadLocal.withInitial(() -> {
+ ObjectMapper objectMapper = new ObjectMapper();
+
+ objectMapper.setDateFormat(new SimpleDateFormat("yyyyMMdd-HH:mm:ss.SSS-Z"));
+ objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
+ objectMapper.configure(FAIL_ON_UNKNOWN_PROPERTIES, false);
+
+ return objectMapper;
+ });
+
+ private JsonUtils() {
+ // to block instantiation
+ }
- static public ObjectMapper getMapper() {
+ public static ObjectMapper getMapper() {
return MAPPER.get();
}
public static String mapToJson(Map<?, ?> map) {
String ret = null;
+
if (MapUtils.isNotEmpty(map)) {
try {
ret = getMapper().writeValueAsString(map);
@@ -82,11 +85,13 @@ public class JsonUtils {
LOG.error("Invalid input data: ", e);
}
}
+
return ret;
}
public static String listToJson(List<?> list) {
String ret = null;
+
if (CollectionUtils.isNotEmpty(list)) {
try {
ret = getMapper().writeValueAsString(list);
@@ -94,11 +99,13 @@ public class JsonUtils {
LOG.error("Invalid input data: ", e);
}
}
+
return ret;
}
public static String setToJson(Set<?> set) {
String ret = null;
+
if (CollectionUtils.isNotEmpty(set)) {
try {
ret = getMapper().writeValueAsString(set);
@@ -106,16 +113,17 @@ public class JsonUtils {
LOG.error("Invalid input data: ", e);
}
}
+
return ret;
}
public static String objectToJson(Object object) {
String ret = null;
- if(object != null) {
+ if (object != null) {
try {
ret = getMapper().writeValueAsString(object);
- } catch(Exception excp) {
+ } catch (Exception excp) {
LOG.warn("objectToJson() failed to convert object to Json", excp);
}
}
@@ -123,65 +131,66 @@ public class JsonUtils {
return ret;
}
- public static <T> T jsonToObject(Reader reader, Class<T> clz) {
+ public static <T> T jsonToObject(Reader reader, Class<T> clz) {
T ret = null;
- if(null != reader) {
+ if (null != reader) {
try {
ret = getMapper().readValue(reader, clz);
- } catch(Exception excp) {
- LOG.warn("jsonToObject() failed to convert json to object: class " + clz + " reader ", excp);
+ } catch (Exception excp) {
+ LOG.warn("jsonToObject() failed to convert json to object: class {} reader ", clz, excp);
}
}
return ret;
}
- public static <T> void objectToWriter(Writer writer, T object) {
- if(null != writer) {
+ public static <T> void objectToWriter(Writer writer, T object) {
+ if (null != writer) {
try {
getMapper().writeValue(writer, object);
- } catch(Exception excp) {
- LOG.warn("objectToWriter() failed to write oject to writer: class " + object + " writer ", excp);
+ } catch (Exception excp) {
+ LOG.warn("objectToWriter() failed to write object to writer: class {} writer ", object, excp);
}
}
}
- public static <T> T jsonToObject(String jsonStr, Class<T> clz) {
+ public static <T> T jsonToObject(String jsonStr, Class<T> clz) {
T ret = null;
- if(StringUtils.isNotEmpty(jsonStr)) {
+ if (StringUtils.isNotEmpty(jsonStr)) {
try {
ret = getMapper().readValue(jsonStr, clz);
- } catch(Exception excp) {
- LOG.warn("jsonToObject() failed to convert json to object: class " +clz + " JSON "+ jsonStr, excp);
+ } catch (Exception excp) {
+ LOG.warn("jsonToObject() failed to convert json to object: class {} JSON {}", clz, jsonStr, excp);
}
}
return ret;
}
- public static <T> T jsonToObject(String jsonStr, TypeReference<T> valueTypeRef) throws JsonProcessingException, JsonMappingException {
+ public static <T> T jsonToObject(String jsonStr, TypeReference<T> valueTypeRef) throws JsonProcessingException {
T ret = null;
- if(StringUtils.isNotEmpty(jsonStr)) {
+
+ if (StringUtils.isNotEmpty(jsonStr)) {
try {
ret = getMapper().readValue(jsonStr, valueTypeRef);
- } catch(Exception excp) {
- LOG.warn("jsonToObject() failed to convert json to object: " + jsonStr, excp);
+ } catch (Exception excp) {
+ LOG.warn("jsonToObject() failed to convert json to object: {}", jsonStr, excp);
}
}
- return (T) ret;
+ return ret;
}
public static Map<String, String> jsonToMapStringString(String jsonStr) {
Map<String, String> ret = null;
- if(StringUtils.isNotEmpty(jsonStr)) {
+ if (StringUtils.isNotEmpty(jsonStr)) {
try {
- ret = (Map<String, String>) getMapper().readValue(jsonStr, TYPE_MAP_STRING_STRING);
- } catch(Exception excp) {
- LOG.warn("jsonToMapStringString() failed to convert json to object: " + jsonStr, excp);
+ ret = getMapper().readValue(jsonStr, TYPE_MAP_STRING_STRING);
+ } catch (Exception excp) {
+ LOG.warn("jsonToMapStringString() failed to convert json to object: {}", jsonStr, excp);
}
}
@@ -193,9 +202,9 @@ public class JsonUtils {
if (StringUtils.isNotEmpty(jsonStr)) {
try {
- ret = (Set<String>) getMapper().readValue(jsonStr, TYPE_SET_STRING);
- } catch(Exception excp) {
- LOG.warn("jsonToSetString() failed to convert json to object: " + jsonStr, excp);
+ ret = getMapper().readValue(jsonStr, TYPE_SET_STRING);
+ } catch (Exception excp) {
+ LOG.warn("jsonToSetString() failed to convert json to object: {}", jsonStr, excp);
}
}
@@ -207,9 +216,9 @@ public class JsonUtils {
if (StringUtils.isNotEmpty(jsonStr)) {
try {
- ret = (List<String>) getMapper().readValue(jsonStr, TYPE_LIST_STRING);
- } catch(Exception excp) {
- LOG.warn("jsonToListString() failed to convert json to object: " + jsonStr, excp);
+ ret = getMapper().readValue(jsonStr, TYPE_LIST_STRING);
+ } catch (Exception excp) {
+ LOG.warn("jsonToListString() failed to convert json to object: {}", jsonStr, excp);
}
}
@@ -218,63 +227,70 @@ public class JsonUtils {
public static List<RangerValiditySchedule> jsonToRangerValiditySchedule(String jsonStr) {
try {
- return (List<RangerValiditySchedule>) getMapper().readValue(jsonStr, TYPE_LIST_RANGER_VALIDITY_SCHEDULE);
+ return getMapper().readValue(jsonStr, TYPE_LIST_RANGER_VALIDITY_SCHEDULE);
} catch (Exception e) {
- LOG.error("Cannot get List<RangerValiditySchedule> from " + jsonStr, e);
+ LOG.error("Cannot get List<RangerValiditySchedule> from {}", jsonStr, e);
+
return null;
}
}
public static List<AuditFilter> jsonToAuditFilterList(String jsonStr) {
try {
- return (List<AuditFilter>) getMapper().readValue(jsonStr, TYPE_LIST_AUDIT_FILTER);
+ return getMapper().readValue(jsonStr, TYPE_LIST_AUDIT_FILTER);
} catch (Exception e) {
- LOG.error("Cannot get List<AuditFilter> from " + jsonStr, e);
+ LOG.error("Cannot get List<AuditFilter> from {}", jsonStr, e);
+
return null;
}
}
public static List<RangerValidityRecurrence> jsonToRangerValidityRecurringSchedule(String jsonStr) {
try {
- return (List<RangerValidityRecurrence>) getMapper().readValue(jsonStr, TYPE_LIST_RANGER_VALIDITY_RECURRENCE);
+ return getMapper().readValue(jsonStr, TYPE_LIST_RANGER_VALIDITY_RECURRENCE);
} catch (Exception e) {
- LOG.error("Cannot get List<RangerValidityRecurrence> from " + jsonStr, e);
+ LOG.error("Cannot get List<RangerValidityRecurrence> from {}", jsonStr, e);
+
return null;
}
}
public static List<RangerPrincipal> jsonToRangerPrincipalList(String jsonStr) {
try {
- return (List<RangerPrincipal>) getMapper().readValue(jsonStr, TYPE_LIST_RANGER_PRINCIPAL);
+ return getMapper().readValue(jsonStr, TYPE_LIST_RANGER_PRINCIPAL);
} catch (Exception e) {
- LOG.error("Cannot get List<RangerPrincipal> from " + jsonStr, e);
+ LOG.error("Cannot get List<RangerPrincipal> from {}", jsonStr, e);
+
return null;
}
}
public static List<RangerTag> jsonToRangerTagList(String jsonStr) {
try {
- return (List<RangerTag>) getMapper().readValue(jsonStr, TYPE_LIST_RANGER_TAG);
+ return getMapper().readValue(jsonStr, TYPE_LIST_RANGER_TAG);
} catch (Exception e) {
- LOG.error("Cannot get List<RangerTag> from " + jsonStr, e);
+ LOG.error("Cannot get List<RangerTag> from {}", jsonStr, e);
+
return null;
}
}
public static List<RangerGdsMaskInfo> jsonToListGdsMaskInfo(String jsonStr) {
try {
- return (List<RangerGdsMaskInfo>) getMapper().readValue(jsonStr, TYPE_LIST_RANGER_GDS_MASK_INFO);
+ return getMapper().readValue(jsonStr, TYPE_LIST_RANGER_GDS_MASK_INFO);
} catch (Exception e) {
- LOG.error("Cannot get Map<String, RangerPolicyItemDataMaskInfo> from " + jsonStr, e);
+ LOG.error("Cannot get Map<String, RangerPolicyItemDataMaskInfo> from {}", jsonStr, e);
+
return null;
}
}
public static Map<String, RangerPolicyResource> jsonToMapPolicyResource(String jsonStr) {
try {
- return (Map<String, RangerPolicyResource>) getMapper().readValue(jsonStr, TYPE_MAP_RANGER_POLICY_RESOURCE);
+ return getMapper().readValue(jsonStr, TYPE_MAP_RANGER_POLICY_RESOURCE);
} catch (Exception e) {
- LOG.error("Cannot get Map<String, RangerPolicyResource> from " + jsonStr, e);
+ LOG.error("Cannot get Map<String, RangerPolicyResource> from {}", jsonStr, e);
+
return null;
}
}
diff --git a/agents-common/src/main/java/org/apache/ranger/authorization/utils/StringUtil.java b/agents-common/src/main/java/org/apache/ranger/authorization/utils/StringUtil.java
index db04e5539..831c62614 100644
--- a/agents-common/src/main/java/org/apache/ranger/authorization/utils/StringUtil.java
+++ b/agents-common/src/main/java/org/apache/ranger/authorization/utils/StringUtil.java
@@ -17,7 +17,12 @@
* under the License.
*/
- package org.apache.ranger.authorization.utils;
+package org.apache.ranger.authorization.utils;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -38,538 +43,519 @@ import java.util.TimeZone;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.collections.MapUtils;
-import org.apache.commons.lang.StringUtils;
-import org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource;
-
public class StringUtil {
private static final TimeZone gmtTimeZone = TimeZone.getTimeZone("GMT+0");
+ private StringUtil() {
+ // to block instantiation
+ }
public static boolean equals(String str1, String str2) {
- boolean ret = false;
-
- if(str1 == null) {
- ret = str2 == null;
- } else if(str2 == null) {
- ret = false;
- } else {
- ret = str1.equals(str2);
- }
-
- return ret;
- }
-
- public static boolean equalsIgnoreCase(String str1, String str2) {
- boolean ret = false;
-
- if(str1 == null) {
- ret = str2 == null;
- } else if(str2 == null) {
- ret = false;
- } else {
- ret = str1.equalsIgnoreCase(str2);
- }
-
- return ret;
- }
-
- public static boolean equals(Collection<String> set1, Collection<String> set2) {
- boolean ret = false;
-
- if(set1 == null) {
- ret = set2 == null;
- } else if(set2 == null) {
- ret = false;
- } else if(set1.size() == set2.size()) {
- ret = set1.containsAll(set2);
- }
-
- return ret;
- }
-
- public static boolean equalsIgnoreCase(Collection<String> set1, Collection<String> set2) {
- boolean ret = false;
-
- if(set1 == null) {
- ret = set2 == null;
- } else if(set2 == null) {
- ret = false;
- } else if(set1.size() == set2.size()) {
- int numFound = 0;
-
- for(String str1 : set1) {
- boolean str1Found = false;
-
- for(String str2 : set2) {
- if(equalsIgnoreCase(str1, str2)) {
- str1Found = true;
-
- break;
- }
- }
-
- if(str1Found) {
- numFound++;
- } else {
- break;
- }
- }
-
- ret = numFound == set1.size();
- }
-
- return ret;
- }
-
- public static boolean matches(String pattern, String str) {
- boolean ret = false;
-
- if(pattern == null || str == null || pattern.isEmpty() || str.isEmpty()) {
- ret = true;
- } else {
- ret = str.matches(pattern);
- }
-
- return ret;
- }
-
- /*
- public static boolean matches(Collection<String> patternSet, Collection<String> strSet) {
- boolean ret = false;
-
- if(patternSet == null || strSet == null || patternSet.isEmpty() || strSet.isEmpty()) {
- ret = true;
- } else {
- boolean foundUnmatched = false;
-
- for(String str : strSet) {
- boolean isMatched = false;
- for(String pattern : patternSet) {
- isMatched = str.matches(pattern);
-
- if(isMatched) {
- break;
- }
- }
-
- foundUnmatched = ! isMatched;
-
- if(foundUnmatched) {
- break;
- }
- }
-
- ret = !foundUnmatched;
- }
-
- return ret;
- }
- */
-
- public static boolean contains(String str, String strToFind) {
- return str != null && strToFind != null && str.contains(strToFind);
- }
-
- public static boolean containsIgnoreCase(String str, String strToFind) {
- return str != null && strToFind != null && str.toLowerCase().contains(strToFind.toLowerCase());
- }
-
- public static boolean contains(String[] strArr, String str) {
- boolean ret = false;
-
- if(strArr != null && strArr.length > 0 && str != null) {
- for(String s : strArr) {
- ret = equals(s, str);
-
- if(ret) {
- break;
- }
- }
- }
-
- return ret;
- }
-
- public static boolean containsIgnoreCase(String[] strArr, String str) {
- boolean ret = false;
-
- if(strArr != null && strArr.length > 0 && str != null) {
- for(String s : strArr) {
- ret = equalsIgnoreCase(s, str);
-
- if(ret) {
- break;
- }
- }
- }
-
- return ret;
- }
-
- public static String toString(Iterable<String> iterable) {
- String ret = "";
-
- if(iterable != null) {
- int count = 0;
- for(String str : iterable) {
- if(count == 0)
- ret = str;
- else
- ret += (", " + str);
- count++;
- }
- }
-
- return ret;
- }
-
- public static String toString(String[] arr) {
- String ret = "";
-
- if(arr != null && arr.length > 0) {
- ret = arr[0];
- for(int i = 1; i < arr.length; i++) {
- ret += (", " + arr[i]);
- }
- }
-
- return ret;
- }
-
- public static String toString(List<String> arr) {
- String ret = "";
-
- if(arr != null && !arr.isEmpty()) {
- ret = arr.get(0);
- for(int i = 1; i < arr.size(); i++) {
- ret += (", " + arr.get(i));
- }
- }
-
- return ret;
- }
-
- public static boolean isEmpty(String str) {
- return str == null || str.trim().isEmpty();
- }
-
- public static <T> boolean isEmpty(Collection<T> set) {
- return set == null || set.isEmpty();
- }
-
- public static String toLower(String str) {
- return str == null ? null : str.toLowerCase();
- }
-
- public static byte[] getBytes(String str) {
- return str == null ? null : str.getBytes();
- }
-
- public static Date getUTCDate() {
- Calendar local = Calendar.getInstance();
- int offset = local.getTimeZone().getOffset(local.getTimeInMillis());
-
- GregorianCalendar utc = new GregorianCalendar(gmtTimeZone);
-
- utc.setTimeInMillis(local.getTimeInMillis());
- utc.add(Calendar.MILLISECOND, -offset);
-
- return utc.getTime();
- }
-
- public static Date getUTCDateForLocalDate(Date date) {
- Calendar local = Calendar.getInstance();
- int offset = local.getTimeZone().getOffset(local.getTimeInMillis());
-
- GregorianCalendar utc = new GregorianCalendar(gmtTimeZone);
-
- utc.setTimeInMillis(date.getTime());
- utc.add(Calendar.MILLISECOND, -offset);
-
- return utc.getTime();
- }
-
- public static Map<String, Object> toStringObjectMap(Map<String, String> map) {
- Map<String, Object> ret = null;
-
- if (map != null) {
- ret = new HashMap<>(map.size());
-
- for (Map.Entry<String, String> e : map.entrySet()) {
- ret.put(e.getKey(), e.getValue());
- }
- }
-
- return ret;
- }
-
- public static Set<String> toSet(String str) {
- Set<String> values = new HashSet<String>();
- if (StringUtils.isNotBlank(str)) {
- for (String item : str.split(",")) {
- if (StringUtils.isNotBlank(item)) {
- values.add(StringUtils.trim(item));
- }
- }
- }
- return values;
- }
-
- public static List<String> toList(String str) {
- List<String> values;
- if (StringUtils.isNotBlank(str)) {
- values = new ArrayList<>();
- for (String item : str.split(",")) {
- if (StringUtils.isNotBlank(item)) {
- values.add(StringUtils.trim(item));
- }
- }
- } else {
- values = Collections.emptyList();
- }
- return values;
- }
-
- public static List<String> getURLs(String configURLs) {
- List<String> configuredURLs = new ArrayList<>();
- if(configURLs!=null) {
- String[] urls = configURLs.split(",");
- for (String strUrl : urls) {
- if (StringUtils.isNotEmpty(StringUtils.trimToEmpty(strUrl))) {
- if (strUrl.endsWith("/")) {
- strUrl = strUrl.substring(0, strUrl.length() - 1);
- }
- configuredURLs.add(strUrl);
- }
- }
- }
- return configuredURLs;
- }
-
- public static Map<String, Map<String, String>> dedupStringsMapOfMap(Map<String, Map<String, String>> value, Map<String, String> strTbl) {
- final Map<String, Map<String, String>> ret;
-
- if (MapUtils.isNotEmpty(value)) {
- ret = new HashMap<>(value.size());
-
- for (Map.Entry<String, Map<String, String>> entry : value.entrySet()) {
- ret.put(dedupString(entry.getKey(), strTbl), dedupStringsMap(entry.getValue(), strTbl));
- }
- } else {
- ret = value;
- }
-
- return ret;
- }
-
- public static Map<String, Set<String>> dedupStringsMapOfSet(Map<String, Set<String>> value, Map<String, String> strTbl) {
- final Map<String, Set<String>> ret;
-
- if (MapUtils.isNotEmpty(value)) {
- ret = new HashMap<>(value.size());
-
- for (Map.Entry<String, Set<String>> entry : value.entrySet()) {
- ret.put(dedupString(entry.getKey(), strTbl), dedupStringsSet(entry.getValue(), strTbl));
- }
- } else {
- ret = value;
- }
-
- return ret;
- }
-
- public static Map<String, List<String>> dedupStringsMapOfList(Map<String, List<String>> value, Map<String, String> strTbl) {
- final Map<String, List<String>> ret;
-
- if (MapUtils.isNotEmpty(value)) {
- ret = new HashMap<>(value.size());
-
- for (Map.Entry<String, List<String>> entry : value.entrySet()) {
- ret.put(dedupString(entry.getKey(), strTbl), dedupStringsList(entry.getValue(), strTbl));
- }
- } else {
- ret = value;
- }
-
- return ret;
- }
-
- public static HashMap<String, List<String>> dedupStringsHashMapOfList(HashMap<String, List<String>> value, Map<String, String> strTbl) {
- final HashMap<String, List<String>> ret;
-
- if (MapUtils.isNotEmpty(value)) {
- ret = new HashMap<>(value.size());
-
- for (Map.Entry<String, List<String>> entry : value.entrySet()) {
- ret.put(dedupString(entry.getKey(), strTbl), dedupStringsList(entry.getValue(), strTbl));
- }
- } else {
- ret = value;
- }
-
- return ret;
- }
-
- public static Map<String, Object> dedupStringsMapOfObject(Map<String, Object> value, Map<String, String> strTbl) {
- final Map<String, Object> ret;
-
- if (MapUtils.isNotEmpty(value)) {
- ret = new HashMap<>(value.size());
-
- for (Map.Entry<String, Object> entry : value.entrySet()) {
- ret.put(dedupString(entry.getKey(), strTbl), entry.getValue());
- }
- } else {
- ret = value;
- }
-
- return ret;
- }
-
- public static Map<String, RangerPolicyResource> dedupStringsMapOfPolicyResource(Map<String, RangerPolicyResource> value, Map<String, String> strTbl) {
- final Map<String, RangerPolicyResource> ret;
-
- if (MapUtils.isNotEmpty(value)) {
- ret = new HashMap<>(value.size());
-
- for (Map.Entry<String, RangerPolicyResource> entry : value.entrySet()) {
- RangerPolicyResource resource = entry.getValue();
-
- resource.dedupStrings(strTbl);
+ final boolean ret;
+
+ if (str1 == null) {
+ ret = str2 == null;
+ } else if (str2 == null) {
+ ret = false;
+ } else {
+ ret = str1.equals(str2);
+ }
+
+ return ret;
+ }
+
+ public static boolean equalsIgnoreCase(String str1, String str2) {
+ final boolean ret;
+
+ if (str1 == null) {
+ ret = str2 == null;
+ } else if (str2 == null) {
+ ret = false;
+ } else {
+ ret = str1.equalsIgnoreCase(str2);
+ }
+
+ return ret;
+ }
+
+ public static boolean equals(Collection<String> set1, Collection<String> set2) {
+ final boolean ret;
+
+ if (set1 == null) {
+ ret = set2 == null;
+ } else if (set2 == null) {
+ ret = false;
+ } else if (set1.size() == set2.size()) {
+ ret = set1.containsAll(set2);
+ } else {
+ ret = false;
+ }
+
+ return ret;
+ }
+
+ public static boolean equalsIgnoreCase(Collection<String> set1, Collection<String> set2) {
+ final boolean ret;
+
+ if (set1 == null) {
+ ret = set2 == null;
+ } else if (set2 == null) {
+ ret = false;
+ } else if (set1.size() == set2.size()) {
+ int numFound = 0;
+
+ for (String str1 : set1) {
+ boolean str1Found = false;
+
+ for (String str2 : set2) {
+ if (equalsIgnoreCase(str1, str2)) {
+ str1Found = true;
+
+ break;
+ }
+ }
+
+ if (str1Found) {
+ numFound++;
+ } else {
+ break;
+ }
+ }
+
+ ret = numFound == set1.size();
+ } else {
+ ret = false;
+ }
+
+ return ret;
+ }
+
+ public static boolean matches(String pattern, String str) {
+ final boolean ret;
+
+ if (pattern == null || str == null || pattern.isEmpty() || str.isEmpty()) {
+ ret = true;
+ } else {
+ ret = str.matches(pattern);
+ }
+
+ return ret;
+ }
+
+ public static boolean contains(String str, String strToFind) {
+ return str != null && strToFind != null && str.contains(strToFind);
+ }
+
+ public static boolean containsIgnoreCase(String str, String strToFind) {
+ return str != null && strToFind != null && str.toLowerCase().contains(strToFind.toLowerCase());
+ }
+
+ public static boolean contains(String[] strArr, String str) {
+ boolean ret = false;
+
+ if (strArr != null && strArr.length > 0 && str != null) {
+ for (String s : strArr) {
+ ret = equals(s, str);
+
+ if (ret) {
+ break;
+ }
+ }
+ }
+
+ return ret;
+ }
+
+ public static boolean containsIgnoreCase(String[] strArr, String str) {
+ boolean ret = false;
+
+ if (strArr != null && strArr.length > 0 && str != null) {
+ for (String s : strArr) {
+ ret = equalsIgnoreCase(s, str);
+
+ if (ret) {
+ break;
+ }
+ }
+ }
+
+ return ret;
+ }
+
+ public static String toString(Iterable<String> iterable) {
+ String ret = "";
+
+ if (iterable != null) {
+ int count = 0;
+
+ for (String str : iterable) {
+ if (count == 0) {
+ ret = str;
+ } else {
+ ret += (", " + str);
+ }
+
+ count++;
+ }
+ }
+
+ return ret;
+ }
+
+ public static String toString(String[] arr) {
+ String ret = "";
+
+ if (arr != null && arr.length > 0) {
+ ret = arr[0];
+
+ for (int i = 1; i < arr.length; i++) {
+ ret += (", " + arr[i]);
+ }
+ }
+
+ return ret;
+ }
+
+ public static String toString(List<String> arr) {
+ String ret = "";
+
+ if (arr != null && !arr.isEmpty()) {
+ ret = arr.get(0);
+
+ for (int i = 1; i < arr.size(); i++) {
+ ret += (", " + arr.get(i));
+ }
+ }
+
+ return ret;
+ }
+
+ public static boolean isEmpty(String str) {
+ return str == null || str.trim().isEmpty();
+ }
+
+ public static <T> boolean isEmpty(Collection<T> set) {
+ return set == null || set.isEmpty();
+ }
+
+ public static String toLower(String str) {
+ return str == null ? null : str.toLowerCase();
+ }
+
+ public static byte[] getBytes(String str) {
+ return str == null ? null : str.getBytes();
+ }
+
+ public static Date getUTCDate() {
+ Calendar local = Calendar.getInstance();
+ int offset = local.getTimeZone().getOffset(local.getTimeInMillis());
+ GregorianCalendar utc = new GregorianCalendar(gmtTimeZone);
+
+ utc.setTimeInMillis(local.getTimeInMillis());
+ utc.add(Calendar.MILLISECOND, -offset);
+
+ return utc.getTime();
+ }
+
+ public static Date getUTCDateForLocalDate(Date date) {
+ Calendar local = Calendar.getInstance();
+ int offset = local.getTimeZone().getOffset(local.getTimeInMillis());
+ GregorianCalendar utc = new GregorianCalendar(gmtTimeZone);
+
+ utc.setTimeInMillis(date.getTime());
+ utc.add(Calendar.MILLISECOND, -offset);
+
+ return utc.getTime();
+ }
+
+ public static Map<String, Object> toStringObjectMap(Map<String, String> map) {
+ Map<String, Object> ret = null;
+
+ if (map != null) {
+ ret = new HashMap<>(map.size());
+
+ for (Map.Entry<String, String> e : map.entrySet()) {
+ ret.put(e.getKey(), e.getValue());
+ }
+ }
+
+ return ret;
+ }
+
+ public static Set<String> toSet(String str) {
+ Set<String> values = new HashSet<>();
+
+ if (StringUtils.isNotBlank(str)) {
+ for (String item : str.split(",")) {
+ if (StringUtils.isNotBlank(item)) {
+ values.add(StringUtils.trim(item));
+ }
+ }
+ }
+
+ return values;
+ }
+
+ public static List<String> toList(String str) {
+ final List<String> values;
+
+ if (StringUtils.isNotBlank(str)) {
+ values = new ArrayList<>();
+
+ for (String item : str.split(",")) {
+ if (StringUtils.isNotBlank(item)) {
+ values.add(StringUtils.trim(item));
+ }
+ }
+ } else {
+ values = Collections.emptyList();
+ }
+
+ return values;
+ }
+
+ public static List<String> getURLs(String configURLs) {
+ List<String> configuredURLs = new ArrayList<>();
+
+ if (configURLs != null) {
+ String[] urls = configURLs.split(",");
+
+ for (String strUrl : urls) {
+ if (StringUtils.isNotEmpty(StringUtils.trimToEmpty(strUrl))) {
+ if (strUrl.endsWith("/")) {
+ strUrl = strUrl.substring(0, strUrl.length() - 1);
+ }
+
+ configuredURLs.add(strUrl);
+ }
+ }
+ }
+
+ return configuredURLs;
+ }
+
+ public static Map<String, Map<String, String>> dedupStringsMapOfMap(Map<String, Map<String, String>> value, Map<String, String> strTbl) {
+ final Map<String, Map<String, String>> ret;
+
+ if (MapUtils.isNotEmpty(value)) {
+ ret = new HashMap<>(value.size());
+
+ for (Map.Entry<String, Map<String, String>> entry : value.entrySet()) {
+ ret.put(dedupString(entry.getKey(), strTbl), dedupStringsMap(entry.getValue(), strTbl));
+ }
+ } else {
+ ret = value;
+ }
+
+ return ret;
+ }
+
+ public static Map<String, Set<String>> dedupStringsMapOfSet(Map<String, Set<String>> value, Map<String, String> strTbl) {
+ final Map<String, Set<String>> ret;
+
+ if (MapUtils.isNotEmpty(value)) {
+ ret = new HashMap<>(value.size());
+
+ for (Map.Entry<String, Set<String>> entry : value.entrySet()) {
+ ret.put(dedupString(entry.getKey(), strTbl), dedupStringsSet(entry.getValue(), strTbl));
+ }
+ } else {
+ ret = value;
+ }
+
+ return ret;
+ }
+
+ public static Map<String, List<String>> dedupStringsMapOfList(Map<String, List<String>> value, Map<String, String> strTbl) {
+ final Map<String, List<String>> ret;
+
+ if (MapUtils.isNotEmpty(value)) {
+ ret = new HashMap<>(value.size());
+
+ for (Map.Entry<String, List<String>> entry : value.entrySet()) {
+ ret.put(dedupString(entry.getKey(), strTbl), dedupStringsList(entry.getValue(), strTbl));
+ }
+ } else {
+ ret = value;
+ }
+
+ return ret;
+ }
+
+ public static HashMap<String, List<String>> dedupStringsHashMapOfList(HashMap<String, List<String>> value, Map<String, String> strTbl) {
+ final HashMap<String, List<String>> ret;
+
+ if (MapUtils.isNotEmpty(value)) {
+ ret = new HashMap<>(value.size());
+
+ for (Map.Entry<String, List<String>> entry : value.entrySet()) {
+ ret.put(dedupString(entry.getKey(), strTbl), dedupStringsList(entry.getValue(), strTbl));
+ }
+ } else {
+ ret = value;
+ }
+
+ return ret;
+ }
+
+ public static Map<String, Object> dedupStringsMapOfObject(Map<String, Object> value, Map<String, String> strTbl) {
+ final Map<String, Object> ret;
+
+ if (MapUtils.isNotEmpty(value)) {
+ ret = new HashMap<>(value.size());
+
+ for (Map.Entry<String, Object> entry : value.entrySet()) {
+ ret.put(dedupString(entry.getKey(), strTbl), entry.getValue());
+ }
+ } else {
+ ret = value;
+ }
+
+ return ret;
+ }
+
+ public static Map<String, RangerPolicyResource> dedupStringsMapOfPolicyResource(Map<String, RangerPolicyResource> value, Map<String, String> strTbl) {
+ final Map<String, RangerPolicyResource> ret;
+
+ if (MapUtils.isNotEmpty(value)) {
+ ret = new HashMap<>(value.size());
+
+ for (Map.Entry<String, RangerPolicyResource> entry : value.entrySet()) {
+ RangerPolicyResource resource = entry.getValue();
+
+ resource.dedupStrings(strTbl);
- ret.put(dedupString(entry.getKey(), strTbl), resource);
- }
- } else {
- ret = value;
- }
+ ret.put(dedupString(entry.getKey(), strTbl), resource);
+ }
+ } else {
+ ret = value;
+ }
- return ret;
- }
+ return ret;
+ }
- public static Map<String, String> dedupStringsMap(Map<String, String> value, Map<String, String> strTbl) {
- final Map<String, String> ret;
+ public static Map<String, String> dedupStringsMap(Map<String, String> value, Map<String, String> strTbl) {
+ final Map<String, String> ret;
- if (MapUtils.isNotEmpty(value)) {
- ret = new HashMap<>(value.size());
+ if (MapUtils.isNotEmpty(value)) {
+ ret = new HashMap<>(value.size());
- for (Map.Entry<String, String> entry : value.entrySet()) {
- ret.put(dedupString(entry.getKey(), strTbl), dedupString(entry.getValue(), strTbl));
- }
- } else {
- ret = value;
- }
+ for (Map.Entry<String, String> entry : value.entrySet()) {
+ ret.put(dedupString(entry.getKey(), strTbl), dedupString(entry.getValue(), strTbl));
+ }
+ } else {
+ ret = value;
+ }
- return ret;
- }
+ return ret;
+ }
- public static Set<String> dedupStringsSet(Set<String> value, Map<String, String> strTbl) {
- final Set<String> ret;
+ public static Set<String> dedupStringsSet(Set<String> value, Map<String, String> strTbl) {
+ final Set<String> ret;
- if (CollectionUtils.isNotEmpty(value)) {
- ret = new HashSet<>(value.size());
+ if (CollectionUtils.isNotEmpty(value)) {
+ ret = new HashSet<>(value.size());
- for (String val : value) {
- ret.add(dedupString(val, strTbl));
- }
- } else {
- ret = value;
- }
+ for (String val : value) {
+ ret.add(dedupString(val, strTbl));
+ }
+ } else {
+ ret = value;
+ }
- return ret;
- }
+ return ret;
+ }
- public static List<String> dedupStringsList(List<String> value, Map<String, String> strTbl) {
- final List<String> ret;
+ public static List<String> dedupStringsList(List<String> value, Map<String, String> strTbl) {
+ final List<String> ret;
- if (CollectionUtils.isNotEmpty(value)) {
- ret = new ArrayList<>(value.size());
+ if (CollectionUtils.isNotEmpty(value)) {
+ ret = new ArrayList<>(value.size());
- for (String val : value) {
- ret.add(dedupString(val, strTbl));
- }
- } else {
- ret = value;
- }
+ for (String val : value) {
+ ret.add(dedupString(val, strTbl));
+ }
+ } else {
+ ret = value;
+ }
- return ret;
- }
+ return ret;
+ }
- public static Collection<String> dedupStringsCollection(Collection<String> value, Map<String, String> strTbl) {
- final Collection<String> ret;
+ public static Collection<String> dedupStringsCollection(Collection<String> value, Map<String, String> strTbl) {
+ final Collection<String> ret;
- if (CollectionUtils.isNotEmpty(value)) {
- ret = value instanceof Set ? new HashSet<>(value.size()) : new ArrayList<>(value.size());
+ if (CollectionUtils.isNotEmpty(value)) {
+ ret = value instanceof Set ? new HashSet<>(value.size()) : new ArrayList<>(value.size());
- for (String val : value) {
- ret.add(dedupString(val, strTbl));
- }
- } else {
- ret = value;
- }
+ for (String val : value) {
+ ret.add(dedupString(val, strTbl));
+ }
+ } else {
+ ret = value;
+ }
- return ret;
- }
+ return ret;
+ }
- public static String dedupString(String str, Map<String, String> strTbl) {
- String ret = str != null ? strTbl.putIfAbsent(str, str) : null;
+ public static String dedupString(String str, Map<String, String> strTbl) {
+ String ret = str != null ? strTbl.putIfAbsent(str, str) : null;
- return ret == null ? str : ret;
- }
+ return ret == null ? str : ret;
+ }
- public static String compressString(String input) throws IOException {
- final String ret;
+ public static String compressString(String input) throws IOException {
+ final String ret;
- if (StringUtils.isEmpty(input)) {
- ret = input;
- } else {
- ret = new String(gzipCompress(input), StandardCharsets.ISO_8859_1);
- }
+ if (StringUtils.isEmpty(input)) {
+ ret = input;
+ } else {
+ ret = new String(gzipCompress(input), StandardCharsets.ISO_8859_1);
+ }
- return ret;
- }
+ return ret;
+ }
- public static String decompressString(String input) throws IOException {
- final String ret;
+ public static String decompressString(String input) throws IOException {
+ final String ret;
- if (StringUtils.isEmpty(input)) {
- ret = input;
- } else {
- ret = gzipDecompress(input.getBytes(StandardCharsets.ISO_8859_1));
- }
+ if (StringUtils.isEmpty(input)) {
+ ret = input;
+ } else {
+ ret = gzipDecompress(input.getBytes(StandardCharsets.ISO_8859_1));
+ }
- return ret;
- }
+ return ret;
+ }
- public static byte[] gzipCompress(String input) throws IOException {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- GZIPOutputStream gos = new GZIPOutputStream(out);
+ public static byte[] gzipCompress(String input) throws IOException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ GZIPOutputStream gos = new GZIPOutputStream(out);
- gos.write(input.getBytes(StandardCharsets.ISO_8859_1));
- gos.close();
+ gos.write(input.getBytes(StandardCharsets.ISO_8859_1));
+ gos.close();
- return out.toByteArray();
- }
+ return out.toByteArray();
+ }
- public static String gzipDecompress(byte[] input) throws IOException {
- ByteArrayInputStream in = new ByteArrayInputStream(input);
- GZIPInputStream gis = new GZIPInputStream(in);
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- byte[] buf = new byte[1024];
+ public static String gzipDecompress(byte[] input) throws IOException {
+ ByteArrayInputStream in = new ByteArrayInputStream(input);
+ GZIPInputStream gis = new GZIPInputStream(in);
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ byte[] buf = new byte[1024];
- while (true) {
- int bytesRead = gis.read(buf, 0, buf.length);
+ while (true) {
+ int bytesRead = gis.read(buf, 0, buf.length);
- if (bytesRead == -1) {
- break;
- }
+ if (bytesRead == -1) {
+ break;
+ }
- out.write(buf, 0, bytesRead);
- }
+ out.write(buf, 0, bytesRead);
+ }
- gis.close();
+ gis.close();
- return new String(out.toByteArray(), StandardCharsets.ISO_8859_1);
- }
+ return new String(out.toByteArray(), StandardCharsets.ISO_8859_1);
+ }
}
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/audit/RangerDefaultAuditHandler.java b/agents-common/src/main/java/org/apache/ranger/plugin/audit/RangerDefaultAuditHandler.java
index 8efea1fba..04f9d95f0 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/audit/RangerDefaultAuditHandler.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/audit/RangerDefaultAuditHandler.java
@@ -19,10 +19,6 @@
package org.apache.ranger.plugin.audit;
-import java.io.Serializable;
-import java.util.*;
-import java.util.concurrent.atomic.AtomicInteger;
-
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.conf.Configuration;
@@ -32,7 +28,10 @@ import org.apache.ranger.audit.provider.MiscUtil;
import org.apache.ranger.authorization.hadoop.constants.RangerHadoopConstants;
import org.apache.ranger.authorization.utils.JsonUtils;
import org.apache.ranger.plugin.contextenricher.RangerTagForEval;
-import org.apache.ranger.plugin.policyengine.*;
+import org.apache.ranger.plugin.policyengine.RangerAccessRequest;
+import org.apache.ranger.plugin.policyengine.RangerAccessResource;
+import org.apache.ranger.plugin.policyengine.RangerAccessResult;
+import org.apache.ranger.plugin.policyengine.RangerAccessResultProcessor;
import org.apache.ranger.plugin.policyengine.gds.GdsAccessResult;
import org.apache.ranger.plugin.service.RangerBasePlugin;
import org.apache.ranger.plugin.util.JsonUtilsV2;
@@ -41,288 +40,269 @@ import org.apache.ranger.plugin.util.RangerRESTUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
public class RangerDefaultAuditHandler implements RangerAccessResultProcessor {
- private static final Logger LOG = LoggerFactory.getLogger(RangerDefaultAuditHandler.class);
-
- private static final String CONF_AUDIT_ID_STRICT_UUID = "xasecure.audit.auditid.strict.uuid";
- private static final boolean DEFAULT_AUDIT_ID_STRICT_UUID = false;
-
+ private static final Logger LOG = LoggerFactory.getLogger(RangerDefaultAuditHandler.class);
+
+ private static final String CONF_AUDIT_ID_STRICT_UUID = "xasecure.audit.auditid.strict.uuid";
+ private static final boolean DEFAULT_AUDIT_ID_STRICT_UUID = false;
+
+ protected final String moduleName;
+
+ private final boolean auditIdStrictUUID;
+ private long sequenceNumber;
+ private final RangerRESTUtils restUtils = new RangerRESTUtils();
+ private String uuid = MiscUtil.generateUniqueId();
+ private AtomicInteger counter = new AtomicInteger(0);
+
+ public RangerDefaultAuditHandler() {
+ auditIdStrictUUID = DEFAULT_AUDIT_ID_STRICT_UUID;
+ moduleName = RangerHadoopConstants.DEFAULT_RANGER_MODULE_ACL_NAME;
+ }
+
+ public RangerDefaultAuditHandler(Configuration config) {
+ auditIdStrictUUID = config.getBoolean(CONF_AUDIT_ID_STRICT_UUID, DEFAULT_AUDIT_ID_STRICT_UUID);
+ moduleName = config.get(RangerHadoopConstants.AUDITLOG_RANGER_MODULE_ACL_NAME_PROP, RangerHadoopConstants.DEFAULT_RANGER_MODULE_ACL_NAME);
+ }
+
+ @Override
+ public void processResult(RangerAccessResult result) {
+ LOG.debug("==> RangerDefaultAuditHandler.processResult({})", result);
+
+ AuthzAuditEvent event = getAuthzEvents(result);
+
+ logAuthzAudit(event);
+
+ LOG.debug("<== RangerDefaultAuditHandler.processResult({})", result);
+ }
+
+ @Override
+ public void processResults(Collection<RangerAccessResult> results) {
+ LOG.debug("==> RangerDefaultAuditHandler.processResults({})", results);
+
+ Collection<AuthzAuditEvent> events = getAuthzEvents(results);
+
+ if (events != null) {
+ logAuthzAudits(events);
+ }
+
+ LOG.debug("<== RangerDefaultAuditHandler.processResults({})", results);
+ }
+
+ public AuthzAuditEvent getAuthzEvents(RangerAccessResult result) {
+ LOG.debug("==> RangerDefaultAuditHandler.getAuthzEvents({})", result);
+
+ AuthzAuditEvent ret = null;
+
+ RangerAccessRequest request = result != null ? result.getAccessRequest() : null;
+
+ if (request != null && result.getIsAudited()) {
+ //RangerServiceDef serviceDef = result.getServiceDef();
+ RangerAccessResource resource = request.getResource();
+ String resourceType = resource == null ? null : resource.getLeafName();
+ String resourcePath = resource == null ? null : resource.getAsString();
+
+ ret = createAuthzAuditEvent();
+
+ ret.setRepositoryName(result.getServiceName());
+ ret.setRepositoryType(result.getServiceType());
+ ret.setResourceType(resourceType);
+ ret.setResourcePath(resourcePath);
+ ret.setRequestData(request.getRequestData());
+ ret.setEventTime(request.getAccessTime() != null ? request.getAccessTime() : new Date());
+ ret.setUser(request.getUser());
+ ret.setAction(request.getAccessType());
+ ret.setAccessResult((short) (result.getIsAllowed() ? 1 : 0));
+ ret.setPolicyId(result.getPolicyId());
+ ret.setAccessType(request.getAction());
+ ret.setClientIP(request.getClientIPAddress());
+ ret.setClientType(request.getClientType());
+ ret.setSessionId(request.getSessionId());
+ ret.setAclEnforcer(moduleName);
+
+ Set<String> tags = getTags(request);
+ if (tags != null) {
+ ret.setTags(tags);
+ }
+
+ ret.setDatasets(getDatasets(request));
+ ret.setProjects(getProjects(request));
+ ret.setAdditionalInfo(getAdditionalInfo(request));
+ ret.setClusterName(request.getClusterName());
+ ret.setZoneName(result.getZoneName());
+ ret.setAgentHostname(restUtils.getAgentHostname());
+ ret.setPolicyVersion(result.getPolicyVersion());
+
+ populateDefaults(ret);
+
+ result.setAuditLogId(ret.getEventId());
+ }
+
+ LOG.debug("<== RangerDefaultAuditHandler.getAuthzEvents({}): {}", result, ret);
+
+ return ret;
+ }
+
+ public Collection<AuthzAuditEvent> getAuthzEvents(Collection<RangerAccessResult> results) {
+ LOG.debug("==> RangerDefaultAuditHandler.getAuthzEvents({})", results);
+
+ List<AuthzAuditEvent> ret = null;
+
+ if (results != null) {
+ // TODO: optimize the number of audit logs created
+ for (RangerAccessResult result : results) {
+ AuthzAuditEvent event = getAuthzEvents(result);
+
+ if (event == null) {
+ continue;
+ }
+
+ if (ret == null) {
+ ret = new ArrayList<>();
+ }
+
+ ret.add(event);
+ }
+ }
+
+ LOG.debug("<== RangerDefaultAuditHandler.getAuthzEvents({}): {}", results, ret);
+
+ return ret;
+ }
+
+ public void logAuthzAudit(AuthzAuditEvent auditEvent) {
+ LOG.debug("==> RangerDefaultAuditHandler.logAuthzAudit({})", auditEvent);
+
+ if (auditEvent != null) {
+ populateDefaults(auditEvent);
+
+ AuditHandler auditProvider = RangerBasePlugin.getAuditProvider(auditEvent.getRepositoryName());
+ if (auditProvider == null || !auditProvider.log(auditEvent)) {
+ MiscUtil.logErrorMessageByInterval(LOG, "fail to log audit event " + auditEvent);
+ }
+ }
+
+ LOG.debug("<== RangerDefaultAuditHandler.logAuthzAudit({})", auditEvent);
+ }
+
+ public void logAuthzAudits(Collection<AuthzAuditEvent> auditEvents) {
+ LOG.debug("==> RangerDefaultAuditHandler.logAuthzAudits({})", auditEvents);
+
+ if (auditEvents != null) {
+ for (AuthzAuditEvent auditEvent : auditEvents) {
+ logAuthzAudit(auditEvent);
+ }
+ }
+
+ LOG.debug("<== RangerDefaultAuditHandler.logAuthzAudits({})", auditEvents);
+ }
+
+ public AuthzAuditEvent createAuthzAuditEvent() {
+ return new AuthzAuditEvent();
+ }
+
+ public final Set<String> getDatasets(RangerAccessRequest request) {
+ GdsAccessResult gdsResult = RangerAccessRequestUtil.getGdsResultFromContext(request.getContext());
+
+ return gdsResult != null ? gdsResult.getDatasets() : null;
+ }
+
+ public final Set<String> getProjects(RangerAccessRequest request) {
+ GdsAccessResult gdsResult = RangerAccessRequestUtil.getGdsResultFromContext(request.getContext());
+
+ return gdsResult != null ? gdsResult.getProjects() : null;
+ }
+
+ public String getAdditionalInfo(RangerAccessRequest request) {
+ if (StringUtils.isBlank(request.getRemoteIPAddress()) && CollectionUtils.isEmpty(request.getForwardedAddresses())) {
+ return null;
+ }
+
+ Map<String, String> addInfomap = new HashMap<>();
+ addInfomap.put("forwarded-ip-addresses", "[" + StringUtils.join(request.getForwardedAddresses(), ", ") + "]");
+ addInfomap.put("remote-ip-address", request.getRemoteIPAddress());
- private final boolean auditIdStrictUUID;
- protected final String moduleName;
- private final RangerRESTUtils restUtils = new RangerRESTUtils();
- private long sequenceNumber = 0;
- private String UUID = MiscUtil.generateUniqueId();
- private AtomicInteger counter = new AtomicInteger(0);
+ return JsonUtils.mapToJson(addInfomap);
+ }
+ protected final Set<String> getTags(RangerAccessRequest request) {
+ Set<String> ret = null;
+ Set<RangerTagForEval> tags = RangerAccessRequestUtil.getRequestTagsFromContext(request.getContext());
+ if (CollectionUtils.isNotEmpty(tags)) {
+ ret = new HashSet<>();
- public RangerDefaultAuditHandler() {
- auditIdStrictUUID = DEFAULT_AUDIT_ID_STRICT_UUID;
- moduleName = RangerHadoopConstants.DEFAULT_RANGER_MODULE_ACL_NAME;
- }
-
- public RangerDefaultAuditHandler(Configuration config) {
- auditIdStrictUUID = config.getBoolean(CONF_AUDIT_ID_STRICT_UUID, DEFAULT_AUDIT_ID_STRICT_UUID);
- moduleName = config.get(RangerHadoopConstants.AUDITLOG_RANGER_MODULE_ACL_NAME_PROP , RangerHadoopConstants.DEFAULT_RANGER_MODULE_ACL_NAME);
- }
+ for (RangerTagForEval tag : tags) {
+ ret.add(writeObjectAsString(tag));
+ }
+ }
- @Override
- public void processResult(RangerAccessResult result) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerDefaultAuditHandler.processResult(" + result + ")");
- }
+ return ret;
+ }
- AuthzAuditEvent event = getAuthzEvents(result);
+ private void populateDefaults(AuthzAuditEvent auditEvent) {
+ if (auditEvent.getAclEnforcer() == null || auditEvent.getAclEnforcer().isEmpty()) {
+ auditEvent.setAclEnforcer("ranger-acl"); // TODO: review
+ }
- logAuthzAudit(event);
+ if (auditEvent.getAgentHostname() == null || auditEvent.getAgentHostname().isEmpty()) {
+ auditEvent.setAgentHostname(MiscUtil.getHostname());
+ }
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerDefaultAuditHandler.processResult(" + result + ")");
- }
- }
+ if (auditEvent.getLogType() == null || auditEvent.getLogType().isEmpty()) {
+ auditEvent.setLogType("RangerAudit");
+ }
- @Override
- public void processResults(Collection<RangerAccessResult> results) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerDefaultAuditHandler.processResults(" + results + ")");
- }
+ if (auditEvent.getEventId() == null || auditEvent.getEventId().isEmpty()) {
+ auditEvent.setEventId(generateNextAuditEventId());
+ }
- Collection<AuthzAuditEvent> events = getAuthzEvents(results);
+ if (auditEvent.getAgentId() == null) {
+ auditEvent.setAgentId(MiscUtil.getApplicationType());
+ }
- if (events != null) {
- logAuthzAudits(events);
- }
+ auditEvent.setSeqNum(sequenceNumber++);
+ }
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerDefaultAuditHandler.processResults(" + results + ")");
- }
- }
+ private String generateNextAuditEventId() {
+ final String ret;
+ if (auditIdStrictUUID) {
+ ret = MiscUtil.generateGuid();
+ } else {
+ int nextId = counter.getAndIncrement();
- public AuthzAuditEvent getAuthzEvents(RangerAccessResult result) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerDefaultAuditHandler.getAuthzEvents(" + result + ")");
- }
+ if (nextId == Integer.MAX_VALUE) {
+ // reset UUID and counter
+ uuid = MiscUtil.generateUniqueId();
+ counter = new AtomicInteger(0);
+ }
- AuthzAuditEvent ret = null;
-
- RangerAccessRequest request = result != null ? result.getAccessRequest() : null;
+ ret = uuid + "-" + nextId;
+ }
- if(request != null && result != null && result.getIsAudited()) {
- //RangerServiceDef serviceDef = result.getServiceDef();
- RangerAccessResource resource = request.getResource();
- String resourceType = resource == null ? null : resource.getLeafName();
- String resourcePath = resource == null ? null : resource.getAsString();
-
- ret = createAuthzAuditEvent();
+ LOG.debug("generateNextAuditEventId(): {}", ret);
- ret.setRepositoryName(result.getServiceName());
- ret.setRepositoryType(result.getServiceType());
- ret.setResourceType(resourceType);
- ret.setResourcePath(resourcePath);
- ret.setRequestData(request.getRequestData());
- ret.setEventTime(request.getAccessTime() != null ? request.getAccessTime() : new Date());
- ret.setUser(request.getUser());
- ret.setAction(request.getAccessType());
- ret.setAccessResult((short) (result.getIsAllowed() ? 1 : 0));
- ret.setPolicyId(result.getPolicyId());
- ret.setAccessType(request.getAction());
- ret.setClientIP(request.getClientIPAddress());
- ret.setClientType(request.getClientType());
- ret.setSessionId(request.getSessionId());
- ret.setAclEnforcer(moduleName);
+ return ret;
+ }
- Set<String> tags = getTags(request);
- if (tags != null) {
- ret.setTags(tags);
- }
-
- ret.setDatasets(getDatasets(request));
- ret.setProjects(getProjects(request));
- ret.setAdditionalInfo(getAdditionalInfo(request));
- ret.setClusterName(request.getClusterName());
- ret.setZoneName(result.getZoneName());
- ret.setAgentHostname(restUtils.getAgentHostname());
- ret.setPolicyVersion(result.getPolicyVersion());
-
- populateDefaults(ret);
-
- result.setAuditLogId(ret.getEventId());
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerDefaultAuditHandler.getAuthzEvents(" + result + "): " + ret);
- }
-
- return ret;
- }
-
- public Collection<AuthzAuditEvent> getAuthzEvents(Collection<RangerAccessResult> results) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerDefaultAuditHandler.getAuthzEvents(" + results + ")");
- }
-
- List<AuthzAuditEvent> ret = null;
-
- if(results != null) {
- // TODO: optimize the number of audit logs created
- for(RangerAccessResult result : results) {
- AuthzAuditEvent event = getAuthzEvents(result);
-
- if(event == null) {
- continue;
- }
-
- if(ret == null) {
- ret = new ArrayList<>();
- }
-
- ret.add(event);
- }
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerDefaultAuditHandler.getAuthzEvents(" + results + "): " + ret);
- }
-
- return ret;
- }
-
- public void logAuthzAudit(AuthzAuditEvent auditEvent) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerDefaultAuditHandler.logAuthzAudit(" + auditEvent + ")");
- }
-
- if(auditEvent != null) {
- populateDefaults(auditEvent);
-
- AuditHandler auditProvider = RangerBasePlugin.getAuditProvider(auditEvent.getRepositoryName());
- if (auditProvider == null || !auditProvider.log(auditEvent)) {
- MiscUtil.logErrorMessageByInterval(LOG, "fail to log audit event " + auditEvent);
- }
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerDefaultAuditHandler.logAuthzAudit(" + auditEvent + ")");
- }
- }
-
- private void populateDefaults(AuthzAuditEvent auditEvent) {
- if( auditEvent.getAclEnforcer() == null || auditEvent.getAclEnforcer().isEmpty()) {
- auditEvent.setAclEnforcer("ranger-acl"); // TODO: review
- }
-
- if (auditEvent.getAgentHostname() == null || auditEvent.getAgentHostname().isEmpty()) {
- auditEvent.setAgentHostname(MiscUtil.getHostname());
- }
-
- if (auditEvent.getLogType() == null || auditEvent.getLogType().isEmpty()) {
- auditEvent.setLogType("RangerAudit");
- }
-
- if (auditEvent.getEventId() == null || auditEvent.getEventId().isEmpty()) {
- auditEvent.setEventId(generateNextAuditEventId());
- }
-
- if (auditEvent.getAgentId() == null) {
- auditEvent.setAgentId(MiscUtil.getApplicationType());
- }
-
- auditEvent.setSeqNum(sequenceNumber++);
- }
-
- public void logAuthzAudits(Collection<AuthzAuditEvent> auditEvents) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerDefaultAuditHandler.logAuthzAudits(" + auditEvents + ")");
- }
-
- if(auditEvents != null) {
- for(AuthzAuditEvent auditEvent : auditEvents) {
- logAuthzAudit(auditEvent);
- }
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerDefaultAuditHandler.logAuthzAudits(" + auditEvents + ")");
- }
- }
-
- public AuthzAuditEvent createAuthzAuditEvent() {
- return new AuthzAuditEvent();
- }
-
- protected final Set<String> getTags(RangerAccessRequest request) {
- Set<String> ret = null;
- Set<RangerTagForEval> tags = RangerAccessRequestUtil.getRequestTagsFromContext(request.getContext());
-
- if (CollectionUtils.isNotEmpty(tags)) {
- ret = new HashSet<>();
-
- for (RangerTagForEval tag : tags) {
- ret.add(writeObjectAsString(tag));
- }
- }
-
- return ret;
- }
-
- public final Set<String> getDatasets(RangerAccessRequest request) {
- GdsAccessResult gdsResult = RangerAccessRequestUtil.getGdsResultFromContext(request.getContext());
-
- return gdsResult != null ? gdsResult.getDatasets() : null;
- }
-
- public final Set<String> getProjects(RangerAccessRequest request) {
- GdsAccessResult gdsResult = RangerAccessRequestUtil.getGdsResultFromContext(request.getContext());
-
- return gdsResult != null ? gdsResult.getProjects() : null;
- }
-
- public String getAdditionalInfo(RangerAccessRequest request) {
- if (StringUtils.isBlank(request.getRemoteIPAddress()) && CollectionUtils.isEmpty(request.getForwardedAddresses())) {
- return null;
- }
- Map<String,String> addInfomap=new HashMap<String,String>();
- addInfomap.put("forwarded-ip-addresses", "[" + StringUtils.join(request.getForwardedAddresses(), ", ") + "]");
- addInfomap.put("remote-ip-address", request.getRemoteIPAddress());
- String addInfojsonStr = JsonUtils.mapToJson(addInfomap);
- return addInfojsonStr;
-
- }
-
- private String generateNextAuditEventId() {
- final String ret;
-
- if (auditIdStrictUUID) {
- ret = MiscUtil.generateGuid();
- } else {
- int nextId = counter.getAndIncrement();
-
- if (nextId == Integer.MAX_VALUE) {
- // reset UUID and counter
- UUID = MiscUtil.generateUniqueId();
- counter = new AtomicInteger(0);
- }
-
- ret = UUID + "-" + Integer.toString(nextId);
- }
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("generateNextAuditEventId(): " + ret);
- }
-
- return ret;
- }
-
- private String writeObjectAsString(Serializable obj) {
- String jsonStr = StringUtils.EMPTY;
- try {
- jsonStr = JsonUtilsV2.objToJson(obj);
- } catch (Exception e) {
- LOG.error("Cannot create JSON string for object:[" + obj + "]", e);
- }
- return jsonStr;
- }
+ private String writeObjectAsString(Serializable obj) {
+ String jsonStr = StringUtils.EMPTY;
+ try {
+ jsonStr = JsonUtilsV2.objToJson(obj);
+ } catch (Exception e) {
+ LOG.error("Cannot create JSON string for object:[{}]", obj, e);
+ }
+ return jsonStr;
+ }
}
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/audit/RangerMultiResourceAuditHandler.java b/agents-common/src/main/java/org/apache/ranger/plugin/audit/RangerMultiResourceAuditHandler.java
index c657cce8f..0fb7798f0 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/audit/RangerMultiResourceAuditHandler.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/audit/RangerMultiResourceAuditHandler.java
@@ -19,55 +19,56 @@
package org.apache.ranger.plugin.audit;
-import java.util.ArrayList;
-import java.util.Collection;
-
import org.apache.ranger.audit.model.AuthzAuditEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.ArrayList;
+import java.util.Collection;
+
public class RangerMultiResourceAuditHandler extends RangerDefaultAuditHandler {
- private static final Logger LOG = LoggerFactory.getLogger(RangerMultiResourceAuditHandler.class);
+ private static final Logger LOG = LoggerFactory.getLogger(RangerMultiResourceAuditHandler.class);
+
+ Collection<AuthzAuditEvent> auditEvents = new ArrayList<>();
- Collection<AuthzAuditEvent> auditEvents = new ArrayList<>();
+ public RangerMultiResourceAuditHandler() {
+ }
- public RangerMultiResourceAuditHandler() {
- }
+ @Override
+ public void logAuthzAudit(AuthzAuditEvent auditEvent) {
+ auditEvents.add(auditEvent);
+ }
+ @Override
+ public void logAuthzAudits(Collection<AuthzAuditEvent> auditEvents) {
+ this.auditEvents.addAll(auditEvents);
+ }
- @Override
- public void logAuthzAudit(AuthzAuditEvent auditEvent) {
- auditEvents.add(auditEvent);
- }
+ public void flushAudit() {
+ try {
+ boolean deniedExists = false;
- @Override
- public void logAuthzAudits(Collection<AuthzAuditEvent> auditEvents) {
- this.auditEvents.addAll(auditEvents);
- }
+ // First iterate to see if there are any denied
+ for (AuthzAuditEvent auditEvent : auditEvents) {
+ if (auditEvent.getAccessResult() == 0) {
+ deniedExists = true;
- public void flushAudit() {
- try {
- boolean deniedExists = false;
- // First iterate to see if there are any denied
- for (AuthzAuditEvent auditEvent : auditEvents) {
- if (auditEvent.getAccessResult() == 0) {
- deniedExists = true;
- break;
- }
- }
+ break;
+ }
+ }
- for (AuthzAuditEvent auditEvent : auditEvents) {
- if (deniedExists && auditEvent.getAccessResult() != 0) {
- continue;
- }
+ for (AuthzAuditEvent auditEvent : auditEvents) {
+ if (deniedExists && auditEvent.getAccessResult() != 0) {
+ continue;
+ }
- super.logAuthzAudit(auditEvent);
- }
- } catch (Throwable t) {
- LOG.error("Error occured while writing audit log... ", t);
- } finally {
- // reset auditEvents once audits are logged
- auditEvents = new ArrayList<>();
- }
- }
+ super.logAuthzAudit(auditEvent);
+ }
+ } catch (Throwable t) {
+ LOG.error("Error occured while writing audit log... ", t);
+ } finally {
+ // reset auditEvents once audits are logged
+ auditEvents = new ArrayList<>();
+ }
+ }
}
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/client/BaseClient.java b/agents-common/src/main/java/org/apache/ranger/plugin/client/BaseClient.java
index b1628f2c8..7eb00fb0b 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/client/BaseClient.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/client/BaseClient.java
@@ -17,14 +17,7 @@
* under the License.
*/
- package org.apache.ranger.plugin.client;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import javax.security.auth.Subject;
+package org.apache.ranger.plugin.client;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.security.SecureClientLogin;
@@ -32,162 +25,175 @@ import org.apache.ranger.plugin.util.PasswordUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.security.auth.Subject;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
public abstract class BaseClient {
- private static final Logger LOG = LoggerFactory.getLogger(BaseClient.class);
-
-
- private static final String DEFAULT_NAME_RULE = "DEFAULT";
- protected static final String DEFAULT_ERROR_MESSAGE = " You can still save the repository and start creating "
- + "policies, but you would not be able to use autocomplete for "
- + "resource names. Check ranger_admin.log for more info.";
-
-
- private String serviceName;
- private String defaultConfigFile;
- private Subject loginSubject;
- private HadoopConfigHolder configHolder;
-
- protected Map<String,String> connectionProperties;
-
- public BaseClient(String svcName, Map<String,String> connectionProperties) {
- this(svcName, connectionProperties, null);
- }
-
- public BaseClient(String serivceName, Map<String,String> connectionProperties, String defaultConfigFile) {
- this.serviceName = serivceName;
- this.connectionProperties = connectionProperties;
- this.defaultConfigFile = defaultConfigFile;
- init();
- login();
- }
-
-
- private void init() {
- if (connectionProperties == null) {
- configHolder = HadoopConfigHolder.getInstance(serviceName);
- }
- else {
- configHolder = HadoopConfigHolder.getInstance(serviceName,connectionProperties, defaultConfigFile);
- }
- }
-
-
- protected void login() {
- ClassLoader prevCl = Thread.currentThread().getContextClassLoader();
- try {
- //Thread.currentThread().setContextClassLoader(configHolder.getClassLoader());
- String lookupPrincipal = SecureClientLogin.getPrincipal(configHolder.getLookupPrincipal(), java.net.InetAddress.getLocalHost().getCanonicalHostName());
- String lookupKeytab = configHolder.getLookupKeytab();
- String nameRules = configHolder.getNameRules();
- if(StringUtils.isEmpty(nameRules)){
- if(LOG.isDebugEnabled()){
- LOG.debug("Name Rule is empty. Setting Name Rule as 'DEFAULT'");
- }
- nameRules = DEFAULT_NAME_RULE;
- }
- String userName = configHolder.getUserName();
- if(StringUtils.isEmpty(lookupPrincipal) || StringUtils.isEmpty(lookupKeytab)){
- if (userName == null) {
- throw createException("Unable to find login username for hadoop environment, [" + serviceName + "]", null);
- }
- String keyTabFile = configHolder.getKeyTabFile();
- if (keyTabFile != null) {
- if ( configHolder.isKerberosAuthentication() ) {
- LOG.info("Init Login: security enabled, using username/keytab");
- loginSubject = SecureClientLogin.loginUserFromKeytab(userName, keyTabFile, nameRules);
- }
- else {
- LOG.info("Init Login: using username");
- loginSubject = SecureClientLogin.login(userName);
- }
- }
- else {
- String encryptedPwd = configHolder.getPassword();
- String password = null;
- if (encryptedPwd != null) {
- try {
- password = PasswordUtils.decryptPassword(encryptedPwd);
- } catch(Exception ex) {
- LOG.info("Password decryption failed; trying connection with received password string");
- password = null;
- } finally {
- if (password == null) {
- password = encryptedPwd;
- }
- }
- } else {
- LOG.info("Password decryption failed: no password was configured");
- }
- if ( configHolder.isKerberosAuthentication() ) {
- LOG.info("Init Login: using username/password");
- loginSubject = SecureClientLogin.loginUserWithPassword(userName, password);
- }
- else {
- LOG.info("Init Login: security not enabled, using username");
- loginSubject = SecureClientLogin.login(userName);
- }
- }
- }else{
- if ( configHolder.isKerberosAuthentication() ) {
- LOG.info("Init Lookup Login: security enabled, using lookupPrincipal/lookupKeytab");
- loginSubject = SecureClientLogin.loginUserFromKeytab(lookupPrincipal, lookupKeytab, nameRules);
- }else{
- LOG.info("Init Login: security not enabled, using username");
- loginSubject = SecureClientLogin.login(userName);
- }
- }
- } catch (IOException ioe) {
- throw createException(ioe);
- } catch (SecurityException se) {
- throw createException(se);
- } finally {
- Thread.currentThread().setContextClassLoader(prevCl);
- }
- }
-
- private HadoopException createException(Exception exp) {
- return createException("Unable to login to Hadoop environment [" + serviceName + "]", exp);
- }
-
- private HadoopException createException(String msgDesc, Exception exp) {
- HadoopException hdpException = new HadoopException(msgDesc, exp);
- final String fullDescription = exp != null ? getMessage(exp) : msgDesc;
- hdpException.generateResponseDataMap(false, fullDescription + DEFAULT_ERROR_MESSAGE,
- msgDesc + DEFAULT_ERROR_MESSAGE, null, null);
- return hdpException;
- }
-
- public String getSerivceName() {
- return serviceName;
- }
-
- protected Subject getLoginSubject() {
- return loginSubject;
- }
-
- protected HadoopConfigHolder getConfigHolder() {
- return configHolder;
- }
-
- public static void generateResponseDataMap(boolean connectivityStatus,
- String message, String description, Long objectId,
- String fieldName, Map<String, Object> responseData) {
- responseData.put("connectivityStatus", connectivityStatus);
- responseData.put("message", message);
- responseData.put("description", description);
- responseData.put("objectId", objectId);
- responseData.put("fieldName", fieldName);
- }
-
- public static String getMessage(Throwable excp) {
- List<String> errList = new ArrayList<>();
- while (excp != null) {
- String message = excp.getMessage();
- if (StringUtils.isNotEmpty(message) && !errList.contains(message + ". \n")) {
- errList.add(message + ". \n");
- }
- excp = excp.getCause();
- }
- return StringUtils.join(errList, "");
- }
+ private static final Logger LOG = LoggerFactory.getLogger(BaseClient.class);
+
+ protected static final String DEFAULT_ERROR_MESSAGE = " You can still save the repository and start creating policies, but you would not be able to use autocomplete for resource names. Check ranger_admin.log for more info.";
+ private static final String DEFAULT_NAME_RULE = "DEFAULT";
+
+ protected Map<String, String> connectionProperties;
+
+ private final String serviceName;
+ private final String defaultConfigFile;
+ private Subject loginSubject;
+ private HadoopConfigHolder configHolder;
+
+ public BaseClient(String svcName, Map<String, String> connectionProperties) {
+ this(svcName, connectionProperties, null);
+ }
+
+ public BaseClient(String serviceName, Map<String, String> connectionProperties, String defaultConfigFile) {
+ this.serviceName = serviceName;
+ this.connectionProperties = connectionProperties;
+ this.defaultConfigFile = defaultConfigFile;
+
+ init();
+ login();
+ }
+
+ public static void generateResponseDataMap(boolean connectivityStatus, String message, String description, Long objectId, String fieldName, Map<String, Object> responseData) {
+ responseData.put("connectivityStatus", connectivityStatus);
+ responseData.put("message", message);
+ responseData.put("description", description);
+ responseData.put("objectId", objectId);
+ responseData.put("fieldName", fieldName);
+ }
+
+ public static String getMessage(Throwable excp) {
+ List<String> errList = new ArrayList<>();
+
+ while (excp != null) {
+ String message = excp.getMessage();
+
+ if (StringUtils.isNotEmpty(message) && !errList.contains(message + ". \n")) {
+ errList.add(message + ". \n");
+ }
+
+ excp = excp.getCause();
+ }
+
+ return StringUtils.join(errList, "");
+ }
+
+ public String getSerivceName() {
+ return serviceName;
+ }
+
+ protected void login() {
+ ClassLoader prevCl = Thread.currentThread().getContextClassLoader();
+
+ try {
+ //Thread.currentThread().setContextClassLoader(configHolder.getClassLoader());
+ String lookupPrincipal = SecureClientLogin.getPrincipal(configHolder.getLookupPrincipal(), java.net.InetAddress.getLocalHost().getCanonicalHostName());
+ String lookupKeytab = configHolder.getLookupKeytab();
+ String nameRules = configHolder.getNameRules();
+
+ if (StringUtils.isEmpty(nameRules)) {
+ LOG.debug("Name Rule is empty. Setting Name Rule as 'DEFAULT'");
+
+ nameRules = DEFAULT_NAME_RULE;
+ }
+
+ String userName = configHolder.getUserName();
+
+ if (StringUtils.isEmpty(lookupPrincipal) || StringUtils.isEmpty(lookupKeytab)) {
+ if (userName == null) {
+ throw createException("Unable to find login username for hadoop environment, [" + serviceName + "]", null);
+ }
+
+ String keyTabFile = configHolder.getKeyTabFile();
+
+ if (keyTabFile != null) {
+ if (configHolder.isKerberosAuthentication()) {
+ LOG.info("Init Login: security enabled, using username/keytab");
+
+ loginSubject = SecureClientLogin.loginUserFromKeytab(userName, keyTabFile, nameRules);
+ } else {
+ LOG.info("Init Login: using username");
+
+ loginSubject = SecureClientLogin.login(userName);
+ }
+ } else {
+ String encryptedPwd = configHolder.getPassword();
+ String password = null;
+
+ if (encryptedPwd != null) {
+ try {
+ password = PasswordUtils.decryptPassword(encryptedPwd);
+ } catch (Exception ex) {
+ LOG.info("Password decryption failed; trying connection with received password string");
+
+ password = null;
+ } finally {
+ if (password == null) {
+ password = encryptedPwd;
+ }
+ }
+ } else {
+ LOG.info("Password decryption failed: no password was configured");
+ }
+
+ if (configHolder.isKerberosAuthentication()) {
+ LOG.info("Init Login: using username/password");
+
+ loginSubject = SecureClientLogin.loginUserWithPassword(userName, password);
+ } else {
+ LOG.info("Init Login: security not enabled, using username");
+
+ loginSubject = SecureClientLogin.login(userName);
+ }
+ }
+ } else {
+ if (configHolder.isKerberosAuthentication()) {
+ LOG.info("Init Lookup Login: security enabled, using lookupPrincipal/lookupKeytab");
+
+ loginSubject = SecureClientLogin.loginUserFromKeytab(lookupPrincipal, lookupKeytab, nameRules);
+ } else {
+ LOG.info("Init Login: security not enabled, using username");
+
+ loginSubject = SecureClientLogin.login(userName);
+ }
+ }
+ } catch (IOException | SecurityException ex) {
+ throw createException(ex);
+ } finally {
+ Thread.currentThread().setContextClassLoader(prevCl);
+ }
+ }
+
+ protected Subject getLoginSubject() {
+ return loginSubject;
+ }
+
+ protected HadoopConfigHolder getConfigHolder() {
+ return configHolder;
+ }
+
+ private void init() {
+ if (connectionProperties == null) {
+ configHolder = HadoopConfigHolder.getInstance(serviceName);
+ } else {
+ configHolder = HadoopConfigHolder.getInstance(serviceName, connectionProperties, defaultConfigFile);
+ }
+ }
+
+ private HadoopException createException(Exception exp) {
+ return createException("Unable to login to Hadoop environment [" + serviceName + "]", exp);
+ }
+
+ private HadoopException createException(String msgDesc, Exception exp) {
+ HadoopException hdpException = new HadoopException(msgDesc, exp);
+ final String fullDescription = exp != null ? getMessage(exp) : msgDesc;
+
+ hdpException.generateResponseDataMap(false, fullDescription + DEFAULT_ERROR_MESSAGE, msgDesc + DEFAULT_ERROR_MESSAGE, null, null);
+
+ return hdpException;
+ }
}
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/client/HadoopConfigHolder.java b/agents-common/src/main/java/org/apache/ranger/plugin/client/HadoopConfigHolder.java
index 492dbcdcf..e8ffd7ea0 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/client/HadoopConfigHolder.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/client/HadoopConfigHolder.java
@@ -17,7 +17,12 @@
* under the License.
*/
- package org.apache.ranger.plugin.client;
+package org.apache.ranger.plugin.client;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.hadoop.security.SecureClientLogin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
@@ -27,450 +32,428 @@ import java.util.Map;
import java.util.Properties;
import java.util.Set;
-import org.apache.commons.lang.StringUtils;
-import org.apache.hadoop.security.SecureClientLogin;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+public class HadoopConfigHolder {
+ private static final Logger LOG = LoggerFactory.getLogger(HadoopConfigHolder.class);
+
+ public static final String GLOBAL_LOGIN_PARAM_PROP_FILE = "hadoop-login.properties";
+ public static final String DEFAULT_DATASOURCE_PARAM_PROP_FILE = "datasource.properties";
+ public static final String RESOURCEMAP_PROP_FILE = "resourcenamemap.properties";
+ public static final String DEFAULT_RESOURCE_NAME = "core-site.xml";
+ public static final String RANGER_SECTION_NAME = "xalogin.xml";
+ public static final String RANGER_LOGIN_USER_NAME_PROP = "username";
+ public static final String RANGER_LOGIN_KEYTAB_FILE_PROP = "keytabfile";
+ public static final String RANGER_LOGIN_PASSWORD = "password";
+ public static final String RANGER_LOOKUP_PRINCIPAL = "lookupprincipal";
+ public static final String RANGER_LOOKUP_KEYTAB = "lookupkeytab";
+ public static final String RANGER_PRINCIPAL = "rangerprincipal";
+ public static final String RANGER_KEYTAB = "rangerkeytab";
+ public static final String RANGER_NAME_RULES = "namerules";
+ public static final String RANGER_AUTH_TYPE = "authtype";
+ public static final String HADOOP_SECURITY_AUTHENTICATION = "hadoop.security.authentication";
+ public static final String HADOOP_NAME_RULES = "hadoop.security.auth_to_local";
+ public static final String HADOOP_SECURITY_AUTHENTICATION_METHOD = "kerberos";
+ public static final String HADOOP_RPC_PROTECTION = "hadoop.rpc.protection";
+ public static final String ENABLE_HIVE_METASTORE_LOOKUP = "enable.hive.metastore.lookup";
+ public static final String HIVE_SITE_FILE_PATH = "hive.site.file.path";
+
+ private static boolean initialized;
+ private static final Map<String, HashMap<String, Properties>> dataSource2ResourceListMap = new HashMap<>();
+ private static final Map<String, HadoopConfigHolder> dataSource2HadoopConfigHolder = new HashMap<>();
+ private static Properties globalLoginProp = new Properties();
+ private static Properties resourcemapProperties;
+ private static final Set<String> rangerInternalPropertyKeys = new HashSet<>();
+
+ private final String datasourceName;
+ private String defaultConfigFile;
+ private String userName;
+ private String keyTabFile;
+ private String password;
+ private String lookupPrincipal;
+ private String lookupKeytab;
+ private String nameRules;
+ private String authType;
+ private String hiveSiteFilePath;
+ private boolean isKerberosAuth;
+ private boolean enableHiveMetastoreLookup;
+ private Map<String, String> connectionProperties;
+
+ private HadoopConfigHolder(String aDatasourceName) {
+ datasourceName = aDatasourceName;
+
+ if (!initialized) {
+ init();
+ }
+
+ initLoginInfo();
+ }
+
+ private HadoopConfigHolder(String aDatasourceName, Map<String, String> connectionProperties) {
+ this(aDatasourceName, connectionProperties, null);
+ }
+
+ private HadoopConfigHolder(String aDatasourceName, Map<String, String> connectionProperties, String defaultConfigFile) {
+ this.datasourceName = aDatasourceName;
+ this.connectionProperties = connectionProperties;
+ this.defaultConfigFile = defaultConfigFile;
+
+ initConnectionProp();
+ initLoginInfo();
+ }
+
+ public static HadoopConfigHolder getInstance(String aDatasourceName) {
+ HadoopConfigHolder ret = dataSource2HadoopConfigHolder.get(aDatasourceName);
+
+ if (ret == null) {
+ synchronized (HadoopConfigHolder.class) {
+ ret = dataSource2HadoopConfigHolder.get(aDatasourceName);
+
+ if (ret == null) {
+ ret = new HadoopConfigHolder(aDatasourceName);
+
+ dataSource2HadoopConfigHolder.put(aDatasourceName, ret);
+ }
+ }
+ }
+
+ return ret;
+ }
+
+ public static HadoopConfigHolder getInstance(String aDatasourceName, Map<String, String> connectionProperties, String defaultConfigFile) {
+ HadoopConfigHolder ret = dataSource2HadoopConfigHolder.get(aDatasourceName);
+
+ if (ret == null) {
+ synchronized (HadoopConfigHolder.class) {
+ ret = dataSource2HadoopConfigHolder.get(aDatasourceName);
+
+ if (ret == null) {
+ ret = new HadoopConfigHolder(aDatasourceName, connectionProperties, defaultConfigFile);
+
+ dataSource2HadoopConfigHolder.put(aDatasourceName, ret);
+ }
+ }
+ } else {
+ if (connectionProperties != null && !connectionProperties.equals(ret.connectionProperties)) {
+ ret = new HadoopConfigHolder(aDatasourceName, connectionProperties);
+
+ dataSource2HadoopConfigHolder.remove(aDatasourceName);
+ dataSource2HadoopConfigHolder.put(aDatasourceName, ret);
+ }
+ }
+
+ return ret;
+ }
+
+ public Properties getRangerSection() {
+ Properties prop = this.getProperties(RANGER_SECTION_NAME);
+
+ if (prop == null) {
+ prop = globalLoginProp;
+ }
+
+ return prop;
+ }
+
+ public String getDatasourceName() {
+ return datasourceName;
+ }
+
+ public boolean hasResourceExists(String aResourceName) { // dilli
+ HashMap<String, Properties> resourceName2PropertiesMap = dataSource2ResourceListMap.get(datasourceName);
+
+ return (resourceName2PropertiesMap != null && resourceName2PropertiesMap.containsKey(aResourceName));
+ }
+
+ public Properties getProperties(String aResourceName) {
+ Properties ret = null;
+ HashMap<String, Properties> resourceName2PropertiesMap = dataSource2ResourceListMap.get(datasourceName);
+
+ if (resourceName2PropertiesMap != null) {
+ ret = resourceName2PropertiesMap.get(aResourceName);
+ }
+
+ return ret;
+ }
+
+ public String getHadoopSecurityAuthentication() {
+ String sectionName = RANGER_SECTION_NAME;
+
+ if (defaultConfigFile != null) {
+ sectionName = defaultConfigFile;
+ }
+
+ LOG.debug("==> HadoopConfigHolder.getHadoopSecurityAuthentication(DataSource : {} Property : {})", sectionName, HADOOP_SECURITY_AUTHENTICATION);
+
+ String ret = getProperties(sectionName, HADOOP_SECURITY_AUTHENTICATION);
+
+ LOG.debug("<== HadoopConfigHolder.getHadoopSecurityAuthentication(DataSource : {} Property : {} Value : {})", sectionName, HADOOP_SECURITY_AUTHENTICATION, ret);
+
+ return ret;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public String getKeyTabFile() {
+ return keyTabFile;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public boolean isKerberosAuthentication() {
+ return isKerberosAuth;
+ }
+
+ public String getLookupPrincipal() {
+ return lookupPrincipal;
+ }
+
+ public String getLookupKeytab() {
+ return lookupKeytab;
+ }
-public class HadoopConfigHolder {
- private static final Logger LOG = LoggerFactory.getLogger(HadoopConfigHolder.class);
- public static final String GLOBAL_LOGIN_PARAM_PROP_FILE = "hadoop-login.properties";
- public static final String DEFAULT_DATASOURCE_PARAM_PROP_FILE = "datasource.properties";
- public static final String RESOURCEMAP_PROP_FILE = "resourcenamemap.properties";
- public static final String DEFAULT_RESOURCE_NAME = "core-site.xml";
- public static final String RANGER_SECTION_NAME = "xalogin.xml";
- public static final String RANGER_LOGIN_USER_NAME_PROP = "username";
- public static final String RANGER_LOGIN_KEYTAB_FILE_PROP = "keytabfile";
- public static final String RANGER_LOGIN_PASSWORD = "password";
- public static final String RANGER_LOOKUP_PRINCIPAL = "lookupprincipal";
- public static final String RANGER_LOOKUP_KEYTAB = "lookupkeytab";
- public static final String RANGER_PRINCIPAL = "rangerprincipal";
- public static final String RANGER_KEYTAB = "rangerkeytab";
- public static final String RANGER_NAME_RULES = "namerules";
- public static final String RANGER_AUTH_TYPE = "authtype";
- public static final String HADOOP_SECURITY_AUTHENTICATION = "hadoop.security.authentication";
- public static final String HADOOP_NAME_RULES = "hadoop.security.auth_to_local";
- public static final String HADOOP_SECURITY_AUTHENTICATION_METHOD = "kerberos";
- public static final String HADOOP_RPC_PROTECTION = "hadoop.rpc.protection";
-
- public static final String ENABLE_HIVE_METASTORE_LOOKUP = "enable.hive.metastore.lookup";
- public static final String HIVE_SITE_FILE_PATH = "hive.site.file.path";
-
- private static boolean initialized;
- private static Map<String,HashMap<String,Properties>> dataSource2ResourceListMap = new HashMap<>();
- private static Map<String,HadoopConfigHolder> dataSource2HadoopConfigHolder = new HashMap<>();
- private static Properties globalLoginProp = new Properties();
- private static Properties resourcemapProperties;
-
- private String datasourceName;
- private String defaultConfigFile;
- private String userName;
- private String keyTabFile;
- private String password;
- private String lookupPrincipal;
- private String lookupKeytab;
- private String nameRules;
- private String authType;
- private String hiveSiteFilePath;
- private boolean isKerberosAuth;
- private boolean enableHiveMetastoreLookup;
-
- private Map<String,String> connectionProperties;
-
- private static Set<String> rangerInternalPropertyKeys = new HashSet<>();
-
- public static HadoopConfigHolder getInstance(String aDatasourceName) {
- HadoopConfigHolder ret = dataSource2HadoopConfigHolder.get(aDatasourceName);
- if (ret == null) {
- synchronized (HadoopConfigHolder.class) {
- HadoopConfigHolder temp = ret;
- if (temp == null) {
- ret = new HadoopConfigHolder(aDatasourceName);
- dataSource2HadoopConfigHolder.put(aDatasourceName, ret);
- }
- }
- }
- return ret;
- }
-
- public static HadoopConfigHolder getInstance(String aDatasourceName, Map<String,String> connectionProperties,
- String defaultConfigFile) {
- HadoopConfigHolder ret = dataSource2HadoopConfigHolder.get(aDatasourceName);
- if (ret == null) {
- synchronized (HadoopConfigHolder.class) {
- HadoopConfigHolder temp = ret;
- if (temp == null) {
- ret = new HadoopConfigHolder(aDatasourceName,connectionProperties, defaultConfigFile);
- dataSource2HadoopConfigHolder.put(aDatasourceName, ret);
- }
- }
- }
- else {
- if (connectionProperties !=null && !connectionProperties.equals(ret.connectionProperties)) {
- ret = new HadoopConfigHolder(aDatasourceName,connectionProperties);
- dataSource2HadoopConfigHolder.remove(aDatasourceName);
- dataSource2HadoopConfigHolder.put(aDatasourceName, ret);
- }
- }
-
- return ret;
- }
-
-
-
- private HadoopConfigHolder(String aDatasourceName) {
- datasourceName = aDatasourceName;
- if (!initialized) {
- init();
- }
- initLoginInfo();
- }
-
- private HadoopConfigHolder(String aDatasourceName,
- Map<String, String> connectionProperties) {
- this(aDatasourceName, connectionProperties, null);
- }
-
- private HadoopConfigHolder(String aDatasourceName, Map<String,String> connectionProperties,
- String defaultConfigFile) {
- datasourceName = aDatasourceName;
- this.connectionProperties = connectionProperties;
- this.defaultConfigFile = defaultConfigFile;
- initConnectionProp();
- initLoginInfo();
- }
-
- private void initConnectionProp() {
- if (!connectionProperties.containsKey(ENABLE_HIVE_METASTORE_LOOKUP)) {
- connectionProperties.put(ENABLE_HIVE_METASTORE_LOOKUP, "false");
- }
- if (!connectionProperties.containsKey(HIVE_SITE_FILE_PATH)) {
- connectionProperties.put(HIVE_SITE_FILE_PATH, "");
- }
-
- for (Map.Entry<String, String> entry : connectionProperties.entrySet()) {
- String key = entry.getKey();
- String resourceName = getResourceName(key);
-
- if (resourceName == null) {
- resourceName = RANGER_SECTION_NAME;
- }
- String val = entry.getValue();
- addConfiguration(datasourceName, resourceName, key, val );
- }
- }
-
- private String getResourceName(String key) {
-
- if (resourcemapProperties == null) {
- initResourceMap();
- }
-
- if (resourcemapProperties != null) {
- String rn = resourcemapProperties.getProperty(key);
- return ( rn != null) ? rn : defaultConfigFile;
- } else {
- return defaultConfigFile;
- }
- }
-
- private static void initResourceMap() {
- Properties props = new Properties();
- InputStream in = HadoopConfigHolder.class.getClassLoader().getResourceAsStream(RESOURCEMAP_PROP_FILE);
- if (in != null) {
- try {
- props.load(in);
- for (Map.Entry<Object, Object> entry : props
- .entrySet()) {
- String value = (String) entry.getValue();
- if (RANGER_SECTION_NAME.equals(value)) {
- String key = (String) entry.getKey();
- rangerInternalPropertyKeys.add(key);
- }
- }
- resourcemapProperties = props;
- } catch (IOException e) {
- throw new HadoopException("Unable to load resource map properties from [" + RESOURCEMAP_PROP_FILE + "]", e);
- }
- finally {
- if (in != null) {
- try {
- in.close();
- } catch (IOException ioe) {
- // Ignore IOException during close of stream
- }
- }
- }
- } else {
- throw new HadoopException("Unable to locate resource map properties from [" + RESOURCEMAP_PROP_FILE + "] in the class path.");
- }
- }
-
-
-
- private static synchronized void init() {
-
- if (initialized) {
- return;
- }
-
- try {
- InputStream in = HadoopConfigHolder.class.getClassLoader().getResourceAsStream(DEFAULT_DATASOURCE_PARAM_PROP_FILE);
- if (in != null) {
- Properties prop = new Properties();
- try {
- prop.load(in);
- } catch (IOException e) {
- throw new HadoopException("Unable to get configuration information for Hadoop environments", e);
- }
- finally {
- try {
- in.close();
- } catch (IOException e) {
- // Ignored exception when the stream is closed.
- }
- }
-
- if (prop.isEmpty()) {
- return;
- }
-
- for (Object keyobj : prop.keySet()) {
- String key = (String)keyobj;
- String val = prop.getProperty(key);
-
- int dotLocatedAt = key.indexOf(".");
-
- if (dotLocatedAt == -1) {
- continue;
- }
-
- String dataSource = key.substring(0,dotLocatedAt);
-
- String propKey = key.substring(dotLocatedAt+1);
- int resourceFoundAt = propKey.indexOf(".");
- if (resourceFoundAt > -1) {
- String resourceName = propKey.substring(0, resourceFoundAt) + ".xml";
- propKey = propKey.substring(resourceFoundAt+1);
- addConfiguration(dataSource, resourceName, propKey, val);
- }
-
- }
- }
-
- in = HadoopConfigHolder.class.getClassLoader().getResourceAsStream(GLOBAL_LOGIN_PARAM_PROP_FILE);
- if (in != null) {
- Properties tempLoginProp = new Properties();
- try {
- tempLoginProp.load(in);
- } catch (IOException e) {
- throw new HadoopException("Unable to get login configuration information for Hadoop environments from file: [" + GLOBAL_LOGIN_PARAM_PROP_FILE + "]", e);
- }
- finally {
- try {
- in.close();
- } catch (IOException e) {
- // Ignored exception when the stream is closed.
- }
- }
- globalLoginProp = tempLoginProp;
- }
- }
- finally {
- initialized = true;
- }
- }
-
-
- private void initLoginInfo() {
- Properties prop = this.getRangerSection();
- if (prop != null) {
- userName = prop.getProperty(RANGER_LOGIN_USER_NAME_PROP);
- keyTabFile = prop.getProperty(RANGER_LOGIN_KEYTAB_FILE_PROP);
- if (StringUtils.trimToNull(prop.getProperty(ENABLE_HIVE_METASTORE_LOOKUP)) != null) {
- try {
- enableHiveMetastoreLookup = Boolean.valueOf(prop.getProperty(ENABLE_HIVE_METASTORE_LOOKUP,"false").trim());
- } catch (Exception e) {
- enableHiveMetastoreLookup = false;
- LOG.error("Error while getting " + ENABLE_HIVE_METASTORE_LOOKUP + " : " + e.getMessage());
- }
- }
- if (StringUtils.trimToNull(prop.getProperty(HIVE_SITE_FILE_PATH)) != null) {
- hiveSiteFilePath = prop.getProperty(HIVE_SITE_FILE_PATH).trim();
- } else {
- hiveSiteFilePath = null;
- }
-
- password = prop.getProperty(RANGER_LOGIN_PASSWORD);
- lookupPrincipal = prop.getProperty(RANGER_LOOKUP_PRINCIPAL);
- lookupKeytab = prop.getProperty(RANGER_LOOKUP_KEYTAB);
- nameRules = prop.getProperty(RANGER_NAME_RULES);
- authType = prop.getProperty(RANGER_AUTH_TYPE, "simple");
-
- String hadoopSecurityAuthentication = getHadoopSecurityAuthentication();
-
- if (hadoopSecurityAuthentication != null) {
- isKerberosAuth = HADOOP_SECURITY_AUTHENTICATION_METHOD.equalsIgnoreCase(hadoopSecurityAuthentication);
- } else {
- isKerberosAuth = (((userName != null) && (userName.indexOf("@") > -1)) || (SecureClientLogin.isKerberosCredentialExists(lookupPrincipal, lookupKeytab)));
- }
- }
- }
-
-
- public Properties getRangerSection() {
- Properties prop = this.getProperties(RANGER_SECTION_NAME);
- if (prop == null) {
- prop = globalLoginProp;
- }
- return prop;
- }
-
-
-
- private static void addConfiguration(String dataSource, String resourceName, String propertyName, String value) {
-
- if (dataSource == null || dataSource.isEmpty()) {
- return;
- }
-
- if (propertyName == null || propertyName.isEmpty()) {
- return;
- }
-
- if (resourceName == null) {
- resourceName = DEFAULT_RESOURCE_NAME;
- }
-
-
- HashMap<String,Properties> resourceName2PropertiesMap = dataSource2ResourceListMap.get(dataSource);
-
- if (resourceName2PropertiesMap == null) {
- resourceName2PropertiesMap = new HashMap<>();
- dataSource2ResourceListMap.put(dataSource, resourceName2PropertiesMap);
- }
-
- Properties prop = resourceName2PropertiesMap.get(resourceName);
- if (prop == null) {
- prop = new Properties();
- resourceName2PropertiesMap.put(resourceName, prop);
- }
- if (value == null) {
- prop.remove(propertyName);
- } else {
- prop.put(propertyName, value);
- }
- }
-
-
- public String getDatasourceName() {
- return datasourceName;
- }
-
- public boolean hasResourceExists(String aResourceName) { // dilli
- HashMap<String,Properties> resourceName2PropertiesMap = dataSource2ResourceListMap.get(datasourceName);
- return (resourceName2PropertiesMap != null && resourceName2PropertiesMap.containsKey(aResourceName));
- }
-
- public Properties getProperties(String aResourceName) {
- Properties ret = null;
- HashMap<String,Properties> resourceName2PropertiesMap = dataSource2ResourceListMap.get(datasourceName);
- if (resourceName2PropertiesMap != null) {
- ret = resourceName2PropertiesMap.get(aResourceName);
- }
- return ret;
- }
-
- public String getHadoopSecurityAuthentication() {
- String ret = null;
- String sectionName = RANGER_SECTION_NAME;
-
- if (defaultConfigFile != null) {
- sectionName = defaultConfigFile;
- }
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> HadoopConfigHolder.getHadoopSecurityAuthentication( " + " DataSource : " + sectionName + " Property : " + HADOOP_SECURITY_AUTHENTICATION + ")" );
- }
-
- ret = getProperties(sectionName,HADOOP_SECURITY_AUTHENTICATION);
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== HadoopConfigHolder.getHadoopSecurityAuthentication(" + " DataSource : " + sectionName + " Property : " + HADOOP_SECURITY_AUTHENTICATION + " Value : " + ret + ")" );
- }
-
- return ret;
- }
-
- public String getUserName() {
- return userName;
- }
-
- public String getKeyTabFile() {
- return keyTabFile;
- }
-
- public String getPassword() {
- return password;
- }
-
- public boolean isKerberosAuthentication() {
- return isKerberosAuth;
- }
-
- public String getLookupPrincipal() {
- return lookupPrincipal;
- }
-
- public String getLookupKeytab() {
- return lookupKeytab;
- }
-
- public String getNameRules() {
- return nameRules;
- }
-
- public String getAuthType() {
- return authType;
- }
-
- public boolean isEnableHiveMetastoreLookup() {
- return enableHiveMetastoreLookup;
- }
-
- public String getHiveSiteFilePath() {
- return hiveSiteFilePath;
- }
-
- public Set<String> getRangerInternalPropertyKeys() {
- return rangerInternalPropertyKeys;
- }
-
- private String getProperties(String sectionName, String property) {
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> HadoopConfigHolder.getProperties( " + " DataSource : " + sectionName + " Property : " + property + ")" );
- }
-
- Properties repoParam = null;
- String ret = null;
-
- HashMap<String,Properties> resourceName2PropertiesMap = dataSource2ResourceListMap.get(this.getDatasourceName());
-
- if (resourceName2PropertiesMap != null) {
- repoParam=resourceName2PropertiesMap.get(sectionName);
- }
-
- if (repoParam != null) {
- ret = (String)repoParam.get(property);
- }
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== HadoopConfigHolder.getProperties( " + " DataSource : " + sectionName + " Property : " + property + " Value : " + ret);
- }
-
- return ret;
- }
-
+ public String getNameRules() {
+ return nameRules;
+ }
+ public String getAuthType() {
+ return authType;
+ }
+
+ public boolean isEnableHiveMetastoreLookup() {
+ return enableHiveMetastoreLookup;
+ }
+
+ public String getHiveSiteFilePath() {
+ return hiveSiteFilePath;
+ }
+
+ public Set<String> getRangerInternalPropertyKeys() {
+ return rangerInternalPropertyKeys;
+ }
+
+ private void initConnectionProp() {
+ if (!connectionProperties.containsKey(ENABLE_HIVE_METASTORE_LOOKUP)) {
+ connectionProperties.put(ENABLE_HIVE_METASTORE_LOOKUP, "false");
+ }
+
+ if (!connectionProperties.containsKey(HIVE_SITE_FILE_PATH)) {
+ connectionProperties.put(HIVE_SITE_FILE_PATH, "");
+ }
+
+ for (Map.Entry<String, String> entry : connectionProperties.entrySet()) {
+ String key = entry.getKey();
+ String resourceName = getResourceName(key);
+
+ if (resourceName == null) {
+ resourceName = RANGER_SECTION_NAME;
+ }
+
+ String val = entry.getValue();
+
+ addConfiguration(datasourceName, resourceName, key, val);
+ }
+ }
+
+ private String getResourceName(String key) {
+ if (resourcemapProperties == null) {
+ initResourceMap();
+ }
+
+ if (resourcemapProperties != null) {
+ String rn = resourcemapProperties.getProperty(key);
+
+ return (rn != null) ? rn : defaultConfigFile;
+ } else {
+ return defaultConfigFile;
+ }
+ }
+
+ private static void initResourceMap() {
+ Properties props = new Properties();
+ InputStream in = HadoopConfigHolder.class.getClassLoader().getResourceAsStream(RESOURCEMAP_PROP_FILE);
+
+ if (in != null) {
+ try {
+ props.load(in);
+ for (Map.Entry<Object, Object> entry : props.entrySet()) {
+ String value = (String) entry.getValue();
+
+ if (RANGER_SECTION_NAME.equals(value)) {
+ String key = (String) entry.getKey();
+
+ rangerInternalPropertyKeys.add(key);
+ }
+ }
+
+ resourcemapProperties = props;
+ } catch (IOException e) {
+ throw new HadoopException("Unable to load resource map properties from [" + RESOURCEMAP_PROP_FILE + "]", e);
+ } finally {
+ try {
+ in.close();
+ } catch (IOException ioe) {
+ // Ignore IOException during close of stream
+ }
+ }
+ } else {
+ throw new HadoopException("Unable to locate resource map properties from [" + RESOURCEMAP_PROP_FILE + "] in the class path.");
+ }
+ }
+
+ private static synchronized void init() {
+ if (initialized) {
+ return;
+ }
+
+ try {
+ InputStream in = HadoopConfigHolder.class.getClassLoader().getResourceAsStream(DEFAULT_DATASOURCE_PARAM_PROP_FILE);
+
+ if (in != null) {
+ Properties prop = new Properties();
+
+ try {
+ prop.load(in);
+ } catch (IOException e) {
+ throw new HadoopException("Unable to get configuration information for Hadoop environments", e);
+ } finally {
+ try {
+ in.close();
+ } catch (IOException e) {
+ // Ignored exception when the stream is closed.
+ }
+ }
+
+ if (prop.isEmpty()) {
+ return;
+ }
+
+ for (Object keyobj : prop.keySet()) {
+ String key = (String) keyobj;
+ String val = prop.getProperty(key);
+ int dotLocatedAt = key.indexOf(".");
+
+ if (dotLocatedAt == -1) {
+ continue;
+ }
+
+ String dataSource = key.substring(0, dotLocatedAt);
+ String propKey = key.substring(dotLocatedAt + 1);
+ int resourceFoundAt = propKey.indexOf(".");
+
+ if (resourceFoundAt > -1) {
+ String resourceName = propKey.substring(0, resourceFoundAt) + ".xml";
+
+ propKey = propKey.substring(resourceFoundAt + 1);
+
+ addConfiguration(dataSource, resourceName, propKey, val);
+ }
+ }
+ }
+
+ in = HadoopConfigHolder.class.getClassLoader().getResourceAsStream(GLOBAL_LOGIN_PARAM_PROP_FILE);
+
+ if (in != null) {
+ Properties tempLoginProp = new Properties();
+
+ try {
+ tempLoginProp.load(in);
+ } catch (IOException e) {
+ throw new HadoopException("Unable to get login configuration information for Hadoop environments from file: [" + GLOBAL_LOGIN_PARAM_PROP_FILE + "]", e);
+ } finally {
+ try {
+ in.close();
+ } catch (IOException e) {
+ // Ignored exception when the stream is closed.
+ }
+ }
+ globalLoginProp = tempLoginProp;
+ }
+ } finally {
+ initialized = true;
+ }
+ }
+
+ private void initLoginInfo() {
+ Properties prop = this.getRangerSection();
+
+ if (prop != null) {
+ userName = prop.getProperty(RANGER_LOGIN_USER_NAME_PROP);
+ keyTabFile = prop.getProperty(RANGER_LOGIN_KEYTAB_FILE_PROP);
+
+ if (StringUtils.trimToNull(prop.getProperty(ENABLE_HIVE_METASTORE_LOOKUP)) != null) {
+ try {
+ enableHiveMetastoreLookup = Boolean.parseBoolean(prop.getProperty(ENABLE_HIVE_METASTORE_LOOKUP, "false").trim());
+ } catch (Exception e) {
+ enableHiveMetastoreLookup = false;
+
+ LOG.error("Error while getting {}: {}", ENABLE_HIVE_METASTORE_LOOKUP, e.getMessage());
+ }
+ }
+ if (StringUtils.trimToNull(prop.getProperty(HIVE_SITE_FILE_PATH)) != null) {
+ hiveSiteFilePath = prop.getProperty(HIVE_SITE_FILE_PATH).trim();
+ } else {
+ hiveSiteFilePath = null;
+ }
+
+ password = prop.getProperty(RANGER_LOGIN_PASSWORD);
+ lookupPrincipal = prop.getProperty(RANGER_LOOKUP_PRINCIPAL);
+ lookupKeytab = prop.getProperty(RANGER_LOOKUP_KEYTAB);
+ nameRules = prop.getProperty(RANGER_NAME_RULES);
+ authType = prop.getProperty(RANGER_AUTH_TYPE, "simple");
+
+ String hadoopSecurityAuthentication = getHadoopSecurityAuthentication();
+
+ if (hadoopSecurityAuthentication != null) {
+ isKerberosAuth = HADOOP_SECURITY_AUTHENTICATION_METHOD.equalsIgnoreCase(hadoopSecurityAuthentication);
+ } else {
+ isKerberosAuth = (((userName != null) && (userName.contains("@"))) || (SecureClientLogin.isKerberosCredentialExists(lookupPrincipal, lookupKeytab)));
+ }
+ }
+ }
+
+ private static void addConfiguration(String dataSource, String resourceName, String propertyName, String value) {
+ if (dataSource == null || dataSource.isEmpty()) {
+ return;
+ }
+
+ if (propertyName == null || propertyName.isEmpty()) {
+ return;
+ }
+
+ if (resourceName == null) {
+ resourceName = DEFAULT_RESOURCE_NAME;
+ }
+
+ HashMap<String, Properties> resourceName2PropertiesMap = dataSource2ResourceListMap.computeIfAbsent(dataSource, k -> new HashMap<>());
+ Properties prop = resourceName2PropertiesMap.computeIfAbsent(resourceName, k -> new Properties());
+
+ if (value == null) {
+ prop.remove(propertyName);
+ } else {
+ prop.put(propertyName, value);
+ }
+ }
+
+ private String getProperties(String sectionName, String property) {
+ LOG.debug("==> HadoopConfigHolder.getProperties(DataSource : {} Property : {})", sectionName, property);
+
+ Properties repoParam = null;
+ String ret = null;
+ HashMap<String, Properties> resourceName2PropertiesMap = dataSource2ResourceListMap.get(this.getDatasourceName());
+
+ if (resourceName2PropertiesMap != null) {
+ repoParam = resourceName2PropertiesMap.get(sectionName);
+ }
+
+ if (repoParam != null) {
+ ret = (String) repoParam.get(property);
+ }
+
+ LOG.debug("<== HadoopConfigHolder.getProperties(DataSource : {} Property : {} Value : {})", sectionName, property, ret);
+
+ return ret;
+ }
}
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/client/HadoopException.java b/agents-common/src/main/java/org/apache/ranger/plugin/client/HadoopException.java
index d66e6e192..6e782d6d3 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/client/HadoopException.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/client/HadoopException.java
@@ -17,64 +17,60 @@
* under the License.
*/
- package org.apache.ranger.plugin.client;
+package org.apache.ranger.plugin.client;
+
+import org.apache.commons.lang.StringUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
-import org.apache.commons.lang.StringUtils;
-
public class HadoopException extends RuntimeException {
- private static final long serialVersionUID = 8872734935128535649L;
-
- public HashMap<String, Object> responseData;
+ private static final long serialVersionUID = 8872734935128535649L;
+
+ public final HashMap<String, Object> responseData = new HashMap<>();
+
+ public HadoopException() {
+ super();
+ }
- public HadoopException() {
- super();
- }
+ public HadoopException(String message, Throwable cause) {
+ super(message, cause);
+ }
- public HadoopException(String message, Throwable cause) {
- super(message, cause);
- }
+ public HadoopException(String message) {
+ super(message);
+ }
- public HadoopException(String message) {
- super(message);
- }
+ public HadoopException(Throwable cause) {
+ super(cause);
+ }
- public HadoopException(Throwable cause) {
- super(cause);
- }
+ public void generateResponseDataMap(boolean connectivityStatus, String message, String description, Long objectId, String fieldName) {
+ responseData.put("connectivityStatus", connectivityStatus);
+ responseData.put("message", message);
+ responseData.put("description", description);
+ responseData.put("objectId", objectId);
+ responseData.put("fieldName", fieldName);
+ }
- public void generateResponseDataMap(boolean connectivityStatus,
- String message, String description, Long objectId, String fieldName) {
- responseData = new HashMap<>();
- responseData.put("connectivityStatus", connectivityStatus);
- responseData.put("message", message);
- responseData.put("description", description);
- responseData.put("objectId", objectId);
- responseData.put("fieldName", fieldName);
- }
+ public String getMessage(Throwable excp) {
+ List<String> errList = new ArrayList<>();
- public String getMessage(Throwable excp) {
- List<String> errList = new ArrayList<>();
- while (excp != null) {
- if (!errList.contains(excp.getMessage() + ". \n") && !errList.contains(excp.toString() + ". \n")) {
- if (excp.getMessage() != null && !(excp.getMessage().equalsIgnoreCase(""))) {
- errList.add(excp.getMessage() + ". \n");
- }
- }
- excp = excp.getCause();
- }
- return StringUtils.join(errList, "");
- }
+ while (excp != null) {
+ if (!errList.contains(excp.getMessage() + ". \n") && !errList.contains(excp + ". \n")) {
+ if (excp.getMessage() != null && !(excp.getMessage().equalsIgnoreCase(""))) {
+ errList.add(excp.getMessage() + ". \n");
+ }
+ }
- public HashMap<String,Object> getResponseData() {
- return responseData;
- }
+ excp = excp.getCause();
+ }
- public void setReponseData(HashMap<String,Object> responseData) {
- this.responseData = responseData;
- }
+ return StringUtils.join(errList, "");
+ }
+ public HashMap<String, Object> getResponseData() {
+ return responseData;
+ }
}
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAbstractConditionEvaluator.java b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAbstractConditionEvaluator.java
index ddd1a54de..30b0745f1 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAbstractConditionEvaluator.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAbstractConditionEvaluator.java
@@ -23,29 +23,30 @@ import org.apache.ranger.plugin.model.RangerServiceDef;
import org.apache.ranger.plugin.model.RangerServiceDef.RangerPolicyConditionDef;
public abstract class RangerAbstractConditionEvaluator implements RangerConditionEvaluator {
- protected RangerServiceDef serviceDef;
- protected RangerPolicyConditionDef conditionDef;
- protected RangerPolicyItemCondition condition;
-
- @Override
- public void setServiceDef(RangerServiceDef serviceDef) {
- this.serviceDef = serviceDef;
- }
-
- @Override
- public void setConditionDef(RangerPolicyConditionDef conditionDef) {
- this.conditionDef = conditionDef;
- }
-
- @Override
- public void setPolicyItemCondition(RangerPolicyItemCondition condition) {
- this.condition = condition;
- }
-
- @Override
- public void init() {
- }
-
- public RangerPolicyItemCondition getPolicyItemCondition() { return condition; }
-
+ protected RangerServiceDef serviceDef;
+ protected RangerPolicyConditionDef conditionDef;
+ protected RangerPolicyItemCondition condition;
+
+ @Override
+ public void setConditionDef(RangerPolicyConditionDef conditionDef) {
+ this.conditionDef = conditionDef;
+ }
+
+ public RangerPolicyItemCondition getPolicyItemCondition() {
+ return condition;
+ }
+
+ @Override
+ public void setPolicyItemCondition(RangerPolicyItemCondition condition) {
+ this.condition = condition;
+ }
+
+ @Override
+ public void setServiceDef(RangerServiceDef serviceDef) {
+ this.serviceDef = serviceDef;
+ }
+
+ @Override
+ public void init() {
+ }
}
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAccessedFromClusterCondition.java b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAccessedFromClusterCondition.java
index 3538b8768..636e638f1 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAccessedFromClusterCondition.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAccessedFromClusterCondition.java
@@ -24,45 +24,36 @@ import org.apache.ranger.plugin.policyengine.RangerAccessRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
public class RangerAccessedFromClusterCondition extends RangerAbstractConditionEvaluator {
- private static final Logger LOG = LoggerFactory.getLogger(RangerAccessedFromClusterCondition.class);
+ private static final Logger LOG = LoggerFactory.getLogger(RangerAccessedFromClusterCondition.class);
- private boolean isAlwaysTrue = false;
+ private boolean isAlwaysTrue;
- @Override
- public void init() {
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAccessedFromClusterCondition.init(" + condition + ")");
- }
+ @Override
+ public void init() {
+ LOG.debug("==> RangerAccessedFromClusterCondition.init({})", condition);
- super.init();
+ super.init();
- isAlwaysTrue = CollectionUtils.isEmpty(condition.getValues());
+ isAlwaysTrue = CollectionUtils.isEmpty(condition.getValues());
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAccessedFromClusterCondition.init(" + condition + ")");
- }
- }
+ LOG.debug("<== RangerAccessedFromClusterCondition.init({})", condition);
+ }
- @Override
- public boolean isMatched(RangerAccessRequest request) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAccessedFromClusterCondition.isMatched(" + condition + ")");
- }
+ @Override
+ public boolean isMatched(RangerAccessRequest request) {
+ LOG.debug("==> RangerAccessedFromClusterCondition.isMatched({})", condition);
- final boolean ret;
+ final boolean ret;
- if (isAlwaysTrue || request.getClusterName() == null) {
- ret = isAlwaysTrue;
- } else {
- ret = condition.getValues().contains(request.getClusterName());
- }
+ if (isAlwaysTrue || request.getClusterName() == null) {
+ ret = isAlwaysTrue;
+ } else {
+ ret = condition.getValues().contains(request.getClusterName());
+ }
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAccessedFromClusterCondition.isMatched(" + condition + "): " + ret);
- }
+ LOG.debug("<== RangerAccessedFromClusterCondition.isMatched({}): {}", condition, ret);
- return ret;
- }
+ return ret;
+ }
}
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAccessedFromClusterTypeCondition.java b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAccessedFromClusterTypeCondition.java
index 9e0a01f5d..f1205d793 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAccessedFromClusterTypeCondition.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAccessedFromClusterTypeCondition.java
@@ -23,44 +23,36 @@ import org.apache.ranger.plugin.policyengine.RangerAccessRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class RangerAccessedFromClusterTypeCondition extends RangerAbstractConditionEvaluator{
- private static final Logger LOG = LoggerFactory.getLogger(RangerAccessedFromClusterTypeCondition.class);
+public class RangerAccessedFromClusterTypeCondition extends RangerAbstractConditionEvaluator {
+ private static final Logger LOG = LoggerFactory.getLogger(RangerAccessedFromClusterTypeCondition.class);
- private boolean isAlwaysTrue = false;
+ private boolean isAlwaysTrue;
- @Override
- public void init() {
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAccessedFromClusterTypeCondition.init(" + condition + ")");
- }
+ @Override
+ public void init() {
+ LOG.debug("==> RangerAccessedFromClusterTypeCondition.init({})", condition);
- super.init();
+ super.init();
- isAlwaysTrue = CollectionUtils.isEmpty(condition.getValues());
+ isAlwaysTrue = CollectionUtils.isEmpty(condition.getValues());
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAccessedFromClusterTypeCondition.init(" + condition + ")");
- }
- }
- @Override
- public boolean isMatched(RangerAccessRequest request) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAccessedFromClusterTypeCondition.isMatched(" + condition + ")");
- }
+ LOG.debug("<== RangerAccessedFromClusterTypeCondition.init({})", condition);
+ }
- final boolean ret;
+ @Override
+ public boolean isMatched(RangerAccessRequest request) {
+ LOG.debug("==> RangerAccessedFromClusterTypeCondition.isMatched({})", condition);
- if (isAlwaysTrue || request.getClusterType() == null) {
- ret = isAlwaysTrue;
- } else {
- ret = condition.getValues().contains(request.getClusterType());
- }
+ final boolean ret;
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAccessedFromClusterTypeCondition.isMatched(" + condition + "): " + ret);
- }
+ if (isAlwaysTrue || request.getClusterType() == null) {
+ ret = isAlwaysTrue;
+ } else {
+ ret = condition.getValues().contains(request.getClusterType());
+ }
- return ret;
- }
+ LOG.debug("<== RangerAccessedFromClusterTypeCondition.isMatched({}): {}", condition, ret);
+ return ret;
+ }
}
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAccessedNotFromClusterCondition.java b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAccessedNotFromClusterCondition.java
index c0850f08b..83138440c 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAccessedNotFromClusterCondition.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAccessedNotFromClusterCondition.java
@@ -24,45 +24,36 @@ import org.apache.ranger.plugin.policyengine.RangerAccessRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
public class RangerAccessedNotFromClusterCondition extends RangerAbstractConditionEvaluator {
- private static final Logger LOG = LoggerFactory.getLogger(RangerAccessedNotFromClusterCondition.class);
+ private static final Logger LOG = LoggerFactory.getLogger(RangerAccessedNotFromClusterCondition.class);
- private boolean isAlwaysTrue = false;
+ private boolean isAlwaysTrue;
- @Override
- public void init() {
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAccessedNotFromClusterCondition.init(" + condition + ")");
- }
+ @Override
+ public void init() {
+ LOG.debug("==> RangerAccessedNotFromClusterCondition.init({})", condition);
- super.init();
+ super.init();
- isAlwaysTrue = CollectionUtils.isEmpty(condition.getValues());
+ isAlwaysTrue = CollectionUtils.isEmpty(condition.getValues());
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAccessedNotFromClusterCondition.init(" + condition + ")");
- }
- }
+ LOG.debug("<== RangerAccessedNotFromClusterCondition.init({})", condition);
+ }
- @Override
- public boolean isMatched(RangerAccessRequest request) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAccessedNotFromClusterCondition.isMatched(" + condition + ")");
- }
+ @Override
+ public boolean isMatched(RangerAccessRequest request) {
+ LOG.debug("==> RangerAccessedNotFromClusterCondition.isMatched({})", condition);
- final boolean ret;
+ final boolean ret;
- if (isAlwaysTrue || request.getClusterName() == null) {
- ret = true;
- } else {
- ret = !condition.getValues().contains(request.getClusterName());
- }
+ if (isAlwaysTrue || request.getClusterName() == null) {
+ ret = true;
+ } else {
+ ret = !condition.getValues().contains(request.getClusterName());
+ }
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAccessedNotFromClusterCondition.isMatched(" + condition + "): " + ret);
- }
+ LOG.debug("<== RangerAccessedNotFromClusterCondition.isMatched({}): {}", condition, ret);
- return ret;
- }
+ return ret;
+ }
}
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAccessedNotFromClusterTypeCondition.java b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAccessedNotFromClusterTypeCondition.java
index fe882960e..f8e5b5f34 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAccessedNotFromClusterTypeCondition.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAccessedNotFromClusterTypeCondition.java
@@ -23,44 +23,36 @@ import org.apache.ranger.plugin.policyengine.RangerAccessRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class RangerAccessedNotFromClusterTypeCondition extends RangerAbstractConditionEvaluator{
- private static final Logger LOG = LoggerFactory.getLogger(RangerAccessedNotFromClusterTypeCondition.class);
+public class RangerAccessedNotFromClusterTypeCondition extends RangerAbstractConditionEvaluator {
+ private static final Logger LOG = LoggerFactory.getLogger(RangerAccessedNotFromClusterTypeCondition.class);
- private boolean isAlwaysTrue = false;
+ private boolean isAlwaysTrue;
- @Override
- public void init() {
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAccessedNotFromClusterTypeCondition.init(" + condition + ")");
- }
+ @Override
+ public void init() {
+ LOG.debug("==> RangerAccessedNotFromClusterTypeCondition.init({})", condition);
- super.init();
+ super.init();
- isAlwaysTrue = CollectionUtils.isEmpty(condition.getValues());
+ isAlwaysTrue = CollectionUtils.isEmpty(condition.getValues());
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAccessedNotFromClusterTypeCondition.init(" + condition + ")");
- }
- }
+ LOG.debug("<== RangerAccessedNotFromClusterTypeCondition.init({})", condition);
+ }
- @Override
- public boolean isMatched(RangerAccessRequest request) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAccessedNotFromClusterTypeCondition.isMatched(" + condition + ")");
- }
+ @Override
+ public boolean isMatched(RangerAccessRequest request) {
+ LOG.debug("==> RangerAccessedNotFromClusterTypeCondition.isMatched({})", condition);
- final boolean ret;
+ final boolean ret;
- if (isAlwaysTrue || request.getClusterType() == null) {
- ret = true;
- } else {
- ret = !condition.getValues().contains(request.getClusterType());
- }
+ if (isAlwaysTrue || request.getClusterType() == null) {
+ ret = true;
+ } else {
+ ret = !condition.getValues().contains(request.getClusterType());
+ }
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAccessedNotFromClusterTypeCondition.isMatched(" + condition + "): " + ret);
- }
+ LOG.debug("<== RangerAccessedNotFromClusterTypeCondition.isMatched({}): {}", condition, ret);
- return ret;
- }
+ return ret;
+ }
}
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAnyOfExpectedTagsPresentConditionEvaluator.java b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAnyOfExpectedTagsPresentConditionEvaluator.java
index c7b78908a..281fc7802 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAnyOfExpectedTagsPresentConditionEvaluator.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAnyOfExpectedTagsPresentConditionEvaluator.java
@@ -30,55 +30,44 @@ import java.util.Set;
// Policy Condition to check if resource Tags does contain any of the policy Condition Tags
public class RangerAnyOfExpectedTagsPresentConditionEvaluator extends RangerAbstractConditionEvaluator {
+ private static final Logger LOG = LoggerFactory.getLogger(RangerAnyOfExpectedTagsPresentConditionEvaluator.class);
- private static final Logger LOG = LoggerFactory.getLogger(RangerAnyOfExpectedTagsPresentConditionEvaluator.class);
+ private final Set<String> policyConditionTags = new HashSet<>();
- private final Set<String> policyConditionTags = new HashSet<>();
+ @Override
+ public void init() {
+ LOG.debug("==> RangerAnyOfExpectedTagsPresentConditionEvaluator.init({})", condition);
- @Override
- public void init() {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAnyOfExpectedTagsPresentConditionEvaluator.init(" + condition + ")");
- }
+ super.init();
- super.init();
+ if (condition != null) {
+ for (String value : condition.getValues()) {
+ policyConditionTags.add(value.trim());
+ }
+ }
- if (condition != null ) {
- for (String value : condition.getValues()) {
- policyConditionTags.add(value.trim());
- }
- }
+ LOG.debug("<== RangerAnyOfExpectedTagsPresentConditionEvaluator.init({}): Tags[{}]", condition, policyConditionTags);
+ }
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAnyOfExpectedTagsPresentConditionEvaluator.init(" + condition + "): Tags[" + policyConditionTags + "]");
- }
- }
+ @Override
+ public boolean isMatched(RangerAccessRequest request) {
+ LOG.debug("==> RangerAnyOfExpectedTagsPresentConditionEvaluator.isMatched({})", request);
- @Override
- public boolean isMatched(RangerAccessRequest request) {
+ boolean matched = false;
+ Set<RangerTagForEval> resourceTags = RangerAccessRequestUtil.getRequestTagsFromContext(request.getContext());
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAnyOfExpectedTagsPresentConditionEvaluator.isMatched(" + request + ")");
- }
+ if (resourceTags != null) {
+ // check if resource Tags does contain any of the policy Condition Tags
+ for (RangerTagForEval tag : resourceTags) {
+ if (policyConditionTags.contains(tag.getType())) {
+ matched = true;
+ break;
+ }
+ }
+ }
- boolean matched = false;
- Set<RangerTagForEval> resourceTags = RangerAccessRequestUtil.getRequestTagsFromContext(request.getContext());
+ LOG.debug("<== RangerAnyOfExpectedTagsPresentConditionEvaluator.isMatched({}): {}", request, matched);
- if (resourceTags != null) {
- // check if resource Tags does contain any of the policy Condition Tags
- for (RangerTagForEval tag : resourceTags) {
- if (policyConditionTags.contains(tag.getType())) {
- matched = true;
- break;
- }
- }
- }
-
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAnyOfExpectedTagsPresentConditionEvaluator.isMatched(" + request+ "): " + matched);
- }
-
- return matched;
- }
+ return matched;
+ }
}
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerConditionEvaluator.java b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerConditionEvaluator.java
index 16f9a3c05..73dea03bc 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerConditionEvaluator.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerConditionEvaluator.java
@@ -25,13 +25,13 @@ import org.apache.ranger.plugin.model.RangerServiceDef.RangerPolicyConditionDef;
import org.apache.ranger.plugin.policyengine.RangerAccessRequest;
public interface RangerConditionEvaluator {
- void setConditionDef(RangerPolicyConditionDef conditionDef);
+ void setConditionDef(RangerPolicyConditionDef conditionDef);
- void setPolicyItemCondition(RangerPolicyItemCondition condition);
+ void setPolicyItemCondition(RangerPolicyItemCondition condition);
- void setServiceDef(RangerServiceDef serviceDef);
+ void setServiceDef(RangerServiceDef serviceDef);
- void init();
+ void init();
- boolean isMatched(RangerAccessRequest request);
+ boolean isMatched(RangerAccessRequest request);
}
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerContextAttributeValueInCondition.java b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerContextAttributeValueInCondition.java
index 5346fbd06..391b276e9 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerContextAttributeValueInCondition.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerContextAttributeValueInCondition.java
@@ -28,49 +28,41 @@ import org.slf4j.LoggerFactory;
import java.util.Map;
public class RangerContextAttributeValueInCondition extends RangerAbstractConditionEvaluator {
- private static final Logger LOG = LoggerFactory.getLogger(RangerContextAttributeValueInCondition.class);
+ private static final Logger LOG = LoggerFactory.getLogger(RangerContextAttributeValueInCondition.class);
- protected String attributeName;
+ protected String attributeName;
- @Override
- public void init() {
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> RangerContextAttributeValueInCondition.init(" + condition + ")");
- }
+ @Override
+ public void init() {
+ LOG.debug("==> RangerContextAttributeValueInCondition.init({})", condition);
- super.init();
+ super.init();
- Map<String, String> evalOptions = conditionDef. getEvaluatorOptions();
+ Map<String, String> evalOptions = conditionDef.getEvaluatorOptions();
- if (MapUtils.isNotEmpty(evalOptions)) {
- attributeName = evalOptions.get("attributeName");
- }
+ if (MapUtils.isNotEmpty(evalOptions)) {
+ attributeName = evalOptions.get("attributeName");
+ }
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== RangerContextAttributeValueInCondition.init(" + condition + ")");
- }
- }
+ LOG.debug("<== RangerContextAttributeValueInCondition.init({})", condition);
+ }
- @Override
- public boolean isMatched(RangerAccessRequest request) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> RangerContextAttributeValueInCondition.isMatched(" + condition + ")");
- }
+ @Override
+ public boolean isMatched(RangerAccessRequest request) {
+ LOG.debug("==> RangerContextAttributeValueInCondition.isMatched({})", condition);
- boolean ret = true;
+ boolean ret = true;
- if(attributeName != null && condition != null && CollectionUtils.isNotEmpty(condition.getValues())) {
- Object val = request.getContext().get(attributeName);
+ if (attributeName != null && condition != null && CollectionUtils.isNotEmpty(condition.getValues())) {
+ Object val = request.getContext().get(attributeName);
- if(val != null) {
- ret = condition.getValues().contains(val);
- }
- }
+ if (val != null) {
+ ret = condition.getValues().contains(val);
+ }
+ }
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== RangerContextAttributeValueInCondition.isMatched(" + condition + "): " + ret);
- }
+ LOG.debug("<== RangerContextAttributeValueInCondition.isMatched({}): {}", condition, ret);
- return ret;
- }
+ return ret;
+ }
}
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerContextAttributeValueNotInCondition.java b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerContextAttributeValueNotInCondition.java
index f11eb7edc..f4d5b3584 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerContextAttributeValueNotInCondition.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerContextAttributeValueNotInCondition.java
@@ -28,49 +28,41 @@ import org.slf4j.LoggerFactory;
import java.util.Map;
public class RangerContextAttributeValueNotInCondition extends RangerAbstractConditionEvaluator {
- private static final Logger LOG = LoggerFactory.getLogger(RangerContextAttributeValueNotInCondition.class);
+ private static final Logger LOG = LoggerFactory.getLogger(RangerContextAttributeValueNotInCondition.class);
- protected String attributeName;
+ protected String attributeName;
- @Override
- public void init() {
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> RangerContextAttributeValueNotInCondition.init(" + condition + ")");
- }
+ @Override
+ public void init() {
+ LOG.debug("==> RangerContextAttributeValueNotInCondition.init({})", condition);
- super.init();
+ super.init();
- Map<String, String> evalOptions = conditionDef. getEvaluatorOptions();
+ Map<String, String> evalOptions = conditionDef.getEvaluatorOptions();
- if (MapUtils.isNotEmpty(evalOptions)) {
- attributeName = evalOptions.get("attributeName");
- }
+ if (MapUtils.isNotEmpty(evalOptions)) {
+ attributeName = evalOptions.get("attributeName");
+ }
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== RangerContextAttributeValueNotInCondition.init(" + condition + ")");
- }
- }
+ LOG.debug("<== RangerContextAttributeValueNotInCondition.init({})", condition);
+ }
- @Override
- public boolean isMatched(RangerAccessRequest request) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> RangerContextAttributeValueNotInCondition.isMatched(" + condition + ")");
- }
+ @Override
+ public boolean isMatched(RangerAccessRequest request) {
+ LOG.debug("==> RangerContextAttributeValueNotInCondition.isMatched({})", condition);
- boolean ret = true;
+ boolean ret = true;
- if(attributeName != null && condition != null && CollectionUtils.isNotEmpty(condition.getValues())) {
- Object val = request.getContext().get(attributeName);
+ if (attributeName != null && condition != null && CollectionUtils.isNotEmpty(condition.getValues())) {
+ Object val = request.getContext().get(attributeName);
- if(val != null) {
- ret = !condition.getValues().contains(val);
- }
- }
+ if (val != null) {
+ ret = !condition.getValues().contains(val);
+ }
+ }
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== RangerContextAttributeValueNotInCondition.isMatched(" + condition + "): " + ret);
- }
+ LOG.debug("<== RangerContextAttributeValueNotInCondition.isMatched({}): {}", condition, ret);
- return ret;
- }
+ return ret;
+ }
}
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerHiveResourcesAccessedTogetherCondition.java b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerHiveResourcesAccessedTogetherCondition.java
index 3ea5de6e3..219acdefd 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerHiveResourcesAccessedTogetherCondition.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerHiveResourcesAccessedTogetherCondition.java
@@ -37,146 +37,123 @@ import java.util.List;
import java.util.Map;
public class RangerHiveResourcesAccessedTogetherCondition extends RangerAbstractConditionEvaluator {
- private static final Logger LOG = LoggerFactory.getLogger(RangerHiveResourcesAccessedTogetherCondition.class);
+ private static final Logger LOG = LoggerFactory.getLogger(RangerHiveResourcesAccessedTogetherCondition.class);
- private List<RangerPolicyResourceMatcher> matchers = new ArrayList<>();
- private boolean isInitialized;
+ private final List<RangerPolicyResourceMatcher> matchers = new ArrayList<>();
+ private boolean isInitialized;
- @Override
- public void init() {
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> RangerHiveResourcesAccessedTogetherCondition.init(" + condition + ")");
- }
+ @Override
+ public void init() {
+ LOG.debug("==> RangerHiveResourcesAccessedTogetherCondition.init({})", condition);
- super.init();
+ super.init();
- if (serviceDef != null) {
- doInitialize();
- } else {
- LOG.error("RangerHiveResourcesAccessedTogetherCondition.init() - ServiceDef not set ... ERROR ..");
- }
+ if (serviceDef != null) {
+ doInitialize();
+ } else {
+ LOG.error("RangerHiveResourcesAccessedTogetherCondition.init() - ServiceDef not set ... ERROR ..");
+ }
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== RangerHiveResourcesAccessedTogetherCondition.init(" + condition + ")");
- }
- }
+ LOG.debug("<== RangerHiveResourcesAccessedTogetherCondition.init({})", condition);
+ }
- @Override
- public boolean isMatched(final RangerAccessRequest request) {
- boolean ret = true;
+ @Override
+ public boolean isMatched(final RangerAccessRequest request) {
+ boolean ret = true;
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> RangerHiveResourcesAccessedTogetherCondition.isMatched(" + request + ")");
- }
-
- if (isInitialized && CollectionUtils.isNotEmpty(matchers)) {
- RangerRequestedResources resources = RangerAccessRequestUtil.getRequestedResourcesFromContext(request.getContext());
-
- ret = resources != null && !resources.isMutuallyExcluded(matchers, request.getContext());
- } else {
- LOG.error("RangerHiveResourcesAccessedTogetherCondition.isMatched() - condition is not initialized correctly and will NOT be enforced");
- }
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== RangerHiveResourcesAccessedTogetherCondition.isMatched(" + request + ")" + ", result=" + ret);
- }
-
- return ret;
- }
-
- private void doInitialize() {
- List<String> mutuallyExclusiveResources = condition.getValues();
-
- if (CollectionUtils.isNotEmpty(mutuallyExclusiveResources)) {
- initializeMatchers(mutuallyExclusiveResources);
-
- if (CollectionUtils.isEmpty(matchers)) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("RangerHiveResourcesAccessedTogetherCondition.doInitialize() - Cannot create matchers from values in MutualExclustionEnforcer");
- }
- } else {
- if (LOG.isDebugEnabled()) {
- LOG.debug("RangerHiveResourcesAccessedTogetherCondition.doInitialize() - Created " + matchers.size() + " matchers from values in MutualExclustionEnforcer");
- }
- }
- } else {
- if (LOG.isDebugEnabled()) {
- LOG.debug("RangerHiveResourcesAccessedTogetherCondition.doInitialize() - No values in MutualExclustionEnforcer");
- }
- }
-
- isInitialized = true;
- }
-
- private void initializeMatchers(List<String> mutuallyExclusiveResources) {
-
- for (String s : mutuallyExclusiveResources) {
-
- String policyResourceSpec = s.trim();
-
- RangerPolicyResourceMatcher matcher = buildMatcher(policyResourceSpec);
-
- if (matcher != null) {
- matchers.add(matcher);
- }
- }
- }
-
- private RangerPolicyResourceMatcher buildMatcher(String policyResourceSpec) {
-
- RangerPolicyResourceMatcher matcher = null;
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> RangerHiveResourcesAccessedTogetherCondition.buildMatcher(" + policyResourceSpec + ")");
- }
-
- // Works only for Hive serviceDef for now
- if (serviceDef != null && EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_HIVE_NAME.equals(serviceDef.getName())) {
- //Parse policyResourceSpec
- char separator = '.';
- String any = "*";
-
- Map<String, RangerPolicy.RangerPolicyResource> policyResources = new HashMap<>();
-
- String[] elements = StringUtils.split(policyResourceSpec, separator);
-
- RangerPolicy.RangerPolicyResource policyResource;
-
- if (elements.length > 0 && elements.length < 4) {
- if (elements.length == 3) {
- policyResource = new RangerPolicy.RangerPolicyResource(elements[2]);
- } else {
- policyResource = new RangerPolicy.RangerPolicyResource(any);
- }
- policyResources.put("column", policyResource);
-
- if (elements.length >= 2) {
- policyResource = new RangerPolicy.RangerPolicyResource(elements[1]);
- } else {
- policyResource = new RangerPolicy.RangerPolicyResource(any);
- }
- policyResources.put("table", policyResource);
-
- policyResource = new RangerPolicy.RangerPolicyResource(elements[0]);
- policyResources.put("database", policyResource);
-
- matcher = new RangerDefaultPolicyResourceMatcher();
- matcher.setPolicyResources(policyResources);
- matcher.setServiceDef(serviceDef);
- matcher.init();
+ LOG.debug("==> RangerHiveResourcesAccessedTogetherCondition.isMatched({})", request);
- } else {
- LOG.error("RangerHiveResourcesAccessedTogetherCondition.buildMatcher() - Incorrect elements in the hierarchy specified ("
- + elements.length + ")");
- }
- } else {
- LOG.error("RangerHiveResourcesAccessedTogetherCondition.buildMatcher() - ServiceDef not set or ServiceDef is not for Hive");
- }
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== RangerHiveResourcesAccessedTogetherCondition.buildMatcher(" + policyResourceSpec + ")" + ", matcher=" + matcher);
- }
+ if (isInitialized && CollectionUtils.isNotEmpty(matchers)) {
+ RangerRequestedResources resources = RangerAccessRequestUtil.getRequestedResourcesFromContext(request.getContext());
- return matcher;
- }
+ ret = resources != null && !resources.isMutuallyExcluded(matchers, request.getContext());
+ } else {
+ LOG.error("RangerHiveResourcesAccessedTogetherCondition.isMatched() - condition is not initialized correctly and will NOT be enforced");
+ }
+
+ LOG.debug("<== RangerHiveResourcesAccessedTogetherCondition.isMatched({}), result={}", request, ret);
+
+ return ret;
+ }
+
+ private void doInitialize() {
+ List<String> mutuallyExclusiveResources = condition.getValues();
+
+ if (CollectionUtils.isNotEmpty(mutuallyExclusiveResources)) {
+ initializeMatchers(mutuallyExclusiveResources);
+
+ if (CollectionUtils.isEmpty(matchers)) {
+ LOG.debug("RangerHiveResourcesAccessedTogetherCondition.doInitialize() - Cannot create matchers from values in MutualExclustionEnforcer");
+ } else {
+ LOG.debug("RangerHiveResourcesAccessedTogetherCondition.doInitialize() - Created {} matchers from values in MutualExclustionEnforcer", matchers.size());
+ }
+ } else {
+ LOG.debug("RangerHiveResourcesAccessedTogetherCondition.doInitialize() - No values in MutualExclustionEnforcer");
+ }
+
+ isInitialized = true;
+ }
+
+ private void initializeMatchers(List<String> mutuallyExclusiveResources) {
+ for (String s : mutuallyExclusiveResources) {
+ String policyResourceSpec = s.trim();
+
+ RangerPolicyResourceMatcher matcher = buildMatcher(policyResourceSpec);
+
+ if (matcher != null) {
+ matchers.add(matcher);
+ }
+ }
+ }
+
+ private RangerPolicyResourceMatcher buildMatcher(String policyResourceSpec) {
+ RangerPolicyResourceMatcher matcher = null;
+
+ LOG.debug("==> RangerHiveResourcesAccessedTogetherCondition.buildMatcher({})", policyResourceSpec);
+
+ // Works only for Hive serviceDef for now
+ if (serviceDef != null && EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_HIVE_NAME.equals(serviceDef.getName())) {
+ //Parse policyResourceSpec
+ char separator = '.';
+ String any = "*";
+
+ Map<String, RangerPolicy.RangerPolicyResource> policyResources = new HashMap<>();
+
+ String[] elements = StringUtils.split(policyResourceSpec, separator);
+
+ RangerPolicy.RangerPolicyResource policyResource;
+
+ if (elements.length > 0 && elements.length < 4) {
+ if (elements.length == 3) {
+ policyResource = new RangerPolicy.RangerPolicyResource(elements[2]);
+ } else {
+ policyResource = new RangerPolicy.RangerPolicyResource(any);
+ }
+ policyResources.put("column", policyResource);
+
+ if (elements.length >= 2) {
+ policyResource = new RangerPolicy.RangerPolicyResource(elements[1]);
+ } else {
+ policyResource = new RangerPolicy.RangerPolicyResource(any);
+ }
+ policyResources.put("table", policyResource);
+
+ policyResource = new RangerPolicy.RangerPolicyResource(elements[0]);
+ policyResources.put("database", policyResource);
+
+ matcher = new RangerDefaultPolicyResourceMatcher();
+ matcher.setPolicyResources(policyResources);
+ matcher.setServiceDef(serviceDef);
+ matcher.init();
+ } else {
+ LOG.error("RangerHiveResourcesAccessedTogetherCondition.buildMatcher() - Incorrect elements in the hierarchy specified ({})", elements.length);
+ }
+ } else {
+ LOG.error("RangerHiveResourcesAccessedTogetherCondition.buildMatcher() - ServiceDef not set or ServiceDef is not for Hive");
+ }
+
+ LOG.debug("<== RangerHiveResourcesAccessedTogetherCondition.buildMatcher({}), matcher={}", policyResourceSpec, matcher);
+
+ return matcher;
+ }
}
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerHiveResourcesNotAccessedTogetherCondition.java b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerHiveResourcesNotAccessedTogetherCondition.java
index 7a82191d2..edac32a6a 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerHiveResourcesNotAccessedTogetherCondition.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerHiveResourcesNotAccessedTogetherCondition.java
@@ -37,146 +37,123 @@ import java.util.List;
import java.util.Map;
public class RangerHiveResourcesNotAccessedTogetherCondition extends RangerAbstractConditionEvaluator {
- private static final Logger LOG = LoggerFactory.getLogger(RangerHiveResourcesNotAccessedTogetherCondition.class);
+ private static final Logger LOG = LoggerFactory.getLogger(RangerHiveResourcesNotAccessedTogetherCondition.class);
- private List<RangerPolicyResourceMatcher> matchers = new ArrayList<>();
- private boolean isInitialized;
+ private final List<RangerPolicyResourceMatcher> matchers = new ArrayList<>();
+ private boolean isInitialized;
- @Override
- public void init() {
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> RangerHiveResourcesNotAccessedTogetherCondition.init(" + condition + ")");
- }
+ @Override
+ public void init() {
+ LOG.debug("==> RangerHiveResourcesNotAccessedTogetherCondition.init({})", condition);
- super.init();
+ super.init();
- if (serviceDef != null) {
- doInitialize();
- } else {
- LOG.error("RangerHiveResourcesNotAccessedTogetherCondition.init() - ServiceDef not set ... ERROR ..");
- }
+ if (serviceDef != null) {
+ doInitialize();
+ } else {
+ LOG.error("RangerHiveResourcesNotAccessedTogetherCondition.init() - ServiceDef not set ... ERROR ..");
+ }
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== RangerHiveResourcesNotAccessedTogetherCondition.init(" + condition + ")");
- }
- }
+ LOG.debug("<== RangerHiveResourcesNotAccessedTogetherCondition.init({})", condition);
+ }
- @Override
- public boolean isMatched(final RangerAccessRequest request) {
- boolean ret = true;
+ @Override
+ public boolean isMatched(final RangerAccessRequest request) {
+ boolean ret = true;
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> RangerHiveResourcesNotAccessedTogetherCondition.isMatched(" + request + ")");
- }
-
- if (isInitialized && CollectionUtils.isNotEmpty(matchers)) {
- RangerRequestedResources resources = RangerAccessRequestUtil.getRequestedResourcesFromContext(request.getContext());
-
- ret = resources == null || resources.isMutuallyExcluded(matchers, request.getContext());
- } else {
- LOG.error("RangerHiveResourcesNotAccessedTogetherCondition.isMatched() - Enforcer is not initialized correctly, Mutual Exclusion will NOT be enforced");
- }
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== RangerHiveResourcesNotAccessedTogetherCondition.isMatched(" + request + ")" + ", result=" + ret);
- }
-
- return ret;
- }
-
- private void doInitialize() {
- List<String> mutuallyExclusiveResources = condition.getValues();
-
- if (CollectionUtils.isNotEmpty(mutuallyExclusiveResources)) {
- initializeMatchers(mutuallyExclusiveResources);
-
- if (CollectionUtils.isEmpty(matchers)) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("RangerHiveResourcesNotAccessedTogetherCondition.doInitialize() - Cannot create matchers from values in MutualExclustionEnforcer");
- }
- } else {
- if (LOG.isDebugEnabled()) {
- LOG.debug("RangerHiveResourcesNotAccessedTogetherCondition.doInitialize() - Created " + matchers.size() + " matchers from values in MutualExclustionEnforcer");
- }
- }
- } else {
- if (LOG.isDebugEnabled()) {
- LOG.debug("RangerHiveResourcesNotAccessedTogetherCondition.doInitialize() - No values in MutualExclustionEnforcer");
- }
- }
-
- isInitialized = true;
- }
-
- private void initializeMatchers(List<String> mutuallyExclusiveResources) {
-
- for (String s : mutuallyExclusiveResources) {
-
- String policyResourceSpec = s.trim();
-
- RangerPolicyResourceMatcher matcher = buildMatcher(policyResourceSpec);
-
- if (matcher != null) {
- matchers.add(matcher);
- }
- }
- }
-
- private RangerPolicyResourceMatcher buildMatcher(String policyResourceSpec) {
-
- RangerPolicyResourceMatcher matcher = null;
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> RangerHiveResourcesNotAccessedTogetherCondition.buildMatcher(" + policyResourceSpec + ")");
- }
-
- // Works only for Hive serviceDef for now
- if (serviceDef != null && EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_HIVE_NAME.equals(serviceDef.getName())) {
- //Parse policyResourceSpec
- char separator = '.';
- String any = "*";
-
- Map<String, RangerPolicy.RangerPolicyResource> policyResources = new HashMap<>();
-
- String[] elements = StringUtils.split(policyResourceSpec, separator);
-
- RangerPolicy.RangerPolicyResource policyResource;
-
- if (elements.length > 0 && elements.length < 4) {
- if (elements.length == 3) {
- policyResource = new RangerPolicy.RangerPolicyResource(elements[2]);
- } else {
- policyResource = new RangerPolicy.RangerPolicyResource(any);
- }
- policyResources.put("column", policyResource);
-
- if (elements.length >= 2) {
- policyResource = new RangerPolicy.RangerPolicyResource(elements[1]);
- } else {
- policyResource = new RangerPolicy.RangerPolicyResource(any);
- }
- policyResources.put("table", policyResource);
-
- policyResource = new RangerPolicy.RangerPolicyResource(elements[0]);
- policyResources.put("database", policyResource);
-
- matcher = new RangerDefaultPolicyResourceMatcher();
- matcher.setPolicyResources(policyResources);
- matcher.setServiceDef(serviceDef);
- matcher.init();
+ LOG.debug("==> RangerHiveResourcesNotAccessedTogetherCondition.isMatched({})", request);
- } else {
- LOG.error("RangerHiveResourcesNotAccessedTogetherCondition.buildMatcher() - Incorrect elements in the hierarchy specified ("
- + elements.length + ")");
- }
- } else {
- LOG.error("RangerHiveResourcesNotAccessedTogetherCondition.buildMatcher() - ServiceDef not set or ServiceDef is not for Hive");
- }
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== RangerHiveResourcesNotAccessedTogetherCondition.buildMatcher(" + policyResourceSpec + ")" + ", matcher=" + matcher);
- }
+ if (isInitialized && CollectionUtils.isNotEmpty(matchers)) {
+ RangerRequestedResources resources = RangerAccessRequestUtil.getRequestedResourcesFromContext(request.getContext());
- return matcher;
- }
+ ret = resources == null || resources.isMutuallyExcluded(matchers, request.getContext());
+ } else {
+ LOG.error("RangerHiveResourcesNotAccessedTogetherCondition.isMatched() - Enforcer is not initialized correctly, Mutual Exclusion will NOT be enforced");
+ }
+
+ LOG.debug("<== RangerHiveResourcesNotAccessedTogetherCondition.isMatched({}), result={}", request, ret);
+
+ return ret;
+ }
+
+ private void doInitialize() {
+ List<String> mutuallyExclusiveResources = condition.getValues();
+
+ if (CollectionUtils.isNotEmpty(mutuallyExclusiveResources)) {
+ initializeMatchers(mutuallyExclusiveResources);
+
+ if (CollectionUtils.isEmpty(matchers)) {
+ LOG.debug("RangerHiveResourcesNotAccessedTogetherCondition.doInitialize() - Cannot create matchers from values in MutualExclustionEnforcer");
+ } else {
+ LOG.debug("RangerHiveResourcesNotAccessedTogetherCondition.doInitialize() - Created {} matchers from values in MutualExclustionEnforcer", matchers.size());
+ }
+ } else {
+ LOG.debug("RangerHiveResourcesNotAccessedTogetherCondition.doInitialize() - No values in MutualExclustionEnforcer");
+ }
+
+ isInitialized = true;
+ }
+
+ private void initializeMatchers(List<String> mutuallyExclusiveResources) {
+ for (String s : mutuallyExclusiveResources) {
+ String policyResourceSpec = s.trim();
+
+ RangerPolicyResourceMatcher matcher = buildMatcher(policyResourceSpec);
+
+ if (matcher != null) {
+ matchers.add(matcher);
+ }
+ }
+ }
+
+ private RangerPolicyResourceMatcher buildMatcher(String policyResourceSpec) {
+ RangerPolicyResourceMatcher matcher = null;
+
+ LOG.debug("==> RangerHiveResourcesNotAccessedTogetherCondition.buildMatcher({})", policyResourceSpec);
+
+ // Works only for Hive serviceDef for now
+ if (serviceDef != null && EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_HIVE_NAME.equals(serviceDef.getName())) {
+ //Parse policyResourceSpec
+ char separator = '.';
+ String any = "*";
+
+ Map<String, RangerPolicy.RangerPolicyResource> policyResources = new HashMap<>();
+
+ String[] elements = StringUtils.split(policyResourceSpec, separator);
+
+ RangerPolicy.RangerPolicyResource policyResource;
+
+ if (elements.length > 0 && elements.length < 4) {
+ if (elements.length == 3) {
+ policyResource = new RangerPolicy.RangerPolicyResource(elements[2]);
+ } else {
+ policyResource = new RangerPolicy.RangerPolicyResource(any);
+ }
+ policyResources.put("column", policyResource);
+
+ if (elements.length >= 2) {
+ policyResource = new RangerPolicy.RangerPolicyResource(elements[1]);
+ } else {
+ policyResource = new RangerPolicy.RangerPolicyResource(any);
+ }
+ policyResources.put("table", policyResource);
+
+ policyResource = new RangerPolicy.RangerPolicyResource(elements[0]);
+ policyResources.put("database", policyResource);
+
+ matcher = new RangerDefaultPolicyResourceMatcher();
+ matcher.setPolicyResources(policyResources);
+ matcher.setServiceDef(serviceDef);
+ matcher.init();
+ } else {
+ LOG.error("RangerHiveResourcesNotAccessedTogetherCondition.buildMatcher() - Incorrect elements in the hierarchy specified ({})", elements.length);
+ }
+ } else {
+ LOG.error("RangerHiveResourcesNotAccessedTogetherCondition.buildMatcher() - ServiceDef not set or ServiceDef is not for Hive");
+ }
+
+ LOG.debug("<== RangerHiveResourcesNotAccessedTogetherCondition.buildMatcher({}), matcher={}", policyResourceSpec, matcher);
+
+ return matcher;
+ }
}
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerIpMatcher.java b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerIpMatcher.java
index f2a077324..e8c9793b5 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerIpMatcher.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerIpMatcher.java
@@ -17,200 +17,188 @@
* under the License.
*/
-
package org.apache.ranger.plugin.conditionevaluator;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.ranger.plugin.policyengine.RangerAccessRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.ranger.plugin.policyengine.RangerAccessRequest;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
/**
* Credits: Large parts of this file have been lifted as is from org.apache.ranger.pdp.knox.URLBasedAuthDB. Credits for those are due to Dilli Arumugam.
+ *
* @author alal
*/
public class RangerIpMatcher extends RangerAbstractConditionEvaluator {
- private static final Logger LOG = LoggerFactory.getLogger(RangerIpMatcher.class);
- private List<String> _exactIps = new ArrayList<>();
- private List<String> _wildCardIps = new ArrayList<>();
- private boolean _allowAny;
-
- @Override
- public void init() {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerIpMatcher.init(" + condition + ")");
- }
-
- super.init();
-
- // NOTE: this evaluator does not use conditionDef!
- if (condition == null) {
- LOG.debug("init: null policy condition! Will match always!");
- _allowAny = true;
- } else if (CollectionUtils.isEmpty(condition.getValues())) {
- LOG.debug("init: empty conditions collection on policy condition! Will match always!");
- _allowAny = true;
- } else if (condition.getValues().contains("*")) {
- _allowAny = true;
- LOG.debug("init: wildcard value found. Will match always.");
- } else {
- for (String ip : condition.getValues()) {
- String digestedIp = digestPolicyIp(ip);
- if (digestedIp.isEmpty()) {
- LOG.debug("init: digested ip was empty! Will match always");
- _allowAny = true;
- } else if (digestedIp.equals(ip)) {
- _exactIps.add(ip);
- } else {
- _wildCardIps.add(digestedIp);
- }
- }
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerIpMatcher.init(" + condition + "): exact-ips[" + _exactIps + "], wildcard-ips[" + _wildCardIps + "]");
- }
- }
-
- @Override
- public boolean isMatched(final RangerAccessRequest request) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerIpMatcher.isMatched(" + request + ")");
- }
-
- boolean ipMatched = true;
- if (_allowAny) {
- LOG.debug("isMatched: allowAny flag is true. Matched!");
- } else {
- String requestIp = extractIp(request);
- if (requestIp == null) {
- LOG.debug("isMatched: couldn't get ip address from request. Ok. Implicitly matched!");
- } else {
- ipMatched = isWildcardMatched(_wildCardIps, requestIp) || isExactlyMatched(_exactIps, requestIp);
- }
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerIpMatcher.isMatched(" + request+ "): " + ipMatched);
- }
-
- return ipMatched;
- }
-
- /**
- * Pre-digests the policy ip address to drop any trailing wildcard specifiers such that a simple beginsWith match can be done to check for match during authorization calls
- * @param ip
- * @return
- */
- static final Pattern allWildcards = Pattern.compile("^((\\*(\\.\\*)*)|(\\*(:\\*)*))$"); // "*", "*.*", "*.*.*", "*:*", "*:*:*", etc.
- static final Pattern trailingWildcardsIp4 = Pattern.compile("(\\.\\*)+$"); // "blah.*", "blah.*.*", etc.
- static final Pattern trailingWildcardsIp6 = Pattern.compile("(:\\*)+$"); // "blah:*", "blah:*:*", etc.
-
- String digestPolicyIp(final String policyIp) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> RangerIpMatcher.digestPolicyIp(" + policyIp + ")");
- }
-
- String result;
- Matcher matcher = allWildcards.matcher(policyIp);
- if (matcher.matches()) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("digestPolicyIp: policyIP[" + policyIp +"] all wildcards.");
- }
- result = "";
- } else if (policyIp.contains(".")) {
- matcher = trailingWildcardsIp4.matcher(policyIp);
- result = matcher.replaceFirst(".");
- } else {
- matcher = trailingWildcardsIp6.matcher(policyIp);
- // also lower cases the ipv6 items
- result = matcher.replaceFirst(":").toLowerCase();
- }
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== RangerIpMatcher.digestPolicyIp(" + policyIp + "): " + policyIp);
- }
- return result;
- }
-
- boolean isWildcardMatched(final List<String> ips, final String requestIp) {
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerIpMatcher.isWildcardMatched(" + ips+ ", " + requestIp + ")");
- }
-
- boolean matchFound = false;
- Iterator<String> iterator = ips.iterator();
- while (iterator.hasNext() && !matchFound) {
- String ip = iterator.next();
- if (requestIp.contains(".") && requestIp.startsWith(ip)) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Wildcard Policy IP[" + ip + "] matches request IPv4[" + requestIp + "].");
- }
- matchFound = true;
- } else if (requestIp.toLowerCase().startsWith(ip)) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Wildcard Policy IP[" + ip + "] matches request IPv6[" + requestIp + "].");
- }
- matchFound = true;
- } else {
- LOG.debug("Wildcard policy IP[" + ip + "] did not match request IP[" + requestIp + "].");
- }
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerIpMatcher.isWildcardMatched(" + ips+ ", " + requestIp + "): " + matchFound);
- }
- return matchFound;
- }
-
- boolean isExactlyMatched(final List<String> ips, final String requestIp) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerIpMatcher.isExactlyMatched(" + ips+ ", " + requestIp + ")");
- }
-
- boolean matchFound = false;
- if (requestIp.contains(".")) {
- matchFound = ips.contains(requestIp);
- } else {
- matchFound = ips.contains(requestIp.toLowerCase());
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerIpMatcher.isExactlyMatched(" + ips+ ", " + requestIp + "): " + matchFound);
- }
- return matchFound;
- }
-
- /**
- * Extracts and returns the ip address from the request. Returns null if one can't be obtained out of the request.
- * @param request
- * @return
- */
- String extractIp(final RangerAccessRequest request) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerIpMatcher.extractIp(" + request+ ")");
- }
-
- String ip = null;
- if (request == null) {
- LOG.debug("isMatched: Unexpected: null request object!");
- } else {
- ip = request.getClientIPAddress();
- if (ip == null) {
- LOG.debug("isMatched: Unexpected: Client ip in request object is null!");
- }
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerIpMatcher.extractIp(" + request+ "): " + ip);
- }
- return ip;
- }
+ private static final Logger LOG = LoggerFactory.getLogger(RangerIpMatcher.class);
+
+ static final Pattern allWildcards = Pattern.compile("^((\\*(\\.\\*)*)|(\\*(:\\*)*))$"); // "*", "*.*", "*.*.*", "*:*", "*:*:*", etc.
+ static final Pattern trailingWildcardsIp4 = Pattern.compile("(\\.\\*)+$"); // "blah.*", "blah.*.*", etc.
+ static final Pattern trailingWildcardsIp6 = Pattern.compile("(:\\*)+$"); // "blah:*", "blah:*:*", etc.
+
+ private final List<String> exactIps = new ArrayList<>();
+ private final List<String> wildCardIps = new ArrayList<>();
+ private boolean allowAny;
+
+ @Override
+ public void init() {
+ LOG.debug("==> RangerIpMatcher.init({})", condition);
+
+ super.init();
+
+ // NOTE: this evaluator does not use conditionDef!
+ if (condition == null) {
+ LOG.debug("init: null policy condition! Will match always!");
+
+ allowAny = true;
+ } else if (CollectionUtils.isEmpty(condition.getValues())) {
+ LOG.debug("init: empty conditions collection on policy condition! Will match always!");
+
+ allowAny = true;
+ } else if (condition.getValues().contains("*")) {
+ allowAny = true;
+
+ LOG.debug("init: wildcard value found. Will match always.");
+ } else {
+ for (String ip : condition.getValues()) {
+ String digestedIp = digestPolicyIp(ip);
+
+ if (digestedIp.isEmpty()) {
+ LOG.debug("init: digested ip was empty! Will match always");
+
+ allowAny = true;
+ } else if (digestedIp.equals(ip)) {
+ exactIps.add(ip);
+ } else {
+ wildCardIps.add(digestedIp);
+ }
+ }
+ }
+
+ LOG.debug("<== RangerIpMatcher.init({}): exact-ips[{}], wildcard-ips[{}]", condition, exactIps, wildCardIps);
+ }
+
+ @Override
+ public boolean isMatched(final RangerAccessRequest request) {
+ LOG.debug("==> RangerIpMatcher.isMatched({})", request);
+
+ boolean ipMatched = true;
+
+ if (allowAny) {
+ LOG.debug("isMatched: allowAny flag is true. Matched!");
+ } else {
+ String requestIp = extractIp(request);
... 108693 lines suppressed ...