Skip to content

Commit

Permalink
RANGER-5061: checkstyle compliance updates - security-admin module (#508
Browse files Browse the repository at this point in the history
)

Co-authored-by: Abhishek Kumar <abhishekkumar100031@gmail.com>
Co-authored-by: Dineshkumar Yadav <59435896+dineshkumar-yadav@users.noreply.github.com>
Co-authored-by: Madhan Neethiraj <madhan@apache.org>
Co-authored-by: Ramesh <rmani@cloudera.com>
Co-authored-by: Vyom Mani Tiwari <vyommani@gmail.com>
  • Loading branch information
6 people authored Jan 13, 2025
1 parent 6d0030a commit 46dfebe
Show file tree
Hide file tree
Showing 670 changed files with 135,448 additions and 136,953 deletions.
63 changes: 63 additions & 0 deletions dev-support/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,69 @@
<suppress files="AuditFileCacheProviderSpool.java" checks="TypeName"/>
<suppress files="AuthzAuditEvent.java" checks="StaticVariableName"/>
<suppress files="buildks.java" checks="TypeName"/>
<suppress files="BaseDao.java" checks="StaticVariableName"/>
<suppress files="ContextUtil.java" checks="HideUtilityClassConstructor"/>
<suppress files="MapUtil.java" checks="HideUtilityClassConstructor"/>
<suppress files="PolicyRefUpdater.java" checks="TypeName"/>
<suppress files="RangerAdminTagEnricher.java" checks="StaticVariableName"/>
<suppress files="RangerCommonEnums.java" checks="HideUtilityClassConstructor"/>
<suppress files="RangerConstants.java" checks="TypeName"/>
<suppress files="RangerRolesUtil.java" checks="TypeName"/>
<suppress files="SearchField.java" checks="TypeName"/>
<suppress files="ServiceDBStore.java" checks="StaticVariableName"/>
<suppress files="ServiceDBStore.java" checks="TypeName"/>
<suppress files="SortField.java" checks="TypeName"/>
<suppress files="SPOOL_FILE_STATUS.java" checks="TypeName"/>
<suppress files="TagDBStore.java" checks="StaticVariableName"/>
<suppress files="TagDBStore.java" checks="TypeName"/>
<suppress files="TimedEventUtil.java" checks="HideUtilityClassConstructor"/>
<suppress files="PatchAssignSecurityZonePersmissionToAdmin_J10026.java" checks="TypeName"/>
<suppress files="PatchAtlasForClassificationResource_J10047" checks="TypeName"/>
<suppress files="PatchForAllServiceDefForPolicyConditionUpdate_J10060" checks="TypeName"/>
<suppress files="PatchForAllServiceDefUpdateForDefaultAuditFilters_J10049" checks="TypeName"/>
<suppress files="PatchForAllServiceDefUpdateForResourceSpecificAccesses_J10012" checks="TypeName"/>
<suppress files="PatchForAtlasAdminAudits_J10043" checks="TypeName"/>
<suppress files="PatchForAtlasResourceAndAccessTypeUpdate_J10016" checks="TypeName"/>
<suppress files="PatchForAtlasServiceDefUpdate_J10013" checks="TypeName"/>
<suppress files="PatchForAtlasToAddEntityLabelAndBusinessMetadata_J10034" checks="TypeName"/>
<suppress files="PatchForAtlasToAddTypeRead_J10040" checks="TypeName"/>
<suppress files="PatchForDefaultAuidtFilters_J10050" checks="TypeName"/>
<suppress files="PatchForExternalUserStatusUpdate_J10056" checks="TypeName"/>
<suppress files="PatchForHBaseDefaultPolicyUpdate_J10045" checks="TypeName"/>
<suppress files="PatchForHBaseServiceDefUpdate_J10035" checks="TypeName"/>
<suppress files="PatchForHiveServiceDefUpdate_J10006" checks="TypeName"/>
<suppress files="PatchForHiveServiceDefUpdate_J10007" checks="TypeName"/>
<suppress files="PatchForHiveServiceDefUpdate_J10009" checks="TypeName"/>
<suppress files="PatchForHiveServiceDefUpdate_J10010" checks="TypeName"/>
<suppress files="PatchForHiveServiceDefUpdate_J10017" checks="TypeName"/>
<suppress files="PatchForHiveServiceDefUpdate_J10027" checks="TypeName"/>
<suppress files="PatchForHiveServiceDefUpdate_J10030" checks="TypeName"/>
<suppress files="PatchForKafkaServiceDefUpdate_J10015" checks="TypeName"/>
<suppress files="PatchForKafkaServiceDefUpdate_J10025" checks="TypeName"/>
<suppress files="PatchForKafkaServiceDefUpdate_J10033" checks="TypeName"/>
<suppress files="PatchForMigratingOldRegimePolicyJson_J10046" checks="TypeName"/>
<suppress files="PatchForMigratingRangerServiceResource_J10037" checks="TypeName"/>
<suppress files="PatchForNifiResourceUpdateExclude_J10011" checks="TypeName"/>
<suppress files="PatchForOzoneDefaultPoliciesUpdate_J10044" checks="TypeName"/>
<suppress files="PatchForOzoneServiceDefConfigUpdate_J10051" checks="TypeName"/>
<suppress files="PatchForOzoneServiceDefUpdate_J10041" checks="TypeName"/>
<suppress files="PatchForPrestoToSupportPresto333_J10038" checks="TypeName"/>
<suppress files="PatchForServiceVersionInfo_J10004" checks="TypeName"/>
<suppress files="PatchForSolrSvcDefAndPoliciesUpdate_J10055" checks="TypeName"/>
<suppress files="PatchForSyncSourceUpdate_J10054" checks="TypeName"/>
<suppress files="PatchForTagServiceDefUpdate_J10008" checks="TypeName"/>
<suppress files="PatchForTagServiceDefUpdate_J10028" checks="TypeName"/>
<suppress files="PatchForTrinoSvcDefUpdate_J10062" checks="TypeName"/>
<suppress files="PatchForUpdatingAtlasSvcDefAndTagPolicies_J10063" checks="TypeName"/>
<suppress files="PatchForUpdatingPolicyJson_J10019" checks="TypeName"/>
<suppress files="PatchForUpdatingTagsJson_J10020" checks="TypeName"/>
<suppress files="PatchForXGlobalState_J10036" checks="TypeName"/>
<suppress files="PatchGrantAuditPermissionToKeyRoleUser_J10014" checks="TypeName"/>
<suppress files="PatchMigration_J10002" checks="TypeName"/>
<suppress files="PatchPasswordEncryption_J10001" checks="TypeName"/>
<suppress files="PatchPermissionModel_J10003" checks="TypeName"/>
<suppress files="PatchPreSql_057_ForUpdateToUniqueGUID_J10052" checks="TypeName"/>
<suppress files="PatchPreSql_058_ForUpdateToUniqueResoureceSignature_J10053" checks="TypeName"/>
<suppress files="PatchSetAccessTypeCategory_J10061" checks="TypeName"/>
<suppress files="PatchTagModulePermission_J10005" checks="TypeName"/>
</suppressions>
3 changes: 3 additions & 0 deletions security-admin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<name>Security Admin Web Application</name>
<description>security-admin-tool java web application</description>
<properties>
<checkstyle.failOnViolation>true</checkstyle.failOnViolation>
<checkstyle.skip>false</checkstyle.skip>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<skipJSTests>false</skipJSTests>
</properties>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,83 +30,60 @@
import org.apache.ranger.plugin.store.EmbeddedServiceDefsUtil;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;

