@Transactional
  protected void setViewInstanceRoleAccess(ViewInstanceEntity viewInstanceEntity, Collection<String> roles) {
    if ((roles != null) && !roles.isEmpty()) {
      PermissionEntity permissionViewUser = permissionDAO.findViewUsePermission();

      ResourceEntity resourceEntity = viewInstanceEntity.getResource();
      if (null == resourceEntity) {
        resourceEntity = instanceDAO.findResourceForViewInstance(viewInstanceEntity.getViewName(),
            viewInstanceEntity.getInstanceName());
      }

      if (permissionViewUser == null) {
        LOG.error("Missing the {} role.  Access to view cannot be set.",
            PermissionEntity.VIEW_USER_PERMISSION_NAME, viewInstanceEntity.getName());
      } else {
        for (String role : roles) {
          PermissionEntity permissionRole = permissionDAO.findByName(role);

          if (permissionRole == null) {
            LOG.warn("Invalid role {} encountered while setting access to view {}, Ignoring.",
                role, viewInstanceEntity.getName());
          } else {
            PrincipalEntity principalRole = permissionRole.getPrincipal();

            if (principalRole == null) {
              LOG.warn("Missing principal ID for role {} encountered while setting access to view {}. Ignoring.",
                  role, viewInstanceEntity.getName());
            } else if (!privilegeDAO.exists(principalRole, resourceEntity, permissionViewUser)) {
              PrivilegeEntity privilegeEntity = new PrivilegeEntity();
              privilegeEntity.setPermission(permissionViewUser);
              privilegeEntity.setPrincipal(principalRole);
              privilegeEntity.setResource(resourceEntity);
              privilegeDAO.create(privilegeEntity);
            }
          }
        }
      }
    }
  }
Set access to the a particular view instance based on a set of roles.
<p>
View access to the specified view instances will be granted to anyone directly or indirectly
assigned to one of the roles in the suppled set of role names.

@param viewInstanceEntity a view instance entity
@param roles              the set of roles to use to for granting access
ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java