@Override
  public void hasPermission(String userName, String permissionName) throws org.apache.ambari.view.SecurityException {

    if (userName == null || userName.length() == 0) {
      throw new SecurityException("No user name specified.");
    }

    if (permissionName == null || permissionName.length() == 0) {
      throw new SecurityException("No permission name specified.");
    }

    if (viewInstanceEntity == null) {
      throw new SecurityException("There is no instance associated with the view context");
    }

    PermissionEntity permissionEntity = viewEntity.getPermission(permissionName);

    if (permissionEntity == null) {
      throw new SecurityException("The permission " + permissionName + " is not defined for " + viewEntity.getName());
    }

    if (!viewRegistry.hasPermission(permissionEntity, viewInstanceEntity.getResource(), userName)) {
      throw new SecurityException("The user " + userName + " has not been granted permission " + permissionName);
    }
  }
Construct a view context from the given view entity.

@param viewEntity    the view entity
@param viewRegistry  the view registry
ambari-server/src/main/java/org/apache/ambari/server/view/ViewContextImpl.java