Skip to content

Conversation

Sanket-Shelar
Copy link
Contributor

… and revokeAccess()

What changes were proposed in this pull request?

Added parameter in ensureAdminAccess() method to pass grantor in case userName is null.

How was this patch tested?

Build passed and checked if grant and revoke are working.

boolean isAdmin = bizUtil.isAdmin();
boolean isKeyAdmin = bizUtil.isKeyAdmin();
String userName = bizUtil.getCurrentUserLoginId();
String userName = bizUtil.getCurrentUserLoginId() != null ? bizUtil.getCurrentUserLoginId() : grantor;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When grantor is provided, that value should be used as userName, instead of bizUtil.getCurrentUserLoginId(). Also, shouldn't isAdmin and isKeyAdmin also be derived from grantor?

final String  userName;
final boolean isAdmin;
final boolean isKeyAdmin;

if (StringUtils.isEmpty(grantor)) { // use currently logged-in user
  userName   = bizUtil.getCurrentUserLoginId();
  isAdmin    = bizUtil.isAdmin();
  isKeyAdmin = bizUtil.isKeyAdmin();
} else {
  // find role of the given grantor; logic from SessionMgr.setUserRoles(userSession)
  Collection<String> userRoles = userMgr.getRolesByLoginId(grantor); // add @Autowired UserMgr userMgr;

  userName   = grantor;
  isAdmin    = userRoles.contains(RangerConstants.ROLE_SYS_ADMIN);
  isKeyAdmin = userRoles.contains(RangerConstants.ROLE_KEY_ADMIN);
}

validator.validate(policy, Action.UPDATE, bizUtil.isAdmin() || isServiceAdmin(policy.getService()) || isZoneAdmin(policy.getZoneName()));

ensureAdminAccess(policy);
ensureAdminAccess(policy, null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid updates to existing use of ensureAdminAccess(policy), I suggest adding following method:

void ensureAdminAccess(RangerPolicy policy) {
  ensureAdminAccess(policy, null);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants