Skip to content

RANGER-5178: Update callers of executeOnTransactionCommit to check for existence of objects #554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -516,42 +516,50 @@ private Long createPrincipal(String user) {
return ret;
}

private boolean doesPolicyExist(XXPolicy xPolicy) {
return daoMgr.getXXPolicy().getById(xPolicy.getId()) != null;
}

private void createPolicyAssociation(Long id, String name) {
LOG.debug("===> PolicyPrincipalAssociator.createPolicyAssociation(policyId={}, type={}, name={}, id={})", xPolicy.getId(), type.name(), name, id);

switch (type) {
case USER: {
XXPolicyRefUser xPolUser = rangerAuditFields.populateAuditFields(new XXPolicyRefUser(), xPolicy);
if (doesPolicyExist(xPolicy)) {
switch (type) {
case USER: {
XXPolicyRefUser xPolUser = rangerAuditFields.populateAuditFields(new XXPolicyRefUser(), xPolicy);

xPolUser.setPolicyId(xPolicy.getId());
xPolUser.setUserId(id);
xPolUser.setUserName(name);
xPolUser.setPolicyId(xPolicy.getId());
xPolUser.setUserId(id);
xPolUser.setUserName(name);

daoMgr.getXXPolicyRefUser().create(xPolUser);
}
break;
case GROUP: {
XXPolicyRefGroup xPolGroup = rangerAuditFields.populateAuditFields(new XXPolicyRefGroup(), xPolicy);
daoMgr.getXXPolicyRefUser().create(xPolUser);
}
break;
case GROUP: {
XXPolicyRefGroup xPolGroup = rangerAuditFields.populateAuditFields(new XXPolicyRefGroup(), xPolicy);

xPolGroup.setPolicyId(xPolicy.getId());
xPolGroup.setGroupId(id);
xPolGroup.setGroupName(name);
xPolGroup.setPolicyId(xPolicy.getId());
xPolGroup.setGroupId(id);
xPolGroup.setGroupName(name);

daoMgr.getXXPolicyRefGroup().create(xPolGroup);
}
break;
case ROLE: {
XXPolicyRefRole xPolRole = rangerAuditFields.populateAuditFields(new XXPolicyRefRole(), xPolicy);
daoMgr.getXXPolicyRefGroup().create(xPolGroup);
}
break;
case ROLE: {
XXPolicyRefRole xPolRole = rangerAuditFields.populateAuditFields(new XXPolicyRefRole(), xPolicy);

xPolRole.setPolicyId(xPolicy.getId());
xPolRole.setRoleId(id);
xPolRole.setRoleName(name);
xPolRole.setPolicyId(xPolicy.getId());
xPolRole.setRoleId(id);
xPolRole.setRoleName(name);

daoMgr.getXXPolicyRefRole().create(xPolRole);
}
break;
default:
daoMgr.getXXPolicyRefRole().create(xPolRole);
}
break;
default:
break;
}
} else {
LOG.info("Policy with id = {} does not exist, skipping policy association!", xPolicy.getId());
}

LOG.debug("<=== PolicyPrincipalAssociator.createPolicyAssociation(policyId={}, type={}, name={}, id={})", xPolicy.getId(), type.name(), name, id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,45 +345,53 @@ private Long createPrincipal(String user) {
return ret;
}

private boolean doesRoleExist() {
return roleId != null && daoMgr.getXXRole().findByRoleId(roleId) != null;
}

private void createRoleAssociation(Long id, String name) {
LOG.debug("===> RolePrincipalAssociator.createRoleAssociation(roleId={}, type={}, name={}, id={})", roleId, type.name(), name, id);

switch (type) {
case USER: {
XXRoleRefUser xRoleRefUser = rangerAuditFields.populateAuditFieldsForCreate(new XXRoleRefUser());
if (doesRoleExist()) {
switch (type) {
case USER: {
XXRoleRefUser xRoleRefUser = rangerAuditFields.populateAuditFieldsForCreate(new XXRoleRefUser());

xRoleRefUser.setRoleId(roleId);
xRoleRefUser.setUserId(id);
xRoleRefUser.setUserName(name);
xRoleRefUser.setUserType(0);
xRoleRefUser.setRoleId(roleId);
xRoleRefUser.setUserId(id);
xRoleRefUser.setUserName(name);
xRoleRefUser.setUserType(0);

daoMgr.getXXRoleRefUser().create(xRoleRefUser);
}
break;
case GROUP: {
XXRoleRefGroup xRoleRefGroup = rangerAuditFields.populateAuditFieldsForCreate(new XXRoleRefGroup());
daoMgr.getXXRoleRefUser().create(xRoleRefUser);
}
break;
case GROUP: {
XXRoleRefGroup xRoleRefGroup = rangerAuditFields.populateAuditFieldsForCreate(new XXRoleRefGroup());

xRoleRefGroup.setRoleId(roleId);
xRoleRefGroup.setGroupId(id);
xRoleRefGroup.setGroupName(name);
xRoleRefGroup.setGroupType(0);
xRoleRefGroup.setRoleId(roleId);
xRoleRefGroup.setGroupId(id);
xRoleRefGroup.setGroupName(name);
xRoleRefGroup.setGroupType(0);

daoMgr.getXXRoleRefGroup().create(xRoleRefGroup);
}
break;
case ROLE: {
XXRoleRefRole xRoleRefRole = rangerAuditFields.populateAuditFieldsForCreate(new XXRoleRefRole());
daoMgr.getXXRoleRefGroup().create(xRoleRefGroup);
}
break;
case ROLE: {
XXRoleRefRole xRoleRefRole = rangerAuditFields.populateAuditFieldsForCreate(new XXRoleRefRole());

xRoleRefRole.setRoleId(roleId);
xRoleRefRole.setSubRoleId(id);
xRoleRefRole.setSubRoleName(name);
xRoleRefRole.setSubRoleType(0);
xRoleRefRole.setRoleId(roleId);
xRoleRefRole.setSubRoleId(id);
xRoleRefRole.setSubRoleName(name);
xRoleRefRole.setSubRoleType(0);

daoMgr.getXXRoleRefRole().create(xRoleRefRole);
}
break;
default:
daoMgr.getXXRoleRefRole().create(xRoleRefRole);
}
break;
default:
break;
}
} else {
LOG.info("Role with id = {} does not exist, skipping role association!", roleId);
}

LOG.debug("<=== RolePrincipalAssociator.createRoleAssociation(roleId={}, type={}, name={}, id={})", roleId, type.name(), name, id);
Expand Down
Loading