@Transactional
  public void copyPrivileges(ViewInstanceEntity sourceInstanceEntity,
                             ViewInstanceEntity targetInstanceEntity) {
    LOG.debug("Copy all privileges from {} to {}", sourceInstanceEntity.getName(), targetInstanceEntity.getName());
    List<PrivilegeEntity> targetInstancePrivileges = privilegeDAO.findByResourceId(targetInstanceEntity.getResource().getId());
    if (targetInstancePrivileges.size() > 0) {
      LOG.warn("Target instance {} already has privileges assigned, these will not be deleted. Manual clean up may be needed", targetInstanceEntity.getName());
    }

    List<PrivilegeEntity> sourceInstancePrivileges = privilegeDAO.findByResourceId(sourceInstanceEntity.getResource().getId());
    for (PrivilegeEntity sourcePrivilege : sourceInstancePrivileges) {
      PrivilegeEntity targetPrivilege = new PrivilegeEntity();
      targetPrivilege.setPrincipal(sourcePrivilege.getPrincipal());
      targetPrivilege.setResource(targetInstanceEntity.getResource());
      targetPrivilege.setPermission(sourcePrivilege.getPermission());
      try {
        privilegeDAO.create(targetPrivilege);
        targetPrivilege.getPrincipal().getPrivileges().add(sourcePrivilege);
      } catch (Exception e) {
        LOG.warn("Could not migrate privilege {} ", targetPrivilege);
        LOG.error("Caught exception", e);
      }

    }
  }
Copy all privileges from one view instance to another

@param sourceInstanceEntity the source instance entity
@param targetInstanceEntity the target instance entity
ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java