Skip to content

Commit

Permalink
RANGER-5061: checkstyle compliance updates - security-admin modules :…
Browse files Browse the repository at this point in the history
… org.apache.ranger.biz package
  • Loading branch information
mneethiraj committed Jan 13, 2025
1 parent 8376b1c commit 62697ee
Show file tree
Hide file tree
Showing 35 changed files with 4,120 additions and 1,630 deletions.
5 changes: 5 additions & 0 deletions dev-support/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,18 @@
<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"/>
Expand Down
364 changes: 253 additions & 111 deletions security-admin/src/main/java/org/apache/ranger/biz/AssetMgr.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ public VXCredentialStore getXCredentialStore(Long id) {

public VXCredentialStore createXCredentialStore(VXCredentialStore vXCredentialStore) {
vXCredentialStore = xCredentialStoreService.createResource(vXCredentialStore);

return vXCredentialStore;
}

public VXCredentialStore updateXCredentialStore(VXCredentialStore vXCredentialStore) {
vXCredentialStore = xCredentialStoreService.updateResource(vXCredentialStore);

return vXCredentialStore;
}

Expand All @@ -81,11 +83,13 @@ public VXPolicyExportAudit getXPolicyExportAudit(Long id) {

public VXPolicyExportAudit createXPolicyExportAudit(VXPolicyExportAudit vXPolicyExportAudit) {
vXPolicyExportAudit = xPolicyExportAuditService.createResource(vXPolicyExportAudit);

return vXPolicyExportAudit;
}

public VXPolicyExportAudit updateXPolicyExportAudit(VXPolicyExportAudit vXPolicyExportAudit) {
vXPolicyExportAudit = xPolicyExportAuditService.updateResource(vXPolicyExportAudit);

return vXPolicyExportAudit;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
* under the License.
*/

/**
*
*/
package org.apache.ranger.biz;

import org.apache.ranger.common.MessageEnums;
Expand Down Expand Up @@ -46,12 +49,14 @@ public RangerDaoManager getDaoManager() {

public void deleteEntity(BaseDao<? extends XXDBBase> baseDao, Long id, String entityName) {
XXDBBase entity = baseDao.getById(id);

if (entity != null) {
try {
baseDao.remove(id);
} catch (Exception e) {
logger.error("Error deleting {}. Id = {}", entityName, id, e);
throw restErrorUtil.createRESTException("This " + entityName + " can't be deleted", MessageEnums.OPER_NOT_ALLOWED_FOR_STATE, id, null, "" + id + ", error=" + e.getMessage());
logger.error("Error deleting {}. Id={}", entityName, id, e);

throw restErrorUtil.createRESTException("This " + entityName + " can't be deleted", MessageEnums.OPER_NOT_ALLOWED_FOR_STATE, id, null, id + ", error=" + e.getMessage());
}
} else {
// Return without error
Expand Down
72 changes: 44 additions & 28 deletions security-admin/src/main/java/org/apache/ranger/biz/GdsDBStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpStatus;
import org.apache.ranger.biz.ServiceDBStore.RemoveRefType;
import org.apache.ranger.biz.ServiceDBStore.REMOVE_REF_TYPE;
import org.apache.ranger.common.GUIDUtil;
import org.apache.ranger.common.MessageEnums;
import org.apache.ranger.common.RESTErrorUtil;
Expand Down Expand Up @@ -110,15 +110,17 @@

@Component
public class GdsDBStore extends AbstractGdsStore {
public static final String RESOURCE_NAME_DATASET_ID = "dataset-id";
public static final String RESOURCE_NAME_PROJECT_ID = "project-id";
public static final String NOT_AUTHORIZED_FOR_DATASET_POLICIES = "User is not authorized to manage policies for this dataset";
public static final String NOT_AUTHORIZED_TO_VIEW_DATASET_POLICIES = "User is not authorized to view policies for this dataset";
public static final String NOT_AUTHORIZED_FOR_PROJECT_POLICIES = "User is not authorized to manage policies for this dataset";
public static final String NOT_AUTHORIZED_TO_VIEW_PROJECT_POLICIES = "User is not authorized to view policies for this dataset";
public static final String GDS_POLICY_NAME_TIMESTAMP_SEP = "@";
private static final Logger LOG = LoggerFactory.getLogger(GdsDBStore.class);
private static final Set<Integer> SHARE_STATUS_AGR = new HashSet<>(Arrays.asList(GdsShareStatus.ACTIVE.ordinal(), GdsShareStatus.GRANTED.ordinal(), GdsShareStatus.REQUESTED.ordinal()));

public static final String RESOURCE_NAME_DATASET_ID = "dataset-id";
public static final String RESOURCE_NAME_PROJECT_ID = "project-id";
public static final String NOT_AUTHORIZED_FOR_DATASET_POLICIES = "User is not authorized to manage policies for this dataset";
public static final String NOT_AUTHORIZED_TO_VIEW_DATASET_POLICIES = "User is not authorized to view policies for this dataset";
public static final String NOT_AUTHORIZED_FOR_PROJECT_POLICIES = "User is not authorized to manage policies for this dataset";
public static final String NOT_AUTHORIZED_TO_VIEW_PROJECT_POLICIES = "User is not authorized to view policies for this dataset";
public static final String GDS_POLICY_NAME_TIMESTAMP_SEP = "@";

private static final Set<Integer> SHARE_STATUS_AGR = new HashSet<>(Arrays.asList(GdsShareStatus.ACTIVE.ordinal(), GdsShareStatus.GRANTED.ordinal(), GdsShareStatus.REQUESTED.ordinal()));

@Autowired
RangerGdsValidator validator;
Expand Down Expand Up @@ -171,6 +173,7 @@ public class GdsDBStore extends AbstractGdsStore {
@PostConstruct
public void initStore() {
LOG.debug("==> GdsInMemoryStore.initStore()");

LOG.debug("<== GdsInMemoryStore.initStore()");
}

Expand Down Expand Up @@ -773,10 +776,13 @@ public PList<RangerSharedResource> searchSharedResources(SearchFilter filter) {
final Collection<RangerPolicyResource> resources = sharedResource.getResource().values();

if (CollectionUtils.isNotEmpty(resources)) {
includeResource = resources.stream().filter(Objects::nonNull).map(RangerPolicyResource::getValues).filter(Objects::nonNull).anyMatch(res -> hasResource(res, resourceContains));
includeResource = resources.stream().filter(Objects::nonNull)
.map(RangerPolicyResource::getValues).filter(Objects::nonNull)
.anyMatch(res -> hasResource(res, resourceContains));

if (!includeResource && sharedResource.getSubResource() != null && CollectionUtils.isNotEmpty(sharedResource.getSubResource().getValues())) {
includeResource = sharedResource.getSubResource().getValues().stream().filter(Objects::nonNull).anyMatch(value -> value.contains(resourceContains));
includeResource = sharedResource.getSubResource().getValues().stream().filter(Objects::nonNull)
.anyMatch(value -> value.contains(resourceContains));
}
}
}
Expand Down Expand Up @@ -1098,7 +1104,7 @@ public RangerPolicy getDatasetPolicy(Long datasetId, Long policyId) throws Excep
}

@Override
public List<RangerPolicy> getDatasetPolicies(Long datasetId) throws Exception {
public List<RangerPolicy> getDatasetPolicies(Long datasetId) {
LOG.debug("==> getDatasetPolicies({})", datasetId);

RangerDataset dataset = datasetService.read(datasetId);
Expand Down Expand Up @@ -1227,7 +1233,7 @@ public RangerPolicy getProjectPolicy(Long projectId, Long policyId) throws Excep
}

@Override
public List<RangerPolicy> getProjectPolicies(Long projectId) throws Exception {
public List<RangerPolicy> getProjectPolicies(Long projectId) {
LOG.debug("==> getProjectPolicies({})", projectId);

RangerProject project = projectService.read(projectId);
Expand Down Expand Up @@ -1351,7 +1357,7 @@ public List<RangerDataShareInDataset> addDataSharesInDataset(List<RangerDataShar
return ret;
}

public ServiceGdsInfo getGdsInfoIfUpdated(String serviceName, Long lastKnownVersion) throws Exception {
public ServiceGdsInfo getGdsInfoIfUpdated(String serviceName, Long lastKnownVersion) {
LOG.debug("==> GdsDBStore.getGdsInfoIfUpdated({}, {})", serviceName, lastKnownVersion);

ServiceGdsInfo latest = serviceGdsInfoCache.get(serviceName);
Expand All @@ -1363,7 +1369,7 @@ public ServiceGdsInfo getGdsInfoIfUpdated(String serviceName, Long lastKnownVers
return ret;
}

public PList<DatasetSummary> getDatasetSummary(SearchFilter filter) throws Exception {
public PList<DatasetSummary> getDatasetSummary(SearchFilter filter) {
LOG.debug("==> getDatasetSummary({})", filter);

PList<RangerDataset> datasets = getUnscrubbedDatasets(filter);
Expand Down Expand Up @@ -1505,7 +1511,7 @@ private void setUserId(SearchFilter filter, String filterParam) {
filter.setParam(filterParam, Long.toString(userId));
}

private List<DatasetSummary> toDatasetSummary(List<RangerDataset> datasets, GdsPermission gdsPermission) throws Exception {
private List<DatasetSummary> toDatasetSummary(List<RangerDataset> datasets, GdsPermission gdsPermission) {
List<DatasetSummary> ret = new ArrayList<>();
String currentUser = bizUtil.getCurrentUserLoginId();

Expand Down Expand Up @@ -1544,7 +1550,10 @@ private List<DatasetSummary> toDatasetSummary(List<RangerDataset> datasets, GdsP
List<DataShareInDatasetSummary> dataSharesSummary = getDataSharesSummary(dataShares, filter);

datasetSummary.setDataShares(dataSharesSummary);
datasetSummary.setTotalResourceCount(dataSharesSummary.stream().map(DataShareInDatasetSummary::getResourceCount).mapToLong(Long::longValue).sum());
datasetSummary.setTotalResourceCount(dataSharesSummary.stream()
.map(DataShareInDatasetSummary::getResourceCount)
.mapToLong(Long::longValue)
.sum());
}

return ret;
Expand Down Expand Up @@ -1602,7 +1611,7 @@ private Long getDIPCountForDataset(Long datasetId) {
return datasetInProjectService.getDatasetsInProjectCount(datasetId);
}

private Map<PrincipalType, Integer> getPrincipalCountForDataset(RangerDataset dataset) throws Exception {
private Map<PrincipalType, Integer> getPrincipalCountForDataset(RangerDataset dataset) {
Map<PrincipalType, Integer> ret = new HashMap<>();
Set<String> users = Collections.emptySet();
Set<String> groups = Collections.emptySet();
Expand Down Expand Up @@ -1935,7 +1944,9 @@ private void removeDIPForDataset(Long datasetId) {
boolean dipDeleted = dipDao.remove(dip.getId());

if (!dipDeleted) {
throw restErrorUtil.createRESTException("DatasetInProject could not be deleted", MessageEnums.ERROR_DELETE_OBJECT, dip.getId(), "DatasetInProjectId", null, HttpStatus.SC_INTERNAL_SERVER_ERROR);
throw restErrorUtil.createRESTException("DatasetInProject could not be deleted",
MessageEnums.ERROR_DELETE_OBJECT, dip.getId(), "DatasetInProjectId", null,
HttpStatus.SC_INTERNAL_SERVER_ERROR);
}
}
}
Expand All @@ -1948,7 +1959,9 @@ private void removeDSHIDForDataset(Long datasetId) {
boolean dshidDeleted = dshidDao.remove(dshid.getId());

if (!dshidDeleted) {
throw restErrorUtil.createRESTException("DataShareInDataset could not be deleted", MessageEnums.ERROR_DELETE_OBJECT, dshid.getId(), "DataShareInDataset", null, HttpStatus.SC_INTERNAL_SERVER_ERROR);
throw restErrorUtil.createRESTException("DataShareInDataset could not be deleted",
MessageEnums.ERROR_DELETE_OBJECT, dshid.getId(), "DataShareInDataset", null,
HttpStatus.SC_INTERNAL_SERVER_ERROR);
}
}
}
Expand All @@ -1961,7 +1974,9 @@ private void removeDIPForProject(Long projectId) {
boolean dipDeleted = dipDao.remove(dip.getId());

if (!dipDeleted) {
throw restErrorUtil.createRESTException("DatasetInProject could not be deleted", MessageEnums.ERROR_DELETE_OBJECT, dip.getId(), "DatasetInProjectId", null, HttpStatus.SC_INTERNAL_SERVER_ERROR);
throw restErrorUtil.createRESTException("DatasetInProject could not be deleted",
MessageEnums.ERROR_DELETE_OBJECT, dip.getId(), "DatasetInProjectId", null,
HttpStatus.SC_INTERNAL_SERVER_ERROR);
}
}
}
Expand Down Expand Up @@ -2070,7 +2085,8 @@ private DataShareInDatasetSummary toDshInDsSummary(RangerDataset dataset, List<R
return summary;
}

private DataShareInDatasetSummary toDshInDsSummary(RangerDataset dataset, RangerDataShare dataShare, RangerDataShareInDataset dshInDs) {
private DataShareInDatasetSummary toDshInDsSummary(RangerDataset dataset, RangerDataShare dataShare,
RangerDataShareInDataset dshInDs) {
Map<String, Long> zoneIds = new HashMap<>();
DataShareInDatasetSummary summary = new DataShareInDatasetSummary();

Expand Down Expand Up @@ -2210,7 +2226,7 @@ private List<RangerPolicy> getPolicies(List<Long> policyIds) {
private void updateGdsVersionForService(Long serviceId) {
updateGdsVersion();

Runnable serviceVersionUpdater = new ServiceDBStore.ServiceVersionUpdater(daoMgr, serviceId, ServiceDBStore.VersionType.GDS_VERSION, RangerPolicyDelta.CHANGE_TYPE_GDS_UPDATE);
Runnable serviceVersionUpdater = new ServiceDBStore.ServiceVersionUpdater(daoMgr, serviceId, ServiceDBStore.VERSION_TYPE.GDS_VERSION, RangerPolicyDelta.CHANGE_TYPE_GDS_UPDATE);

daoMgr.getRangerTransactionSynchronizationAdapter().executeOnTransactionCommit(serviceVersionUpdater);
}
Expand All @@ -2229,7 +2245,7 @@ private void updateGdsVersionForProject(Long projectId) {
List<Long> serviceIds = daoMgr.getXXGdsProject().findServiceIdsForProject(projectId);

for (Long serviceId : serviceIds) {
Runnable serviceVersionUpdater = new ServiceDBStore.ServiceVersionUpdater(daoMgr, serviceId, ServiceDBStore.VersionType.GDS_VERSION, RangerPolicyDelta.CHANGE_TYPE_GDS_UPDATE);
Runnable serviceVersionUpdater = new ServiceDBStore.ServiceVersionUpdater(daoMgr, serviceId, ServiceDBStore.VERSION_TYPE.GDS_VERSION, RangerPolicyDelta.CHANGE_TYPE_GDS_UPDATE);

daoMgr.getRangerTransactionSynchronizationAdapter().executeOnTransactionCommit(serviceVersionUpdater);
}
Expand All @@ -2241,7 +2257,7 @@ private void updateGdsVersionForDataset(Long datasetId) {
List<Long> serviceIds = daoMgr.getXXGdsDataset().findServiceIdsForDataset(datasetId);

for (Long serviceId : serviceIds) {
Runnable serviceVersionUpdater = new ServiceDBStore.ServiceVersionUpdater(daoMgr, serviceId, ServiceDBStore.VersionType.GDS_VERSION, RangerPolicyDelta.CHANGE_TYPE_GDS_UPDATE);
Runnable serviceVersionUpdater = new ServiceDBStore.ServiceVersionUpdater(daoMgr, serviceId, ServiceDBStore.VERSION_TYPE.GDS_VERSION, RangerPolicyDelta.CHANGE_TYPE_GDS_UPDATE);

daoMgr.getRangerTransactionSynchronizationAdapter().executeOnTransactionCommit(serviceVersionUpdater);
}
Expand All @@ -2258,11 +2274,11 @@ private void updateGdsVersionForDataShare(Long dataShareId) {
private GdsPermission deletePrincipalFromAcl(RangerGdsObjectACL acl, String principalName, String principalType) {
final Map<String, GdsPermission> principalAcls;

if (principalType.equalsIgnoreCase(RemoveRefType.USER.toString())) {
if (principalType.equalsIgnoreCase(REMOVE_REF_TYPE.USER.toString())) {
principalAcls = acl.getUsers();
} else if (principalType.equalsIgnoreCase(RemoveRefType.GROUP.toString())) {
} else if (principalType.equalsIgnoreCase(REMOVE_REF_TYPE.GROUP.toString())) {
principalAcls = acl.getGroups();
} else if (principalType.equalsIgnoreCase(RemoveRefType.ROLE.toString())) {
} else if (principalType.equalsIgnoreCase(REMOVE_REF_TYPE.ROLE.toString())) {
principalAcls = acl.getRoles();
} else {
principalAcls = null;
Expand Down
Loading

0 comments on commit 62697ee

Please sign in to comment.