public class AccessAuditsService {
protected List<SortField> sortFields = new ArrayList<SortField>();
protected List<SearchField> searchFields;
protected List<SortField> sortFields = new ArrayList<>();
protected List<SearchField> searchFields = new ArrayList<>();

@Autowired
protected
RESTErrorUtil restErrorUtil;
protected RESTErrorUtil restErrorUtil;

@Autowired
protected
RangerDaoManager daoManager;
protected RangerDaoManager daoManager;

public AccessAuditsService() {
searchFields = new ArrayList<SearchField>();
searchFields.add(new SearchField("id", "id",
SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("accessType", "access",
SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("aclEnforcer", "enforcer",
SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("agentId", "agent",
SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("repoName", "repo",
SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("sessionId", "sess",
SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("requestUser", "reqUser",
SearchField.DATA_TYPE.STR_LIST, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("excludeUser", "exlUser",
SearchField.DATA_TYPE.STR_LIST, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("requestData", "reqData", SearchField.DATA_TYPE.STRING,
SearchField.SEARCH_TYPE.PARTIAL));
searchFields.add(new SearchField("resourcePath", "resource", SearchField.DATA_TYPE.STRING,
SearchField.SEARCH_TYPE.PARTIAL));
searchFields.add(new SearchField("clientIP", "cliIP",
SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.FULL));

searchFields.add(new SearchField("auditType", "logType",
SearchField.DATA_TYPE.INTEGER, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("accessResult", "result",
SearchField.DATA_TYPE.INTEGER, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("id", "id", SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("accessType", "access", SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("aclEnforcer", "enforcer", SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("agentId", "agent", SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("repoName", "repo", SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("sessionId", "sess", SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("requestUser", "reqUser", SearchField.DATA_TYPE.STR_LIST, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("excludeUser", "exlUser", SearchField.DATA_TYPE.STR_LIST, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("requestData", "reqData", SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.PARTIAL));
searchFields.add(new SearchField("resourcePath", "resource", SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.PARTIAL));
searchFields.add(new SearchField("clientIP", "cliIP", SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.FULL));

searchFields.add(new SearchField("auditType", "logType", SearchField.DATA_TYPE.INTEGER, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("accessResult", "result", SearchField.DATA_TYPE.INTEGER, SearchField.SEARCH_TYPE.FULL));
// searchFields.add(new SearchField("assetId", "obj.assetId",
// SearchField.DATA_TYPE.INTEGER, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("policyId", "policy",
SearchField.DATA_TYPE.INTEGER, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("repoType", "repoType",
SearchField.DATA_TYPE.INTEGER, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("policyId", "policy", SearchField.DATA_TYPE.INTEGER, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("repoType", "repoType", SearchField.DATA_TYPE.INTEGER, SearchField.SEARCH_TYPE.FULL));
/* Note; search fields starting with '-' denotes exclude conditions,
* it should be handled manually if audit destination does not support the same.
* solr support this way while cloudwatch does not.
*/
searchFields.add(new SearchField("-repoType", "-repoType",
SearchField.DATA_TYPE.INTEGER, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("-requestUser", "-reqUser",
SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("resourceType", "resType",
SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("reason", "reason",
SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("action", "action",
SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.FULL));

searchFields.add(new SearchField("startDate", "evtTime",
SearchField.DATA_TYPE.DATE, SearchField.SEARCH_TYPE.GREATER_EQUAL_THAN));
searchFields.add(new SearchField("endDate", "evtTime", SearchField.DATA_TYPE.DATE,
SearchField.SEARCH_TYPE.LESS_EQUAL_THAN));
searchFields.add(new SearchField("-repoType", "-repoType", SearchField.DATA_TYPE.INTEGER, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("-requestUser", "-reqUser", SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("resourceType", "resType", SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("reason", "reason", SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("action", "action", SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.FULL));

searchFields.add(new SearchField("startDate", "evtTime", SearchField.DATA_TYPE.DATE, SearchField.SEARCH_TYPE.GREATER_EQUAL_THAN));
searchFields.add(new SearchField("endDate", "evtTime", SearchField.DATA_TYPE.DATE, SearchField.SEARCH_TYPE.LESS_EQUAL_THAN));

searchFields.add(new SearchField("tags", "tags", SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.PARTIAL));
searchFields.add(new SearchField("cluster", "cluster",
SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("zoneName", "zoneName",
SearchField.DATA_TYPE.STR_LIST, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("agentHost", "agentHost",
SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.PARTIAL));

sortFields.add(new SortField("eventTime", "evtTime", true,
SortField.SORT_ORDER.DESC));
searchFields.add(new SearchField("cluster", "cluster", SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("zoneName", "zoneName", SearchField.DATA_TYPE.STR_LIST, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("agentHost", "agentHost", SearchField.DATA_TYPE.STRING, SearchField.SEARCH_TYPE.PARTIAL));

sortFields.add(new SortField("eventTime", "evtTime", true, SortField.SORT_ORDER.DESC));
sortFields.add(new SortField("policyId", "policy", false, SORT_ORDER.ASC));
sortFields.add(new SortField("requestUser", "reqUser", false, SORT_ORDER.ASC));
sortFields.add(new SortField("resourceType", "resType", false, SORT_ORDER.ASC));
Expand All @@ -120,13 +97,16 @@ public AccessAuditsService() {
protected void updateUserExclusion(Map<String, Object> paramList) {
String val = (String) paramList.get("excludeServiceUser");

if (val != null && Boolean.valueOf(val.trim())) {
if (val != null && Boolean.parseBoolean(val.trim())) {
// add param to negate requestUsers which will be added as filter query
List<String> excludeUsersList = getExcludeUsersList();

if (CollectionUtils.isNotEmpty(excludeUsersList)) {
Object oldUserExclusions = paramList.get("-requestUser");
if (oldUserExclusions instanceof Collection && (!((Collection<?>)oldUserExclusions).isEmpty())) {
excludeUsersList.addAll((Collection<String>)oldUserExclusions);

if (oldUserExclusions instanceof Collection && (!((Collection<?>) oldUserExclusions).isEmpty())) {
excludeUsersList.addAll((Collection<String>) oldUserExclusions);

paramList.put("-requestUser", excludeUsersList);
} else {
paramList.put("-requestUser", excludeUsersList);
Expand All @@ -137,32 +117,38 @@ protected void updateUserExclusion(Map<String, Object> paramList) {

private List<String> getExcludeUsersList() {
//for excluding serviceUsers using existing property in ranger-admin-site
List<String> excludeUsersList = new ArrayList<String>(getServiceUserList());
List<String> excludeUsersList = new ArrayList<>(getServiceUserList());

//for excluding additional users using new property in ranger-admin-site
String additionalExcludeUsers = PropertiesUtil.getProperty("ranger.accesslogs.exclude.users.list");
List<String> additionalExcludeUsersList = null;
String additionalExcludeUsers = PropertiesUtil.getProperty("ranger.accesslogs.exclude.users.list");
List<String> additionalExcludeUsersList;

if (StringUtils.isNotBlank(additionalExcludeUsers)) {
additionalExcludeUsersList = new ArrayList<>(Arrays.asList(StringUtils.split(additionalExcludeUsers, ",")));

for (String serviceUser : additionalExcludeUsersList) {
if (StringUtils.isNotBlank(serviceUser) && !excludeUsersList.contains(serviceUser.trim())) {
excludeUsersList.add(serviceUser);
}
}
}

return excludeUsersList;
}

private List<String> getServiceUserList() {
String components = EmbeddedServiceDefsUtil.DEFAULT_BOOTSTRAP_SERVICEDEF_LIST;
List<String> serviceUsersList = new ArrayList<String>();
List<String> componentNames = Arrays.asList(StringUtils.split(components,","));
for(String componentName : componentNames) {
String serviceUser = PropertiesUtil.getProperty("ranger.plugins."+componentName+".serviceuser");
if(StringUtils.isNotBlank(serviceUser)) {
String components = EmbeddedServiceDefsUtil.DEFAULT_BOOTSTRAP_SERVICEDEF_LIST;
List<String> serviceUsersList = new ArrayList<>();
String[] componentNames = StringUtils.split(components, ",");

for (String componentName : componentNames) {
String serviceUser = PropertiesUtil.getProperty("ranger.plugins." + componentName + ".serviceuser");

if (StringUtils.isNotBlank(serviceUser)) {
serviceUsersList.add(serviceUser);
}
}

return serviceUsersList;
}
}
Loading

0 comments on commit 46dfebe

Please # to comment.