/**
   * Determine whether or not access to the given cluster resource should be allowed based
   * on the privileges of the current user.
   *
   * @param cluster   the cluster
   * @param readOnly  indicate whether or not this check is for a read only operation
   *
   * @return true if the access to this cluster is allowed
   */
private boolean checkPermission(Cluster cluster, boolean readOnly) {
    for (GrantedAuthority grantedAuthority : securityHelper.getCurrentAuthorities()) {
      if (grantedAuthority instanceof AmbariGrantedAuthority) {
        AmbariGrantedAuthority authority       = (AmbariGrantedAuthority) grantedAuthority;
        PrivilegeEntity        privilegeEntity = authority.getPrivilegeEntity();
        Integer                permissionId    = privilegeEntity.getPermission().getId();
        // admin has full access
        if (permissionId.equals(PermissionEntity.AMBARI_ADMINISTRATOR_PERMISSION)) {
          return true;
        }
        if (cluster != null) {
          if (cluster.checkPermission(privilegeEntity, readOnly)) {
            return true;
          }
        }
      }
    }
    // TODO : should we log this?
    return false;
  }
private boolean checkPermission(Cluster cluster, boolean readOnly) {
for (GrantedAuthority grantedAuthority : securityHelper.getCurrentAuthorities()) {
if (grantedAuthority instanceof AmbariGrantedAuthority) {
AmbariGrantedAuthority authority = (AmbariGrantedAuthority) grantedAuthority;
PrivilegeEntity privilegeEntity = authority.getPrivilegeEntity();
Integer permissionId = privilegeEntity.getPermission().getId();
// admin has full access
if (permissionId.equals(PermissionEntity.AMBARI_ADMINISTRATOR_PERMISSION)) {
return true;
}
if (cluster != null) {
if (cluster.checkPermission(privilegeEntity, readOnly)) {
return true;
}
}
}
}
// TODO : should we log this?
return false;
}
private boolean checkPermission(Cluster cluster, boolean readOnly) {
for (GrantedAuthority grantedAuthority : securityHelper.getCurrentAuthorities()) {
if (grantedAuthority instanceof AmbariGrantedAuthority) {
AmbariGrantedAuthority authority = (AmbariGrantedAuthority) grantedAuthority;
PrivilegeEntity privilegeEntity = authority.getPrivilegeEntity();
Integer permissionId = privilegeEntity.getPermission().getId();
// admin has full access
if (permissionId.equals(PermissionEntity.AMBARI_ADMINISTRATOR_PERMISSION)) {
return true;
}
if (cluster != null) {
if (cluster.checkPermission(privilegeEntity, readOnly)) {
return true;
}
}
}
}
// TODO : should we log this?
return false;
}
private boolean checkPermission(Cluster cluster, boolean readOnly) {
for (GrantedAuthority grantedAuthority : securityHelper.getCurrentAuthorities()) {
if (grantedAuthority instanceof AmbariGrantedAuthority) {
AmbariGrantedAuthority authority = (AmbariGrantedAuthority) grantedAuthority;
PrivilegeEntity privilegeEntity = authority.getPrivilegeEntity();
Integer permissionId = privilegeEntity.getPermission().getId();
// admin has full access
if (permissionId.equals(PermissionEntity.AMBARI_ADMINISTRATOR_PERMISSION)) {
return true;
}
if (cluster != null) {
if (cluster.checkPermission(privilegeEntity, readOnly)) {
return true;
}
}
}
}
// TODO : should we log this?
return false;
}